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 L{Types} @param host: Option host string to poll for sources """ if not support.check_conn_support(conn, support.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 support.is_error_nosupport(e): return [] raise
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 support.check_conn_support(conn, support.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 support.is_error_nosupport(e): return [] raise
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) try: try: self._install_finished = False t.start() if meter: 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) if meter: meter.end(self.capacity) logging.debug("Storage volume '%s' install complete." % self.name) return vol except libvirt.libvirtError, e: if support.is_error_nosupport(e): raise RuntimeError("Libvirt version does not support " "storage cloning.") except Exception, e: raise RuntimeError("Couldn't create storage volume " "'%s': '%s'" % (self.name, str(e)))
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 support.is_error_nosupport(e): logging.warn("Could not set autostart flag: libvirt " "connection does not support autostart.") else: raise e
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) try: try: self._install_finished = False t.start() if meter: 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) if meter: meter.end(self.capacity) logging.debug("Storage volume '%s' install complete." % self.name) return vol except libvirt.libvirtError, e: if support.is_error_nosupport(e): raise RuntimeError("Libvirt version does not support " "storage cloning.") except Exception, e: raise RuntimeError("Couldn't create storage volume " "'%s': '%s'" % (self.name, str(e)))