feature #476: vm class to obtain vm attributes

This commit is contained in:
Jaime Melis committed 2011-05-20 11:17:47 +02:00
1 parent 0d7eb3c147
commit df3aa7f438
2 files changed
+18 -3

No files matched your search

+2 -1
View File
@@ -5,7 +5,8 @@ module OpenNebulaVLANKVM
def get_info
vminfo = Hash.new
vminfo[:dumpxml] = `#{COMMANDS[:virsh]} dumpxml #{@deploy_id}`
deploy_id = @vm['DEPLOY_ID']
vminfo[:dumpxml] = `#{COMMANDS[:virsh]} dumpxml #{deploy_id} 2>/dev/null`
vminfo.each_key{|k| vminfo[k] = nil if vminfo[k].to_s.strip.empty?}
vminfo
end
+16 -2
View File
@@ -83,12 +83,28 @@ class Nics < Array
end
end
class VM
def initialize(vm_root)
@vm_root = vm_root
end
def [](element)
if @vm_root
val = @vm_root.elements[element]
if val.text
return val.text
end
end
nil
end
end
class OpenNebulaVLAN
attr_reader :vm_info, :hypervisor, :nics
def initialize(vm_tpl, hypervisor=nil)
@vm_root = REXML::Document.new(vm_tpl).root
@vm = VM.new(@vm_root)
@vm_info = Hash.new
if !hypervisor
@@ -96,8 +112,6 @@ class OpenNebulaVLAN
end
@hypervisor = hypervisor
@deploy_id = @vm_root.elements['DEPLOY_ID'].text
case hypervisor
when "kvm"
require 'KVMVLAN'