You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2014/01/12 23:07:01 UTC

[1/5] git commit: Modify libvirt driver to use consistent method names.

Updated Branches:
  refs/heads/trunk 43c772c38 -> edaff3f8d


Modify libvirt driver to use consistent method names.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/37b8c8bd
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/37b8c8bd
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/37b8c8bd

Branch: refs/heads/trunk
Commit: 37b8c8bd45008c099d6453c478c9245529991ce4
Parents: 43c772c
Author: Tomaz Muraus <to...@apache.org>
Authored: Sun Jan 12 21:54:00 2014 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Sun Jan 12 21:54:00 2014 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/libvirt_driver.py | 29 ++++++++++++-------------
 1 file changed, 14 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/37b8c8bd/libcloud/compute/drivers/libvirt_driver.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/libvirt_driver.py b/libcloud/compute/drivers/libvirt_driver.py
index a6a4309..ac1ec24 100644
--- a/libcloud/compute/drivers/libvirt_driver.py
+++ b/libcloud/compute/drivers/libvirt_driver.py
@@ -37,22 +37,21 @@ class LibvirtNodeDriver(NodeDriver):
     website = 'http://libvirt.org/'
 
     NODE_STATE_MAP = {
-        0: NodeState.TERMINATED,
-        1: NodeState.RUNNING,
-        2: NodeState.PENDING,
-        3: NodeState.TERMINATED,  # paused
-        4: NodeState.TERMINATED,  # shutting down
-        5: NodeState.TERMINATED,
-        6: NodeState.UNKNOWN,  # crashed
-        7: NodeState.UNKNOWN,  # last
+        0: NodeState.TERMINATED,  # no state
+        1: NodeState.RUNNING,  # domain is running
+        2: NodeState.PENDING,  # domain is blocked on resource
+        3: NodeState.TERMINATED,  # domain is paused by user
+        4: NodeState.TERMINATED,  # domain is being shut down
+        5: NodeState.TERMINATED,  # domain is shut off
+        6: NodeState.UNKNOWN,  # domain is crashed
+        7: NodeState.UNKNOWN,  # domain is suspended by guest power management
     }
 
     def __init__(self, uri):
         """
-        :param  uri: URI (required)
+        :param  uri: Hypervisor URI (e.g. vbox:///session, qemu:///system,
+                     etc.).
         :type   uri: ``str``
-
-        :rtype: ``None``
         """
         if not have_libvirt:
             raise RuntimeError('Libvirt driver requires \'libvirt\' Python ' +
@@ -94,7 +93,7 @@ class LibvirtNodeDriver(NodeDriver):
         domain = self._get_domain_for_node(node=node)
         return domain.destroy() == 0
 
-    def ex_start(self, node):
+    def ex_start_node(self, node):
         """
         Start a stopped node.
 
@@ -106,7 +105,7 @@ class LibvirtNodeDriver(NodeDriver):
         domain = self._get_domain_for_node(node=node)
         return domain.create() == 0
 
-    def ex_shutdown(self, node):
+    def ex_shutdown_node(self, node):
         """
         Shutdown a running node.
 
@@ -118,7 +117,7 @@ class LibvirtNodeDriver(NodeDriver):
         domain = self._get_domain_for_node(node=node)
         return domain.shutdown() == 0
 
-    def ex_suspend(self, node):
+    def ex_suspend_node(self, node):
         """
         Suspend a running node.
 
@@ -130,7 +129,7 @@ class LibvirtNodeDriver(NodeDriver):
         domain = self._get_domain_for_node(node=node)
         return domain.suspend() == 0
 
-    def ex_resume(self, node):
+    def ex_resume_node(self, node):
         """
         Resume a suspended node.
 


[2/5] git commit: Modify list_nodes method in the libvirt driver to it returns all nodes (including stopped ones).

Posted by to...@apache.org.
Modify list_nodes method in the libvirt driver to it returns all nodes
(including stopped ones).

Also modify other methods to use domain uuid instead of domain id so those
methods also work on stopped nodes which don't have an id assigned.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/4aeb37c1
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/4aeb37c1
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/4aeb37c1

Branch: refs/heads/trunk
Commit: 4aeb37c123515f38a06e93d4e5c2398bc6eda7b0
Parents: 37b8c8b
Author: Tomaz Muraus <to...@apache.org>
Authored: Sun Jan 12 22:01:32 2014 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Sun Jan 12 22:01:32 2014 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/libvirt_driver.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/4aeb37c1/libcloud/compute/drivers/libvirt_driver.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/libvirt_driver.py b/libcloud/compute/drivers/libvirt_driver.py
index ac1ec24..644902f 100644
--- a/libcloud/compute/drivers/libvirt_driver.py
+++ b/libcloud/compute/drivers/libvirt_driver.py
@@ -61,8 +61,7 @@ class LibvirtNodeDriver(NodeDriver):
         self.connection = libvirt.open(uri)
 
     def list_nodes(self):
-        domain_ids = self.connection.listDomainsID()
-        domains = [self.connection.lookupByID(id) for id in domain_ids]
+        domains = self.connection.listAllDomains()
 
         nodes = []
         for domain in domains:
@@ -78,9 +77,11 @@ class LibvirtNodeDriver(NodeDriver):
                      'types': self.connection.getType(),
                      'used_memory': memory / 1024, 'vcpu_count': vcpu_count,
                      'used_cpu_time': used_cpu_time}
+
             node = Node(id=domain.ID(), name=domain.name(), state=state,
                         public_ips=[], private_ips=[], driver=self,
                         extra=extra)
+            node._uuid = domain.UUIDString()  # we want to use a custom UUID
             nodes.append(node)
 
         return nodes
@@ -142,5 +143,8 @@ class LibvirtNodeDriver(NodeDriver):
         return domain.resume() == 0
 
     def _get_domain_for_node(self, node):
-        domain = self.connection.lookupByID(int(node.id))
+        """
+        Return libvirt domain object for the provided node.
+        """
+        domain = self.connection.lookupByUUIDString(node.uuid)
         return domain


[3/5] git commit: Add and use _to_nodes and _to_node method.

Posted by to...@apache.org.
Add and use _to_nodes and _to_node method.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/7012c6d1
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/7012c6d1
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/7012c6d1

Branch: refs/heads/trunk
Commit: 7012c6d17d064df01b899d90cc8ac0b19a6c3e51
Parents: 4aeb37c
Author: Tomaz Muraus <to...@apache.org>
Authored: Sun Jan 12 22:04:30 2014 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Sun Jan 12 22:04:30 2014 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/libvirt_driver.py | 43 ++++++++++++-------------
 1 file changed, 21 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/7012c6d1/libcloud/compute/drivers/libvirt_driver.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/libvirt_driver.py b/libcloud/compute/drivers/libvirt_driver.py
index 644902f..a9cc6fc 100644
--- a/libcloud/compute/drivers/libvirt_driver.py
+++ b/libcloud/compute/drivers/libvirt_driver.py
@@ -62,28 +62,7 @@ class LibvirtNodeDriver(NodeDriver):
 
     def list_nodes(self):
         domains = self.connection.listAllDomains()
-
-        nodes = []
-        for domain in domains:
-            state, max_mem, memory, vcpu_count, used_cpu_time = domain.info()
-
-            if state in self.NODE_STATE_MAP:
-                state = self.NODE_STATE_MAP[state]
-            else:
-                state = NodeState.UNKNOWN
-
-            # TODO: Use XML config to get Mac address and then parse ips
-            extra = {'uuid': domain.UUIDString(), 'os_type': domain.OSType(),
-                     'types': self.connection.getType(),
-                     'used_memory': memory / 1024, 'vcpu_count': vcpu_count,
-                     'used_cpu_time': used_cpu_time}
-
-            node = Node(id=domain.ID(), name=domain.name(), state=state,
-                        public_ips=[], private_ips=[], driver=self,
-                        extra=extra)
-            node._uuid = domain.UUIDString()  # we want to use a custom UUID
-            nodes.append(node)
-
+        nodes = self._to_nodes(domains=domains)
         return nodes
 
     def reboot_node(self, node):
@@ -142,6 +121,26 @@ class LibvirtNodeDriver(NodeDriver):
         domain = self._get_domain_for_node(node=node)
         return domain.resume() == 0
 
