def _get_all_stats(self, conn): if not self._all_stats_supported: return {} statflags = 0 if self.config.get_stats_enable_cpu_poll(): statflags |= libvirt.VIR_DOMAIN_STATS_STATE statflags |= libvirt.VIR_DOMAIN_STATS_CPU_TOTAL statflags |= libvirt.VIR_DOMAIN_STATS_VCPU if self.config.get_stats_enable_memory_poll(): statflags |= libvirt.VIR_DOMAIN_STATS_BALLOON if self.config.get_stats_enable_disk_poll(): statflags |= libvirt.VIR_DOMAIN_STATS_BLOCK if self.config.get_stats_enable_net_poll(): statflags |= libvirt.VIR_DOMAIN_STATS_INTERFACE if statflags == 0: return {} ret = {} try: timestamp = time.time() rawallstats = conn.get_backend().getAllDomainStats(statflags, 0) # Reformat the output to be a bit more friendly for dom, domallstats in rawallstats: domallstats["virt-manager.timestamp"] = timestamp ret[dom.UUIDString()] = domallstats except libvirt.libvirtError as err: if util.is_error_nosupport(err): logging.debug("conn does not support getAllDomainStats()") self._all_stats_supported = False else: logging.debug("Error call getAllDomainStats(): %s", err) return ret
def pool_list_from_sources(conn, name, pool_type, host=None): """ Return a list of StoragePool instances built from libvirt's pool source enumeration (if supported). @param conn: Libvirt connection @param name: Name for the new pool @param pool_type: Pool type string from I{Types} @param host: Option host string to poll for sources """ if not conn.check_conn_support(conn.SUPPORT_CONN_FINDPOOLSOURCES): return [] pool_class = StoragePool.get_pool_class(pool_type) pool_inst = pool_class(conn=conn, name=name) if host: source_xml = "<source><host name='%s'/></source>" % host else: source_xml = "<source/>" try: xml = conn.findStoragePoolSources(pool_type, source_xml, 0) except libvirt.libvirtError, e: if util.is_error_nosupport(e): return [] raise
def _try_command(func, args, check_all_error=False): try: func(*args) except libvirt.libvirtError, e: if util.is_error_nosupport(e): return False if check_all_error: return False
def reboot_cb(): no_support = False reboot_err = None try: vm.reboot() except Exception, reboot_err: no_support = util.is_error_nosupport(reboot_err) if not no_support: raise RuntimeError(_("Error rebooting domain: %s" % str(reboot_err)))
def install(self, meter=None): """ Build and install storage volume from xml """ xml = self.get_xml_config() logging.debug("Creating storage volume '%s' with xml:\n%s", self.name, xml) t = threading.Thread(target=self._progress_thread, name="Checking storage allocation", args=(meter,)) t.setDaemon(True) if not meter: meter = urlgrabber.progress.BaseMeter() cloneflags = 0 createflags = 0 if (self.format == "qcow2" and not self.backing_store and not self.conn.is_test() and self.conn.check_support( self.conn.SUPPORT_POOL_METADATA_PREALLOC, self.pool)): createflags |= libvirt.VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA try: self._install_finished = False t.start() meter.start(size=self.capacity, text=_("Allocating '%s'") % self.name) if self.input_vol: vol = self.pool.createXMLFrom(xml, self.input_vol, cloneflags) else: logging.debug("Using vol create flags=%s", createflags) vol = self.pool.createXML(xml, createflags) self._install_finished = True t.join() meter.end(self.capacity) logging.debug("Storage volume '%s' install complete.", self.name) return vol except libvirt.libvirtError, e: if util.is_error_nosupport(e): raise RuntimeError("Libvirt version does not support " "storage cloning.") raise
def _old_mem_stats_helper(self, vm): totalmem = 1 curmem = 0 try: stats = vm.get_backend().memoryStats() totalmem = stats.get("actual", 1) curmem = max(0, totalmem - stats.get("unused", totalmem)) except libvirt.libvirtError as err: if util.is_error_nosupport(err): logging.debug("conn does not support memoryStats") self._mem_stats_supported = False else: logging.debug("Error reading mem stats: %s", err) return totalmem, curmem
def _flag_autostart(self): """ Set the autostart flag for self.domain if the user requested it """ if not self.autostart: return try: self.domain.setAutostart(True) except libvirt.libvirtError, e: if util.is_error_nosupport(e): logging.warn("Could not set autostart flag: libvirt " "connection does not support autostart.") else: raise e
def _populate_initial_state(self): logging.debug("libvirt version=%s", self._backend.local_libvirt_version()) logging.debug("daemon version=%s", self._backend.daemon_version()) logging.debug("conn version=%s", self._backend.conn_version()) logging.debug("%s capabilities:\n%s", self.get_uri(), self.caps.get_xml_config()) self._add_conn_events() # Prime CPU cache self.caps.get_cpu_values("x86_64") try: self._backend.setKeepAlive(20, 1) except Exception, e: if type(e) is not AttributeError and not util.is_error_nosupport(e): raise logging.debug("Connection doesn't support KeepAlive, " "skipping")
def _populate_initial_state(self): logging.debug("libvirt version=%s", self._backend.local_libvirt_version()) logging.debug("daemon version=%s", self._backend.daemon_version()) logging.debug("conn version=%s", self._backend.conn_version()) logging.debug("%s capabilities:\n%s", self.get_uri(), self.caps.get_xml_config()) self._add_conn_events() # Prime CPU cache self.caps.get_cpu_values("x86_64") try: self._backend.setKeepAlive(20, 1) except Exception, e: if (type(e) is not AttributeError and not util.is_error_nosupport(e)): raise logging.debug("Connection doesn't support KeepAlive, " "skipping")
def _get_all_stats(self, conn): if not self._all_stats_supported: return [] stats = [] try: stats = conn.get_backend().getAllDomainStats( libvirt.VIR_DOMAIN_STATS_STATE | libvirt.VIR_DOMAIN_STATS_CPU_TOTAL | libvirt.VIR_DOMAIN_STATS_VCPU | libvirt.VIR_DOMAIN_STATS_BALLOON | libvirt.VIR_DOMAIN_STATS_BLOCK | libvirt.VIR_DOMAIN_STATS_INTERFACE, 0) except libvirt.libvirtError as err: if util.is_error_nosupport(err): logging.debug("conn does not support getAllDomainStats()") self._all_stats_supported = False else: logging.debug("Error call getAllDomainStats(): %s", err) return stats
def _old_disk_stats_helper(self, vm, dev): try: io = vm.get_backend().blockStats(dev) if io: rd = io[1] wr = io[3] return rd, wr except libvirt.libvirtError as err: if util.is_error_nosupport(err): logging.debug("conn does not support blockStats") self._disk_stats_supported = False return 0, 0 logging.debug("Error in blockStats for '%s' dev '%s': %s", vm.get_name(), dev, err) if vm.is_active(): logging.debug("Adding %s to skip list", dev) vm.stats_disk_skip.append(dev) else: logging.debug("Aren't running, don't add to skiplist") return 0, 0
def _old_net_stats_helper(self, vm, dev): try: io = vm.get_backend().interfaceStats(dev) if io: rx = io[0] tx = io[4] return rx, tx except libvirt.libvirtError as err: if util.is_error_nosupport(err): logging.debug("conn does not support interfaceStats") self._net_stats_supported = False return 0, 0 logging.debug("Error in interfaceStats for '%s' dev '%s': %s", vm.get_name(), dev, err) if vm.is_active(): logging.debug("Adding %s to skip list", dev) vm.stats_net_skip.append(dev) else: logging.debug("Aren't running, don't add to skiplist") return 0, 0
def install(self, meter=None): """ Build and install storage volume from xml """ xml = self.get_xml_config() logging.debug("Creating storage volume '%s' with xml:\n%s", self.name, xml) t = threading.Thread(target=self._progress_thread, name="Checking storage allocation", args=(meter,)) t.setDaemon(True) if not meter: meter = urlgrabber.progress.BaseMeter() try: self._install_finished = False t.start() meter.start(size=self.capacity, text=_("Allocating '%s'") % self.name) if self.input_vol: vol = self.pool.createXMLFrom(xml, self.input_vol, 0) else: vol = self.pool.createXML(xml, 0) self._install_finished = True t.join() meter.end(self.capacity) logging.debug("Storage volume '%s' install complete.", self.name) return vol except libvirt.libvirtError, e: if util.is_error_nosupport(e): raise RuntimeError("Libvirt version does not support " "storage cloning.") raise
def _old_disk_stats_helper(self, vm, dev): statslist = self.get_vm_statslist(vm) try: io = vm.get_backend().blockStats(dev) if io: rd = io[1] wr = io[3] return rd, wr except libvirt.libvirtError as err: if util.is_error_nosupport(err): logging.debug("conn does not support blockStats") self._disk_stats_supported = False return 0, 0 logging.debug("Error in blockStats for '%s' dev '%s': %s", vm.get_name(), dev, err) if vm.is_active(): logging.debug("Adding %s to skip list", dev) statslist.stats_disk_skip.append(dev) else: logging.debug("Aren't running, don't add to skiplist") return 0, 0