Example #1
0
    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)
Example #2
0
    def uuid(self):

        """
        Returns the UUID string
        """

        try:
            return self.resource.UUIDString()
        except libvirt.libvirtError, e:
            raise_exception(e)
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
    def name(self):

        """
        Returns the domain name
        """

        try:
            return self.resource.name()
        except libvirt.libvirtError, e:
            raise_exception(e)
Example #6
0
    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)
Example #7
0
    def create(self):

        """
        Creates the domain.
        """

        try:
            self.resource.create()
        except libvirt.libvirtError, e:
            raise_exception(e)
Example #8
0
    def capabilities(self):

        """
        Return the capabilities XML for the libvirt connection.
        """

        try:
            return self.connection.getCapabilities()
        except libvirt.libvirtError, e:
            raise_exception(e)
Example #9
0
    def destroy(self):

        """
        Destroys the domain.
        """

        try:
            self.resource.destroy()
        except libvirt.libvirtError, e:
            raise_exception(e)
Example #10
0
    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)
Example #11
0
    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)
Example #12
0
    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)
Example #13
0
    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)
Example #14
0
    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)
Example #15
0
    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)
Example #16
0
    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)
Example #17
0
    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)
Example #18
0
    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)
Example #19
0
    def __init__(self, uri=''):

        try:
            self.connection = libvirt.open(uri)
        except libvirt.libvirtError, e:
            raise_exception(e)