mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
catalog_items model
This commit is contained in:
parent
5e4b7264f5
commit
b51763596f
3 changed files with 50 additions and 0 deletions
|
@ -49,6 +49,8 @@ module Fog
|
|||
collection :organizations
|
||||
model :catalog
|
||||
collection :catalogs
|
||||
model :catalog_item
|
||||
collection :catalog_items
|
||||
|
||||
request_path 'fog/vcloudng/requests/compute'
|
||||
request :get_organizations
|
||||
|
|
20
lib/fog/vcloudng/models/compute/catalog_item.rb
Normal file
20
lib/fog/vcloudng/models/compute/catalog_item.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Vcloudng
|
||||
|
||||
class CatalogItem < Fog::Model
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :name
|
||||
attribute :type
|
||||
attribute :href
|
||||
attribute :description, :aliases => 'Description'
|
||||
attribute :vapp_template_id
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
28
lib/fog/vcloudng/models/compute/catalog_items.rb
Normal file
28
lib/fog/vcloudng/models/compute/catalog_items.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/vcloudng/models/compute/catalog_item'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Vcloudng
|
||||
|
||||
class CatalogItems < Fog::Collection
|
||||
model Fog::Compute::Vcloudng::CatalogItem
|
||||
|
||||
attribute :catalog
|
||||
|
||||
def all(catalog_id = catalog.id)
|
||||
data = service.get_catalog(catalog_id).body
|
||||
catalog_items = data["CatalogItems"].select { |link| link["type"] == "application/vnd.vmware.vcloud.catalogItem+xml" }
|
||||
catalog_item_ids = catalog_items.map {|catalog_item| catalog_item['id'] }
|
||||
catalog_item_ids.map{ |catalog_item_id| get(catalog_item_id)}
|
||||
end
|
||||
|
||||
def get(catalog_item_id)
|
||||
data = service.get_catalog_item(catalog_item_id).body
|
||||
%w(CatalogItems Entity).each {|key_to_delete| data.delete(key_to_delete) }
|
||||
new(data)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue