Class: VCloudCloud::Steps::SaveAgentEnv
Instance Attribute Summary
#client, #state
Instance Method Summary
collapse
#initialize, #rollback
Instance Method Details
#cleanup ⇒ Object
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
|
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]
metadata_link = "#{vm.metadata_link.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?
metadata = VCloudSdk::Xml::WrapperFactory.create_instance 'MetadataValue'
metadata.value = env_json
client.invoke_and_wait :put, metadata_link,
:payload => metadata,
:headers => { :content_type => VCloudSdk::Xml::MEDIA_TYPE[:METADATA_ITEM_VALUE] }
state[:vm] = client.reload state[:vm]
state[:iso] = iso_path
end
|