def domain_by_name(self, name): """ Lookup and return a libvirt domain by name. """ try: return self.connection.lookupByName(name) except libvirt.libvirtError, e: raise_exception(e)
def uuid(self): """ Returns the UUID string """ try: return self.resource.UUIDString() except libvirt.libvirtError, e: raise_exception(e)
def domain_by_id(self, identifier): """ Lookup and return a libvirt domain by ID. """ try: return self.connection.lookupByID(identifier) except libvirt.libvirtError, e: raise_exception(e)
def domain_by_uuid(self, uuid): """ Lookup and return a libvirt domain by UUID string. """ try: return self.connection.lookupByUUIDString(uuid) except libvirt.libvirtError, e: raise_exception(e)
def name(self): """ Returns the domain name """ try: return self.resource.name() except libvirt.libvirtError, e: raise_exception(e)
def domain_event(self, callback, domain=None): """ Registers an event callback """ try: self.connection.domainEventRegister(callback, domain.resource) except libvirt.libvirtError, e: raise_exception(e)
def create(self): """ Creates the domain. """ try: self.resource.create() except libvirt.libvirtError, e: raise_exception(e)
def capabilities(self): """ Return the capabilities XML for the libvirt connection. """ try: return self.connection.getCapabilities() except libvirt.libvirtError, e: raise_exception(e)
def destroy(self): """ Destroys the domain. """ try: self.resource.destroy() except libvirt.libvirtError, e: raise_exception(e)
def domain_define(self, xml): """ Defines a new domain, or redefines an existing domain using the given XML string. """ try: return self.connection.defineXML(xml) except libvirt.libvirtError, e: raise_exception(e)
def is_shutoff(self): """ Returns True if the domain is shutoff """ try: state = self.resource.state(0) return state == libvirt.VIR_DOMAIN_SHUTOFF except libvirt.libvirtError, e: raise_exception(e)
def is_crashed(self): """ Returns True if the domain is crashed """ try: state = self.resource.state(0) return state == libvirt.VIR_DOMAIN_CRASHED except libvirt.libvirtError, e: raise_exception(e)
def is_shutdown(self): """ Returns True if the domain is shutting down """ try: state = self.resource.state(0) return state == libvirt.VIR_DOMAIN_SHUTDOWN except libvirt.libvirtError, e: raise_exception(e)
def is_blocked(self): """ Returns True if the domain is blocked """ try: state = self.resource.state(0) return state == libvirt.VIR_DOMAIN_BLOCKED except libvirt.libvirtError, e: raise_exception(e)
def is_running(self): """ Returns True if the domain is running """ try: state = self.resource.state(0) return state == libvirt.VIR_DOMAIN_RUNNING except libvirt.libvirtError, e: raise_exception(e)
def domains(self): """ Returns all libvirt domains in a generator. """ try: for domain_id in self.connection.listDomainsID(): yield self.domain_by_id(domain_id) for domain_name in self.connection.listDefinedDomains(): yield self.domain_by_name(domain_name) except libvirt.libvirtError, e: raise_exception(e)
def network_by_name(self, name): """ :param name: The network name :type name: ``str`` :rtype: ``libvirt.network`` Lookup and return a libvirt network by name. .. seealso:: :py:meth:`~.network.Network.by_name` """ try: return self.connection.networkLookupByName(name) except libvirt.libvirtError, e: raise_exception(e)
def network_by_uuid(self, uuid): """ :param uuid: The network UUID string :type uuid: ``str`` :rtype: ``libvirt.network`` Lookup and return a libvirt network by UUID string. .. seealso:: :py:meth:`~.network.Network.by_uuid` """ try: return self.connection.networkLookupByUUIDString(uuid) except libvirt.libvirtError, e: raise_exception(e)
def __init__(self, uri=''): try: self.connection = libvirt.open(uri) except libvirt.libvirtError, e: raise_exception(e)