Esempio n. 1
0
def delete(job_id):
    try:
        _delete(job_id)
    except ClientError as e:
        logging.info('Cannot delete job, error: %s', e)
        return response.error(e.name)
    return response.success()
Esempio n. 2
0
    def test_success_with_message(self):
        MESSAGE = "the message was overwritten"
        res = response.success(message=MESSAGE)

        template = doneCode
        self.assertEqual(res["status"]["code"], template["code"])
        self.assertEqual(res["status"]["message"], MESSAGE)
Esempio n. 3
0
 def test_unregister_missing(self):
     existing_sec = make_secret()
     secret.register([existing_sec])
     missing_sec = make_secret()
     res = secret.unregister([missing_sec["uuid"], existing_sec["uuid"]])
     self.assertEqual(res, response.success())
     self.assertEqual({}, self.connection.secrets)
Esempio n. 4
0
File: secret.py Progetto: nirs/vdsm
def unregister(uuids):
    try:
        uuids = [str(uuid.UUID(s)) for s in uuids]
    except ValueError as e:
        logging.warning("Attempt to unregister invalid uuid %s: %s" %
                        (uuids, e))
        return response.error("secretBadRequestErr")

    con = libvirtconnection.get()
    try:
        for sec_uuid in uuids:
            logging.info("Unregistering secret %r", sec_uuid)
            try:
                virsecret = con.secretLookupByUUIDString(sec_uuid)
            except libvirt.libvirtError as e:
                if e.get_error_code() != libvirt.VIR_ERR_NO_SECRET:
                    raise
                logging.debug("No such secret %r", sec_uuid)
            else:
                virsecret.undefine()
    except libvirt.libvirtError as e:
        logging.error("Could not unregister secrets: %s", e)
        return response.error("secretUnregisterErr")

    return response.success()
Esempio n. 5
0
def abort(job_id):
    try:
        job = get(job_id)
        job.abort()
    except ClientError as e:
        logging.info('Cannot abort job, error: %s', e)
        return response.error(e.name)
    return response.success()
Esempio n. 6
0
 def test_unregister_existing(self):
     sec1 = make_secret(password="******")
     sec2 = make_secret(password="******")
     secret.register([sec1, sec2])
     res = secret.unregister([sec1["uuid"]])
     self.assertEqual(res, response.success())
     self.assertNotIn(sec1["uuid"], self.connection.secrets)
     self.assertIn(sec2["uuid"], self.connection.secrets)
Esempio n. 7
0
    def teardownImage(self, domainId, poolId, imageId):
        if imageId == TEARDOWN_ERROR_IMAGE_ID:
            return response.error('teardownError')

        imagepath = _vol_path(self._image_path_base, domainId, poolId, imageId)
        resultpath = _vol_path(self._image_path_base, domainId, poolId,
                               imageId, ext='.res')
        os.rename(imagepath, resultpath)
        return response.success()
Esempio n. 8
0
 def test_register_new(self):
     sec1 = make_secret(password="******")
     sec2 = make_secret(password="******")
     res = secret.register([sec1, sec2])
     self.assertEqual(res, response.success())
     virsec1 = self.connection.secrets[sec1["uuid"]]
     self.assertEqual("sec1 password", virsec1.value)
     virsec2 = self.connection.secrets[sec2["uuid"]]
     self.assertEqual("sec2 password", virsec2.value)
Esempio n. 9
0
 def test_register_change_usage_id(self):
     sec = make_secret(usage_id="ovirt/provider_uuid/secert_uuid")
     secret.register([sec])
     # Change usage id
     sec["usageID"] = "ovirt/domain_uuid/secret_uuid"
     res = secret.register([sec])
     self.assertEqual(res, response.success())
     virsec = self.connection.secrets[sec["uuid"]]
     self.assertEqual("ovirt/domain_uuid/secret_uuid", virsec.usage_id)
Esempio n. 10
0
def get_external_vm_names(uri, username, password):
    try:
        conn = libvirtconnection.open_connection(uri=uri,
                                                 username=username,
                                                 passwd=password)
    except libvirt.libvirtError as e:
        logging.error('error connecting to hypervisor: %r', e.message)
        return response.error('V2VConnection', e.message)

    with closing(conn):
        vms = [vm.name() for vm in _list_domains(conn)]
        return response.success(vmNames=vms)
