1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 15:15:22 +00:00

page speed serving enhancements

handle xml doc enhancements
This commit is contained in:
Ing. Jan KRCMAR 2018-02-14 15:22:57 +01:00
parent 9dc9fea2a1
commit 15d7216368
3 changed files with 63 additions and 39 deletions

View file

@ -52,17 +52,17 @@ def instances(request):
def get_userinstances_info(instance):
info = {}
uis = UserInstance.objects.filter(instance=instance)
info['count'] = len(uis)
if len(uis) > 0:
info['count'] = uis.count()
if info['count'] > 0:
info['first_user'] = uis[0]
else:
info['first_user'] = None
return info
def refresh_instance_database(comp, vm, info):
instances_count = Instance.objects.filter(name=vm).count()
if instances_count > 1:
for i in Instance.objects.filter(name=vm):
instances = Instance.objects.filter(name=vm)
if instances.count() > 1:
for i in instances:
user_instances_count = UserInstance.objects.filter(instance=i).count()
if user_instances_count == 0:
addlogmsg(request.user.username, i.name, _("Deleting due to multiple records."))
@ -94,9 +94,10 @@ def instances(request):
if connection_manager.host_is_up(comp.type, comp.hostname):
try:
conn = wvmHostDetails(comp, comp.login, comp.password, comp.type)
if conn.get_host_instances():
all_host_vms[comp.id, comp.name] = conn.get_host_instances()
for vm, info in conn.get_host_instances().items():
host_instances = conn.get_host_instances()
if host_instances:
all_host_vms[comp.id, comp.name] = host_instances
for vm, info in host_instances.items():
refresh_instance_database(comp, vm, info)
conn.close()
@ -182,7 +183,7 @@ def instance(request, compute_id, vname):
messages = []
compute = get_object_or_404(Compute, pk=compute_id)
computes = Compute.objects.all()
computes_count = len(computes)
computes_count = computes.count()
users = User.objects.all().order_by('username')
publickeys = UserSSHKey.objects.filter(user_id=request.user.id)
keymaps = QEMU_KEYMAPS
@ -247,7 +248,7 @@ def instance(request, compute_id, vname):
def check_user_quota(instance, cpu, memory, disk_size):
user_instances = UserInstance.objects.filter(user_id=request.user.id, instance__is_template=False)
instance += len(user_instances)
instance += user_instances.count()
for usr_inst in user_instances:
if connection_manager.host_is_up(usr_inst.instance.compute.type,
usr_inst.instance.compute.hostname):

View file

@ -443,55 +443,71 @@ 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')
return (dev_type, interface)
for dev in self.wvm.listAllDevices(0):
xml = dev.XMLDesc(0)
dev_type = util.get_xml_path(xml, '/device/capability/@type')
(dev_type, interface) = util.get_xml_path(xml, func=get_info)
if dev_type == 'net':
netdevice.append(util.get_xml_path(xml, '/device/capability/interface'))
netdevice.append(interface)
return netdevice
def get_host_instances(self):
vname = {}
for name in self.get_instances():
dom = self.get_instance(name)
mem = util.get_xml_path(dom.XMLDesc(0), "/domain/currentMemory")
def get_info(ctx):
mem = util.get_xpath(ctx, "/domain/currentMemory")
mem = int(mem) / 1024
cur_vcpu = util.get_xml_path(dom.XMLDesc(0), "/domain/vcpu/@current")
cur_vcpu = util.get_xpath(ctx, "/domain/vcpu/@current")
if cur_vcpu:
vcpu = cur_vcpu
else:
vcpu = util.get_xml_path(dom.XMLDesc(0), "/domain/vcpu")
title = util.get_xml_path(dom.XMLDesc(0), "/domain/title")
description = util.get_xml_path(dom.XMLDesc(0), "/domain/description")
vcpu = util.get_xpath(ctx, "/domain/vcpu")
title = util.get_xpath(ctx, "/domain/title")
title = title if title else ''
description = util.get_xpath(ctx, "/domain/description")
description = description if description else ''
return (mem, vcpu, title, description)
for name in self.get_instances():
dom = self.get_instance(name)
xml = dom.XMLDesc(0)
(mem, vcpu, title, description) = util.get_xml_path(xml, func=get_info)
vname[dom.name()] = {
'status': dom.info()[0],
'uuid': dom.UUIDString(),
'vcpu': vcpu,
'memory': mem,
'title': title if title else '',
'description': description if description else '',
'title': title,
'description': description,
}
return vname
def get_user_instances(self, name):
dom = self.get_instance(name)
mem = util.get_xml_path(dom.XMLDesc(0), "/domain/currentMemory")
mem = int(mem) / 1024
cur_vcpu = util.get_xml_path(dom.XMLDesc(0), "/domain/vcpu/@current")
if cur_vcpu:
vcpu = cur_vcpu
else:
vcpu = util.get_xml_path(dom.XMLDesc(0), "/domain/vcpu")
title = util.get_xml_path(dom.XMLDesc(0), "/domain/title")
description = util.get_xml_path(dom.XMLDesc(0), "/domain/description")
xml = dom.XMLDesc(0)
def get_info(ctx):
mem = util.get_xpath(ctx, "/domain/currentMemory")
mem = int(mem) / 1024
cur_vcpu = util.get_xpath(ctx, "/domain/vcpu/@current")
if cur_vcpu:
vcpu = cur_vcpu
else:
vcpu = util.get_xpath(ctx, "/domain/vcpu")
title = util.get_xpath(ctx, "/domain/title")
title = title if title else ''
description = util.get_xpath(ctx, "/domain/description")
description = description if description else ''
return (mem, vcpu, title, description)
(mem, vcpu, title, description) = util.get_xml_path(xml, func=get_info)
return {
'name': dom.name(),
'status': dom.info()[0],
'uuid': dom.UUIDString(),
'vcpu': vcpu,
'memory': mem,
'title': title if title else '',
'description': description if description else '',
'title': title,
'description': description,
}
def close(self):

View file

@ -94,13 +94,7 @@ def get_xml_path(xml, path=None, func=None):
ctx = doc.xpathNewContext()
if path:
ret = ctx.xpathEval(path)
if ret is not None:
if type(ret) == list:
if len(ret) >= 1:
result = ret[0].content
else:
result = ret
result = get_xpath(ctx, path)
elif func:
result = func(ctx)
@ -115,6 +109,19 @@ def get_xml_path(xml, path=None, func=None):
return result
def get_xpath(ctx, path):
result = None
ret = ctx.xpathEval(path)
if ret is not None:
if type(ret) == list:
if len(ret) >= 1:
result = ret[0].content
else:
result = ret
return result
def pretty_mem(val):
val = int(val)
if val > (10 * 1024 * 1024):