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

catalog and catalogs model

This commit is contained in:
Rodrigo Estebanez 2013-06-18 18:56:19 +02:00
parent 4966ecc69a
commit 5e4b7264f5
5 changed files with 68 additions and 0 deletions

View file

@ -47,6 +47,8 @@ module Fog
model_path 'fog/vcloudng/models/compute'
model :organization
collection :organizations
model :catalog
collection :catalogs
request_path 'fog/vcloudng/requests/compute'
request :get_organizations

View file

@ -0,0 +1,24 @@
require 'fog/core/model'
module Fog
module Compute
class Vcloudng
class Catalog < Fog::Model
identity :id
attribute :name
attribute :type
attribute :href
attribute :description, :aliases => 'Description'
attribute :is_published, :aliases => 'IsPublished'
def catalog_items
end
end
end
end
end

View file

@ -0,0 +1,28 @@
require 'fog/core/collection'
require 'fog/vcloudng/models/compute/catalog'
module Fog
module Compute
class Vcloudng
class Catalogs < Fog::Collection
model Fog::Compute::Vcloudng::Catalog
attribute :organization
def all
data = service.get_organization(organization.id).body
catalogs = data["Links"].select { |link| link["type"] == "application/vnd.vmware.vcloud.catalog+xml" }
catalogs.each {|catalog| catalog['id'] =catalog['href'].split('/').last }
load(catalogs)
end
def get(catalog_id)
data = service.get_catalog(catalog_id).body
%w(CatalogItems Links).each {|key_to_delete| data.delete(key_to_delete) }
new(data)
end
end
end
end
end

View file

@ -13,6 +13,17 @@ module Fog
attribute :href
attribute :description, :aliases => 'Description'
attribute :links, :aliases => 'Links'
def vdc
end
def catalogs
requires :id
service.catalogs(:organization => self)
end
end
end
end

View file

@ -36,6 +36,9 @@ module Fog
when 'Catalog'
catalog = extract_attributes(attributes)
@response['name'] = catalog['name']
@response['type'] = catalog['type']
@response['href'] = catalog['href']
@response['id'] = catalog['href'].split('/').last
when "Link"
link = extract_attributes(attributes)
@response["Links"] << link