mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
feature #1112: Fix update VDC functions. Added options for onevdc. Improved onevdc list
This commit is contained in:
parent
739128baa8
commit
eb900c3c2e
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user