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:
parent
9dc9fea2a1
commit
15d7216368
3 changed files with 63 additions and 39 deletions
|
@ -52,17 +52,17 @@ def instances(request):
|
||||||
def get_userinstances_info(instance):
|
def get_userinstances_info(instance):
|
||||||
info = {}
|
info = {}
|
||||||
uis = UserInstance.objects.filter(instance=instance)
|
uis = UserInstance.objects.filter(instance=instance)
|
||||||
info['count'] = len(uis)
|
info['count'] = uis.count()
|
||||||
if len(uis) > 0:
|
if info['count'] > 0:
|
||||||
info['first_user'] = uis[0]
|
info['first_user'] = uis[0]
|
||||||
else:
|
else:
|
||||||
info['first_user'] = None
|
info['first_user'] = None
|
||||||
return info
|
return info
|
||||||
|
|
||||||
def refresh_instance_database(comp, vm, info):
|
def refresh_instance_database(comp, vm, info):
|
||||||
instances_count = Instance.objects.filter(name=vm).count()
|
instances = Instance.objects.filter(name=vm)
|
||||||
if instances_count > 1:
|
if instances.count() > 1:
|
||||||
for i in Instance.objects.filter(name=vm):
|
for i in instances:
|
||||||
user_instances_count = UserInstance.objects.filter(instance=i).count()
|
user_instances_count = UserInstance.objects.filter(instance=i).count()
|
||||||
if user_instances_count == 0:
|
if user_instances_count == 0:
|
||||||
addlogmsg(request.user.username, i.name, _("Deleting due to multiple records."))
|
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):
|
if connection_manager.host_is_up(comp.type, comp.hostname):
|
||||||
try:
|
try:
|
||||||
conn = wvmHostDetails(comp, comp.login, comp.password, comp.type)
|
conn = wvmHostDetails(comp, comp.login, comp.password, comp.type)
|
||||||
if conn.get_host_instances():
|
host_instances = conn.get_host_instances()
|
||||||
all_host_vms[comp.id, comp.name] = conn.get_host_instances()
|
if host_instances:
|
||||||
for vm, info in conn.get_host_instances().items():
|
all_host_vms[comp.id, comp.name] = host_instances
|
||||||
|
for vm, info in host_instances.items():
|
||||||
refresh_instance_database(comp, vm, info)
|
refresh_instance_database(comp, vm, info)
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
|
@ -182,7 +183,7 @@ def instance(request, compute_id, vname):
|
||||||
messages = []
|
messages = []
|
||||||
compute = get_object_or_404(Compute, pk=compute_id)
|
compute = get_object_or_404(Compute, pk=compute_id)
|
||||||
computes = Compute.objects.all()
|
computes = Compute.objects.all()
|
||||||
computes_count = len(computes)
|
computes_count = computes.count()
|
||||||
users = User.objects.all().order_by('username')
|
users = User.objects.all().order_by('username')
|
||||||
publickeys = UserSSHKey.objects.filter(user_id=request.user.id)
|
publickeys = UserSSHKey.objects.filter(user_id=request.user.id)
|
||||||
keymaps = QEMU_KEYMAPS
|
keymaps = QEMU_KEYMAPS
|
||||||
|
@ -247,7 +248,7 @@ def instance(request, compute_id, vname):
|
||||||
|
|
||||||
def check_user_quota(instance, cpu, memory, disk_size):
|
def check_user_quota(instance, cpu, memory, disk_size):
|
||||||
user_instances = UserInstance.objects.filter(user_id=request.user.id, instance__is_template=False)
|
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:
|
for usr_inst in user_instances:
|
||||||
if connection_manager.host_is_up(usr_inst.instance.compute.type,
|
if connection_manager.host_is_up(usr_inst.instance.compute.type,
|
||||||
usr_inst.instance.compute.hostname):
|
usr_inst.instance.compute.hostname):
|
||||||
|
|
|
@ -443,55 +443,71 @@ class wvmConnect(object):
|
||||||
|
|
||||||
def get_net_device(self):
|
def get_net_device(self):
|
||||||
netdevice = []
|
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):
|
for dev in self.wvm.listAllDevices(0):
|
||||||
xml = dev.XMLDesc(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':
|
if dev_type == 'net':
|
||||||
netdevice.append(util.get_xml_path(xml, '/device/capability/interface'))
|
netdevice.append(interface)
|
||||||
return netdevice
|
return netdevice
|
||||||
|
|
||||||
def get_host_instances(self):
|
def get_host_instances(self):
|
||||||
vname = {}
|
vname = {}
|
||||||
for name in self.get_instances():
|
def get_info(ctx):
|
||||||
dom = self.get_instance(name)
|
mem = util.get_xpath(ctx, "/domain/currentMemory")
|
||||||
mem = util.get_xml_path(dom.XMLDesc(0), "/domain/currentMemory")
|
|
||||||
mem = int(mem) / 1024
|
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:
|
if cur_vcpu:
|
||||||
vcpu = cur_vcpu
|
vcpu = cur_vcpu
|
||||||
else:
|
else:
|
||||||
vcpu = util.get_xml_path(dom.XMLDesc(0), "/domain/vcpu")
|
vcpu = util.get_xpath(ctx, "/domain/vcpu")
|
||||||
title = util.get_xml_path(dom.XMLDesc(0), "/domain/title")
|
title = util.get_xpath(ctx, "/domain/title")
|
||||||
description = util.get_xml_path(dom.XMLDesc(0), "/domain/description")
|
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()] = {
|
vname[dom.name()] = {
|
||||||
'status': dom.info()[0],
|
'status': dom.info()[0],
|
||||||
'uuid': dom.UUIDString(),
|
'uuid': dom.UUIDString(),
|
||||||
'vcpu': vcpu,
|
'vcpu': vcpu,
|
||||||
'memory': mem,
|
'memory': mem,
|
||||||
'title': title if title else '',
|
'title': title,
|
||||||
'description': description if description else '',
|
'description': description,
|
||||||
}
|
}
|
||||||
return vname
|
return vname
|
||||||
|
|
||||||
def get_user_instances(self, name):
|
def get_user_instances(self, name):
|
||||||
dom = self.get_instance(name)
|
dom = self.get_instance(name)
|
||||||
mem = util.get_xml_path(dom.XMLDesc(0), "/domain/currentMemory")
|
xml = dom.XMLDesc(0)
|
||||||
mem = int(mem) / 1024
|
def get_info(ctx):
|
||||||
cur_vcpu = util.get_xml_path(dom.XMLDesc(0), "/domain/vcpu/@current")
|
mem = util.get_xpath(ctx, "/domain/currentMemory")
|
||||||
if cur_vcpu:
|
mem = int(mem) / 1024
|
||||||
vcpu = cur_vcpu
|
cur_vcpu = util.get_xpath(ctx, "/domain/vcpu/@current")
|
||||||
else:
|
if cur_vcpu:
|
||||||
vcpu = util.get_xml_path(dom.XMLDesc(0), "/domain/vcpu")
|
vcpu = cur_vcpu
|
||||||
title = util.get_xml_path(dom.XMLDesc(0), "/domain/title")
|
else:
|
||||||
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)
|
||||||
|
(mem, vcpu, title, description) = util.get_xml_path(xml, func=get_info)
|
||||||
return {
|
return {
|
||||||
'name': dom.name(),
|
'name': dom.name(),
|
||||||
'status': dom.info()[0],
|
'status': dom.info()[0],
|
||||||
'uuid': dom.UUIDString(),
|
'uuid': dom.UUIDString(),
|
||||||
'vcpu': vcpu,
|
'vcpu': vcpu,
|
||||||
'memory': mem,
|
'memory': mem,
|
||||||
'title': title if title else '',
|
'title': title,
|
||||||
'description': description if description else '',
|
'description': description,
|
||||||
}
|
}
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
|
|
@ -94,13 +94,7 @@ def get_xml_path(xml, path=None, func=None):
|
||||||
ctx = doc.xpathNewContext()
|
ctx = doc.xpathNewContext()
|
||||||
|
|
||||||
if path:
|
if path:
|
||||||
ret = ctx.xpathEval(path)
|
result = get_xpath(ctx, path)
|
||||||
if ret is not None:
|
|
||||||
if type(ret) == list:
|
|
||||||
if len(ret) >= 1:
|
|
||||||
result = ret[0].content
|
|
||||||
else:
|
|
||||||
result = ret
|
|
||||||
|
|
||||||
elif func:
|
elif func:
|
||||||
result = func(ctx)
|
result = func(ctx)
|
||||||
|
@ -115,6 +109,19 @@ def get_xml_path(xml, path=None, func=None):
|
||||||
return result
|
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):
|
def pretty_mem(val):
|
||||||
val = int(val)
|
val = int(val)
|
||||||
if val > (10 * 1024 * 1024):
|
if val > (10 * 1024 * 1024):
|
||||||
|
|
Loading…
Reference in a new issue