mirror of
				https://github.com/retspen/webvirtcloud
				synced 2025-07-31 12:41:08 +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
				
			
		|  | @ -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): | ||||
|  |  | |||
|  | @ -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): | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue