mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
feature #789: Moved update from OCAInteraction to VDC
This commit is contained in:
parent
0d42887ca6
commit
dec5dbd0c8
@ -46,25 +46,6 @@ module OZones
|
||||
vdc_attributes["VDC"] = attributes
|
||||
return vdc_attributes
|
||||
end
|
||||
|
||||
# Returns the host acls as an array of strings.
|
||||
# The acls of the VDC are updated and the host acl ids removed
|
||||
def get_host_acls!(new_host_acls = nil)
|
||||
acl_ids = self.acls.split(',')
|
||||
vdc_acl = acl_ids.slice!(0,HOST_ACL_FIRST_ID)
|
||||
|
||||
newacl = ""
|
||||
vdc_acl.each{|id|
|
||||
newacl << id << ','
|
||||
}
|
||||
|
||||
newacl.chomp
|
||||
newacl << new_host_acls if new_host_acls
|
||||
|
||||
self.acls = newacl
|
||||
|
||||
return acl_ids
|
||||
end
|
||||
end
|
||||
|
||||
###########################################################################
|
||||
@ -112,7 +93,6 @@ module OZones
|
||||
|
||||
#Create a vdc record
|
||||
@vdc = Vdc.new
|
||||
@vdc.raise_on_save_failure = true
|
||||
|
||||
vdcpass = Digest::SHA1.hexdigest(vdc_data.delete(:vdcadminpass))
|
||||
@vdc.attributes = vdc_data
|
||||
@ -142,20 +122,10 @@ module OZones
|
||||
aclp = OpenNebula::AclPool.new(@client)
|
||||
rules = get_acls
|
||||
|
||||
acls_str = ""
|
||||
rc, acls_str = create_acls(rules)
|
||||
return rollback(group, user,acls_str,rc) if OpenNebula.is_error?(rc)
|
||||
|
||||
rules.each{ |rule_str|
|
||||
acl = OpenNebula::Acl.new(OpenNebula::Acl.build_xml,@client)
|
||||
rc = acl.allocate(*OpenNebula::Acl.parse_rule(rule_str))
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rollback(group, user, acls_str, rc)
|
||||
end
|
||||
|
||||
acls_str << acl.id.to_s << ","
|
||||
}
|
||||
|
||||
@vdc.acls = acls_str.chop
|
||||
@vdc.acls = acls_str
|
||||
|
||||
return true
|
||||
end
|
||||
@ -188,6 +158,36 @@ module OZones
|
||||
end
|
||||
end
|
||||
|
||||
def update(host_list)
|
||||
# Delete existing host ACLs
|
||||
delete_host_acls
|
||||
|
||||
# Create new ACLs. TODO Rollback ACL creation
|
||||
host_acls = get_host_acls(host_list)
|
||||
rc, acls_str = create_acls(host_acls)
|
||||
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
|
||||
#Create the new acl string.
|
||||
@vdc.acls =~ /((\d,){HOST_ACL_FIRST_ID}).*/
|
||||
|
||||
newacls = $1.chop
|
||||
newacls << acls_str
|
||||
|
||||
#Update the VDC Record
|
||||
begin
|
||||
@vdc.raise_on_save_failure = true
|
||||
@vdc.hosts = host_list
|
||||
@vdc.acls = newacls
|
||||
|
||||
@vdc.save
|
||||
rescue => e
|
||||
return OpenNebula::Error.new(e.message)
|
||||
end
|
||||
|
||||
return @vdc.to_json
|
||||
end
|
||||
|
||||
private
|
||||
#######################################################################
|
||||
# Functions to generate ACL Strings
|
||||
@ -307,5 +307,23 @@ module OZones
|
||||
|
||||
return rc
|
||||
end
|
||||
|
||||
# Creates an acl array of acl strings. Returns true or error and
|
||||
# a comma-separated list with the new acl ids
|
||||
def create_acls(acls)
|
||||
acls_str = ""
|
||||
rc = true
|
||||
|
||||
acls.each{|rule|
|
||||
acl = OpenNebula::Acl.new(OpenNebula::Acl.build_xml,@client)
|
||||
rc = acl.allocate(*OpenNebula::Acl.parse_rule(rule))
|
||||
|
||||
break if OpenNebula.is_error?(rc)
|
||||
|
||||
acls_str << acl.id.to_s << ","
|
||||
}
|
||||
|
||||
return rc, acls_str.chop
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -189,8 +189,8 @@ class OzonesServer
|
||||
|
||||
resource = case kind
|
||||
when "vdc" then
|
||||
vdc_data=Hash.new
|
||||
vdc_id = nil
|
||||
vdc_data = Hash.new
|
||||
vdc_id = nil
|
||||
data.each{|key,value|
|
||||
vdc_data[key.downcase.to_sym]=value if key!="id"
|
||||
vdc_id = value if key=="id"
|
||||
@ -204,19 +204,12 @@ class OzonesServer
|
||||
end
|
||||
|
||||
# Check if the referenced Vdc exists
|
||||
vdc=OZones::Vdc.get(vdc_id)
|
||||
if !vdc
|
||||
error = OZones::Error.new("Error: Vdc " +
|
||||
"#{vdc_id} not found, cannot update Vdc.")
|
||||
return [404, error.to_json]
|
||||
end
|
||||
|
||||
# Get the zone where the Vdc belongs
|
||||
zone=OZones::Zones.get(vdc.zones.id)
|
||||
if !zone
|
||||
error = OZones::Error.new("Error: Zone " +
|
||||
"#{vdc.zones.id} not found, cannot update Vdc.")
|
||||
return [404, error.to_json]
|
||||
begin
|
||||
vdc=OZones::OpenNebulaVdc.new(vdc_id, zone)
|
||||
rescue
|
||||
return [404, OZones::Error.new("Error: Vdc " \
|
||||
"#{vdc_id} not found, cannot update Vdc.").to_json]
|
||||
|
||||
end
|
||||
|
||||
if (!vdc_data[:force] or vdc_data[:force].upcase!="YES") and
|
||||
@ -227,25 +220,14 @@ class OzonesServer
|
||||
" was given.").to_json]
|
||||
end
|
||||
|
||||
rc = @ocaInt.update_vdc_hosts(zone, vdc, vdc_data[:hosts])
|
||||
rc = vdc.update(vdc_data[:hosts])
|
||||
|
||||
if !OpenNebula.is_error?(rc)
|
||||
vdc.hosts = vdc_data[:hosts]
|
||||
vdc.get_host_acls!(rc)
|
||||
|
||||
vdc.save
|
||||
|
||||
if vdc.saved?
|
||||
return [200, vdc.to_json]
|
||||
else
|
||||
return [500, OZones::Error.new(
|
||||
"Error: Couldn't update resource #{kind}.").to_json]
|
||||
end
|
||||
|
||||
return [200, rc]
|
||||
else
|
||||
return [500, OZones::Error.new(
|
||||
"Error: Couldn't update resource #{kind.upcase}." +
|
||||
" Failed to update ACLs").to_json]
|
||||
"Error: Couldn't update resource #{kind.upcase}." \
|
||||
" Reason: #{rc.message}").to_json]
|
||||
end
|
||||
else
|
||||
error = OZones::Error.new(
|
||||
|
Loading…
x
Reference in New Issue
Block a user