diff --git a/src/ozones/Client/bin/onevdc b/src/ozones/Client/bin/onevdc index fcfc31a725..0ad2e6c85b 100755 --- a/src/ozones/Client/bin/onevdc +++ b/src/ozones/Client/bin/onevdc @@ -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 diff --git a/src/ozones/Client/lib/OZonesClient.rb b/src/ozones/Client/lib/OZonesClient.rb index 511479ecd9..9587ea5b1f 100644 --- a/src/ozones/Client/lib/OZonesClient.rb +++ b/src/ozones/Client/lib/OZonesClient.rb @@ -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}") diff --git a/src/ozones/Client/lib/cli/ozones_helper.rb b/src/ozones/Client/lib/cli/ozones_helper.rb index 44d212c68c..6363e1f7fb 100644 --- a/src/ozones/Client/lib/cli/ozones_helper.rb +++ b/src/ozones/Client/lib/cli/ozones_helper.rb @@ -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 diff --git a/src/ozones/Client/lib/cli/ozones_helper/vdc_helper.rb b/src/ozones/Client/lib/cli/ozones_helper/vdc_helper.rb index 9f82bd6d83..b3d56bdd2c 100644 --- a/src/ozones/Client/lib/cli/ozones_helper/vdc_helper.rb +++ b/src/ozones/Client/lib/cli/ozones_helper/vdc_helper.rb @@ -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)