Esempio n. 1
0
 def lookup(self, pool):
     handle = None
     if isinstance(pool, basestring):
         handle = self._lookupByName(pool)
         if not handle and UUID.validate(pool):
             handle = self._lookupByUUID(pool)
     # TODO: in the future, handle storage pool objects
     # warn if no handle has been found
     if not handle:
         log.warn("Unable to find pool '{0}'".format(pool) +
                  " on '{1}'".format(self._drv.getURI()))
     # return handle
     return handle
Esempio n. 2
0
 def lookup(self, pool):
     handle = None
     if isinstance(pool, basestring):
         handle = self._lookupByName(pool)
         if not handle and UUID.validate(pool):
             handle = self._lookupByUUID(pool)
     # TODO: in the future, handle storage pool objects
     # warn if no handle has been found
     if not handle:
         log.warn("Unable to find pool '{0}'".format(pool) +
                  " on '{1}'".format(self._drv.getURI()))
     # return handle
     return handle
Esempio n. 3
0
    def _lookupByUUID(self, uuid):
        # type checking
        if not isinstance(uuid, basestring) or not UUID.validate(uuid):
            reason = "'uuid' field '{0}' is not valid".format(uuid)
            raise DomainManagerError(reason)

        handle = None
        try:
            connection = self._drv.connection
            # NOTE: lookup by UUID takes raw bytes, not hexbytes
            uuid = binascii.unhexlify(uuid.replace('-', ''))
            handle = connection.lookupByUUID(uuid)
        except libvirt.libvirtError as e:
            log.warning('{0}'.format(e))
        return handle
Esempio n. 4
0
    def _lookupByUUID(self, uuid):
        # type checking
        if not isinstance(uuid, str) or not UUID.validate(uuid):
            reason = "'uuid' field '{0}' is not valid".format(uuid)
            raise DomainManagerError(reason)

        handle = None
        try:
            connection = self._drv.connection
            # NOTE: lookup by UUID takes raw bytes, not hexbytes
            uuid = binascii.unhexlify(uuid.replace('-', ''))
            handle = connection.lookupByUUID(uuid)
        except libvirt.libvirtError as e:
            log.warning('{0}'.format(e))
        return handle
Esempio n. 5
0
 def lookup(self, domain):
     handle = None
     if isinstance(domain, (tuple, list)):
         handle = list()
         for dom in domain:
             handle.append(self.lookup(dom))
         handle = tuple(handle)
     elif isinstance(domain, int):
         handle = self._lookupByID(domain)
     elif isinstance(domain, basestring):
         handle = self._lookupByName(domain)
         if not handle and UUID.validate(domain.lower()):
             handle = self._lookupByUUID(domain)
         if not handle and domain.isdigit():
             handle = self._lookupByID(int(domain))
         if not handle:
             log.warn("Unable to find domain {0} on {1}".format(domain,
                      self._uri))
     return handle
Esempio n. 6
0
 def lookup(self, domain):
     handle = None
     if isinstance(domain, (tuple, list)):
         handle = list()
         for dom in domain:
             handle.append(self.lookup(dom))
         handle = tuple(handle)
     elif isinstance(domain, int):
         handle = self._lookupByID(domain)
     elif isinstance(domain, str):
         handle = self._lookupByName(domain)
         if not handle and UUID.validate(domain.lower()):
             handle = self._lookupByUUID(domain)
         if not handle and domain.isdigit():
             handle = self._lookupByID(int(domain))
         if not handle:
             log.warn("Unable to find domain {0} on {1}".format(
                 domain, self._uri))
     return handle
Esempio n. 7
0
 def test_uuid_validate(self):
     self.assertFalse(UUID.validate("not a uuid"))
Esempio n. 8
0
 def test_uuid_generate(self):
     uuid = UUID.normalize("01234567-abcd-ef01-2345-deadbeaff00d")
     self.assertTrue(UUID.validate(uuid))
     self.assertEquals(uuid, "01234567-abcd-ef01-2345-deadbeaff00d")
Esempio n. 9
0
 def test_uuid(self):
     uuid = UUID.generate()
     self.assertTrue(UUID.validate(uuid))
     self.assertEqual(len(uuid), 36)
     self.assertEqual(uuid.count("-"), 4)
Esempio n. 10
0
 def test_uuid_validate(self):
     self.assertFalse(UUID.validate("not a uuid"))
Esempio n. 11
0
 def test_uuid_generate(self):
     uuid = UUID.normalize("01234567-abcd-ef01-2345-deadbeaff00d")
     self.assertTrue(UUID.validate(uuid))
     self.assertEquals(uuid, "01234567-abcd-ef01-2345-deadbeaff00d")
Esempio n. 12
0
 def test_uuid(self):
     uuid = UUID.generate()
     self.assertTrue(UUID.validate(uuid))
     self.assertEqual(len(uuid), 36)
     self.assertEqual(uuid.count("-"), 4)