mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-27 03:21:29 +03:00
feature #1112: Improved OCA API functions to check cluster resources. VDC now check cluster consistency when creating or updating the VDC
This commit is contained in:
parent
82505a07ef
commit
036699ae64
@ -161,14 +161,10 @@ module OpenNebula
|
||||
# ---------------------------------------------------------------------
|
||||
|
||||
# Returns whether or not the host with 'id' is part of this cluster
|
||||
# @param id [Integer] host ID
|
||||
# @param id [Integer|Array] host ID
|
||||
# @return [Boolean] true if found
|
||||
def contains_host(id)
|
||||
#This doesn't work in ruby 1.8.5
|
||||
#return self["HOSTS/ID[.=#{uid}]"] != nil
|
||||
|
||||
id_array = retrieve_elements('HOSTS/ID')
|
||||
return id_array != nil && id_array.include?(id.to_s)
|
||||
def contains_host?(id)
|
||||
contains_resource?('HOSTS/ID', id)
|
||||
end
|
||||
|
||||
# Returns an array with the numeric host ids
|
||||
@ -184,14 +180,10 @@ module OpenNebula
|
||||
end
|
||||
|
||||
# Returns whether or not the datastore with 'id' is part of this cluster
|
||||
# @param id [Integer] datastore ID
|
||||
# @param id [Integer|Array] datastore ID
|
||||
# @return [Boolean] true if found
|
||||
def contains_datastore(id)
|
||||
#This doesn't work in ruby 1.8.5
|
||||
#return self["DATASTORES/ID[.=#{uid}]"] != nil
|
||||
|
||||
id_array = retrieve_elements('DATASTORES/ID')
|
||||
return id_array != nil && id_array.include?(id.to_s)
|
||||
def contains_datastore?(id)
|
||||
contains_resource?('DATASTORES/ID', id)
|
||||
end
|
||||
|
||||
# Returns an array with the numeric datastore ids
|
||||
@ -207,14 +199,10 @@ module OpenNebula
|
||||
end
|
||||
|
||||
# Returns whether or not the vnet with 'id' is part of this cluster
|
||||
# @param id [Integer] vnet ID
|
||||
# @param id [Integer|Arrray] vnet ID
|
||||
# @return [Boolean] true if found
|
||||
def contains_vnet(id)
|
||||
#This doesn't work in ruby 1.8.5
|
||||
#return self["HOSTS/ID[.=#{uid}]"] != nil
|
||||
|
||||
id_array = retrieve_elements('VNETS/ID')
|
||||
return id_array != nil && id_array.include?(id.to_s)
|
||||
def contains_vnet?(id)
|
||||
contains_resource?('VNETS/ID', id)
|
||||
end
|
||||
|
||||
# Returns an array with the numeric vnet ids
|
||||
@ -228,5 +216,21 @@ module OpenNebula
|
||||
|
||||
return array
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def contains_resource?(xpath, id)
|
||||
id_array = retrieve_elements(xpath)
|
||||
|
||||
return false if id_array.nil?
|
||||
|
||||
id = [id] if id.class != Array
|
||||
|
||||
id.each { |i|
|
||||
return false if !id_array.include?(i.to_s)
|
||||
}
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -148,12 +148,16 @@ module OZones
|
||||
vdcpass = vdc_data.delete(:VDCADMINPASS)
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# Create a vdc record
|
||||
# Create a vdc record & check cluster consistency
|
||||
#-------------------------------------------------------------------
|
||||
@vdc = Vdc.new
|
||||
|
||||
@vdc.attributes = vdc_data
|
||||
|
||||
rc = resources_in_cluster?(rsrc)
|
||||
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# Create a group in the zone with the VDC name
|
||||
#-------------------------------------------------------------------
|
||||
@ -202,6 +206,9 @@ module OZones
|
||||
return true
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
#######################################################################
|
||||
def destroy
|
||||
#-------------------------------------------------------------------
|
||||
# Delete the resources from the VDC
|
||||
@ -228,7 +235,9 @@ module OZones
|
||||
return @vdc.destroy
|
||||
end
|
||||
|
||||
#Cleans bootstrap operations in a zone
|
||||
#######################################################################
|
||||
# Cleans bootstrap operations in a zone
|
||||
#######################################################################
|
||||
def clean_bootstrap
|
||||
delete_acls
|
||||
|
||||
@ -236,7 +245,17 @@ module OZones
|
||||
OpenNebula::Group.new_with_id(@vdc.GROUP_ID, @client).delete
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
#######################################################################
|
||||
def update(rsrc_hash)
|
||||
#-------------------------------------------------------------------
|
||||
# Check cluster consistency
|
||||
#-------------------------------------------------------------------
|
||||
rc = resources_in_cluster?(rsrc_hash)
|
||||
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Delete existing host ACLs
|
||||
# ------------------------------------------------------------------
|
||||
@ -408,5 +427,31 @@ module OZones
|
||||
|
||||
return rc, acls_ids
|
||||
end
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
def resources_in_cluster?(rsrc_hash)
|
||||
cluster = OpenNebula::Cluster.new_with_id(@vdc.CLUSTER_ID, @client)
|
||||
rc = cluster.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return OpenNebula::Error.new("Error getting cluster: #{rc.message}")
|
||||
end
|
||||
|
||||
if !cluster.contains_datastore?(rsrc_hash[:DATASTORES])
|
||||
return OpenNebula::Error.new("Some Datastores are not in cluster")
|
||||
end
|
||||
|
||||
if !cluster.contains_host?(rsrc_hash[:HOSTS])
|
||||
return OpenNebula::Error.new("Some Hosts are not in cluster")
|
||||
end
|
||||
|
||||
if !cluster.contains_vnet?(rsrc_hash[:NETWORKS])
|
||||
return OpenNebula::Error.new("Some Networks are not in cluster")
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user