From d00b00a07214e82e05064d4fc785ecc27676bbbb Mon Sep 17 00:00:00 2001 From: sergiojvg Date: Fri, 24 May 2019 05:24:23 -0500 Subject: [PATCH] F #964: Allow FILES_DS for vCenter (#3351) --- .../lib/vcenter_driver/virtual_machine.rb | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb index 93ebc1cb6e1..ffe80c0098a 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb @@ -1454,6 +1454,15 @@ def sync(deploy = {}) # get token and context extraconfig += extraconfig_context + # get file_ds + if (files = one_item["TEMPLATE/CONTEXT/FILES_DS"]) + file_id = 0 + files.split(' ').each do |file| + extraconfig += extraconfig_file(file, file_id) + file_id += 1 + end + end + # vnc configuration (for config_array hash) extraconfig += extraconfig_vnc @@ -1478,6 +1487,18 @@ def sync(deploy = {}) @item.ReconfigVM_Task(:spec => spec).wait_for_completion end + def extraconfig_file(file, id) + path, name = file.split(':') + name = name.gsub('\'', '') + file_content = Base64.encode64(File.read(path)) + file_content.prepend("#{name}\n") + + [ + { :key => "guestinfo.opennebula.file.#{id}", + :value => file_content } + ] + end + def extraconfig_context context_text = "# Context variables generated by OpenNebula\n" one_item.each('TEMPLATE/CONTEXT/*') do |context_element|