Class: VCloudCloud::Steps::CreateMedia

Inherits:
VCloudCloud::Step show all
Defined in:
lib/cloud/vcloud/steps/create_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, iso, image_type, storage_profile, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/cloud/vcloud/steps/create_media.rb', line 4

def perform(name, iso, image_type, storage_profile, &block)
  # get the file properties
  media_file = File.new iso, 'rb'

  # create the media item
  params = VCloudSdk::Xml::WrapperFactory.create_instance 'Media'
  params.name = name
  params.size = media_file.stat.size
  params.image_type = image_type
  params.storage_profile = storage_profile
  media = client.invoke :post, client.vdc.upload_media_link, :payload => params

  # cache the newly created item
  state[:media] = media
end

#rollbackObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cloud/vcloud/steps/create_media.rb', line 20

def rollback
  # get the time to delete
  media = state[:media]

  client.timed_loop do
    media = client.reload media
    if media.running_tasks.empty?
      # delete the item
      client.invoke_and_wait :delete, media.delete_link
      break
    else
      # need to wait for pending tasks to complete
      media = client.wait_entity media
    end
  end

  # remove the item from the state
  state.delete :media
end