Beispiel #1
0
 def test_reconnect(self):
     # test with an inexisting connection (not cached)
     with ConnectionManager(self.uri) as cm:
         cm._drv = None
         self.assertIsNotNone(cm.connection)
         self.assertIsInstance(cm.connection, libvirt.virConnect)
     # test with an existing connection (already cached)
     with ConnectionManager(self.uri) as cmo:
         # call version to force call to connect()
         version = cmo.version
         cmo._drv = None
         with ConnectionManager(self.uri) as cmi:
             version = cmi.version
             self.assertIsNotNone(cmi.connection)
             self.assertIsInstance(cmi.connection, libvirt.virConnect)
Beispiel #2
0
    def __init__(self, connection):

        self._wait_timeout = 30
        self._connection = ConnectionManager(connection)
        self._domain = DomainManager(connection)

        super(LibVirtMachineManager, self).__init__()
Beispiel #3
0
    def depends_on(cls, *args, **kwargs):
        # singleton is based on the uri, extracted from the libvirt handler
        (handler, ) = args[0]
        if isinstance(handler, basestring):
            handler = ConnectionManager(handler)
        if isinstance(handler, ConnectionManager):
            handler = handler.connection
        if not isinstance(handler, libvirt.virConnect):
            what = type(handler)
            reason = "Invalid type for 'connection' field: {0}".format(what)
            raise DomainManagerError(reason)

        try:
            uri = handler.getURI()
        except libvirt.libvirtError as e:
            reason = "unable to get domain uri from connection handle"
            raise DomainManagerError(reason)
        return uri
    def depends_on(cls, *args, **kwargs):
        # singleton is based on the uri, extracted from the libvirt handler
        (handler,) = args[0]
        if isinstance(handler, basestring):
            handler = ConnectionManager(handler)
        if isinstance(handler, ConnectionManager):
            handler = handler.connection
        if not isinstance(handler, libvirt.virConnect):
            what = type(handler)
            reason = "Invalid type for 'connection' field: {0}".format(what)
            raise DomainManagerError(reason)

        try:
            uri = handler.getURI()
        except libvirt.libvirtError as e:
            reason = "unable to get domain uri from connection handle"
            raise DomainManagerError(reason)
        return uri
Beispiel #5
0
 def test_connection(self):
     with ConnectionManager(self.uri) as cm:
         self.assertIsNotNone(cm.connection)
         self.assertIsInstance(cm.connection, libvirt.virConnect)
Beispiel #6
0
 def test_uri(self):
     with ConnectionManager(self.uri) as cm:
         self.assertEqual(cm.uri, self.uri)
Beispiel #7
0
 def test_create_uri(self):
     with self.assertRaises(NotImplementedError):
         with ConnectionManager(self.uri) as cm:
             cm.create_uri("dummy")
Beispiel #8
0
 def test_version(self):
     with ConnectionManager(self.uri) as cm:
         self.assertIsNotNone(cm.version)
         self.assertEqual(len(cm.version), 3)
         self.assertIsInstance(cm.version, tuple)
Beispiel #9
0
 def test_with(self):
     with ConnectionManager(self.uri) as cm:
         pass
Beispiel #10
0
 def test_constructor(self):
     cm = ConnectionManager(self.uri)
     self.assertIsNotNone(cm)
Beispiel #11
0
 def test_constructor_with_connection_manager(self):
     with ConnectionManager(self.uri) as cm:
         dm = DomainManager(cm)
         self.assertIsNotNone(dm)
         self.assertIsInstance(dm, DomainManager)