1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-06 12:58:18 +03:00

Feature #1726: Metadata can be forced into .vmx files

(cherry picked from commit 83330906574692813dae20d96946d51260dcdd90)

Conflicts:
	src/vmm/LibVirtDriverVMware.cc
This commit is contained in:
C12G Support Team 2013-01-15 18:34:57 +01:00 committed by Tino Vazquez
parent 069c2878c8
commit 9ec4399f08
2 changed files with 64 additions and 12 deletions

View File

@ -77,6 +77,7 @@ int LibVirtDriver::deployment_description_vmware(
const VectorAttribute * raw;
string data;
string default_raw;
string data_vmx;
// ------------------------------------------------------------------------
@ -447,6 +448,9 @@ int LibVirtDriver::deployment_description_vmware(
{
data = raw->vector_value("DATA");
file << "\t" << data << endl;
data_vmx = raw->vector_value("DATA_VMX");
file << "\t<metadata>" << data_vmx << "</metadata>" << endl;
}
}

View File

@ -17,6 +17,8 @@
require "scripts_common"
require 'yaml'
require "CommandManager"
require 'rexml/document'
include REXML
class VMwareDriver
# -------------------------------------------------------------------------#
@ -48,6 +50,7 @@ class VMwareDriver
conf = YAML::load(File.read(CONF_FILE))
@uri = conf[:libvirt_uri].gsub!('@HOST@', host)
@host = host
@user = conf[:username]
if conf[:password] and !conf[:password].empty?
@ -180,7 +183,9 @@ class VMwareDriver
# ------------------------------------------------------------------------ #
def restore(checkpoint)
begin
vm_folder=VAR_LOCATION + "/vms/" + File.basename(File.dirname(checkpoint))
vm_folder=VAR_LOCATION <<
"/vms/" <<
File.basename(File.dirname(checkpoint))
dfile=`ls -1 #{vm_folder}/deployment*|tail -1`
dfile.strip!
rescue => e
@ -268,7 +273,7 @@ class VMwareDriver
cmd = "#{BIN_LOCATION}/tty_expect -u #{@user} -p #{@pass} #{command}"
end
#Performs a action usgin libvirt
#Performs a action usign libvirt
def do_action(cmd, log=true)
rc = LocalCommand.run(esx_cmd(cmd))
@ -281,6 +286,20 @@ class VMwareDriver
end
end
#Performs a remote action using ssh
def do_ssh_action(cmd, log=true)
rc = SSHCommand.run("'#{cmd}'", @host)
if rc.code == 0
return [true, rc.stdout]
else
err = "Error executing: #{cmd} on host: #{@host} " <<
"err: #{rc.stderr} out: #{rc.stdout}"
OpenNebula.log_error(err) if log
return [false, rc.code]
end
end
# Undefines a domain in the ESX hypervisor
def undefine_domain(id)
rc, info = do_action("virsh -c #{@uri} undefine #{id}")
@ -312,6 +331,35 @@ class VMwareDriver
deploy_id.strip!
dfile_hash = Document.new(File.open(dfile).read)
metadata = XPath.first(dfile_hash, "//metadata")
if metadata
# Get the ds_id for system_ds from the first disk
metadata = metadata.text
disk = XPath.first(dfile_hash, "//disk").text
source = XPath.first(dfile_hash, "//disk/source").attributes['file']
ds_id = source.match(/^\[(.*)\](.*)/)[1]
name = XPath.first(dfile_hash, "//name").text
vm_id = name.match(/^one-(.*)/)[1]
# Reconstruct path to vmx
path_to_vmx = "/vmfs/volumes/#{ds_id}/#{vm_id}/disk.0/#{name}.vmx"
# Create temp file with metadata
File.open("/tmp/one-tmp-file", 'w') {|f|
f.write(metadata.gsub("\\n","\n"))
}
`scp /tmp/one-tmp-file #{@host}:/tmp`
# Add metadata to .vmx file
cmd = "cat /tmp/one-tmp-file >> #{path_to_vmx}"
do_ssh_action(cmd)
end
return deploy_id
end