+    def _to_nodes(self, domains):
+        nodes = [self._to_node(domain=domain) for domain in domains]
+        return nodes
+
+    def _to_node(self, domain):
+        state, max_mem, memory, vcpu_count, used_cpu_time = domain.info()
+        state = self.NODE_STATE_MAP.get(state, NodeState.UNKNOWN)
+
+        # TODO: Use XML config to get Mac address and then parse ips
+        extra = {'uuid': domain.UUIDString(), 'os_type': domain.OSType(),
+                 'types': self.connection.getType(),
+                 'used_memory': memory / 1024, 'vcpu_count': vcpu_count,
+                 'used_cpu_time': used_cpu_time}
+
+        node = Node(id=domain.ID(), name=domain.name(), state=state,
+                    public_ips=[], private_ips=[], driver=self,
+                    extra=extra)
+        node._uuid = domain.UUIDString()  # we want to use a custom UUID
+        return node
+
     def _get_domain_for_node(self, node):
         """
         Return libvirt domain object for the provided node.


[5/5] git commit: docs: re-generature documentation fixtures.

Posted by to...@apache.org.
docs: re-generature documentation fixtures.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/edaff3f8
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/edaff3f8
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/edaff3f8

Branch: refs/heads/trunk
Commit: edaff3f8d31a3de05b86e7d39361aa210c81c6be
Parents: c5baf9c
Author: Tomaz Muraus <to...@apache.org>
Authored: Sun Jan 12 22:58:03 2014 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Sun Jan 12 22:58:03 2014 +0100

----------------------------------------------------------------------
 docs/compute/_supported_providers.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/edaff3f8/docs/compute/_supported_providers.rst
----------------------------------------------------------------------
diff --git a/docs/compute/_supported_providers.rst b/docs/compute/_supported_providers.rst
index 477f14d..077fb35 100644
--- a/docs/compute/_supported_providers.rst
+++ b/docs/compute/_supported_providers.rst
@@ -40,7 +40,7 @@ Provider                              Documentation
 `Ikoula`_                             :doc:`Click </compute/drivers/ikoula>`      IKOULA              :mod:`libcloud.compute.drivers.ikoula`         :class:`IkoulaNodeDriver`           
 `Joyent`_                                                                         JOYENT              :mod:`libcloud.compute.drivers.joyent`         :class:`JoyentNodeDriver`           
 `KTUCloud`_                                                                       KTUCLOUD            :mod:`libcloud.compute.drivers.ktucloud`       :class:`KTUCloudNodeDriver`         
-`Libvirt`_                                                                        LIBVIRT             :mod:`libcloud.compute.drivers.libvirt_driver` :class:`LibvirtNodeDriver`          
+`Libvirt`_                            :doc:`Click </compute/drivers/libvirt>`     LIBVIRT             :mod:`libcloud.compute.drivers.libvirt_driver` :class:`LibvirtNodeDriver`          
 `Linode`_                                                                         LINODE              :mod:`libcloud.compute.drivers.linode`         :class:`LinodeNodeDriver`           
 `NephoScale`_                                                                     NEPHOSCALE          :mod:`libcloud.compute.drivers.nephoscale`     :class:`NephoscaleNodeDriver`       
 `Nimbus`_                             :doc:`Click </compute/drivers/nimbus>`      NIMBUS              :mod:`libcloud.compute.drivers.ec2`            :class:`NimbusNodeDriver`           


[4/5] git commit: docs: Add documentation for libvirt driver.

Posted by to...@apache.org.
docs: Add documentation for libvirt driver.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/c5baf9c0
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/c5baf9c0
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/c5baf9c0

Branch: refs/heads/trunk
Commit: c5baf9c061fd8b912a49ff4ae0b86313f23212cf
Parents: 7012c6d
Author: Tomaz Muraus <to...@apache.org>
Authored: Sun Jan 12 22:57:01 2014 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Sun Jan 12 22:57:01 2014 +0100

----------------------------------------------------------------------
 docs/compute/drivers/libvirt.rst                | 81 ++++++++++++++++++++
 .../compute/libvirt/connect_qemu_kvm.py         |  5 ++
 .../compute/libvirt/connect_virtualbox.py       |  5 ++
 3 files changed, 91 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/c5baf9c0/docs/compute/drivers/libvirt.rst
----------------------------------------------------------------------
diff --git a/docs/compute/drivers/libvirt.rst b/docs/compute/drivers/libvirt.rst
new file mode 100644
index 0000000..cd200ba
--- /dev/null
+++ b/docs/compute/drivers/libvirt.rst
@@ -0,0 +1,81 @@
+Libvirt Compute Driver Documentation
+====================================
+
+.. note::
+
+    Libvirt driver in current version of Libcloud is still experimental and
+    doesn't support advanced functionality like creating a node and so on.
+
+`libvirt`_ is an open source toolkit for managing different hypervisors. It
+ca be used to manage Xen, KVM, Vmware ESX, QEMU and many other hypervisors.
+
+.. figure:: /_static/images/provider_logos/libvirt.png
+    :align: center
+    :width: 200
+    :target: http://libvirt.org
+
+For full list of the supported hypervisors, please see the
+`Hypervisor drivers <http://libvirt.org/drivers.html#hypervisor>`_ page.
+
+Requirements
+------------
+
+To be able to use this driver you need to install libvirt client and
+`libvirt-python`_ Python package.
+
+Libvirt client is available in standard package repositories of most popular
+Linux distributions which means you can install it using your distribution's
+package manager.
+
+Example #1 - Ubuntu, Debian, etc. (apt-get):
+
+.. sourcecode:: bash
+
+    sudo apt-get install libvirt-client
+
+Example #2 - Fedora, RHEL, etc. (yum):
+
+.. sourcecode:: bash
+
+    sudo yum install libvirt-client
+
+Python package can be installed using pip:
+
+.. sourcecode:: bash
+
+    pip install libvirt-python
+
+Connecting to a hypervisor
+--------------------------
+
+To instantiate the driver and connect to a hypervisor, you need to pass ``uri``
+argument to the driver constructor.
+
+This argument tells the driver which libvirt driver (qemu, xen, virtualbox,
+etc.) this connection refers to. For a full list of supported URIs, please
+refer to the `Connection URIs <http://libvirt.org/uri.html>` page.
+
+Example 1 - Connecting to QEMU and KVM hypervisor
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+This example shows how to connect to a local QEMU or KVM instance.
+
+.. literalinclude:: /examples/compute/libvirt/connect_qemu_kvm.py
+   :language: python
+
+For more details and information on how to connect to a remote instance, please
+see `Connections to QEMU driver <http://libvirt.org/drvqemu.html#uris>`_ page.
+
+Example 2 - Connecting to Virtualbox hypervisor
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+This example shows how to connect to a local Virtualbox instance.
+
+.. literalinclude:: /examples/compute/libvirt/connect_virtualbox.py
+   :language: python
+
+For more details and information on how to connect to a remote instance, please
+see `VirtualBox hypervisor driver <http://libvirt.org/drvvbox.html>`_ page.
+
+.. _`libvirt`: http://libvirt.org
+.. _`libvirt-python`: https://pypi.python.org/pypi/libvirt-python

http://git-wip-us.apache.org/repos/asf/libcloud/blob/c5baf9c0/docs/examples/compute/libvirt/connect_qemu_kvm.py
----------------------------------------------------------------------
diff --git a/docs/examples/compute/libvirt/connect_qemu_kvm.py b/docs/examples/compute/libvirt/connect_qemu_kvm.py
new file mode 100644
index 0000000..775ddd2
--- /dev/null
+++ b/docs/examples/compute/libvirt/connect_qemu_kvm.py
@@ -0,0 +1,5 @@
+from libcloud.compute.types import Provider
+from libcloud.compute.providers import get_driver
+
+cls = get_driver(Provider.LIBVIRT)
+driver = cls(uri='qemu:///system')

http://git-wip-us.apache.org/repos/asf/libcloud/blob/c5baf9c0/docs/examples/compute/libvirt/connect_virtualbox.py
----------------------------------------------------------------------
diff --git a/docs/examples/compute/libvirt/connect_virtualbox.py b/docs/examples/compute/libvirt/connect_virtualbox.py
new file mode 100644
index 0000000..af2c3de
--- /dev/null
+++ b/docs/examples/compute/libvirt/connect_virtualbox.py
@@ -0,0 +1,5 @@
+from libcloud.compute.types import Provider
+from libcloud.compute.providers import get_driver
+
+cls = get_driver(Provider.LIBVIRT)
+driver = cls(uri='vbox:///session')