def _update_guests_stats(self): vm_list = self.get_list() for name in vm_list: try: dom = VMModel.get_vm(name, self.conn) vm_uuid = dom.UUIDString() info = dom.info() state = DOM_STATE_MAP[info[0]] if state != 'running': stats[vm_uuid] = {} continue if stats.get(vm_uuid, None) is None: stats[vm_uuid] = {} timestamp = time.time() prevStats = stats.get(vm_uuid, {}) seconds = timestamp - prevStats.get('timestamp', 0) stats[vm_uuid].update({'timestamp': timestamp}) self._get_percentage_cpu_usage(vm_uuid, info, seconds) self._get_network_io_rate(vm_uuid, dom, seconds) self._get_disk_io_rate(vm_uuid, dom, seconds) except Exception as e: # VM might be deleted just after we get the list. # This is OK, just skip. kimchi_log.debug('Error processing VM stats: %s', e.message) continue
def _clean_scan(self, pool_name): try: conn = self.conn.get() pool = conn.storagePoolLookupByName(pool_name.encode("utf-8")) pool.destroy() with self.objstore as session: session.delete('scanning', pool_name) except Exception, e: err = "Exception %s occured when cleaning scan result" kimchi_log.debug(err % e.message)
def swupdate(self, *name): try: swupdate = SoftwareUpdate() except: raise OperationFailed('KCHPKGUPD0004E') pkgs = swupdate.getNumOfUpdates() if pkgs == 0: raise OperationFailed('KCHPKGUPD0001E') kimchi_log.debug('Host is going to be updated.') taskid = add_task('', swupdate.doUpdate, self.objstore, None) return self.task.lookup(taskid)
def _do_deep_scan(self, params): scan_params = dict(ignore_list=[]) scan_params['scan_path'] = params['path'] params['type'] = 'dir' for pool in self.get_list(): try: res = self.storagepool_lookup(pool) if res['state'] == 'active': scan_params['ignore_list'].append(res['path']) except Exception, e: err = "Exception %s occured when get ignore path" kimchi_log.debug(err % e.message)
def clean_stale(self, window=SCAN_TTL): """ Clear scan pools generated before time window, Clear all scan pools if window is -1. """ try: now = time.time() clean_list = glob.glob("/tmp/kimchi-scan-*") for d in clean_list: transient_pool = \ os.path.basename(d).replace('kimchi-scan-', '')[0: -6] if now - os.path.getmtime(d) > window: shutil.rmtree(d) self.clean_cb(transient_pool) except OSError as e: msg = "Exception %s occured when cleaning stale pool, ignore" kimchi_log.debug(msg % e.message)
def lookup(self, name): pool = self.get_storagepool(name, self.conn) info = pool.info() autostart = True if pool.autostart() else False persistent = True if pool.isPersistent() else False xml = pool.XMLDesc(0) path = xpath_get_text(xml, "/pool/target/path")[0] pool_type = xpath_get_text(xml, "/pool/@type")[0] source = self._get_storage_source(pool_type, xml) # FIXME: nfs workaround - prevent any libvirt operation # for a nfs if the corresponding NFS server is down. if pool_type == 'netfs' and not self._nfs_status_online(pool): kimchi_log.debug( "NFS pool %s is offline, reason: NFS " "server %s is unreachable.", name, source['addr']) # Mark state as '4' => inaccessible. info[0] = 4 # skip calculating volumes nr_volumes = 0 else: nr_volumes = self._get_storagepool_vols_num(pool) res = { 'state': POOL_STATE_MAP[info[0]], 'path': path, 'source': source, 'type': pool_type, 'autostart': autostart, 'capacity': info[1], 'allocated': info[2], 'available': info[3], 'nr_volumes': nr_volumes, 'persistent': persistent } if not pool.isPersistent(): # Deal with deep scan generated pool try: with self.objstore as session: task_id = session.get('scanning', name) res['task_id'] = str(task_id) res['type'] = 'kimchi-iso' except NotFoundError: # User created normal pool pass return res
def lookup(self, name): pool = self.get_storagepool(name, self.conn) info = pool.info() autostart = True if pool.autostart() else False persistent = True if pool.isPersistent() else False xml = pool.XMLDesc(0) path = xmlutils.xpath_get_text(xml, "/pool/target/path")[0] pool_type = xmlutils.xpath_get_text(xml, "/pool/@type")[0] source = self._get_storage_source(pool_type, xml) # FIXME: nfs workaround - prevent any libvirt operation # for a nfs if the corresponding NFS server is down. if pool_type == 'netfs' and not self._nfs_status_online(pool): kimchi_log.debug("NFS pool %s is offline, reason: NFS " "server %s is unreachable.", name, source['addr']) # Mark state as '4' => inaccessible. info[0] = 4 # skip calculating volumes nr_volumes = 0 else: nr_volumes = self._get_storagepool_vols_num(pool) res = {'state': POOL_STATE_MAP[info[0]], 'path': path, 'source': source, 'type': pool_type, 'autostart': autostart, 'capacity': info[1], 'allocated': info[2], 'available': info[3], 'nr_volumes': nr_volumes, 'persistent': persistent} if not pool.isPersistent(): # Deal with deep scan generated pool try: with self.objstore as session: task_id = session.get('scanning', name) res['task_id'] = str(task_id) res['type'] = 'kimchi-iso' except NotFoundError: # User created normal pool pass return res
def probe(self): if not self.bootable: raise IsoFormatError("KCHISO0002E", {'filename': self.path}) matcher = Matcher(self.volume_id) for d, v, regex in iso_dir: if matcher.search(regex): distro = d if hasattr(v, '__call__'): version = v(matcher) else: version = v return (distro, version) msg = "probe_iso: Unable to identify ISO %s with Volume ID: %s" kimchi_log.debug(msg, self.path, self.volume_id) return ('unknown', 'unknown')
def get_list(self): iso_volumes = [] conn = self.conn.get() pools = conn.listStoragePools() pools += conn.listDefinedStoragePools() for pool_name in pools: try: pool = StoragePoolModel.get_storagepool(pool_name, self.conn) pool.refresh(0) volumes = pool.listVolumes() except Exception, e: # Skip inactive pools kimchi_log.debug("Shallow scan: skipping pool %s because of " "error: %s", (pool_name, e.message)) continue for volume in volumes: res = self.storagevolume.lookup(pool_name, volume) if res['format'] == 'iso': res['name'] = '%s' % volume iso_volumes.append(res)
def get_list(self): iso_volumes = [] conn = self.conn.get() pools = conn.listStoragePools() pools += conn.listDefinedStoragePools() for pool_name in pools: try: pool = StoragePoolModel.get_storagepool(pool_name, self.conn) pool.refresh(0) volumes = pool.listVolumes() except Exception, e: # Skip inactive pools kimchi_log.debug("Shallow scan: skipping pool %s because of " "error: %s", (pool_name, e.message)) continue for volume in volumes: res = self.storagevolume.lookup(pool_name, volume.decode("utf-8")) if res['format'] == 'iso': res['name'] = '%s' % volume iso_volumes.append(res)