1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-27 03:21:29 +03:00

Merge branch 'feature-1112' of git.opennebula.org:one into feature-1112

This commit is contained in:
Daniel Molina 2012-03-16 18:36:22 +01:00
commit 5dd2fe63c3
12 changed files with 100 additions and 85 deletions

View File

@ -399,6 +399,18 @@ EOT
end
end
# If the cluster name is empty, returns a '-' char.
#
# @param str [String || Hash] Cluster name, or empty Hash (when <CLUSTER/>)
# @return [String] the same Cluster name, or '-' if it is empty
def OpenNebulaHelper.cluster_str(str)
if str != nil && !str.empty?
str
else
"-"
end
end
def OpenNebulaHelper.update_template(id, resource)
require 'tempfile'

View File

@ -57,11 +57,7 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper
end
column :CLUSTER, "Name of the Cluster", :left, :size=>8 do |d|
if d["CLUSTER"] == "none"
"-"
else
d["CLUSTER"]
end
OpenNebulaHelper.cluster_str(d["CLUSTER"])
end
column :IMAGES, "Number of Images", :left, :size=>6 do |d|
@ -111,8 +107,7 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper
puts str % ["NAME", datastore.name]
puts str % ["USER", datastore['UNAME']]
puts str % ["GROUP", datastore['GNAME']]
puts str % ["CLUSTER", datastore['CLUSTER']]
puts str % ["CLUSTER_ID", datastore['CLUSTER_ID']]
puts str % ["CLUSTER", OpenNebulaHelper.cluster_str(datastore['CLUSTER'])]
puts str % ["DS_MAD", datastore['DS_MAD']]
puts str % ["TM_MAD", datastore['TM_MAD']]

View File

@ -44,11 +44,7 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
end
column :CLUSTER, "Name of the Cluster", :left, :size=>8 do |d|
if d["CLUSTER"] == "none"
"-"
else
d["CLUSTER"]
end
OpenNebulaHelper.cluster_str(d["CLUSTER"])
end
column :RVM, "Number of Virtual Machines running", :size=>6 do |d|
@ -126,7 +122,7 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
puts str % ["ID", host.id.to_s]
puts str % ["NAME", host.name]
puts str % ["CLUSTER", host['CLUSTER']]
puts str % ["CLUSTER", OpenNebulaHelper.cluster_str(host['CLUSTER'])]
puts str % ["STATE", host.state_str]
puts str % ["IM_MAD", host['IM_MAD']]
puts str % ["VM_MAD", host['VM_MAD']]

View File

@ -55,11 +55,7 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
end
column :CLUSTER, "Name of the Cluster", :left, :size=>8 do |d|
if d["CLUSTER"] == "none"
"-"
else
d["CLUSTER"]
end
OpenNebulaHelper.cluster_str(d["CLUSTER"])
end
column :TYPE, "Type of Virtual Network", :size=>6 do |d|
@ -111,7 +107,7 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
puts str % ["NAME", vn['NAME']]
puts str % ["USER", vn['UNAME']]
puts str % ["GROUP", vn['GNAME']]
puts str % ["CLUSTER", vn['CLUSTER']]
puts str % ["CLUSTER", OpenNebulaHelper.cluster_str(vn['CLUSTER'])]
puts str % ["TYPE", vn.type_str]
puts str % ["BRIDGE", vn["BRIDGE"]]
puts str % ["VLAN", OpenNebulaHelper.boolean_to_str(vn['VLAN'])]

View File

@ -26,7 +26,7 @@
/* Regular ones start from ID 100 */
/* -------------------------------------------------------------------------- */
const string ClusterPool::NONE_CLUSTER_NAME = "none";
const string ClusterPool::NONE_CLUSTER_NAME = "";
const int ClusterPool::NONE_CLUSTER_ID = -1;
/* -------------------------------------------------------------------------- */

View File

@ -126,7 +126,7 @@ module Migrator
" <TM_MAD>shared</TM_MAD>" <<
" <BASE_PATH>#{var_location}/datastores/0</BASE_PATH>" <<
" <CLUSTER_ID>-1</CLUSTER_ID>" <<
" <CLUSTER>none</CLUSTER>" <<
" <CLUSTER/>" <<
" <IMAGES/>" <<
" <TEMPLATE>" <<
" <DS_MAD><![CDATA[-]]></DS_MAD>" <<
@ -169,7 +169,7 @@ module Migrator
# Add Cluster elements
doc.root.add_element("CLUSTER_ID").text = "-1"
doc.root.add_element("CLUSTER").text = "none"
doc.root.add_element("CLUSTER").text = ""
@db[:host_pool].insert(
:oid => row[:oid],
@ -198,7 +198,7 @@ module Migrator
# Add Cluster elements
doc.root.add_element("CLUSTER_ID").text = "-1"
doc.root.add_element("CLUSTER").text = "none"
doc.root.add_element("CLUSTER").text = ""
@db[:network_pool].insert(
:oid => row[:oid],
@ -283,7 +283,7 @@ module Migrator
" <TM_MAD>shared</TM_MAD>" <<
" <BASE_PATH>#{var_location}/datastores/1</BASE_PATH>" <<
" <CLUSTER_ID>-1</CLUSTER_ID>" <<
" <CLUSTER>none</CLUSTER>" <<
" <CLUSTER/>" <<
images_element <<
" <TEMPLATE>" <<
" <DS_MAD><![CDATA[fs]]></DS_MAD>" <<

View File

@ -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

View File

@ -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, ""]

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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]