Class: Vra::CatalogItem

Inherits:
Object
  • Object
show all
Defined in:
lib/vra-restapi/catalog_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, opts) ⇒ CatalogItem

Returns a new instance of CatalogItem.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vra-restapi/catalog_item.rb', line 23

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

#clientObject (readonly)

Returns the value of attribute client.



22
23
24
# File 'lib/vra-restapi/catalog_item.rb', line 22

def client
  @client
end

#idObject (readonly)

Returns the value of attribute id.



22
23
24
# File 'lib/vra-restapi/catalog_item.rb', line 22

def id
  @id
end

Instance Method Details

#blueprint_idObject



77
78
79
# File 'lib/vra-restapi/catalog_item.rb', line 77

def blueprint_id
  @catalog_item_data['providerBinding']['bindingId']
end

#descriptionObject



53
54
55
# File 'lib/vra-restapi/catalog_item.rb', line 53

def description
  @catalog_item_data['description']
end

#fetch_catalog_itemObject



43
44
45
46
47
# File 'lib/vra-restapi/catalog_item.rb', line 43

def fetch_catalog_item
  @catalog_item_data = JSON.parse(client.http_get!("/catalog-service/api/consumer/catalogItems/#{id}"))
rescue Vra::Exception::HTTPNotFound
  raise Vra::Exception::NotFound, "catalog ID #{id} does not exist"
end

#nameObject



49
50
51
# File 'lib/vra-restapi/catalog_item.rb', line 49

def name
  @catalog_item_data['name']
end

#statusObject



57
58
59
# File 'lib/vra-restapi/catalog_item.rb', line 57

def status
  @catalog_item_data['status']
end

#subtenant_idObject



69
70
71
# File 'lib/vra-restapi/catalog_item.rb', line 69

def subtenant_id
  @catalog_item_data['organization']['subtenantRef']
end

#subtenant_nameObject



73
74
75
# File 'lib/vra-restapi/catalog_item.rb', line 73

def subtenant_name
  @catalog_item_data['organization']['subtenantLabel']
end

#tenant_idObject



61
62
63
# File 'lib/vra-restapi/catalog_item.rb', line 61

def tenant_id
  @catalog_item_data['organization']['tenantRef']
end

#tenant_nameObject



65
66
67
# File 'lib/vra-restapi/catalog_item.rb', line 65

def tenant_name
  @catalog_item_data['organization']['tenantLabel']
end