Module: Chef::Knife::VcCatalogCommon

Included in:
VcCatalogItemShow, VcCatalogShow, VcOvfUpload
Defined in:
lib/chef/knife/common/vc_catalog_common.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(includer) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/chef/knife/common/vc_catalog_common.rb', line 22

def self.included(includer)
  includer.class_eval do
    option :vcloud_catalog,
           :long => "--catalog CATALOG_NAME",
           :description => "Catalog to whom Catalog Item belongs",
           :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_catalog] = key }
  end
end

Instance Method Details

#get_catalog(catalog_arg) ⇒ Object

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
38
39
40
# File 'lib/chef/knife/common/vc_catalog_common.rb', line 31

def get_catalog(catalog_arg)
  catalog = nil
  org_name = locate_org_option

  org = connection.get_organization_by_name org_name
  catalog = connection.get_catalog_by_name org, catalog_arg

  raise ArgumentError, "Catalog #{catalog_arg} not found" unless catalog
  catalog
end

#get_catalog_item(catalog_item_arg) ⇒ Object

Raises:

  • (ArgumentError)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/chef/knife/common/vc_catalog_common.rb', line 42

def get_catalog_item(catalog_item_arg)
  item = nil
  catalog_name = locate_config_value(:vcloud_catalog)

  unless catalog_name
    notice_msg("--catalog not specified, assuming CATALOG_ITEM is an ID")
    item = connection.get_catalog_item catalog_item_arg
  else
    catalog = get_catalog(catalog_name)
    item = connection.get_catalog_item_by_name catalog[:id], catalog_item_arg
  end
  raise ArgumentError, "Catalog Item #{catalog_item_arg} not found" unless item
  item
end