Class: VCloudCloud::Steps::SaveAgentEnv

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

Constant Summary collapse

NO_ERROR_SHELL_OUTPUT_HACK =
'no-error'

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



37
38
39
# File 'lib/cloud/vcloud/steps/save_agent_env.rb', line 37

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

#perform(&block) ⇒ Object



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

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 && >&2 printf #{NO_ERROR_SHELL_OUTPUT_HACK}"
  _, stdout, stderr = Open3.popen3("#{command}")
  message = "command `#{command}`: output `#{stdout.readlines}`"
  @logger.debug message
  raise message unless stderr.readlines.include? NO_ERROR_SHELL_OUTPUT_HACK

   = 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