mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Task #905: Capitalize ozones data
All data is now represented with keys in capital letters. Resources attributes must be accessed with capital letters. Server JSON is directly parsed with symbolize_keys => true.
This commit is contained in:
parent
c806c7288d
commit
de9423c69c
@ -78,7 +78,7 @@ module OZonesHelper
|
||||
|
||||
|
||||
def get_id(rc)
|
||||
id = rc.body.match('\"id\":(.*)$')[1].strip
|
||||
id = rc.body.match('\"ID\":(.*)$')[1].strip
|
||||
if id[-1..-1] == ","
|
||||
id = id[0..id.size-2]
|
||||
end
|
||||
|
@ -62,7 +62,7 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
vdc = Zona::OZonesJSON.parse_json(rc.body, @vdc_str.upcase)
|
||||
end
|
||||
|
||||
hosts = vdc['hosts'].split(',').collect!{|x| x.to_i}
|
||||
hosts = vdc['HOSTS'].split(',').collect!{|x| x.to_i}
|
||||
host_array.concat(hosts).uniq!
|
||||
|
||||
new_host = host_array.join(',')
|
||||
@ -90,7 +90,7 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
vdc = Zona::OZonesJSON.parse_json(rc.body, @vdc_str.upcase)
|
||||
end
|
||||
|
||||
hosts = vdc['hosts'].split(',').collect!{|x| x.to_i}
|
||||
hosts = vdc['HOSTS'].split(',').collect!{|x| x.to_i}
|
||||
|
||||
new_host = (hosts - host_array).join(',')
|
||||
template = "ID=#{id}\nHOSTS=#{new_host}\n"
|
||||
@ -112,12 +112,12 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
|
||||
CLIHelper.print_header(str_h1 % ["VDC #{vdc['name']} INFORMATION"])
|
||||
|
||||
puts str % ["ID ", vdc['id'].to_s]
|
||||
puts str % ["NAME ", vdc['name'].to_s]
|
||||
puts str % ["GROUP_ID ", vdc['group_id'].to_s]
|
||||
puts str % ["ZONEID ", vdc['zones_id'].to_s]
|
||||
puts str % ["VDCADMIN ", vdc['vdcadminname'].to_s]
|
||||
puts str % ["HOST IDs ", vdc['hosts'].to_s]
|
||||
puts str % ["ID ", vdc['ID'].to_s]
|
||||
puts str % ["NAME ", vdc['NAME'].to_s]
|
||||
puts str % ["GROUP_ID ", vdc['GROUP_ID'].to_s]
|
||||
puts str % ["ZONEID ", vdc['ZONES_ID'].to_s]
|
||||
puts str % ["VDCADMIN ", vdc['VDCADMINNAME'].to_s]
|
||||
puts str % ["HOST IDs ", vdc['HOSTS'].to_s]
|
||||
puts
|
||||
|
||||
return 0
|
||||
@ -126,16 +126,16 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
def format_pool(pool, options)
|
||||
st=CLIHelper::ShowTable.new(nil) do
|
||||
column :ID, "Identifier for VDC", :size=>4 do |d,e|
|
||||
d["id"]
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the VDC", :right, :size=>15 do |d,e|
|
||||
d["name"]
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
column :ZONEID, "Id of the Zone where it belongs",
|
||||
:right, :size=>40 do |d,e|
|
||||
d["zones_id"]
|
||||
d["ZONES_ID"]
|
||||
end
|
||||
|
||||
default :ID, :NAME, :ZONEID
|
||||
|
@ -36,17 +36,17 @@ class ZonesHelper < OZonesHelper::OZHelper
|
||||
str_h1="%-61s"
|
||||
str="%-15s: %-20s"
|
||||
|
||||
CLIHelper.print_header(str_h1 % ["ZONE #{zone['name']} INFORMATION"])
|
||||
CLIHelper.print_header(str_h1 % ["ZONE #{zone['NAME']} INFORMATION"])
|
||||
|
||||
puts str % ["ID ", zone['id'].to_s]
|
||||
puts str % ["NAME ", zone['name'].to_s]
|
||||
puts str % ["ZONE ADMIN ",zone['onename'].to_s]
|
||||
puts str % ["ZONE PASS ", zone['onepass'].to_s]
|
||||
puts str % ["ENDPOINT ", zone['endpoint'].to_s]
|
||||
puts str % ["# VDCS ", zone['vdcs'].size.to_s]
|
||||
puts str % ["ID ", zone['ID'].to_s]
|
||||
puts str % ["NAME ", zone['NAME'].to_s]
|
||||
puts str % ["ZONE ADMIN ",zone['ONENAME'].to_s]
|
||||
puts str % ["ZONE PASS ", zone['ONEPASS'].to_s]
|
||||
puts str % ["ENDPOINT ", zone['ENDPOINT'].to_s]
|
||||
puts str % ["# VDCS ", zone['VDCS'].size.to_s]
|
||||
puts
|
||||
|
||||
if zone['vdcs'].size == 0
|
||||
if zone['VDCS'].size == 0
|
||||
return [0, zone]
|
||||
end
|
||||
|
||||
@ -54,17 +54,17 @@ class ZonesHelper < OZonesHelper::OZHelper
|
||||
|
||||
st=CLIHelper::ShowTable.new(nil) do
|
||||
column :ID, "Identifier for VDC", :size=>4 do |d,e|
|
||||
d["id"]
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the VDC", :right, :size=>15 do |d,e|
|
||||
d["name"]
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
default :ID, :NAME
|
||||
end
|
||||
|
||||
st.show(zone["vdcs"], options)
|
||||
st.show(zone["VDCS"], options)
|
||||
|
||||
return [0, zone]
|
||||
end
|
||||
@ -72,15 +72,15 @@ class ZonesHelper < OZonesHelper::OZHelper
|
||||
def format_pool(pool, options)
|
||||
st=CLIHelper::ShowTable.new(nil) do
|
||||
column :ID, "Identifier for Zone", :size=>4 do |d,e|
|
||||
d["id"]
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the Zone", :right, :size=>15 do |d,e|
|
||||
d["name"]
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
column :ENDPOINT, "Endpoint of the Zone", :right, :size=>40 do |d,e|
|
||||
d["endpoint"]
|
||||
d["ENDPOINT"]
|
||||
end
|
||||
|
||||
default :ID, :NAME, :ENDPOINT
|
||||
@ -89,4 +89,4 @@ class ZonesHelper < OZonesHelper::OZHelper
|
||||
|
||||
return 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -260,7 +260,7 @@ EOT
|
||||
return value
|
||||
else
|
||||
if Zona.is_http_error?(value)
|
||||
str = "Operating with #{kind.upcase} failed with HTTP error"
|
||||
str = "Operating with #{kind} failed with HTTP error"
|
||||
str = " " + str + "code: #{value.code}\n"
|
||||
if value.body
|
||||
# Try to extract error message
|
||||
@ -287,7 +287,7 @@ EOT
|
||||
# @return [String, Zona::Error] JSON string or Error
|
||||
def self.to_body(kind, tmpl_str)
|
||||
tmpl = OpenNebula::Configuration.new(tmpl_str)
|
||||
res = { "#{kind}" => tmpl.conf }
|
||||
res = { "#{kind.upcase}" => tmpl.conf }
|
||||
|
||||
return OZonesJSON.to_json(res)
|
||||
end
|
||||
|
@ -30,8 +30,8 @@ module Zona
|
||||
@client = client
|
||||
@json_hash = hash
|
||||
|
||||
@pe_id = self["id"] ? self["id"].to_i : nil
|
||||
@name = self["name"] ? self["name"] : nil
|
||||
@pe_id = self["ID"] ? self["ID"].to_i : nil
|
||||
@name = self["NAME"] ? self["NAME"] : nil
|
||||
end
|
||||
|
||||
# Retrieves details about an object and fills in
|
||||
@ -48,8 +48,8 @@ module Zona
|
||||
|
||||
rc = nil
|
||||
|
||||
@pe_id = self["id"] ? self["id"].to_i : nil
|
||||
@name = self["name"] ? self["name"] : nil
|
||||
@pe_id = self["ID"] ? self["ID"].to_i : nil
|
||||
@name = self["NAME"] ? self["NAME"] : nil
|
||||
|
||||
end
|
||||
rc
|
||||
@ -72,7 +72,7 @@ module Zona
|
||||
|
||||
if !Zona.is_error?(rc)
|
||||
initialize_json(rc.body,kind.upcase)
|
||||
@pe_id = self["id"].to_i
|
||||
@pe_id = self["ID"].to_i
|
||||
rc = nil
|
||||
end
|
||||
rc
|
||||
@ -98,7 +98,7 @@ module Zona
|
||||
# @param [Zona::Client] client OZones Client for this element
|
||||
# @return [OZonesElement] A new element object
|
||||
def self.new_with_id(id, client=nil)
|
||||
self.new(self.build_json(id),client)
|
||||
self.new(self.build_json(id.to_i),client)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -23,14 +23,15 @@ module Zona
|
||||
class VDC < OZonesElement
|
||||
|
||||
# String describing the kind of this resource
|
||||
# Should become part of the requests to server: get /vdc/...
|
||||
VDC_KIND = "vdc"
|
||||
|
||||
# Builds minimal JSON description for a VDC
|
||||
# @param [#to_i] pe_id VDC's ID
|
||||
# @param [Integer] pe_id VDC's ID
|
||||
# @return [Hash,Zona::Error] Hash description of the object, or Error
|
||||
def self.build_json(pe_id=nil)
|
||||
if pe_id
|
||||
json = "{\"VDC\":{\"id\":#{pe_id}}}"
|
||||
json = "{\"VDC\":{\"ID\":#{pe_id}}}"
|
||||
else
|
||||
json = '{"VDC":{}}'
|
||||
end
|
||||
@ -85,14 +86,14 @@ module Zona
|
||||
return Error.new('VDC not info-ed') if !@json_hash
|
||||
|
||||
# array of hosts, integers
|
||||
hosts = self["hosts"].split(',').collect!{|x| x.to_i}
|
||||
hosts = self["HOSTS"].split(',').collect!{|x| x.to_i}
|
||||
hosts.concat(hosts_array).uniq!
|
||||
|
||||
new_hosts = hosts.join(',')
|
||||
template = {:id => @pe_id, :hosts => new_hosts}
|
||||
template[:force] = "yes" if options[:force]
|
||||
template = {:ID => @pe_id, :HOSTS => new_hosts}
|
||||
template[:FORCE] = "YES" if options[:FORCE]
|
||||
|
||||
template = {:vdc => template}
|
||||
template = {:VDC => template}
|
||||
|
||||
rc = @client.put_resource(VDC_KIND,@pe_id,template.to_json)
|
||||
return rc if Zona.is_error?(rc)
|
||||
@ -106,10 +107,10 @@ module Zona
|
||||
def delhosts(hosts_array)
|
||||
return Error.new('VDC not info-ed') if !@json_hash
|
||||
|
||||
hosts = self["hosts"].split(',').collect!{|x| x.to_i}
|
||||
hosts = self["HOSTS"].split(',').collect!{|x| x.to_i}
|
||||
|
||||
new_hosts = (hosts - hosts_array).join(',')
|
||||
template = {:vdc => {:id => @pe_id, :hosts => new_hosts}}
|
||||
template = {:VDC => {:ID => @pe_id, :HOSTS => new_hosts}}
|
||||
|
||||
rc = @client.put_resource(VDC_KIND,@pe_id,template.to_json)
|
||||
return rc if Zona.is_error?(rc)
|
||||
|
@ -29,7 +29,7 @@ module Zona
|
||||
# @return [Hash,Zona::Error] Hash description of the object, or Error
|
||||
def self.build_json(pe_id=nil)
|
||||
if pe_id
|
||||
json = "{\"ZONE\":{\"id\":#{pe_id}}}"
|
||||
json = "{\"ZONE\":{\"ID\":#{pe_id}}}"
|
||||
else
|
||||
json = '{"ZONE":{}}'
|
||||
end
|
||||
|
@ -35,8 +35,8 @@ module OZones
|
||||
zone_pool_hash = zone.to_hash["ZONE"]
|
||||
|
||||
client = OpenNebula::Client.new(
|
||||
zone.onename + ":" + zone.onepass,
|
||||
zone.endpoint,
|
||||
zone.ONENAME + ":" + zone.ONEPASS,
|
||||
zone.ENDPOINT,
|
||||
false)
|
||||
|
||||
pool = factory(client)
|
||||
|
@ -26,13 +26,13 @@ module OZones
|
||||
|
||||
OZones::Zones.all.each{|zone|
|
||||
zone.vdcs.all.each{|vdc|
|
||||
htaccess << "RewriteRule ^#{vdc.name} " +
|
||||
"#{zone.endpoint} [P]\n"
|
||||
if zone.sunsendpoint != nil
|
||||
htaccess << "RewriteRule ^sunstone_#{vdc.name}/(.+) " +
|
||||
"#{zone.sunsendpoint}/$1 [P]\n"
|
||||
htaccess << "RewriteRule ^sunstone_#{vdc.name} " +
|
||||
"#{zone.sunsendpoint}/ [P]\n"
|
||||
htaccess << "RewriteRule ^#{vdc.NAME} " +
|
||||
"#{zone.ENDPOINT} [P]\n"
|
||||
if zone.SUNSENDPOINT != nil
|
||||
htaccess << "RewriteRule ^sunstone_#{vdc.NAME}/(.+) " +
|
||||
"#{zone.SUNSENDPOINT}/$1 [P]\n"
|
||||
htaccess << "RewriteRule ^sunstone_#{vdc.NAME} " +
|
||||
"#{zone.SUNSENDPOINT}/ [P]\n"
|
||||
end
|
||||
}
|
||||
}
|
||||
@ -44,4 +44,4 @@ module OZones
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -21,13 +21,13 @@ module OZones
|
||||
include OpenNebulaJSON::JSONUtils
|
||||
extend OpenNebulaJSON::JSONUtils
|
||||
|
||||
property :id, Serial
|
||||
property :name, String, :required => true, :unique => true
|
||||
property :group_id, Integer
|
||||
property :vdcadminname, String, :required => true
|
||||
property :vdcadmin_id, Integer
|
||||
property :acls, String
|
||||
property :hosts, String
|
||||
property :ID, Serial
|
||||
property :NAME, String, :required => true, :unique => true
|
||||
property :GROUP_ID, Integer
|
||||
property :VDCADMINNAME, String, :required => true
|
||||
property :VDCADMIN_ID, Integer
|
||||
property :ACLS, String
|
||||
property :HOSTS, String
|
||||
|
||||
belongs_to :zones
|
||||
|
||||
@ -36,14 +36,27 @@ module OZones
|
||||
zonePoolHash["VDC_POOL"] = Hash.new
|
||||
zonePoolHash["VDC_POOL"]["VDC"] = Array.new unless self.all.empty?
|
||||
self.all.each{|vdc|
|
||||
zonePoolHash["VDC_POOL"]["VDC"] << vdc.attributes
|
||||
# Hack! zones_ID does not respect the
|
||||
# "all capital letters" policy
|
||||
attrs = vdc.attributes.clone
|
||||
attrs[:ZONES_ID] = vdc.attributes[:zones_ID]
|
||||
attrs.delete(:zones_ID)
|
||||
|
||||
zonePoolHash["VDC_POOL"]["VDC"] << attrs
|
||||
}
|
||||
return zonePoolHash
|
||||
end
|
||||
|
||||
def to_hash
|
||||
vdc_attributes = Hash.new
|
||||
vdc_attributes["VDC"] = attributes
|
||||
|
||||
# Hack! zones_ID does not respect the
|
||||
# "all capital letters" policy
|
||||
attrs = attributes.clone
|
||||
attrs[:ZONES_ID] = attributes[:zones_ID]
|
||||
attrs.delete(:zones_ID)
|
||||
|
||||
vdc_attributes["VDC"] = attrs
|
||||
return vdc_attributes
|
||||
end
|
||||
end
|
||||
@ -57,7 +70,7 @@ module OZones
|
||||
#######################################################################
|
||||
# Constants
|
||||
#######################################################################
|
||||
VDC_ATTRS = [:vdcadminname, :vdcadminpass, :name, :hosts]
|
||||
VDC_ATTRS = [:VDCADMINNAME, :VDCADMINPASS, :NAME, :HOSTS]
|
||||
|
||||
attr_reader :vdc
|
||||
attr_reader :zone
|
||||
@ -72,14 +85,14 @@ module OZones
|
||||
raise "VDC with id #{vdcid} not found."
|
||||
end
|
||||
|
||||
@zone = OZones::Zones.get(@vdc.zones_id)
|
||||
@zone = OZones::Zones.get(@vdc.zones_ID)
|
||||
else
|
||||
@zone = zone
|
||||
end
|
||||
|
||||
@client = OpenNebula::Client.new(
|
||||
"#{@zone.onename}:#{@zone.onepass}",
|
||||
@zone.endpoint,
|
||||
"#{@zone.ONENAME}:#{@zone.ONEPASS}",
|
||||
@zone.ENDPOINT,
|
||||
false)
|
||||
end
|
||||
|
||||
@ -102,24 +115,24 @@ module OZones
|
||||
#Create a vdc record
|
||||
@vdc = Vdc.new
|
||||
|
||||
vdcpass = Digest::SHA1.hexdigest(vdc_data.delete(:vdcadminpass))
|
||||
vdcpass = Digest::SHA1.hexdigest(vdc_data.delete(:VDCADMINPASS))
|
||||
@vdc.attributes = vdc_data
|
||||
|
||||
# Create a group in the zone with the VDC name
|
||||
group = OpenNebula::Group.new(OpenNebula::Group.build_xml, @client)
|
||||
rc = group.allocate(@vdc.name)
|
||||
rc = group.allocate(@vdc.NAME)
|
||||
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
|
||||
@vdc.group_id = group.id
|
||||
@vdc.GROUP_ID = group.id
|
||||
|
||||
# Create the VDC admin user in the Zone
|
||||
user = OpenNebula::User.new(OpenNebula::User.build_xml, @client)
|
||||
rc = user.allocate(@vdc.vdcadminname, vdcpass)
|
||||
rc = user.allocate(@vdc.VDCADMINNAME, vdcpass)
|
||||
|
||||
return rollback(group, nil, nil, rc) if OpenNebula.is_error?(rc)
|
||||
|
||||
@vdc.vdcadmin_id = user.id
|
||||
@vdc.VDCADMIN_ID = user.id
|
||||
|
||||
# Change primary group of the admin user to the VDC group
|
||||
rc = user.chgrp(group.id)
|
||||
@ -132,7 +145,7 @@ module OZones
|
||||
rc, acls_str = create_acls(rules)
|
||||
return rollback(group, user,acls_str,rc) if OpenNebula.is_error?(rc)
|
||||
|
||||
@vdc.acls = acls_str
|
||||
@vdc.ACLS = acls_str
|
||||
|
||||
return true
|
||||
end
|
||||
@ -150,13 +163,13 @@ module OZones
|
||||
up.info
|
||||
|
||||
up.each{|user|
|
||||
if user['GID'].to_i == @vdc.group_id
|
||||
if user['GID'].to_i == @vdc.GROUP_ID
|
||||
user.delete
|
||||
end
|
||||
}
|
||||
|
||||
# Delete the group
|
||||
OpenNebula::Group.new_with_id(@vdc.group_id, @client).delete
|
||||
OpenNebula::Group.new_with_id(@vdc.GROUP_ID, @client).delete
|
||||
|
||||
return @vdc.destroy
|
||||
end
|
||||
@ -165,18 +178,18 @@ module OZones
|
||||
def clean_bootstrap
|
||||
delete_acls
|
||||
|
||||
OpenNebula::User.new_with_id(@vdc.vdcadmin_id, @client).delete
|
||||
OpenNebula::Group.new_with_id(@vdc.group_id, @client).delete
|
||||
OpenNebula::User.new_with_id(@vdc.VDCADMIN_ID, @client).delete
|
||||
OpenNebula::Group.new_with_id(@vdc.GROUP_ID, @client).delete
|
||||
end
|
||||
|
||||
def update(host_list)
|
||||
# Delete existing host ACLs
|
||||
delete_host_acls
|
||||
|
||||
if @vdc.acls =~ /((\d+,){#{HOST_ACL_FIRST_ID}}).*/
|
||||
if @vdc.ACLS =~ /((\d+,){#{HOST_ACL_FIRST_ID}}).*/
|
||||
newacls = $1.chop
|
||||
else
|
||||
newacls = @vdc.acls.clone
|
||||
newacls = @vdc.ACLS.clone
|
||||
end
|
||||
|
||||
# Create new ACLs. TODO Rollback ACL creation
|
||||
@ -194,8 +207,8 @@ module OZones
|
||||
#Update the VDC Record
|
||||
begin
|
||||
@vdc.raise_on_save_failure = true
|
||||
@vdc.hosts = host_list
|
||||
@vdc.acls = newacls
|
||||
@vdc.HOSTS = host_list
|
||||
@vdc.ACLS = newacls
|
||||
|
||||
@vdc.save
|
||||
rescue => e
|
||||
@ -218,12 +231,12 @@ module OZones
|
||||
rule_str = Array.new
|
||||
|
||||
# Grant permissions to the group
|
||||
rule_str << "@#{@vdc.group_id} VM+NET+IMAGE+TEMPLATE/* " \
|
||||
rule_str << "@#{@vdc.GROUP_ID} VM+NET+IMAGE+TEMPLATE/* " \
|
||||
"CREATE+INFO_POOL_MINE"
|
||||
|
||||
# Grant permissions to the vdc admin
|
||||
rule_str << "##{@vdc.vdcadmin_id} USER/* CREATE"
|
||||
rule_str << "##{@vdc.vdcadmin_id} USER/@#{@vdc.group_id} " \
|
||||
rule_str << "##{@vdc.VDCADMIN_ID} USER/* CREATE"
|
||||
rule_str << "##{@vdc.VDCADMIN_ID} USER/@#{@vdc.GROUP_ID} " \
|
||||
"MANAGE+DELETE+INFO"
|
||||
|
||||
###############################################################
|
||||
@ -238,12 +251,12 @@ module OZones
|
||||
rule_str = Array.new
|
||||
|
||||
if host_list == nil
|
||||
host_list = @vdc.hosts
|
||||
host_list = @vdc.HOSTS
|
||||
end
|
||||
|
||||
# Grant permissions to use the vdc hosts
|
||||
host_list.split(',').each{|hostid|
|
||||
rule_str << "@#{@vdc.group_id} HOST/##{hostid} USE"
|
||||
rule_str << "@#{@vdc.GROUP_ID} HOST/##{hostid} USE"
|
||||
}
|
||||
|
||||
return rule_str
|
||||
@ -254,7 +267,7 @@ module OZones
|
||||
#######################################################################
|
||||
# Deletes ACLs for the hosts
|
||||
def delete_host_acls
|
||||
host_acls = @vdc.acls.split(',')[HOST_ACL_FIRST_ID..-1]
|
||||
host_acls = @vdc.ACLS.split(',')[HOST_ACL_FIRST_ID..-1]
|
||||
|
||||
if host_acls
|
||||
host_acls.each{|acl|
|
||||
@ -265,7 +278,7 @@ module OZones
|
||||
|
||||
# Delete ACLs
|
||||
def delete_acls
|
||||
@vdc.acls.split(",").each{|acl|
|
||||
@vdc.ACLS.split(",").each{|acl|
|
||||
OpenNebula::Acl.new_with_id(acl.to_i, @client).delete
|
||||
}
|
||||
end
|
||||
@ -276,7 +289,7 @@ module OZones
|
||||
ip.info
|
||||
|
||||
ip.each{|image|
|
||||
image.delete if image['GID'].to_i == @vdc.group_id
|
||||
image.delete if image['GID'].to_i == @vdc.GROUP_ID
|
||||
}
|
||||
end
|
||||
|
||||
@ -286,7 +299,7 @@ module OZones
|
||||
tp.info
|
||||
|
||||
tp.each{|template|
|
||||
template.delete if template['GID'].to_i == @vdc.group_id
|
||||
template.delete if template['GID'].to_i == @vdc.GROUP_ID
|
||||
}
|
||||
end
|
||||
|
||||
@ -296,7 +309,7 @@ module OZones
|
||||
vmp.info
|
||||
|
||||
vmp.each{|vm|
|
||||
vm.delete if vm['GID'].to_i == @vdc.group_id
|
||||
vm.delete if vm['GID'].to_i == @vdc.GROUP_ID
|
||||
}
|
||||
end
|
||||
|
||||
@ -306,7 +319,7 @@ module OZones
|
||||
vnp.info
|
||||
|
||||
vnp.each{|vn|
|
||||
vnp.delete if vn['GID'].to_i == @vdc.group_id
|
||||
vnp.delete if vn['GID'].to_i == @vdc.GROUP_ID
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -24,19 +24,19 @@ module OZones
|
||||
#######################################################################
|
||||
# Data Model for the Zone
|
||||
#######################################################################
|
||||
property :id, Serial
|
||||
property :name, String, :required => true, :unique => true
|
||||
property :onename, String, :required => true
|
||||
property :onepass, String, :required => true
|
||||
property :endpoint, String, :required => true
|
||||
property :sunsendpoint, String
|
||||
property :ID, Serial
|
||||
property :NAME, String, :required => true, :unique => true
|
||||
property :ONENAME, String, :required => true
|
||||
property :ONEPASS, String, :required => true
|
||||
property :ENDPOINT, String, :required => true
|
||||
property :SUNSENDPOINT, String
|
||||
|
||||
has n, :vdcs
|
||||
|
||||
#######################################################################
|
||||
# Constants
|
||||
#######################################################################
|
||||
ZONE_ATTRS = [:onename, :onepass, :endpoint, :name]
|
||||
ZONE_ATTRS = [:ONENAME, :ONEPASS, :ENDPOINT, :NAME]
|
||||
|
||||
#######################################################################
|
||||
# JSON Functions
|
||||
@ -48,7 +48,7 @@ module OZones
|
||||
|
||||
self.all.each{|zone|
|
||||
zonePoolHash["ZONE_POOL"]["ZONE"] <<
|
||||
zone.attributes.merge({:numbervdcs => zone.vdcs.all.size})
|
||||
zone.attributes.merge({:NUMBERVDCS => zone.vdcs.all.size})
|
||||
}
|
||||
|
||||
return zonePoolHash
|
||||
@ -57,10 +57,10 @@ module OZones
|
||||
def to_hash
|
||||
zone_attributes = Hash.new
|
||||
zone_attributes["ZONE"] = attributes
|
||||
zone_attributes["ZONE"][:vdcs] = Array.new
|
||||
zone_attributes["ZONE"][:VDCS] = Array.new
|
||||
|
||||
self.vdcs.all.each{|vdc|
|
||||
zone_attributes["ZONE"][:vdcs]<< vdc.attributes
|
||||
zone_attributes["ZONE"][:VDCS]<< vdc.attributes
|
||||
}
|
||||
|
||||
return zone_attributes
|
||||
@ -69,12 +69,7 @@ module OZones
|
||||
#######################################################################
|
||||
# Zone Data Management
|
||||
#######################################################################
|
||||
def self.create(data)
|
||||
zone_data = Hash.new
|
||||
|
||||
data.each{|key,value|
|
||||
zone_data[key.downcase.to_sym] = value
|
||||
}
|
||||
def self.create(zone_data)
|
||||
|
||||
ZONE_ATTRS.each { |param|
|
||||
if !zone_data[param]
|
||||
@ -84,17 +79,20 @@ module OZones
|
||||
}
|
||||
|
||||
# Digest and check credentials
|
||||
zone_data[:onepass] = Digest::SHA1.hexdigest(zone_data[:onepass])
|
||||
zone_data[:ONEPASS] = Digest::SHA1.hexdigest(zone_data[:ONEPASS])
|
||||
|
||||
rc = OpenNebulaZone::check_oneadmin(zone_data[:onename],
|
||||
zone_data[:onepass],
|
||||
zone_data[:endpoint])
|
||||
$stderr.puts zone_data
|
||||
|
||||
rc = OpenNebulaZone::check_oneadmin(zone_data[:ONENAME],
|
||||
zone_data[:ONEPASS],
|
||||
zone_data[:ENDPOINT])
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return OZones::Error.new("Error: Couldn't create zone. "\
|
||||
"Reason: #{rc.message}")
|
||||
end
|
||||
|
||||
|
||||
# Create the zone
|
||||
begin
|
||||
zone = Zones.new
|
||||
@ -124,8 +122,8 @@ module OZones
|
||||
end
|
||||
|
||||
@client = OpenNebula::Client.new(
|
||||
"#{@zone.onename}:#{@zone.onepass}",
|
||||
@zone.endpoint,
|
||||
"#{@zone.ONENAME}:#{@zone.ONEPASS}",
|
||||
@zone.ENDPOINT,
|
||||
false)
|
||||
end
|
||||
|
||||
|
@ -77,22 +77,16 @@ class OzonesServer
|
||||
############################################################################
|
||||
def create_vdc (body,pr)
|
||||
#Setup POST data
|
||||
data = parse_json(body,"vdc")
|
||||
vdc_data = parse_json_sym(body,:VDC)
|
||||
|
||||
if OpenNebula.is_error?(data)
|
||||
if OpenNebula.is_error?(vdc_data)
|
||||
return [400, OZones::Error.new("Error: Couldn't update vdc. " \
|
||||
"Reason: #{data.message}.").to_json]
|
||||
end
|
||||
|
||||
vdc_data = Hash.new
|
||||
|
||||
data.each{|key,value|
|
||||
vdc_data[key.downcase.to_sym] = value
|
||||
}
|
||||
|
||||
#Get the Zone that will host the VDC. And check resouces
|
||||
zoneid = vdc_data.delete(:zoneid)
|
||||
force = vdc_data.delete(:force)
|
||||
zoneid = vdc_data.delete(:ZONEID)
|
||||
force = vdc_data.delete(:FORCE)
|
||||
|
||||
if !zoneid
|
||||
return [400, OZones::Error.new("Error: Couldn't create vdc. " \
|
||||
@ -106,7 +100,7 @@ class OzonesServer
|
||||
end
|
||||
|
||||
if (!force or force.upcase!="YES") and
|
||||
!host_uniqueness?(zone, vdc_data[:hosts])
|
||||
!host_uniqueness?(zone, vdc_data[:HOSTS])
|
||||
|
||||
return [403, OZones::Error.new("Error: Couldn't create vdc. " \
|
||||
"Hosts are not unique, use force to override").to_json]
|
||||
@ -140,7 +134,7 @@ class OzonesServer
|
||||
|
||||
def create_zone(body, pr)
|
||||
#Setup POST data
|
||||
data = parse_json(body,"zone")
|
||||
data = parse_json_sym(body,:ZONE)
|
||||
|
||||
if OpenNebula.is_error?(data)
|
||||
return [400, OZones::Error.new("Error: Couldn't update vdc. " \
|
||||
@ -162,21 +156,15 @@ class OzonesServer
|
||||
############################################################################
|
||||
def update_vdc(vdc_id, body)
|
||||
#Setup PUT data
|
||||
data = parse_json(body,"vdc")
|
||||
vdc_data = parse_json_sym(body,:VDC)
|
||||
|
||||
if OpenNebula.is_error?(data)
|
||||
if OpenNebula.is_error?(vdc_data)
|
||||
return [400, OZones::Error.new("Error: Couldn't update vdc. " \
|
||||
"Reason: #{data.message}.").to_json]
|
||||
end
|
||||
|
||||
vdc_data = Hash.new
|
||||
|
||||
data.each{|key,value|
|
||||
vdc_data[key.downcase.to_sym]=value
|
||||
}
|
||||
|
||||
hosts = vdc_data.delete(:hosts)
|
||||
force = vdc_data.delete(:force)
|
||||
hosts = vdc_data.delete(:HOSTS)
|
||||
force = vdc_data.delete(:FORCE)
|
||||
|
||||
# Check parameters
|
||||
if !hosts
|
||||
@ -260,8 +248,8 @@ class OzonesServer
|
||||
|
||||
all_hosts = ""
|
||||
zone.vdcs.all.each{|vdc|
|
||||
if vdc.hosts != nil and !vdc.hosts.empty? and vdc.id != vdc_id
|
||||
all_hosts << ',' << vdc.hosts
|
||||
if vdc.HOSTS != nil and !vdc.HOSTS.empty? and vdc.id != vdc_id
|
||||
all_hosts << ',' << vdc.HOSTS
|
||||
end
|
||||
}
|
||||
|
||||
|
@ -416,7 +416,7 @@ function hostsListCB(req,list){
|
||||
return;
|
||||
};
|
||||
var host_json = oZones.Helper.pool("HOST",this.ZONE);
|
||||
updateHostsList(req, host_json,'#datatable_agg_hosts',this.ZONE.id,this.ZONE.name);
|
||||
updateHostsList(req, host_json,'#datatable_agg_hosts',this.ZONE.ID,this.ZONE.NAME);
|
||||
updateZonesDashboard("hosts",host_json);
|
||||
});
|
||||
}
|
||||
@ -429,7 +429,7 @@ function vmsListCB(req,list){
|
||||
return;
|
||||
};
|
||||
var vms_json = oZones.Helper.pool("VM",this.ZONE);
|
||||
updateVMsList(req, vms_json,'#datatable_agg_vms',this.ZONE.id,this.ZONE.name);
|
||||
updateVMsList(req, vms_json,'#datatable_agg_vms',this.ZONE.ID,this.ZONE.NAME);
|
||||
updateZonesDashboard("vms",vms_json);
|
||||
});
|
||||
}
|
||||
@ -442,7 +442,7 @@ function vnsListCB(req,list){
|
||||
return;
|
||||
};
|
||||
var vn_json = oZones.Helper.pool("VNET",this.ZONE);
|
||||
updateVNsList(req, vn_json,'#datatable_agg_vnets',this.ZONE.id,this.ZONE.name);
|
||||
updateVNsList(req, vn_json,'#datatable_agg_vnets',this.ZONE.ID,this.ZONE.NAME);
|
||||
updateZonesDashboard("vnets",vn_json);
|
||||
});
|
||||
}
|
||||
@ -455,7 +455,7 @@ function imagesListCB(req,list){
|
||||
return;
|
||||
};
|
||||
var image_json = oZones.Helper.pool("IMAGE",this.ZONE);
|
||||
updateImagesList(req,image_json,'#datatable_agg_images',this.ZONE.id,this.ZONE.name);
|
||||
updateImagesList(req,image_json,'#datatable_agg_images',this.ZONE.ID,this.ZONE.NAME);
|
||||
updateZonesDashboard("images",image_json);
|
||||
});
|
||||
}
|
||||
@ -468,7 +468,7 @@ function usersListCB(req,list){
|
||||
return;
|
||||
};
|
||||
var user_json = oZones.Helper.pool("USER",this.ZONE);
|
||||
updateUsersList(req,user_json,'#datatable_agg_users',this.ZONE.id,this.ZONE.name);
|
||||
updateUsersList(req,user_json,'#datatable_agg_users',this.ZONE.ID,this.ZONE.NAME);
|
||||
updateZonesDashboard("users",user_json);
|
||||
});
|
||||
}
|
||||
@ -481,7 +481,7 @@ function templatesListCB(req,list){
|
||||
return;
|
||||
};
|
||||
var template_json = oZones.Helper.pool("VMTEMPLATE",this.ZONE);
|
||||
updateTemplatesList(req,template_json,'#datatable_agg_templates',this.ZONE.id,this.ZONE.name);
|
||||
updateTemplatesList(req,template_json,'#datatable_agg_templates',this.ZONE.ID,this.ZONE.NAME);
|
||||
updateZonesDashboard("templates",template_json);
|
||||
});
|
||||
}
|
||||
|
@ -224,11 +224,11 @@ function vdcElementArray(vdc_json){
|
||||
var vdc = vdc_json.VDC;
|
||||
|
||||
return [
|
||||
'<input type="checkbox" id="vdc_'+vdc.id+'" name="selected_items" value="'+vdc.id+'"/>',
|
||||
vdc.id,
|
||||
vdc.name,
|
||||
vdc.zones_id,
|
||||
vdc.hosts ? vdc.hosts : "none"
|
||||
'<input type="checkbox" id="vdc_'+vdc.ID+'" name="selected_items" value="'+vdc.ID+'"/>',
|
||||
vdc.ID,
|
||||
vdc.NAME,
|
||||
vdc.ZONES_ID,
|
||||
vdc.HOSTS ? vdc.HOSTS : "none"
|
||||
];
|
||||
}
|
||||
|
||||
@ -253,7 +253,7 @@ function addVDCElement(req,vdc_json){
|
||||
}
|
||||
|
||||
function updateVDCElement(request, vdc_json){
|
||||
var id = vdc_json.VDC.id;
|
||||
var id = vdc_json.VDC.ID;
|
||||
var element = vdcElementArray(vdc_json);
|
||||
updateSingleElement(element,dataTable_vdcs,'#vdc_'+id);
|
||||
}
|
||||
@ -276,36 +276,36 @@ function updateVDCInfo(req,vdc_json){
|
||||
content :
|
||||
'<table id="info_vdc_table" class="info_table">\
|
||||
<thead>\
|
||||
<tr><th colspan="2">Virtual Data Center - '+vdc.name+'</th></tr>\
|
||||
<tr><th colspan="2">Virtual Data Center - '+vdc.NAME+'</th></tr>\
|
||||
</thead>\
|
||||
<tbody>\
|
||||
<tr>\
|
||||
<td class="key_td">ID</td>\
|
||||
<td class="value_td">'+vdc.id+'</td>\
|
||||
<td class="value_td">'+vdc.ID+'</td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td class="key_td">Name</td>\
|
||||
<td class="value_td">'+vdc.name+'</td>\
|
||||
<td class="value_td">'+vdc.NAME+'</td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td class="key_td">Zone ID</td>\
|
||||
<td class="value_td">'+vdc.zones_id+'</td>\
|
||||
<td class="value_td">'+vdc.ZONES_ID+'</td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td class="key_td">Hosts</td>\
|
||||
<td class="value_td">'+(vdc.hosts? vdc.hosts : "none")+'</td>\
|
||||
<td class="value_td">'+(vdc.HOSTS? vdc.HOSTS : "none")+'</td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td class="key_td">Admin name</td>\
|
||||
<td class="value_td">'+vdc.vdcadminname+'</td>\
|
||||
<td class="value_td">'+vdc.VDCADMINNAME+'</td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td class="key_td">Group ID</td>\
|
||||
<td class="value_td">'+vdc.group_id+'</td>\
|
||||
<td class="value_td">'+vdc.GROUP_ID+'</td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td class="key_td">ACLs</td>\
|
||||
<td class="value_td">'+vdc.acls+'</td>\
|
||||
<td class="value_td">'+vdc.ACLS+'</td>\
|
||||
</tr>\
|
||||
</tbody>\
|
||||
</table>'
|
||||
@ -461,16 +461,16 @@ function setupCreateVDCDialog(){
|
||||
};
|
||||
|
||||
var vdc_json = {
|
||||
"vdc" : {
|
||||
"name" : name,
|
||||
"zoneid" : zoneid,
|
||||
"vdcadminname" : vdcadminname,
|
||||
"vdcadminpass" : vdcadminpass,
|
||||
"force" : force
|
||||
"VDC" : {
|
||||
"NAME" : name,
|
||||
"ZONEID" : zoneid,
|
||||
"VDCADMINNAME" : vdcadminname,
|
||||
"VDCADMINPASS" : vdcadminpass,
|
||||
"FORCE" : force
|
||||
}
|
||||
};
|
||||
if (hosts.length){
|
||||
vdc_json["vdc"]["hosts"]=hosts;
|
||||
vdc_json["VDC"]["HOSTS"]=hosts;
|
||||
};
|
||||
|
||||
Sunstone.runAction("VDC.create",vdc_json);
|
||||
@ -549,15 +549,15 @@ function setupUpdateVDCDialog(){
|
||||
};
|
||||
|
||||
var vdc_json = {
|
||||
"vdc" : {
|
||||
"id": id,
|
||||
"force": force,
|
||||
"hosts": hosts
|
||||
"VDC" : {
|
||||
"ID": id,
|
||||
"FORCE": force,
|
||||
"HOSTS": ""
|
||||
}
|
||||
};
|
||||
|
||||
if (hosts.length){
|
||||
vdc_json["vdc"]["hosts"]=hosts;
|
||||
vdc_json["VDC"]["HOSTS"]=hosts;
|
||||
};
|
||||
Sunstone.runAction("VDC.update",id,vdc_json);
|
||||
dialog.dialog('close');
|
||||
|
@ -228,10 +228,10 @@ function zoneElementArray(zone_json){
|
||||
var zone = zone_json.ZONE;
|
||||
|
||||
return [
|
||||
'<input type="checkbox" id="zone_'+zone.id+'" name="selected_items" value="'+zone.id+'"/>',
|
||||
zone.id,
|
||||
zone.name,
|
||||
zone.endpoint
|
||||
'<input type="checkbox" id="zone_'+zone.ID+'" name="selected_items" value="'+zone.ID+'"/>',
|
||||
zone.ID,
|
||||
zone.NAME,
|
||||
zone.ENDPOINT
|
||||
];
|
||||
}
|
||||
|
||||
@ -281,32 +281,32 @@ function updateZoneInfo(req,zone_json){
|
||||
content :
|
||||
'<table id="info_zone_table" class="info_table">\
|
||||
<thead>\
|
||||
<tr><th colspan="2">Zone information - '+zone.name+'</th></tr>\
|
||||
<tr><th colspan="2">Zone information - '+zone.NAME+'</th></tr>\
|
||||
</thead>\
|
||||
<tbody>\
|
||||
<tr>\
|
||||
<td class="key_td">ID</td>\
|
||||
<td class="value_td">'+zone.id+'</td>\
|
||||
<td class="value_td">'+zone.ID+'</td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td class="key_td">Administrator</td>\
|
||||
<td class="value_td">'+zone.onename+'</td>\
|
||||
<td class="value_td">'+zone.ONENAME+'</td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td class="key_td">Password</td>\
|
||||
<td class="value_td">'+zone.onepass+'</td>\
|
||||
<td class="value_td">'+zone.ONEPASS+'</td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td class="key_td">Endpoint</td>\
|
||||
<td class="value_td">'+zone.endpoint+'</td>\
|
||||
<td class="value_td">'+zone.ENDPOINT+'</td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td class="key_td">Sunstone endpoint</td>\
|
||||
<td class="value_td"><a href="'+zone.sunsendpoint+'" target="_blank">'+zone.sunsendpoint+'<span class="ui-icon ui-icon-extlink" style="display:inline-block;" /></a></td>\
|
||||
<td class="value_td">'+ (zone.SUNSENDPOINT.length? '<a href="'+zone.SUNSENDPOINT+'" target="_blank">'+zone.SUNSENDPOINT+'<span class="ui-icon ui-icon-extlink" style="display:inline-block;" /></a>' : "") +'</td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td class="key_td">#VDCs</td>\
|
||||
<td class="value_td">'+zone.vdcs.length+'</td>\
|
||||
<td class="value_td">'+zone.VDCS.length+'</td>\
|
||||
</tr>\
|
||||
</tbody>\
|
||||
</table>'
|
||||
@ -524,12 +524,12 @@ function updateZoneInfo(req,zone_json){
|
||||
/*End init dataTables*/
|
||||
|
||||
//Retrieve pools in the meantime
|
||||
Sunstone.runAction("Zone.host",zone.id);
|
||||
Sunstone.runAction("Zone.vmtemplate",zone.id);
|
||||
Sunstone.runAction("Zone.vms",zone.id);
|
||||
Sunstone.runAction("Zone.vnet",zone.id);
|
||||
Sunstone.runAction("Zone.image",zone.id);
|
||||
Sunstone.runAction("Zone.user",zone.id);
|
||||
Sunstone.runAction("Zone.host",zone.ID);
|
||||
Sunstone.runAction("Zone.vmtemplate",zone.ID);
|
||||
Sunstone.runAction("Zone.vms",zone.ID);
|
||||
Sunstone.runAction("Zone.vnet",zone.ID);
|
||||
Sunstone.runAction("Zone.image",zone.ID);
|
||||
Sunstone.runAction("Zone.user",zone.ID);
|
||||
}
|
||||
|
||||
|
||||
@ -559,12 +559,12 @@ function setupCreateZoneDialog(){
|
||||
}
|
||||
|
||||
var zone_json = {
|
||||
"zone": {
|
||||
"name": name,
|
||||
"endpoint": endpoint,
|
||||
"onename": onename,
|
||||
"onepass": onepass,
|
||||
"sunsendpoint" : sunsendpoint
|
||||
"ZONE": {
|
||||
"NAME": name,
|
||||
"ENDPOINT": endpoint,
|
||||
"ONENAME": onename,
|
||||
"ONEPASS": onepass,
|
||||
"SUNSENDPOINT" : sunsendpoint
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -41,6 +41,22 @@ module OpenNebulaJSON
|
||||
end
|
||||
end
|
||||
|
||||
def parse_json_sym(json_str, root_element)
|
||||
begin
|
||||
parser = JSON.parser.new(json_str, {:symbolize_names => true})
|
||||
hash = parser.parse
|
||||
|
||||
if hash.has_key?(root_element)
|
||||
return hash[root_element]
|
||||
end
|
||||
|
||||
Error.new("Error parsing JSON:\ root element not present")
|
||||
|
||||
rescue => e
|
||||
Error.new(e.message)
|
||||
end
|
||||
end
|
||||
|
||||
def template_to_str(attributes, indent=true)
|
||||
if indent
|
||||
ind_enter="\n"
|
||||
|
Loading…
x
Reference in New Issue
Block a user