mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
feature #1112: Zone VDC API methods to add/del datastores and networks. Fix update method in the server. Updated CLI tool
This commit is contained in:
parent
25460dd995
commit
713b7217f3
@ -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
|
||||
|
@ -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, ""]
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user