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/13 19:54:10 UTC
[1/2] git commit: Add more extension methods to the libvirt driver.
Updated Branches:
refs/heads/trunk a67c8beef -> dc8dfdfc3
Add more extension methods to the libvirt driver.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/aec5d337
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/aec5d337
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/aec5d337
Branch: refs/heads/trunk
Commit: aec5d33791ce6626612acd51a53589f474e7dcd1
Parents: a67c8be
Author: Tomaz Muraus <to...@apache.org>
Authored: Mon Jan 13 03:45:40 2014 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Mon Jan 13 03:45:40 2014 +0100
----------------------------------------------------------------------
libcloud/compute/drivers/libvirt_driver.py | 95 ++++++++++++++++++++++++-
1 file changed, 94 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/aec5d337/libcloud/compute/drivers/libvirt_driver.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/libvirt_driver.py b/libcloud/compute/drivers/libvirt_driver.py
index 1937146..ae20f0f 100644
--- a/libcloud/compute/drivers/libvirt_driver.py
+++ b/libcloud/compute/drivers/libvirt_driver.py
@@ -14,9 +14,13 @@
# limitations under the License.
import re
+import os
+import time
import platform
import subprocess
+import mimetypes
+from os.path import join as pjoin
from collections import defaultdict
from xml.etree import ElementTree as ET
@@ -36,7 +40,6 @@ class LibvirtNodeDriver(NodeDriver):
"""
Libvirt (http://libvirt.org/) node driver.
- Usage: LibvirtNodeDriver(uri='vbox:///session').
To enable debug mode, set LIBVIR_DEBUG environment variable.
"""
@@ -97,6 +100,8 @@ class LibvirtNodeDriver(NodeDriver):
"""
Shutdown a running node.
+ Note: Usually this will result in sending an ACPI event to the node.
+
:param node: Node which should be used
:type node: :class:`Node`
@@ -129,6 +134,78 @@ class LibvirtNodeDriver(NodeDriver):
domain = self._get_domain_for_node(node=node)
return domain.resume() == 0
+ def ex_take_node_screenshot(self, node, directory, screen=0):
+ """
+ Take a screenshot of a monitoring of a running instance.
+
+ :param node: Node to take the screenshot of.
+ :type node: :class:`libcloud.compute.base.Node`
+
+ :param directory: Path where the screenshot will be saved.
+ :type directory: ``str``
+
+ :param screen: ID of the monitor to take the screenshot of.
+ :type screen: ``int``
+
+ :return: Full path where the screenshot has been saved.
+ :rtype: ``str``
+ """
+ if not os.path.exists(directory) or not os.path.isdir(directory):
+ raise ValueError('Invalid value for directory argument')
+
+ domain = self._get_domain_for_node(node=node)
+ stream = self.connection.newStream()
+ mime_type = domain.screenshot(stream=stream, screen=0)
+ extensions = mimetypes.guess_all_extensions(type=mime_type)
+
+ if extensions:
+ extension = extensions[0]
+ else:
+ extension = '.png'
+
+ name = 'screenshot-%s%s' % (int(time.time()), extension)
+ file_path = pjoin(directory, name)
+
+ with open(file_path, 'wb') as fp:
+ def write(stream, buf, opaque):
+ fp.write(buf)
+
+ stream.recvAll(write, None)
+
+ try:
+ stream.finish()
+ except Exception:
+ # Finish is not supported by all backends
+ pass
+
+ return file_path
+
+ def ex_get_hypervisor_hostname(self):
+ """
+ Return a system hostname on which the hypervisor is running.
+ """
+ hostname = self.connection.getHostname()
+ return hostname
+
+ def ex_get_hypervisor_sysinfo(self):
+ """
+ Retrieve hypervisor system information.
+
+ :rtype: ``dict``
+ """
+ xml = self.connection.getSysinfo()
+ etree = ET.XML(xml)
+
+ attributes = ['bios', 'system', 'processor', 'memory_device']
+
+ sysinfo = {}
+ for attribute in attributes:
+ element = etree.find(attribute)
+ entries = self._get_entries(element=element)
+ sysinfo[attribute] = entries
+
+ return sysinfo
+
def _to_nodes(self, domains):
nodes = [self._to_node(domain=domain) for domain in domains]
return nodes
@@ -212,6 +289,22 @@ class LibvirtNodeDriver(NodeDriver):
domain = self.connection.lookupByUUIDString(node.uuid)
return domain
+ def _get_entries(self, element):
+ """
+ Parse entries dictionary.
+
+ :rtype: ``dict``
+ """
+ elements = element.findall('entry')
+
+ result = {}
+ for element in elements:
+ name = element.get('name')
+ value = element.text
+ result[name] = value
+
+ return result
+
def _parse_arp_table(self, arp_output):
"""
Parse arp command output and return a dictionary which maps mac address
[2/2] git commit: docs: Update libvirt docs.
Posted by to...@apache.org.
docs: Update libvirt docs.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/dc8dfdfc
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/dc8dfdfc
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/dc8dfdfc
Branch: refs/heads/trunk
Commit: dc8dfdfc39413c4254b4f6cb8d41b9f6e7710bd1
Parents: aec5d33
Author: Tomaz Muraus <to...@apache.org>
Authored: Mon Jan 13 19:10:26 2014 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Mon Jan 13 19:10:26 2014 +0100
----------------------------------------------------------------------
docs/compute/drivers/libvirt.rst | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/dc8dfdfc/docs/compute/drivers/libvirt.rst
----------------------------------------------------------------------
diff --git a/docs/compute/drivers/libvirt.rst b/docs/compute/drivers/libvirt.rst
index cd200ba..7c7714a 100644
--- a/docs/compute/drivers/libvirt.rst
+++ b/docs/compute/drivers/libvirt.rst
@@ -79,3 +79,25 @@ see `VirtualBox hypervisor driver <http://libvirt.org/drvvbox.html>`_ page.
.. _`libvirt`: http://libvirt.org
.. _`libvirt-python`: https://pypi.python.org/pypi/libvirt-python
+
+Enabling libvirt debug mode
+---------------------------
+
+To enable libvirt debug mode, simply set ``LIBVIRT_DEBUG`` environment
+variable.
+
+For example:
+
+.. sourcecode:: bash
+
+ LIBVIRT_DEBUG=1 python my_script.py
+
+When debug mode is enabled, libvirt client will print all kind of debugging
+information to the standard error.
+
+API Docs
+--------
+
+.. autoclass:: libcloud.compute.drivers.libvirt_driver.LibvirtNodeDriver
+ :members:
+ :inherited-members: