[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[et-mgmt-tools] [PATCH 3/6] Add VirtualDevice class



The patch below adds a VirtualDevice class. My goal is
to eventually have all device classes extend this, but
it is not a pressing need at the moment. This is added
in preparation for the VirtualDevice fixes coming next.

Thanks,
Cole

# HG changeset patch
# User "Cole Robinson <crobinso redhat com>"
# Date 1217985724 14400
# Node ID c98567a840436ff1ef8e81de130510e09606c2a6
# Parent  cb14cc14d8ebc7e80e592d61cae823a5ef8e4cc5
Add VirtualDevice class, eventually should be used as parent class for all domain device xml classes.

diff -r cb14cc14d8eb -r c98567a84043 virtinst/VirtualDevice.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/virtinst/VirtualDevice.py	Tue Aug 05 21:22:04 2008 -0400
@@ -0,0 +1,78 @@
+#
+# Base class for all VM devices
+#
+# Copyright 2008  Red Hat, Inc.
+# Cole Robinson <crobinso redhat com>
+#
+# 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; either version 2 of the License, or
+# (at your option)  any later version.
+#
+# 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.
+
+import libvirt
+import logging
+
+import CapabilitiesParser
+import util
+from virtinst import _virtinst as _
+
+class VirtualDevice(object):
+    """
+    Base class for all domain xml device objects.
+    """
+
+    def __init__(self, conn=None):
+        """
+        Initialize device state
+
+        @param conn: libvirt connection to validate device against
+        @type conn: virConnect
+        """
+
+        if conn:
+            if not isinstance(conn, libvirt.virConnect):
+                raise ValueError, _("'conn' must be a virConnectPtr instance")
+        self._conn = conn
+
+        self.__remote = None
+        if self.conn:
+            self.__remote = util.is_remote(self.conn.getURI())
+
+        self._caps = None
+        if self.conn:
+            self._caps = CapabilitiesParser.parse(self.conn.getCapabilities())
+
+    def get_conn(self):
+        return self._conn
+    conn = property(get_conn)
+
+    def _is_remote(self):
+        return self.__remote
+
+    def _check_bool(self, val, name):
+        if val not in [True, False]:
+            raise ValueError, _("'%s' must be True or False" % name)
+
+    def _check_str(self, val, name):
+        if type(val) is not str:
+            raise ValueError, _("'%s' must be a string, not '%s'." %
+                                (name, type(val)))
+
+    def get_xml_config(self):
+        """
+        Construct and return device xml
+
+        @return: device xml representation as a string
+        @rtype: str
+        """
+        raise NotImplementedError()

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]