mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
Feature #817: Add support for --force option in onevdc command
This commit is contained in:
parent
8729149cdc
commit
1943ce6206
@ -26,7 +26,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS
|
||||
|
||||
|
||||
FORCE={
|
||||
:name => "force",
|
||||
:short => "-f",
|
||||
:large => "--force",
|
||||
:description => "Force the usage of Hosts in more than one VDC"
|
||||
}
|
||||
|
||||
begin
|
||||
helper = VDCHelper.new "vdc"
|
||||
rescue Exception => e
|
||||
@ -34,8 +41,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
exit -1
|
||||
end
|
||||
|
||||
command :create, 'Create a new VDC', :file do
|
||||
helper.create_resource(args[0])
|
||||
command :create, 'Create a new VDC', :file, :options=>[FORCE] do
|
||||
helper.create_resource(args[0], options)
|
||||
end
|
||||
|
||||
command :show, 'Show information of a particular VDC', :vdcid do
|
||||
@ -52,12 +59,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
|
||||
command :addhost, 'Adds the set of hosts to the VDC',
|
||||
:vdcid, :range do
|
||||
:vdcid, :range, :options=>[FORCE] do
|
||||
helper.addhost(args[0], args[1], options)
|
||||
end
|
||||
|
||||
command :delhost, 'Deletes the set of hosts from the VDC',
|
||||
:vdcid, :range do
|
||||
:vdcid, :range, :options=>[FORCE] do
|
||||
helper.delhost(args[0], args[1], options)
|
||||
end
|
||||
end
|
||||
|
@ -91,6 +91,10 @@ EOT
|
||||
######################################################################
|
||||
def post_resource(kind, template)
|
||||
tmpl_str = File.read(template)
|
||||
post_resource_str(kind, tmpl_str)
|
||||
end
|
||||
|
||||
def post_resource_str(kind, tmpl_str)
|
||||
body_str = OZonesClient::to_body(tmpl_str)
|
||||
|
||||
url = URI.parse("#{@endpoint}/#{kind}")
|
||||
|
@ -34,11 +34,8 @@ module OZonesHelper
|
||||
if OZonesClient::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
else
|
||||
id=rc.body.match('\"id\":(.*)$')[1].strip
|
||||
if id[-1..-1] == ","
|
||||
id = id[0..id.size-2]
|
||||
end
|
||||
[0, "ID: #{id}"]
|
||||
id = get_id(rc)
|
||||
[0, "ID: #{id}"]
|
||||
end
|
||||
end
|
||||
|
||||
@ -74,6 +71,19 @@ module OZonesHelper
|
||||
[0, "#{message}"]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
########################################################################
|
||||
# Helpers
|
||||
########################################################################
|
||||
|
||||
|
||||
def get_id(rc)
|
||||
id = rc.body.match('\"id\":(.*)$')[1].strip
|
||||
if id[-1..-1] == ","
|
||||
id = id[0..id.size-2]
|
||||
end
|
||||
|
||||
return id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -24,8 +24,21 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
super(user, pass, endpoint_str, timeout, debug_flag)
|
||||
end
|
||||
|
||||
def create_resource(template)
|
||||
super(@vdc_str,template)
|
||||
def create_resource(template, options)
|
||||
tmpl_str = File.read(template)
|
||||
|
||||
if options[:force]
|
||||
tmpl_str << "FORCE=YES\n"
|
||||
end
|
||||
|
||||
rc = @client.post_resource_str(@vdc_str, tmpl_str)
|
||||
|
||||
if OZonesClient::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
else
|
||||
id = get_id(rc)
|
||||
[0, "ID: #{id}"]
|
||||
end
|
||||
end
|
||||
|
||||
def list_pool(options)
|
||||
@ -42,7 +55,7 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
|
||||
def addhost(id, host_array, options)
|
||||
rc = @client.get_resource(@vdc_str, id)
|
||||
|
||||
|
||||
if OZonesClient::is_error?(rc)
|
||||
return [-1, rc.message]
|
||||
else
|
||||
@ -54,7 +67,11 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
|
||||
new_host = host_array.join(',')
|
||||
template = "ID=#{id}\nHOSTS=#{new_host}\n"
|
||||
|
||||
|
||||
if options[:force]
|
||||
template << "FORCE=YES\n"
|
||||
end
|
||||
|
||||
rc = @client.put_resource(@vdc_str, id, template)
|
||||
|
||||
if OZonesClient::is_error?(rc)
|
||||
@ -77,7 +94,11 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
|
||||
new_host = (hosts - host_array).join(',')
|
||||
template = "ID=#{id}\nHOSTS=#{new_host}\n"
|
||||
|
||||
|
||||
if options[:force]
|
||||
template << "FORCE=YES\n"
|
||||
end
|
||||
|
||||
rc = @client.put_resource(@vdc_str, id, template)
|
||||
|
||||
if OZonesClient::is_error?(rc)
|
||||
|
Loading…
x
Reference in New Issue
Block a user