1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

feature #476: vm class to obtain vm attributes

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

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

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'