diff --git a/src/ozones/Client/bin/onevdc b/src/ozones/Client/bin/onevdc index c3657390e9..2872771b1a 100755 --- a/src/ozones/Client/bin/onevdc +++ b/src/ozones/Client/bin/onevdc @@ -50,6 +50,32 @@ cmd=CommandParser::CmdParser.new(ARGV) do :description => "Force the usage of Hosts in more than one VDC" } + HOST={ + :name => "hosts", + :short => "-s 1,2,3", + :large => "--hosts 1,2,3", + :description => "Host IDs", + :format => Array + } + + DS={ + :name => "datastores", + :short => "-d 1,2,3", + :large => "--datastores 1,2,3", + :description => "Datastore IDs", + :format => Array + } + + NET={ + :name => "networks", + :short => "-n 1,2,3", + :large => "--networks 1,2,3", + :description => "Network IDs", + :format => Array + } + + ADD_DEL_OPTIONS=[HOST, DS, NET] + begin helper = VDCHelper.new "vdc" rescue Exception => e @@ -74,12 +100,28 @@ 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, - :options=>[FORCE] do - helper.addhost(args[0], args[1], options) + command :add, 'Adds the set of resources to the VDC', :vdcid, + :options=>[FORCE].concat(ADD_DEL_OPTIONS) do + if options[:hosts].nil? and options[:datastores].nil? and + options[:networks].nil? + STDERR.puts "At least one resource type must be specified: " \ + "network (-n), host (-s) or datastore (-d) " + exit 1 + end + + helper.add(args[0], options) end - command :delhost, 'Deletes the set of hosts from the VDC', :vdcid, :range do - helper.delhost(args[0], args[1]) + command :del, 'Deletes the set of resources from the VDC', :vdcid, + :options => ADD_DEL_OPTIONS do + + if options[:hosts].nil? and options[:datastores].nil? and + options[:networks].nil? + STDERR.puts "At least one resource type must be specified: " \ + "network (-n), host (-s) or datastore (-d) " + exit 1 + end + + helper.del(args[0], options) 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 0cac03e533..8f8a98b026 100644 --- a/src/ozones/Client/lib/cli/ozones_helper/vdc_helper.rb +++ b/src/ozones/Client/lib/cli/ozones_helper/vdc_helper.rb @@ -77,34 +77,70 @@ class VDCHelper < OZonesHelper::OZHelper super(@vdc_str,id, options) end - def addhost(id, host_array, options) + def add(id, options) vdc = Zona::VDC.new(Zona::VDC.build_json(id), @client) rc = vdc.info return [-1, rc.message] if Zona::is_error?(rc) - rc = vdc.add_hosts(host_array, :FORCE => options[:force]) + exit_code = 0 + message = "" + + rc = vdc.add_hosts(options[:hosts], :FORCE => options[:force]) if Zona::is_error?(rc) - return [-1, rc.message] + message << "Error adding hosts to VDC:\n\t#{rc.message}\n" + exit_code = -1 end - [0, ""] + rc = vdc.add_networks(options[:networks]) + + if Zona::is_error?(rc) + message << "Error adding networks to VDC:\n#{rc.message}\n" + exit_code = -1 + end + + rc = vdc.add_datastores(options[:datastores]) + + if Zona::is_error?(rc) + message << "Error adding datastores to VDC:\n\t#{rc.message}\n" + exit_code = -1 + end + + return [exit_code, message] end - def delhost(id, host_array) + def del(id, options) 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) + exit_code = 0 + message = "" + + rc = vdc.del_hosts(options[:hosts]) if Zona::is_error?(rc) - return [-1, rc.message] + message << "Error deleting to VDC:\n\t#{rc.message}\n" + exit_code = -1 end - [0, ""] + rc = vdc.del_networks(options[:networks]) + + if Zona::is_error?(rc) + message << "Error deleting networks to VDC:\n#{rc.message}\n" + exit_code = -1 + end + + rc = vdc.del_datastores(options[:datastores]) + + if Zona::is_error?(rc) + message << "Error deleting datastores to VDC:\n\t#{rc.message}\n" + exit_code = -1 + end + + return [exit_code, message] end private @@ -135,16 +171,36 @@ class VDCHelper < OZonesHelper::OZHelper d[:ID] end - column :NAME, "Name of the VDC", :right, :size=>15 do |d,e| + column :NAME, "Name of the VDC", :left, :size=>15 do |d,e| d[:NAME] end - column :ZONEID, "Id of the Zone where it belongs", - :right, :size=>40 do |d,e| + column :ZONE, "Id of the Zone where it belongs", + :right, :size=>5 do |d,e| d[:ZONES_ID] end - default :ID, :NAME, :ZONEID + column :CLUSTER, "Cluster where it belongs", + :right, :size=>7 do |d,e| + d[:CLUSTER_ID] + end + + column :HOSTS, "Number of hosts in the VDC", + :right, :size=>5 do |d,e| + d[:RESOURCES][:HOSTS].size + end + + column :DATASTORES, "Number of datastores in the VDC", + :right, :size=>10 do |d,e| + d[:RESOURCES][:DATASTORES].size + end + + column :NETWORKS, "Number of networks in the VDC", + :right, :size=>8 do |d,e| + d[:RESOURCES][:NETWORKS].size + end + + default :ID, :ZONE, :CLUSTER, :NAME, :HOSTS, :NETWORKS, :DATASTORES end st.show(pool[:VDC], options) diff --git a/src/ozones/Client/lib/zona/VDCElement.rb b/src/ozones/Client/lib/zona/VDCElement.rb index c4ac085538..33fd06e65e 100644 --- a/src/ozones/Client/lib/zona/VDCElement.rb +++ b/src/ozones/Client/lib/zona/VDCElement.rb @@ -106,7 +106,7 @@ module Zona end def del_datastores(ds_array) - delresource(:DATASTORESS, ds_array) + delresource(:DATASTORES, ds_array) end alias :add_host :add_hosts @@ -122,10 +122,16 @@ module Zona def addresource(type, rsrc_array, options={}) return nil if rsrc_array.nil? + return nil if rsrc_array.empty? return Error.new('VDC not info-ed') if !@json_hash + orig_resources = self[:RESOURCES][type].clone + + rsrc_array.map! {|i| i.to_i} self[:RESOURCES][type].concat(rsrc_array).uniq! + return nil if self[:RESOURCES][type] == orig_resources + template = { :ID => @pe_id, :RESOURCES => self[:RESOURCES] @@ -141,10 +147,16 @@ module Zona def delresource(type, rsrc_array) return nil if rsrc_array.nil? + return nil if rsrc_array.empty? return Error.new('VDC not info-ed') if !@json_hash + orig_resources = self[:RESOURCES][type].clone + + rsrc_array.map! {|i| i.to_i} self[:RESOURCES][type] = self[:RESOURCES][type] - rsrc_array + return nil if self[:RESOURCES][type] == orig_resources + template = { :VDC => { :ID => @pe_id, @@ -156,7 +168,5 @@ module Zona return rc if Zona.is_error?(rc) nil end - - end end diff --git a/src/ozones/Server/lib/OZones/VDC.rb b/src/ozones/Server/lib/OZones/VDC.rb index d3c5725edd..19587c5605 100644 --- a/src/ozones/Server/lib/OZones/VDC.rb +++ b/src/ozones/Server/lib/OZones/VDC.rb @@ -333,12 +333,15 @@ module OZones end # Delete ACLs - def delete_acls(first_id = 0) + def delete_acls(first = 0) rsrc = @vdc.resources return if rsrc[:ACLS].nil? - rsrc[:ACLS][first_id..-1].each { |acl_id| + OzonesServer::logger.debug { + "Deleting VDC ACL rules: #{rsrc[:ACLS][first..-1]}" } + + rsrc[:ACLS][first..-1].each { |acl_id| OpenNebula::Acl.new_with_id(acl_id, @client).delete } end diff --git a/src/ozones/Server/models/OzonesServer.rb b/src/ozones/Server/models/OzonesServer.rb index 05ee088354..f9d83e9b86 100644 --- a/src/ozones/Server/models/OzonesServer.rb +++ b/src/ozones/Server/models/OzonesServer.rb @@ -198,7 +198,7 @@ class OzonesServer < CloudServer return [403, OZones::Error.new("Error: Couldn't update vdc. " \ "Hosts are not unique, use force to override").to_json] end - + logger.debug {"----> #{vdc_data}"} rc = vdc.update(vdc_data[:RESOURCES]) if !OpenNebula.is_error?(rc)