From 5e4b7264f5f2213d60b0206bc3594845943f0ca1 Mon Sep 17 00:00:00 2001 From: Rodrigo Estebanez Date: Tue, 18 Jun 2013 18:56:19 +0200 Subject: [PATCH] catalog and catalogs model --- lib/fog/vcloudng/compute.rb | 2 ++ lib/fog/vcloudng/models/compute/catalog.rb | 24 ++++++++++++++++ lib/fog/vcloudng/models/compute/catalogs.rb | 28 +++++++++++++++++++ .../vcloudng/models/compute/organization.rb | 11 ++++++++ .../vcloudng/parsers/compute/get_catalog.rb | 3 ++ 5 files changed, 68 insertions(+) create mode 100644 lib/fog/vcloudng/models/compute/catalog.rb create mode 100644 lib/fog/vcloudng/models/compute/catalogs.rb diff --git a/lib/fog/vcloudng/compute.rb b/lib/fog/vcloudng/compute.rb index 66ac23306..637bc7182 100644 --- a/lib/fog/vcloudng/compute.rb +++ b/lib/fog/vcloudng/compute.rb @@ -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 diff --git a/lib/fog/vcloudng/models/compute/catalog.rb b/lib/fog/vcloudng/models/compute/catalog.rb new file mode 100644 index 000000000..3f0429c0d --- /dev/null +++ b/lib/fog/vcloudng/models/compute/catalog.rb @@ -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 \ No newline at end of file diff --git a/lib/fog/vcloudng/models/compute/catalogs.rb b/lib/fog/vcloudng/models/compute/catalogs.rb new file mode 100644 index 000000000..e0cd51b03 --- /dev/null +++ b/lib/fog/vcloudng/models/compute/catalogs.rb @@ -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 \ No newline at end of file diff --git a/lib/fog/vcloudng/models/compute/organization.rb b/lib/fog/vcloudng/models/compute/organization.rb index c2bbe55f2..844308ac4 100644 --- a/lib/fog/vcloudng/models/compute/organization.rb +++ b/lib/fog/vcloudng/models/compute/organization.rb @@ -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 diff --git a/lib/fog/vcloudng/parsers/compute/get_catalog.rb b/lib/fog/vcloudng/parsers/compute/get_catalog.rb index 4b1fa80a6..cb4876b7b 100644 --- a/lib/fog/vcloudng/parsers/compute/get_catalog.rb +++ b/lib/fog/vcloudng/parsers/compute/get_catalog.rb @@ -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