mirror of
https://github.com/retspen/webvirtcloud
synced 2025-07-31 12:41:08 +00:00
Libxml2 converted to lxml, django framework upgrade to 1.11.x and some bug fixes
This commit is contained in:
parent
beea57189c
commit
ace30ca952
16 changed files with 265 additions and 106 deletions
|
|
@ -444,8 +444,8 @@ class wvmConnect(object):
|
|||
def get_net_device(self):
|
||||
netdevice = []
|
||||
def get_info(ctx):
|
||||
dev_type = util.get_xpath(ctx, '/device/capability/@type')
|
||||
interface = util.get_xpath(ctx, '/device/capability/interface')
|
||||
dev_type = util.get_xpath('/device/capability/@type')
|
||||
interface = util.get_xpath('/device/capability/interface')
|
||||
return (dev_type, interface)
|
||||
for dev in self.wvm.listAllDevices(0):
|
||||
xml = dev.XMLDesc(0)
|
||||
|
|
@ -456,17 +456,17 @@ class wvmConnect(object):
|
|||
|
||||
def get_host_instances(self):
|
||||
vname = {}
|
||||
def get_info(ctx):
|
||||
mem = util.get_xpath(ctx, "/domain/currentMemory")
|
||||
def get_info(doc):
|
||||
mem = util.get_xpath(doc, "/domain/currentMemory")
|
||||
mem = int(mem) / 1024
|
||||
cur_vcpu = util.get_xpath(ctx, "/domain/vcpu/@current")
|
||||
cur_vcpu = util.get_xpath(doc, "/domain/vcpu/@current")
|
||||
if cur_vcpu:
|
||||
vcpu = cur_vcpu
|
||||
else:
|
||||
vcpu = util.get_xpath(ctx, "/domain/vcpu")
|
||||
title = util.get_xpath(ctx, "/domain/title")
|
||||
vcpu = util.get_xpath(doc, "/domain/vcpu")
|
||||
title = util.get_xpath(doc, "/domain/title")
|
||||
title = title if title else ''
|
||||
description = util.get_xpath(ctx, "/domain/description")
|
||||
description = util.get_xpath(doc, "/domain/description")
|
||||
description = description if description else ''
|
||||
return (mem, vcpu, title, description)
|
||||
for name in self.get_instances():
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@ from vrtManager.connection import wvmConnect
|
|||
from vrtManager.util import get_xml_path
|
||||
|
||||
|
||||
def cpu_version(ctx):
|
||||
for info in ctx.xpathEval('/sysinfo/processor/entry'):
|
||||
elem = info.xpathEval('@name')[0].content
|
||||
def cpu_version(doc):
|
||||
for info in doc.xpath('/sysinfo/processor/entry'):
|
||||
elem = info.xpath('@name')[0]
|
||||
if elem == 'version':
|
||||
return info.content
|
||||
return info
|
||||
return 'Unknown'
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -203,10 +203,10 @@ class wvmInstance(wvmConnect):
|
|||
|
||||
def get_net_device(self):
|
||||
def get_mac_ipaddr(net, mac_host):
|
||||
def fixed(ctx):
|
||||
for net in ctx.xpathEval('/network/ip/dhcp/host'):
|
||||
mac = net.xpathEval('@mac')[0].content
|
||||
host = net.xpathEval('@ip')[0].content
|
||||
def fixed(doc):
|
||||
for net in doc.xpath('/network/ip/dhcp/host'):
|
||||
mac = net.xpath('@mac')[0]
|
||||
host = net.xpath('@ip')[0]
|
||||
if mac == mac_host:
|
||||
return host
|
||||
return None
|
||||
|
|
@ -215,9 +215,9 @@ class wvmInstance(wvmConnect):
|
|||
|
||||
def networks(ctx):
|
||||
result = []
|
||||
for net in ctx.xpathEval('/domain/devices/interface'):
|
||||
mac_host = net.xpathEval('mac/@address')[0].content
|
||||
nic_host = net.xpathEval('source/@network|source/@bridge|source/@dev|target/@dev')[0].content
|
||||
for net in ctx.xpath('/domain/devices/interface'):
|
||||
mac_host = net.xpath('mac/@address')[0]
|
||||
nic_host = net.xpath('source/@network|source/@bridge|source/@dev|target/@dev')[0]
|
||||
try:
|
||||
net = self.get_network(nic_host)
|
||||
ip = get_mac_ipaddr(net, mac_host)
|
||||
|
|
@ -229,7 +229,7 @@ class wvmInstance(wvmConnect):
|
|||
return util.get_xml_path(self._XMLDesc(0), func=networks)
|
||||
|
||||
def get_disk_device(self):
|
||||
def disks(ctx):
|
||||
def disks(doc):
|
||||
result = []
|
||||
dev = None
|
||||
volume = None
|
||||
|
|
@ -237,13 +237,14 @@ class wvmInstance(wvmConnect):
|
|||
src_fl = None
|
||||
disk_format = None
|
||||
disk_size = None
|
||||
for disk in ctx.xpathEval('/domain/devices/disk'):
|
||||
device = disk.xpathEval('@device')[0].content
|
||||
|
||||
for disk in doc.xpath('/domain/devices/disk'):
|
||||
device = disk.xpath('@device')[0]
|
||||
if device == 'disk':
|
||||
try:
|
||||
dev = disk.xpathEval('target/@dev')[0].content
|
||||
src_fl = disk.xpathEval('source/@file|source/@dev|source/@name|source/@volume')[0].content
|
||||
disk_format = disk.xpathEval('driver/@type')[0].content
|
||||
dev = disk.xpath('target/@dev')[0]
|
||||
src_fl = disk.xpath('source/@file|source/@dev|source/@name|source/@volume')[0]
|
||||
disk_format = disk.xpath('driver/@type')[0]
|
||||
try:
|
||||
vol = self.get_volume_by_path(src_fl)
|
||||
volume = vol.name()
|
||||
|
|
@ -263,19 +264,19 @@ class wvmInstance(wvmConnect):
|
|||
return util.get_xml_path(self._XMLDesc(0), func=disks)
|
||||
|
||||
def get_media_device(self):
|
||||
def disks(ctx):
|
||||
def disks(doc):
|
||||
result = []
|
||||
dev = None
|
||||
volume = None
|
||||
storage = None
|
||||
src_fl = None
|
||||
for media in ctx.xpathEval('/domain/devices/disk'):
|
||||
device = media.xpathEval('@device')[0].content
|
||||
for media in doc.xpath('/domain/devices/disk'):
|
||||
device = media.xpath('@device')[0]
|
||||
if device == 'cdrom':
|
||||
try:
|
||||
dev = media.xpathEval('target/@dev')[0].content
|
||||
dev = media.xpath('target/@dev')
|
||||
try:
|
||||
src_fl = media.xpathEval('source/@file')[0].content
|
||||
src_fl = media.xpath('source/@file')
|
||||
vol = self.get_volume_by_path(src_fl)
|
||||
volume = vol.name()
|
||||
stg = vol.storagePoolLookupByVolume()
|
||||
|
|
@ -487,8 +488,7 @@ class wvmInstance(wvmConnect):
|
|||
return socket
|
||||
|
||||
def get_console_type(self):
|
||||
console_type = util.get_xml_path(self._XMLDesc(0),
|
||||
"/domain/devices/graphics/@type")
|
||||
console_type = util.get_xml_path(self._XMLDesc(0),"/domain/devices/graphics/@type")
|
||||
return console_type
|
||||
|
||||
def set_console_type(self, console_type):
|
||||
|
|
|
|||
|
|
@ -166,11 +166,11 @@ class wvmNetwork(wvmConnect):
|
|||
return bool(util.get_xml_path(xml, "/network/ip/dhcp/bootp/@file"))
|
||||
|
||||
def get_mac_ipaddr(self):
|
||||
def network(ctx):
|
||||
def network(doc):
|
||||
result = []
|
||||
for net in ctx.xpathEval('/network/ip/dhcp/host'):
|
||||
host = net.xpathEval('@ip')[0].content
|
||||
mac = net.xpathEval('@mac')[0].content
|
||||
for net in doc.xpath('/network/ip/dhcp/host'):
|
||||
host = net.xpath('@ip')[0].text
|
||||
mac = net.xpathEval('@mac')[0].text
|
||||
result.append({'host': host, 'mac': mac})
|
||||
return result
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import random
|
||||
import libxml2
|
||||
import lxml.etree as etree
|
||||
import libvirt
|
||||
import string
|
||||
|
||||
|
|
@ -86,41 +86,43 @@ def get_xml_path(xml, path=None, func=None):
|
|||
of a passed function (receives xpathContext as its only arg)
|
||||
"""
|
||||
doc = None
|
||||
ctx = None
|
||||
#ctx = None
|
||||
result = None
|
||||
|
||||
try:
|
||||
doc = libxml2.parseDoc(xml)
|
||||
ctx = doc.xpathNewContext()
|
||||
#try:
|
||||
doc = etree.fromstring(xml)
|
||||
#ctx = doc.xpathNewContext()
|
||||
if path:
|
||||
result = get_xpath(doc, path)
|
||||
|
||||
if path:
|
||||
result = get_xpath(ctx, path)
|
||||
elif func:
|
||||
result = func(doc)
|
||||
|
||||
elif func:
|
||||
result = func(ctx)
|
||||
|
||||
else:
|
||||
raise ValueError("'path' or 'func' is required.")
|
||||
finally:
|
||||
if doc:
|
||||
doc.freeDoc()
|
||||
if ctx:
|
||||
ctx.xpathFreeContext()
|
||||
else:
|
||||
raise ValueError("'path' or 'func' is required.")
|
||||
#finally:
|
||||
#if doc:
|
||||
# doc.freeDoc()
|
||||
#if ctx:
|
||||
# ctx.xpathFreeContext()
|
||||
return result
|
||||
|
||||
|
||||
def get_xpath(ctx, path):
|
||||
def get_xpath(doc, path):
|
||||
result = None
|
||||
ret = ctx.xpathEval(path)
|
||||
|
||||
ret = doc.xpath(path)
|
||||
if ret is not None:
|
||||
if type(ret) == list:
|
||||
if len(ret) >= 1:
|
||||
result = ret[0].content
|
||||
if hasattr(ret[0],'text'):
|
||||
result = ret[0].text
|
||||
else:
|
||||
result = ret[0]
|
||||
else:
|
||||
result = ret
|
||||
|
||||
return result
|
||||
|
||||
return result
|
||||
|
||||
def pretty_mem(val):
|
||||
val = int(val)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue