Class: VSphereCloud::AgentEnv
- Inherits:
-
Object
- Object
- VSphereCloud::AgentEnv
show all
- Includes:
- RetryBlock, VimSdk
- Defined in:
- lib/cloud/vsphere/agent_env.rb
Constant Summary
Constants included
from VimSdk
VimSdk::BASE_VERSION, VimSdk::DYNAMIC_TYPES, VimSdk::SOAP_BODY_END, VimSdk::SOAP_BODY_START, VimSdk::SOAP_BODY_TAG, VimSdk::SOAP_END, VimSdk::SOAP_ENVELOPE_END, VimSdk::SOAP_ENVELOPE_START, VimSdk::SOAP_ENVELOPE_TAG, VimSdk::SOAP_FAULT_TAG, VimSdk::SOAP_HEADER_END, VimSdk::SOAP_HEADER_START, VimSdk::SOAP_HEADER_TAG, VimSdk::SOAP_NAMESPACE_MAP, VimSdk::SOAP_START, VimSdk::VERSION1, VimSdk::XMLNS_SOAPENC, VimSdk::XMLNS_SOAPENV, VimSdk::XMLNS_VMODL_BASE, VimSdk::XMLNS_XSD, VimSdk::XMLNS_XSI, VimSdk::XML_ENCODING, VimSdk::XML_HEADER
Instance Method Summary
collapse
Methods included from RetryBlock
#retry_block, #retry_with_timeout
Constructor Details
#initialize(client, file_provider, cloud_searcher) ⇒ AgentEnv
Returns a new instance of AgentEnv.
6
7
8
9
10
|
# File 'lib/cloud/vsphere/agent_env.rb', line 6
def initialize(client, file_provider, cloud_searcher)
@client = client
@file_provider = file_provider
@cloud_searcher = cloud_searcher
end
|
Instance Method Details
#clean_env(vm) ⇒ Object
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/cloud/vsphere/agent_env.rb', line 48
def clean_env(vm)
cdrom = @client.get_cdrom_device(vm)
env_iso_folder = env_iso_folder(cdrom)
return unless env_iso_folder
datacenter = @client.find_parent(vm, Vim::Datacenter)
@client.delete_path(datacenter, File.join(env_iso_folder, 'env.json'))
@client.delete_path(datacenter, File.join(env_iso_folder, 'env.iso'))
end
|
#env_iso_folder(cdrom_device) ⇒ Object
43
44
45
46
|
# File 'lib/cloud/vsphere/agent_env.rb', line 43
def env_iso_folder(cdrom_device)
return unless cdrom_device && cdrom_device.backing.respond_to?(:file_name)
File.dirname(cdrom_device.backing.file_name)
end
|
#get_current_env(vm, datacenter_name) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/cloud/vsphere/agent_env.rb', line 12
def get_current_env(vm, datacenter_name)
cdrom = @client.get_cdrom_device(vm)
env_iso_folder = env_iso_folder(cdrom)
return unless env_iso_folder
datastore_name = cdrom.backing.datastore.name
datastore_pattern = Regexp.escape(datastore_name)
result = env_iso_folder.match(/\[#{datastore_pattern}\] (.*)/)
raise Bosh::Clouds::CloudError.new("Could not find matching datastore name '#{datastore_name}'") unless result
env_path = result[1]
contents = @file_provider.fetch_file(datacenter_name, datastore_name, "#{env_path}/env.json")
raise Bosh::Clouds::CloudError.new("Unable to load env.json from '#{env_path}/env.json'") unless contents
JSON.load(contents)
end
|
#set_env(vm, location, env) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/cloud/vsphere/agent_env.rb', line 29
def set_env(vm, location, env)
env_json = JSON.dump(env)
disconnect_cdrom(vm)
clean_env(vm)
@file_provider.upload_file(location[:datacenter], location[:datastore], "#{location[:vm]}/env.json", env_json)
@file_provider.upload_file(location[:datacenter], location[:datastore], "#{location[:vm]}/env.iso", generate_env_iso(env_json))
datastore = @cloud_searcher.get_managed_object(Vim::Datastore, name: location[:datastore])
file_name = "[#{location[:datastore]}] #{location[:vm]}/env.iso"
update_cdrom_env(vm, datastore, file_name)
end
|