Loading ccnode/common.py +31 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ import re import psutil from subprocess import Popen, PIPE, STDOUT from multiprocessing import cpu_count from platform import platform, machine from platform import platform, machine, system from socket import gethostbyaddr, gethostname from jobs import JobManager Loading Loading @@ -83,6 +83,24 @@ class LocalHost(Host): bios = None return bios def get_chassis_asset(self): ''' ''' asset = None data = open('/sys/class/dmi/id/chassis_asset_tag').read().strip() if data: asset = data return asset def get_chassis_serial(self): ''' ''' serial = None data = open('/sys/class/dmi/id/chassis_serial').read().strip() if data: serial = data return serial def get_name(self): ''' ''' Loading Loading @@ -113,6 +131,18 @@ class LocalHost(Host): pass return result def get_system(self): ''' ''' result = None try: p = system() if p: result = p.lower() except: pass return result def get_uptime(self): ''' ''' Loading ccnode/handlers.py +27 −3 Original line number Diff line number Diff line Loading @@ -71,12 +71,13 @@ class NodeHandler(RpcHandler): 'htype' : self._tag_map_direct('get_hv_type', -1), 'hserial' : self._tag_map_direct('get_hw_serial', -1), 'hvendor' : self._tag_map_direct('get_hw_vendor', -1), 'hmachine' : self._tag_map_direct('get_hw_product', -1), 'hmodel' : self._tag_map_direct('get_hw_product', -1), 'arch' : self._tag_map_direct('get_arch', -1), 'hvm' : self._tag_map_direct('get_hvm_available', -1), 'cpu' : self._tag_map_direct('get_cpu', -1), 'cpucore' : self._tag_map_direct('get_cpu_core', -1), 'cputhread' : self._tag_map_direct('get_cpu_thread', -1), 'cpulogical': self._tag_map_direct('get_cpu_thread', -1), 'chaserial' : self._tag_map_direct('get_chassis_serial', -1), 'chaasset' : self._tag_map_direct('get_chassis_asset', -1), # one day 'hbios' : self._tag_map_direct('get_hw_bios', 24*3600), 'hvver' : self._tag_map_direct('get_hv_version', 24*3600), Loading Loading @@ -124,6 +125,7 @@ class NodeHandler(RpcHandler): # one hour 'cpu' : self._tag_map_direct('get_cpu_core', 3600), 'mem' : self._tag_map_direct('get_mem', 3600), 'memmax' : self._tag_map_direct('get_mem_maxbaloon', 3600), 'vncport' : self._tag_map_direct('get_vnc_port', 3600), # one minute # 5 seconds Loading @@ -136,6 +138,7 @@ class NodeHandler(RpcHandler): } self.VM_TAG_GLOB = { 'disk*' : self._tag_map_helper(self._helper_vm_disk, 3600), 'nic*' : self._tag_map_helper(self._helper_vm_nic, 3600), } # FIXME Loading Loading @@ -248,6 +251,27 @@ class NodeHandler(RpcHandler): result = None return result def _helper_vm_nic(self, vm, tag_name=None, resolve=True): ''' ''' result = {} nics = vm.get_nics() if len(nics): result['nic'] = ' '.join([str(i) for i in range(0, len(nics))]) for nic_id, nic in enumerate(nics): mac = nic.get('mac') if mac: result['nic%i_mac' % nic_id] = str(mac) model = nic.get('model') if model: result['nic%i_model' % nic_id] = str(model) source = nic.get('source') if source: result['nic%i_source' % nic_id] = str(source) if not result: result = None return result def scheduler_run(self): ''' ''' Loading ccnode/libvirtwrapper.py +32 −0 Original line number Diff line number Diff line Loading @@ -716,6 +716,38 @@ class LibvirtVm(VM): pass return volumes def get_nics(self): ''' ''' nics = [] try: xroot = xml.dom.minidom.parseString( self._domain.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE)) xdomain = xroot.getElementsByTagName('domain').pop() xdevices = xdomain.getElementsByTagName('devices').pop() # iter on "interface" devices for xint in xdevices.getElementsByTagName('interface'): nic = {} try: # search for network interfaces if xint.getAttribute('type') in ['bridge']: # mac nic['mac'] = xint.getElementsByTagName('mac').pop()\ .getAttribute('address') # model nic['model'] = xint.getElementsByTagName('model').pop()\ .getAttribute('type') # source nic['source'] = xint.getElementsByTagName('source')\ .pop().getAttribute('bridge') except: pass else: nics.append(nic) except: pass return nics #### helpers Loading Loading
ccnode/common.py +31 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ import re import psutil from subprocess import Popen, PIPE, STDOUT from multiprocessing import cpu_count from platform import platform, machine from platform import platform, machine, system from socket import gethostbyaddr, gethostname from jobs import JobManager Loading Loading @@ -83,6 +83,24 @@ class LocalHost(Host): bios = None return bios def get_chassis_asset(self): ''' ''' asset = None data = open('/sys/class/dmi/id/chassis_asset_tag').read().strip() if data: asset = data return asset def get_chassis_serial(self): ''' ''' serial = None data = open('/sys/class/dmi/id/chassis_serial').read().strip() if data: serial = data return serial def get_name(self): ''' ''' Loading Loading @@ -113,6 +131,18 @@ class LocalHost(Host): pass return result def get_system(self): ''' ''' result = None try: p = system() if p: result = p.lower() except: pass return result def get_uptime(self): ''' ''' Loading
ccnode/handlers.py +27 −3 Original line number Diff line number Diff line Loading @@ -71,12 +71,13 @@ class NodeHandler(RpcHandler): 'htype' : self._tag_map_direct('get_hv_type', -1), 'hserial' : self._tag_map_direct('get_hw_serial', -1), 'hvendor' : self._tag_map_direct('get_hw_vendor', -1), 'hmachine' : self._tag_map_direct('get_hw_product', -1), 'hmodel' : self._tag_map_direct('get_hw_product', -1), 'arch' : self._tag_map_direct('get_arch', -1), 'hvm' : self._tag_map_direct('get_hvm_available', -1), 'cpu' : self._tag_map_direct('get_cpu', -1), 'cpucore' : self._tag_map_direct('get_cpu_core', -1), 'cputhread' : self._tag_map_direct('get_cpu_thread', -1), 'cpulogical': self._tag_map_direct('get_cpu_thread', -1), 'chaserial' : self._tag_map_direct('get_chassis_serial', -1), 'chaasset' : self._tag_map_direct('get_chassis_asset', -1), # one day 'hbios' : self._tag_map_direct('get_hw_bios', 24*3600), 'hvver' : self._tag_map_direct('get_hv_version', 24*3600), Loading Loading @@ -124,6 +125,7 @@ class NodeHandler(RpcHandler): # one hour 'cpu' : self._tag_map_direct('get_cpu_core', 3600), 'mem' : self._tag_map_direct('get_mem', 3600), 'memmax' : self._tag_map_direct('get_mem_maxbaloon', 3600), 'vncport' : self._tag_map_direct('get_vnc_port', 3600), # one minute # 5 seconds Loading @@ -136,6 +138,7 @@ class NodeHandler(RpcHandler): } self.VM_TAG_GLOB = { 'disk*' : self._tag_map_helper(self._helper_vm_disk, 3600), 'nic*' : self._tag_map_helper(self._helper_vm_nic, 3600), } # FIXME Loading Loading @@ -248,6 +251,27 @@ class NodeHandler(RpcHandler): result = None return result def _helper_vm_nic(self, vm, tag_name=None, resolve=True): ''' ''' result = {} nics = vm.get_nics() if len(nics): result['nic'] = ' '.join([str(i) for i in range(0, len(nics))]) for nic_id, nic in enumerate(nics): mac = nic.get('mac') if mac: result['nic%i_mac' % nic_id] = str(mac) model = nic.get('model') if model: result['nic%i_model' % nic_id] = str(model) source = nic.get('source') if source: result['nic%i_source' % nic_id] = str(source) if not result: result = None return result def scheduler_run(self): ''' ''' Loading
ccnode/libvirtwrapper.py +32 −0 Original line number Diff line number Diff line Loading @@ -716,6 +716,38 @@ class LibvirtVm(VM): pass return volumes def get_nics(self): ''' ''' nics = [] try: xroot = xml.dom.minidom.parseString( self._domain.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE)) xdomain = xroot.getElementsByTagName('domain').pop() xdevices = xdomain.getElementsByTagName('devices').pop() # iter on "interface" devices for xint in xdevices.getElementsByTagName('interface'): nic = {} try: # search for network interfaces if xint.getAttribute('type') in ['bridge']: # mac nic['mac'] = xint.getElementsByTagName('mac').pop()\ .getAttribute('address') # model nic['model'] = xint.getElementsByTagName('model').pop()\ .getAttribute('type') # source nic['source'] = xint.getElementsByTagName('source')\ .pop().getAttribute('bridge') except: pass else: nics.append(nic) except: pass return nics #### helpers Loading