Fabian Deutsch has uploaded a new change for review. Change subject: Add ovirt.node.utils.virt ......................................................................
Add ovirt.node.utils.virt Change-Id: Iffb95b07cd1f8831e29f352005cf8c0aac53281c Signed-off-by: Fabian Deutsch <[email protected]> --- A scripts/tui/src/ovirt/node/utils/virt.py 1 file changed, 96 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/05/9905/1 diff --git a/scripts/tui/src/ovirt/node/utils/virt.py b/scripts/tui/src/ovirt/node/utils/virt.py new file mode 100644 index 0000000..433b813 --- /dev/null +++ b/scripts/tui/src/ovirt/node/utils/virt.py @@ -0,0 +1,96 @@ +#!/usr/bin/python +# +# virt.py - Copyright (C) 2012 Red Hat, Inc. +# Written by Fabian Deutsch <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. A copy of the GNU General Public License is +# also available at http://www.gnu.org/copyleft/gpl.html. + +""" +Some convenience functions related to virtualization +""" + +import os.path +import logging +import libvirt +import ovirt.node.utils.process as process + +LOGGER = logging.getLogger(__name__) + + +def virtualization_hardware_is_available(): + """Determins if virtualization hardware is available. + + Returns: + True if there is hardware virtualization hardware available + """ + has_virtualization = False + + has_module = False + with open("/proc/modules") as modules: + for line in modules: + has_module = (line.startswith("kvm_intel") or \ + line.startswith("kvm_amd")) + if has_module: + break + + if has_module and os.path.exists("/dev/kvm"): + has_virtualization = True + + return has_virtualization + + +def virtualization_hardware_is_enabled(): + """Determins if virtualization hardware is available and enabled. + + Returns: + True if there is hardware virtualization hardware available and enabled + """ + is_enabled = False + if virtualization_hardware_is_available(): + with open("/proc/cpuinfo") as cpuinfo: + for line in cpuinfo: + if line.startswith("flags"): + if "vmx" in line or "svm" in line: + is_enabled= True + return is_enabled + + +def virtualization_hardware_status(): + """Status of virtualization on this machine. + + Returns: + Status of hardware virtualization support on this machine as a human + read-able string + """ + if virtualization_hardware_is_enabled(): + return "Virtualization hardware was detected and is enabled" + if virtualization_hardware_is_available(): + return "Virtualization hardware was detected but is disabled" + return "No virtualization hardware was detected on this system" + + +class LibvirtConnection(object): + def __init__(self, readonly=True): + if readonly: + self.con = libvirt.openReadOnly(None) + else: + raise Exception("Not supported") + + def __enter__(self, *args, **kwargs): + return self.con + + def __exit__(self, *args, **kwargs): + self.con.close() -- To view, visit http://gerrit.ovirt.org/9905 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iffb95b07cd1f8831e29f352005cf8c0aac53281c Gerrit-PatchSet: 1 Gerrit-Project: ovirt-node Gerrit-Branch: master Gerrit-Owner: Fabian Deutsch <[email protected]> _______________________________________________ node-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/node-patches