Esempio n. 11
0
    def _callMethod(self, methodName, *args, **kwargs):
        try:
            method = _COMMAND_CONVERTER[methodName]
        except KeyError as e:
            raise Exception("Attempt to call function: %s with "
                            "arguments: %s error: %s" %
                            (methodName, args, e))

        class_name, method_name = method.split('.')
        params = self._prepare_args(class_name, method_name, args, kwargs)

        req = JsonRpcRequest(method, params, reqId=str(uuid4()))

        responses = self._client.call(
            req, timeout=self._timeouts.get(
                method_name,
                kwargs.pop('_transport_timeout', self._default_timeout)))
        if responses:
            resp = responses[0]
        else:
            raise JsonRpcNoResponseError(method)

        if resp.error is not None:
            return response.error_raw(resp.error["code"],
                                      resp.error["message"])

        if not self._xml_compat:
            return response.success_raw(resp.result)

        if resp.result and resp.result is not True:
            # None is translated to True inside our JSONRPC implementation
            if isinstance(resp.result, list):
                return response.success(items=resp.result)
            elif isinstance(resp.result, six.string_types):
                return response.success(resp.result)
            else:
                return response.success(**resp.result)

        return response.success()
Esempio n. 12
0
 def test_register_replace(self):
     # Register 2 secrets
     sec1 = make_secret(password="******")
     sec2 = make_secret(password="******")
     secret.register([sec1, sec2])
     # Replace existing secret value
     sec2["password"] = make_password("sec2 new password")
     res = secret.register([sec2])
     self.assertEqual(res, response.success())
     virsec1 = self.connection.secrets[sec1["uuid"]]
     self.assertEqual("sec1 password", virsec1.value)
     virsec2 = self.connection.secrets[sec2["uuid"]]
     self.assertEqual("sec2 new password", virsec2.value)
Esempio n. 13
0
def get_ova_info(ova_path):
    ns = {'ovf': _OVF_NS, 'rasd': _RASD_NS}

    try:
        root = ET.fromstring(_read_ovf_from_ova(ova_path))
    except ET.ParseError as e:
        raise V2VError('Error reading ovf from ova, position: %r' % e.position)

    vm = {}
    _add_general_ovf_info(vm, root, ns, ova_path)
    _add_disks_ovf_info(vm, root, ns)
    _add_networks_ovf_info(vm, root, ns)

    return response.success(vmList=vm)
Esempio n. 14
0
    def start(self):
        # are there any available methods for power-down?
        if self.chain.callbacks:
            # flag for successful power-down event detection
            # this flag is common for both shutdown and reboot workflows
            # because we want to exit the CallbackChain in case either
            # of them happens
            self.event.clear()

            self.chain.start()
            return response.success(message=self.returnMsg)
        else:
            # No tools, no ACPI
            return response.error(
                'exist',
                message='VM without ACPI or active oVirt guest agent. '
                        'Try Forced Shutdown.')
Esempio n. 15
0
 def test_register_clear(self):
     self.connection.secrets = {
         "uuid1": vmfakecon.Secret(self.connection, "uuid1", "ceph",
                                   "ovirt/name1", None),
         "uuid2": vmfakecon.Secret(self.connection, "uuid2", "ceph",
                                   "name2", None),
     }
     sec = make_secret()
     res = secret.register([sec], clear=True)
     # Should succeed
     self.assertEqual(res, response.success())
     # Should remove existing ovirt secrets
     self.assertNotIn("uuid1", self.connection.secrets)
     # Should keep non-ovirt secrets
     self.assertIn("uuid2", self.connection.secrets)
     # Should register new secret
     virsec = self.connection.secrets[sec["uuid"]]
     self.assertEqual(sec["password"].value, virsec.value)
Esempio n. 16
0
File: secret.py Progetto: nirs/vdsm
def register(secrets, clear=False):
    try:
        secrets = [Secret(params) for params in secrets]
    except ValueError as e:
        logging.warning("Attempt to register invalid secret: %s", e)
        return response.error("secretBadRequestErr")

    con = libvirtconnection.get()
    try:
        for secret in secrets:
            logging.info("Registering secret %s", secret)
            secret.register(con)
        if clear:
            uuids = frozenset(sec.uuid for sec in secrets)
            for virsecret in con.listAllSecrets():
                if virsecret.UUIDString() not in uuids and _is_ovirt_secret(virsecret):
                    virsecret.undefine()
    except libvirt.libvirtError as e:
        logging.error("Could not register secret %s: %s", secret, e)
        return response.error("secretRegisterErr")

    return response.success()
Esempio n. 17
0
File: v2v.py Progetto: igoihman/vdsm
def convert_ova(ova_path, vminfo, job_id, irs):
    command = OvaCommand(ova_path, vminfo, job_id, irs)
    job = ImportVm(job_id, command)
    job.start()
    _add_job(job_id, job)
    return response.success()
Esempio n. 18
0
 def lease_info(self, lease):
     key = (lease["sd_id"], lease["lease_id"])
     if key not in self.leases:
         return exception.GeneralException().response()
     return response.success(result=self.leases[key])
