diff --git a/src/ozones/Client/bin/onevdc b/src/ozones/Client/bin/onevdc index f6ff4ced27..c3657390e9 100755 --- a/src/ozones/Client/bin/onevdc +++ b/src/ozones/Client/bin/onevdc @@ -74,12 +74,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper.delete_resource(args[0],options) end - command :addhost, 'Adds the set of hosts to the VDC', :vdcid, :range do + command :addhost, 'Adds the set of hosts to the VDC', :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 - helper.delhost(args[0], args[1], options) + command :delhost, 'Deletes the set of hosts from the VDC', :vdcid, :range do + helper.delhost(args[0], args[1]) 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 8831ac7def..0cac03e533 100644 --- a/src/ozones/Client/lib/cli/ozones_helper/vdc_helper.rb +++ b/src/ozones/Client/lib/cli/ozones_helper/vdc_helper.rb @@ -78,25 +78,12 @@ class VDCHelper < OZonesHelper::OZHelper end def addhost(id, host_array, options) - rc = @client.get_resource(@vdc_str, id) + vdc = Zona::VDC.new(Zona::VDC.build_json(id), @client) + rc = vdc.info - if Zona::is_error?(rc) - return [-1, rc.message] - else - vdc = Zona::OZonesJSON.parse_json(rc.body, @vdc_str.upcase) - end + return [-1, rc.message] if Zona::is_error?(rc) - hosts = vdc[:HOSTS].split(',').collect!{|x| x.to_i} - host_array.concat(hosts).uniq! - - new_host = host_array.join(',') - template = "ID=#{id}\nHOSTS=#{new_host}\n" - - if options[:force] - template << "FORCE=YES\n" - end - - rc = @client.put_resource_str(@vdc_str, id, template) + rc = vdc.add_hosts(host_array, :FORCE => options[:force]) if Zona::is_error?(rc) return [-1, rc.message] @@ -105,24 +92,16 @@ class VDCHelper < OZonesHelper::OZHelper [0, ""] end - def delhost(id, host_array, options) - rc = @client.get_resource(@vdc_str, id) + def delhost(id, host_array) + vdc = Zona::VDC.new(Zona::VDC.build_json(id), @client) + rc = vdc.info + + return [-1, rc.message] if Zona::is_error?(rc) + + rc = vdc.del_hosts(host_array) if Zona::is_error?(rc) return [-1, rc.message] - else - vdc = Zona::OZonesJSON.parse_json(rc.body, @vdc_str.upcase) - end - - hosts = vdc[:HOSTS].split(',').collect!{|x| x.to_i} - - new_host = (hosts - host_array).join(',') - template = "ID=#{id}\nHOSTS=#{new_host}\n" - - rc = @client.put_resource_str(@vdc_str, id, template) - - if Zona.is_error?(rc) - return [-1, rc.message] end [0, ""] diff --git a/src/ozones/Client/lib/zona.rb b/src/ozones/Client/lib/zona.rb index e479e67d2d..cf4b2172a8 100644 --- a/src/ozones/Client/lib/zona.rb +++ b/src/ozones/Client/lib/zona.rb @@ -278,7 +278,8 @@ EOT if value.body ehash = OZonesJSON.parse_json(value.body,"error") - str << ehash[:message] if !ehash.nil? + + str << ehash[:message] if !ehash.nil? or !Zona.is_error?(ehash) end return Error.new(str) diff --git a/src/ozones/Client/lib/zona/VDCElement.rb b/src/ozones/Client/lib/zona/VDCElement.rb index 730e6db0e9..c4ac085538 100644 --- a/src/ozones/Client/lib/zona/VDCElement.rb +++ b/src/ozones/Client/lib/zona/VDCElement.rb @@ -73,7 +73,6 @@ module Zona super(VDC_KIND) end - # Adds hosts to a VDC. The specified hosts are added to the VDC's # current ones. # @param [Array<#to_i>] hosts_array array of hosts IDs @@ -82,17 +81,57 @@ module Zona # @option options [Boolean] :force allows hosts to add hosts # which already belong to other VDCs # @return [Zona::Error] nil or Error - def addhosts(hosts_array,options={}) + def add_hosts(hosts_array,options={}) + addresource(:HOSTS, hosts_array, options) + end + + def add_networks(net_array,options={}) + addresource(:NETWORKS, net_array, options) + end + + def add_datastores(ds_array,options={}) + addresource(:DATASTORES, ds_array, options) + end + + # Delete hosts from a VDC. The specified hosts are removed from the VDC. + # @param [Array<#to_i>] hosts_array array of the VDC's hosts IDs + # to be removed. If a host is not in the VDC, then it is ignored. + # @return [Zona::Error] nil or Error + def del_hosts(hosts_array) + delresource(:HOSTS, hosts_array) + end + + def del_networks(net_array) + delresource(:NETWORKS, net_array) + end + + def del_datastores(ds_array) + delresource(:DATASTORESS, ds_array) + end + + alias :add_host :add_hosts + alias :del_host :del_hosts + + alias :add_network :add_networks + alias :del_network :del_networks + + alias :add_datastore :add_datastores + alias :del_datastore :del_datastores + + private + + def addresource(type, rsrc_array, options={}) + return nil if rsrc_array.nil? return Error.new('VDC not info-ed') if !@json_hash - # array of hosts, integers - hosts = self[:HOSTS].split(',').collect!{|x| x.to_i} - hosts.concat(hosts_array).uniq! + self[:RESOURCES][type].concat(rsrc_array).uniq! + + template = { + :ID => @pe_id, + :RESOURCES => self[:RESOURCES] + } - new_hosts = hosts.join(',') - template = {:ID => @pe_id, :HOSTS => new_hosts} template[:FORCE] = "YES" if options[:FORCE] - template = {:VDC => template} rc = @client.put_resource(VDC_KIND,@pe_id,template.to_json) @@ -100,25 +139,24 @@ module Zona nil end - # Delete hosts from a VDC. The specified hosts are removed from the VDC. - # @param [Array<#to_i>] hosts_array array of the VDC's hosts IDs - # to be removed. If a host is not in the VDC, then it is ignored. - # @return [Zona::Error] nil or Error - def delhosts(hosts_array) + def delresource(type, rsrc_array) + return nil if rsrc_array.nil? return Error.new('VDC not info-ed') if !@json_hash - hosts = self[:HOSTS].split(',').collect!{|x| x.to_i} + self[:RESOURCES][type] = self[:RESOURCES][type] - rsrc_array - new_hosts = (hosts - hosts_array).join(',') - template = {:VDC => {:ID => @pe_id, :HOSTS => new_hosts}} + template = { + :VDC => { + :ID => @pe_id, + :RESOURCES => self[:RESOURCES] + } + } rc = @client.put_resource(VDC_KIND,@pe_id,template.to_json) return rc if Zona.is_error?(rc) nil end - alias :addhost :addhosts - alias :delhost :delhosts end end diff --git a/src/ozones/Server/lib/OZones/VDC.rb b/src/ozones/Server/lib/OZones/VDC.rb index e090699497..d3c5725edd 100644 --- a/src/ozones/Server/lib/OZones/VDC.rb +++ b/src/ozones/Server/lib/OZones/VDC.rb @@ -242,7 +242,7 @@ module OZones # ------------------------------------------------------------------ delete_resource_acls - acls = @vcd.resources[:ACLS] + acls = @vdc.resources[:ACLS] acls.slice!(RESOURCE_ACL_FIRST_ID..-1) @@ -255,8 +255,7 @@ module OZones return rc if OpenNebula.is_error?(rc) - acls << acls_id - + acls.concat(acls_ids) end rsrc_hash[:ACLS] = acls diff --git a/src/ozones/Server/models/OzonesServer.rb b/src/ozones/Server/models/OzonesServer.rb index 01e68d09bb..05ee088354 100644 --- a/src/ozones/Server/models/OzonesServer.rb +++ b/src/ozones/Server/models/OzonesServer.rb @@ -189,8 +189,8 @@ class OzonesServer < CloudServer "#{e.message}").to_json] end - vdc_data[:CLUSTER_ID] = vdc.CLUSTER_ID - vdc_data[:ID] = vdc.ID + vdc_data[:CLUSTER_ID] = vdc.vdc.CLUSTER_ID + vdc_data[:ID] = vdc.vdc.ID force = vdc_data.delete(:FORCE) @@ -265,7 +265,6 @@ class OzonesServer < CloudServer all_hosts = Array.new zone.vdcs.all(:CLUSTER_ID =>c_id).each{ |vdc| - rsrc = vdc.resources if !rsrc[:HOSTS].empty? and vdc.ID != vdc_data[:ID]