1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[vcloud|compute] introduce organizations

A vcloud usually contains more than one organization which then
contains all the other computing parts (such as vdcs etc.). So far
we keep the old way, to query the first organization by default, but
also allow it to be set.
This commit is contained in:
Peter Meier 2011-09-26 10:54:36 +02:00
parent 9864c78f50
commit 8743df0bd4
3 changed files with 96 additions and 0 deletions

View file

@ -64,6 +64,8 @@ module Fog
PORT = 443
SCHEME = 'https'
attr_writer :default_organization_uri
requires :vcloud_username, :vcloud_password, :vcloud_host
recognizes :vcloud_port, :vcloud_scheme, :vcloud_path, :vcloud_default_vdc
recognizes :provider # remove post deprecation
@ -83,6 +85,8 @@ module Fog
collection :tasks
model :vdc
collection :vdcs
model :organization
collection :organizations
request_path 'fog/vcloud/requests/compute'
request :clone_vapp

View file

@ -0,0 +1,63 @@
module Fog
module Vcloud
class Compute
class Organization < Fog::Vcloud::Model
identity :href
ignore_attributes :xmlns, :xmlns_xsi, :xmlns_xsd
attribute :name
attribute :type
attribute :full_name, :aliases => :FullName
attribute :other_links, :aliases => :Link
def networks
@networks ||= Fog::Vcloud::Compute::Networks.
new( :connection => connection,
:href => href )
end
def servers
@servers ||= Fog::Vcloud::Compute::Servers.
new( :connection => connection,
:href => href )
end
def tasks
load_unless_loaded!
@tasks ||= Fog::Vcloud::Compute::Tasks.
new( :connection => connection,
:href => other_links.find{|l| l[:type] == 'application/vnd.vmware.vcloud.tasksList+xml'}[:href] )
end
def vdcs
@vdcs ||= Fog::Vcloud::Compute::Vdcs.
new( :connection => connection,
:href => href )
end
private
def collection_based_on_type(type, klass = nil)
load_unless_loaded!
test_links = other_links.kind_of?(Array) ? other_links : [other_links]
if link = test_links.detect { |link| link[:type] == type }
case type
when "application/vnd.vmware.vcloud.catalog+xml"
Fog::Vcloud::Compute::Catalog
when "application/vnd.vmware.vcloud.vdc+xml"
Fog::Vcloud::Compute::Vdc
when "application/vnd.vmware.vcloud.network+xml"
Fog::Vcloud::Compute::Network
when "application/vnd.vmware.vcloud.network+xml"
Fog::Vcloud::Compute::Network
end.new( :connection => connection, :href => link[:href] )
else
[ ]
end
end
end
end
end
end

View file

@ -0,0 +1,29 @@
require 'fog/vcloud/models/compute/organization'
module Fog
module Vcloud
class Compute
class Organizations < Collection
model Fog::Vcloud::Compute::Organization
undef_method :create
def all
data = connection.login.body[:Org].select { |org| org[:type] == "application/vnd.vmware.vcloud.org+xml" }
data.each { |org| org.delete_if { |key, value| [:rel].include?(key) } }
load(data)
end
def get(uri)
if data = connection.get_organization(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end