class Vra::CatalogItem
Attributes
client[R]
id[R]
Public Class Methods
dump_template(client, id)
click to toggle source
@param [String] - the id of the catalog item @param [Vra::Client] - a vra client object @return [String] - returns a json string of the catalog template
# 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)
click to toggle source
@param [Vra::Client] - a vra client object @param [String] - the directory path to write the files to @param [Boolean] - set to true if you wish the file name to be the id of the catalog item @return [Array] - a array of all the files that were generated
# 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
new(client, opts)
click to toggle source
# 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
write_template(client, id, filename = nil)
click to toggle source
@param client [Vra::Client] - a vra client object @param id [String] - the id of the catalog item @param filename [String] - the name of the file you want to output the template to if left blank, will default to the id of the item @note outputs the catalog template to a file in serialized format
# 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) filename rescue Vra::Exception::HTTPError => e raise e end end
Public Instance Methods
blueprint_id()
click to toggle source
# File lib/vra/catalog_item.rb, line 86 def blueprint_id @catalog_item_data["providerBinding"]["bindingId"] end
description()
click to toggle source
# File lib/vra/catalog_item.rb, line 56 def description @catalog_item_data["description"] end
fetch_catalog_item()
click to toggle source
# 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()
click to toggle source
# File lib/vra/catalog_item.rb, line 52 def name @catalog_item_data["name"] end
organization()
click to toggle source
# File lib/vra/catalog_item.rb, line 64 def organization return {} if @catalog_item_data["organization"].nil? @catalog_item_data["organization"] end
status()
click to toggle source
# File lib/vra/catalog_item.rb, line 60 def status @catalog_item_data["status"] end
subtenant_id()
click to toggle source
# File lib/vra/catalog_item.rb, line 78 def subtenant_id organization["subtenantRef"] end
subtenant_name()
click to toggle source
# File lib/vra/catalog_item.rb, line 82 def subtenant_name organization["subtenantLabel"] end
tenant_id()
click to toggle source
# File lib/vra/catalog_item.rb, line 70 def tenant_id organization["tenantRef"] end
tenant_name()
click to toggle source
# File lib/vra/catalog_item.rb, line 74 def tenant_name organization["tenantLabel"] end