Class: VCloudCloud::Steps::InsertCatalogMedia

Inherits:
VCloudCloud::Step show all
Defined in:
lib/cloud/vcloud/steps/insert_catalog_media.rb

Instance Attribute Summary

Attributes inherited from VCloudCloud::Step

#client, #state

Instance Method Summary collapse

Methods inherited from VCloudCloud::Step

#cleanup, #initialize

Constructor Details

This class inherits a constructor from VCloudCloud::Step

Instance Method Details

#perform(name, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cloud/vcloud/steps/insert_catalog_media.rb', line 4

def perform(name, &block)
  media, _ = client.media name
  params = VCloudSdk::Xml::WrapperFactory.create_instance 'MediaInsertOrEjectParams'
  params.media_href = media.href
  vm = state[:vm]
  @logger.debug "INSERTMEDIA #{media.name} into VM #{vm.name}"
  client.timed_loop do
    media = client.reload media
    vm = client.reload vm
    if media.running_tasks.empty? && media.prerunning_tasks.empty?
      client.invoke_and_wait :post, vm.insert_media_link,
              :payload => params,
              :headers => { :content_type => VCloudSdk::Xml::MEDIA_TYPE[:MEDIA_INSERT_EJECT_PARAMS] }
      break
    else
      media = client.wait_entity media
    end
  end
  state[:vm] = client.reload vm
end

#rollbackObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cloud/vcloud/steps/insert_catalog_media.rb', line 25

def rollback
  vm = state[:vm]
  name = vm.name

  catalog_media = client.catalog_item :media, name, VCloudSdk::Xml::MEDIA_TYPE[:MEDIA]
  # return if doesn't exist
  return unless catalog_media
  media = client.resolve_link catalog_media.entity
  params = VCloudSdk::Xml::WrapperFactory.create_instance 'MediaInsertOrEjectParams'
  params.media_href = media.href
  vm = state[:vm]
  client.timed_loop do
    media = client.reload media
    vm = client.reload vm
    if media.running_tasks.empty?
      client.invoke_and_wait :post, vm.eject_media_link,
                             :payload => params,
                             :headers => { :content_type => VCloudSdk::Xml::MEDIA_TYPE[:MEDIA_INSERT_EJECT_PARAMS] }
      break
    else
      media = client.wait_entity media
    end
  end
end