Esempio n. 19
0
 def createVm(self, vmParams, vmRecover=False):
     self.vmRequests[vmParams['vmId']] = (vmParams, vmRecover)
     return response.success(vmList={})
Esempio n. 20
0
 def refreshVolume(self, sdUUID, spUUID, imgUUID, volUUID):
     return response.success()
Esempio n. 21
0
 def getVolumeSize(self, domainID, poolID, imageID, volumeID):
     # For block storage we "truesize" and "apparentsize" are always
     # the same, they exists only for compatibility with file volumes
     key = (domainID, poolID, imageID, volumeID)
     size = self.volume_sizes[key]
     return response.success(apparentsize=size, truesize=size)
Esempio n. 22
0
    def test_success_with_args(self):
        res = response.success(a=1, b=2)

        self.assertEqual(res, {"status": doneCode, "a": 1, "b": 2})
Esempio n. 23
0
 def run(self):
     return response.success()
Esempio n. 24
0
 def test_delete_inactive_job(self, status):
     job = TestingJob(status)
     jobs.add(job)
     self.assertEqual(response.success(), jobs.delete(job.id))
Esempio n. 25
0
 def test_delete_inactive_job(self, status):
     job = TestingJob(status)
     jobs.add(job)
     self.assertEqual(response.success(), jobs.delete(job.id))
Esempio n. 26
0
 def test_passthrough(self):
     foo = "foo"
     res = self.vm.succeed_passthrough(foo=foo)
     self.assertEqual(res, response.success(foo=foo))
Esempio n. 27
0
 def migrationCreate(self, params, limit):
     self.attempts += 1
     if self.attempts > self._initial_failures:
         return response.success()
     return self._exc.response()
Esempio n. 28
0
 def test_success_without_return(self):
     res = self.vm.succeed()
     self.assertEqual(res, response.success())
Esempio n. 29
0
 def succeed_passthrough(self, foo):
     return response.success(foo=foo)
Esempio n. 30
0
 def cont(self):
     return response.success()
Esempio n. 31
0
 def succeed_passthrough(self, foo):
     return response.success(foo=foo)
Esempio n. 32
0
 def freeze(self):
     self.froze = True
     return response.success()
Esempio n. 33
0
 def test_success_with_extra_args(self, args):
     res = response.success(**args)
     self.assertEqual(res['status']['code'], 0)
     self.assertEqual(res['status']['message'], 'Done')
     for key in args:
         self.assertEqual(res[key], args[key])
Esempio n. 34
0
def convert_ova(ova_path, vminfo, job_id, irs):
    command = OvaCommand(ova_path, vminfo, job_id, irs)
    job = ImportVm(job_id, command)
    job.start()
    _add_job(job_id, job)
    return response.success()
Esempio n. 35
0
 def createVm(self, vmParams, vmRecover=False):
     self.vmRequests[vmParams['vmId']] = (vmParams, vmRecover)
     return response.success(vmList={})
Esempio n. 36
0
 def test_passthrough(self):
     foo = 'foo'
     res = self.vm.succeed_passthrough(foo=foo)
     self.assertEquals(res, response.success(foo=foo))
Esempio n. 37
0
 def __init__(self, *args, **kwargs):
     self.status = response.success()
     self._alive = False
Esempio n. 38
0
 def test_success_without_return(self):
     res = self.vm.succeed()
     self.assertEquals(res, response.success())
Esempio n. 39
0
 def imageSyncVolumeChain(self, domainID, imageID, volumeID, newVols):
     return response.success()
Esempio n. 40
0
 def __init__(self, *args, **kwargs):
     self.status = response.success()
     self._alive = False
Esempio n. 41
0
 def createVm(self, vmParams):
     return response.success(vmList=[self])
Esempio n. 42
0
 def getVolumeSize(self, domainID, poolID, imageID, volumeID):
     return response.success(apparentsize=1024, truesize=1024)
Esempio n. 43
0
 def lease_info(self, lease):
     key = (lease["sd_id"], lease["lease_id"])
     if key not in self.leases:
         return exception.GeneralException().response()
     return response.success(result=self.leases[key])
Esempio n. 44
0
 def prepareImage(self, domainId, poolId, imageId, volumeId,
                  allowIllegal=False):
     imagepath = _vol_path(self._image_path_base, domainId, poolId, imageId)
     with io.open(imagepath, 'w'):
         pass
     return response.success(path=imagepath)
Esempio n. 45
0
 def createVm(self, vmParams):
     return response.success(vmList=[self])
Esempio n. 46
0
 def getVolumeSize(self, domainID, poolID, imageID, volumeID):
     # For block storage we "truesize" and "apparentsize" are always
     # the same, they exists only for compatibility with file volumes
     key = (domainID, poolID, imageID, volumeID)
     size = self.volume_sizes[key]
     return response.success(apparentsize=size, truesize=size)