Class: VCloudCloud::Steps::SaveAgentEnv

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

Instance Attribute Summary

Attributes inherited from VCloudCloud::Step

#client, #state

Instance Method Summary collapse

Methods inherited from VCloudCloud::Step

#initialize, #rollback

Constructor Details

This class inherits a constructor from VCloudCloud::Step

Instance Method Details

#cleanupObject



34
35
36
# File 'lib/cloud/vcloud/steps/save_agent_env.rb', line 34

def cleanup
  FileUtils.remove_entry_secure state[:tmpdir] if state[:tmpdir]
end

#perform(&block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cloud/vcloud/steps/save_agent_env.rb', line 7

def perform(&block)
  vm = client.reload state[:vm]
   = "#{vm..href}/#{state[:env_metadata_key]}"

  @logger.debug "AGENT_ENV #{vm.urn} #{state[:env].inspect}"

  env_json = Yajl::Encoder.encode state[:env]
  @logger.debug "ENV.ISO Content: #{env_json}"
  tmpdir = state[:tmpdir] = Dir.mktmpdir
  env_path = File.join tmpdir, 'env'
  iso_path = File.join tmpdir, 'env.iso'
  File.open(env_path, 'w') { |f| f.write env_json }
  command = "#{create_iso_cmd} -o #{iso_path} #{env_path} 2>&1"
  output = `#{command}`
  message = "command `#{command}`: exited with stats: `#{$?.exitstatus}`: and output `#{output}`"
  @logger.debug message
  raise message unless $?.success?

   = VCloudSdk::Xml::WrapperFactory.create_instance 'MetadataValue'
  .value = env_json
  client.invoke_and_wait :put, ,
            :payload => ,
            :headers => { :content_type => VCloudSdk::Xml::MEDIA_TYPE[:METADATA_ITEM_VALUE] }
  state[:vm] = client.reload state[:vm]
  state[:iso] = iso_path
end