Class: VCloudSdk::Catalog
- Inherits:
-
Object
- Object
- VCloudSdk::Catalog
- Includes:
- Infrastructure
- Defined in:
- lib/ruby_vcloud_sdk/catalog.rb
Constant Summary
Constants included from Infrastructure
Infrastructure::ERROR_STATUSES, Infrastructure::SUCCESS_STATUS
Instance Method Summary collapse
- #delete_all_items ⇒ Object
- #delete_item(name, item_type = nil) ⇒ Object
-
#find_item(name, item_type = nil) ⇒ Object
Find catalog item from catalog by name and type.
- #find_vapp_template_by_name(name) ⇒ Object
- #id ⇒ Object
-
#initialize(session, link) ⇒ Catalog
constructor
A new instance of Catalog.
- #instantiate_vapp_template(template_name, vdc_name, vapp_name, description = nil, disk_locality = nil) ⇒ Object
- #item_exists?(name, item_type = nil) ⇒ Boolean
- #items ⇒ Object
- #list_items ⇒ Object
- #name ⇒ Object
- #upload_media(vdc_name, media_name, file, storage_profile_name = nil, image_type = "iso") ⇒ Object
- #upload_vapp_template(vdc_name, template_name, directory, storage_profile_name = nil) ⇒ Object
Constructor Details
#initialize(session, link) ⇒ Catalog
10 11 12 13 |
# File 'lib/ruby_vcloud_sdk/catalog.rb', line 10 def initialize(session, link) @session = session @link = link end |
Instance Method Details
#delete_all_items ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/ruby_vcloud_sdk/catalog.rb', line 63 def delete_all_items admin_xml.catalog_items.map do |link| Config.logger.info "Deleting catalog item \"#{link.name}\"" delete_item_by_link(link) end nil end |
#delete_item(name, item_type = nil) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/ruby_vcloud_sdk/catalog.rb', line 54 def delete_item(name, item_type = nil) link = find_item_link(name) item = VCloudSdk::CatalogItem.new(@session, link) check_item_type(item, item_type) delete_item_by_link(link) nil end |
#find_item(name, item_type = nil) ⇒ Object
Find catalog item from catalog by name and type. If item_type is set to nil, returns catalog item as long as its name match. Raises an exception if catalog is not found. Raises ObjectNotFoundError if an item matching the name and type is not found. Otherwise, returns the catalog item.
40 41 42 43 44 45 |
# File 'lib/ruby_vcloud_sdk/catalog.rb', line 40 def find_item(name, item_type = nil) link = find_item_link(name) item = VCloudSdk::CatalogItem.new(@session, link) check_item_type(item, item_type) item end |
#find_vapp_template_by_name(name) ⇒ Object
128 129 130 |
# File 'lib/ruby_vcloud_sdk/catalog.rb', line 128 def find_vapp_template_by_name(name) find_item(name, Xml::MEDIA_TYPE[:VAPP_TEMPLATE]) end |
#id ⇒ Object
19 20 21 |
# File 'lib/ruby_vcloud_sdk/catalog.rb', line 19 def id @link.href_id end |
#instantiate_vapp_template(template_name, vdc_name, vapp_name, description = nil, disk_locality = nil) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/ruby_vcloud_sdk/catalog.rb', line 132 def instantiate_vapp_template(template_name, vdc_name, vapp_name, description = nil, disk_locality = nil) instantiate_vapp_params = create_instantiate_vapp_params( template_name, vapp_name, description, disk_locality) vdc = find_vdc_by_name vdc_name vapp = connection.post(vdc.instantiate_vapp_template_link, instantiate_vapp_params) vapp.running_tasks.each do |task| begin monitor_task(task, @session.time_limit[:instantiate_vapp_template]) rescue ApiError => e Config.logger.error(e, "Instantiate vApp template #{vapp_name} " + "failed. Task #{task.operation} did not complete successfully.") raise e end end vdc = find_vdc_by_name vdc_name # Refresh information about vdc vdc.find_vapp_by_name vapp_name end |
#item_exists?(name, item_type = nil) ⇒ Boolean
47 48 49 50 51 52 |
# File 'lib/ruby_vcloud_sdk/catalog.rb', line 47 def item_exists?(name, item_type = nil) items.any? do |item| item.name == name && (item_type.nil? || item.type == item_type) end end |
#items ⇒ Object
23 24 25 26 27 |
# File 'lib/ruby_vcloud_sdk/catalog.rb', line 23 def items admin_xml.catalog_items.map do |item| VCloudSdk::CatalogItem.new(@session, item) end end |
#list_items ⇒ Object
29 30 31 32 33 |
# File 'lib/ruby_vcloud_sdk/catalog.rb', line 29 def list_items admin_xml.catalog_items.map do |item_link| item_link.name end end |
#name ⇒ Object
15 16 17 |
# File 'lib/ruby_vcloud_sdk/catalog.rb', line 15 def name admin_xml.name end |
#upload_media(vdc_name, media_name, file, storage_profile_name = nil, image_type = "iso") ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ruby_vcloud_sdk/catalog.rb', line 71 def upload_media( vdc_name, media_name, file, storage_profile_name = nil, image_type = "iso") if item_exists?(media_name) fail CloudError, "Catalog Item '#{media_name}' already exists in catalog #{name}" end Config.logger.info %Q{ Uploading file #{file} as media #{media_name} of type #{image_type} to catalog #{name}, storage profile #{storage_profile_name}, vdc #{vdc_name} } media_file = file.is_a?(String) ? File.new(file, "rb") : file vdc = find_vdc_by_name vdc_name storage_profile = vdc.storage_profile_xml_node storage_profile_name media = upload_media_params media_name, vdc, media_file, image_type, storage_profile media = upload_media_file media, media_file add_item(media) end |
#upload_vapp_template(vdc_name, template_name, directory, storage_profile_name = nil) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/ruby_vcloud_sdk/catalog.rb', line 102 def upload_vapp_template( vdc_name, template_name, directory, storage_profile_name = nil) if item_exists?(template_name) fail "vApp template '#{template_name}' already exists in catalog #{name}" end vdc = find_vdc_by_name vdc_name storage_profile = vdc.storage_profile_xml_node storage_profile_name Config.logger.info "Uploading vApp #{template_name} to #{vdc.name}" vapp_template = upload_vapp_template_params(template_name, vdc, storage_profile) vapp_template = upload_vapp_files(vapp_template, ovf_directory(directory)) validate_vapp_template_tasks vapp_template Config.logger.info %Q{ Template #{template_name} uploaded, adding to catalog #{name}. } add_item(vapp_template) end |