Class: Vra::CatalogItem
- Inherits:
-
Object
- Object
- Vra::CatalogItem
- Defined in:
- lib/vra/catalog_item.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
-
.dump_template(client, id) ⇒ String
-
returns a json string of the catalog template.
-
-
.dump_templates(client, dir_name = "vra_templates", use_id = false) ⇒ Array[String]
-
a array of all the files that were generated.
-
-
.write_template(client, id, filename = nil) ⇒ Object
if left blank, will default to the id of the item.
Instance Method Summary collapse
- #blueprint_id ⇒ Object
- #description ⇒ Object
- #fetch_catalog_item ⇒ Object
-
#initialize(client, opts) ⇒ CatalogItem
constructor
A new instance of CatalogItem.
- #name ⇒ Object
- #organization ⇒ Object
- #status ⇒ Object
- #subtenant_id ⇒ Object
- #subtenant_name ⇒ Object
- #tenant_id ⇒ Object
- #tenant_name ⇒ Object
Constructor Details
#initialize(client, opts) ⇒ CatalogItem
Returns a new instance of CatalogItem.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vra/catalog_item.rb', line 26 def initialize(client, opts) @client = client @id = opts[:id] @catalog_item_data = opts[:data] if @id.nil? && @catalog_item_data.nil? raise ArgumentError, "must supply an id or a catalog item data hash" end if !@id.nil? && !@catalog_item_data.nil? raise ArgumentError, "must supply an id OR a catalog item data hash, not both" end if @catalog_item_data.nil? fetch_catalog_item else @id = @catalog_item_data["id"] end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
25 26 27 |
# File 'lib/vra/catalog_item.rb', line 25 def client @client end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
25 26 27 |
# File 'lib/vra/catalog_item.rb', line 25 def id @id end |
Class Method Details
.dump_template(client, id) ⇒ String
Returns - returns a json string of the catalog template.
93 94 95 96 |
# File 'lib/vra/catalog_item.rb', line 93 def self.dump_template(client, id) response = client.http_get("/catalog-service/api/consumer/entitledCatalogItems/#{id}/requests/template") response.body end |
.dump_templates(client, dir_name = "vra_templates", use_id = false) ⇒ Array[String]
Returns - a array of all the files that were generated.
120 121 122 123 124 125 126 127 128 |
# File 'lib/vra/catalog_item.rb', line 120 def self.dump_templates(client, dir_name = "vra_templates", use_id = false) FileUtils.mkdir_p(dir_name) unless File.exist?(dir_name) client.catalog.entitled_items.map do |c| id = use_id ? c.id : c.name.tr(" ", "_") filename = File.join(dir_name, "#{id}.json").downcase write_template(client, c.id, filename) filename end end |
.write_template(client, id, filename = nil) ⇒ Object
Note:
outputs the catalog template to a file in serialized format
if left blank, will default to the id of the item
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/vra/catalog_item.rb', line 103 def self.write_template(client, id, filename = nil) filename ||= "#{id}.json" begin contents = dump_template(client, id) data = JSON.parse(contents) pretty_contents = JSON.pretty_generate(data) File.write(filename, pretty_contents) return filename rescue Vra::Exception::HTTPError => e raise e end end |
Instance Method Details
#blueprint_id ⇒ Object
86 87 88 |
# File 'lib/vra/catalog_item.rb', line 86 def blueprint_id @catalog_item_data["providerBinding"]["bindingId"] end |
#description ⇒ Object
56 57 58 |
# File 'lib/vra/catalog_item.rb', line 56 def description @catalog_item_data["description"] end |
#fetch_catalog_item ⇒ Object
46 47 48 49 50 |
# File 'lib/vra/catalog_item.rb', line 46 def fetch_catalog_item @catalog_item_data = client.get_parsed("/catalog-service/api/consumer/catalogItems/#{id}") rescue Vra::Exception::HTTPNotFound raise Vra::Exception::NotFound, "catalog ID #{id} does not exist" end |
#name ⇒ Object
52 53 54 |
# File 'lib/vra/catalog_item.rb', line 52 def name @catalog_item_data["name"] end |
#organization ⇒ Object
64 65 66 67 68 |
# File 'lib/vra/catalog_item.rb', line 64 def organization return {} if @catalog_item_data["organization"].nil? @catalog_item_data["organization"] end |
#status ⇒ Object
60 61 62 |
# File 'lib/vra/catalog_item.rb', line 60 def status @catalog_item_data["status"] end |
#subtenant_id ⇒ Object
78 79 80 |
# File 'lib/vra/catalog_item.rb', line 78 def subtenant_id organization["subtenantRef"] end |
#subtenant_name ⇒ Object
82 83 84 |
# File 'lib/vra/catalog_item.rb', line 82 def subtenant_name organization["subtenantLabel"] end |
#tenant_id ⇒ Object
70 71 72 |
# File 'lib/vra/catalog_item.rb', line 70 def tenant_id organization["tenantRef"] end |
#tenant_name ⇒ Object
74 75 76 |
# File 'lib/vra/catalog_item.rb', line 74 def tenant_name organization["tenantLabel"] end |