Class: VCloudCloud::Steps::EjectCatalogMedia

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

Instance Attribute Summary

Attributes inherited from VCloudCloud::Step

#client, #state

Instance Method Summary collapse

Methods inherited from VCloudCloud::Step

#cleanup, #initialize, #rollback

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
24
25
26
# File 'lib/cloud/vcloud/steps/eject_catalog_media.rb', line 4

def perform(name, &block)
  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]
  @logger.debug "EJECTMEDIA #{media.name} from VM #{vm.name}"
  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
  state[:vm] = client.reload vm
end