예제 #1
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)

        timeout = kwargs.pop('_transport_timeout', CALL_TIMEOUT)

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

        responses = self._client.call(req, timeout=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
            return response.success(**resp.result)

        return response.success()
예제 #2
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)
예제 #3
0
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()
예제 #4
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)
예제 #5
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()
예제 #6
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)
예제 #7
0
파일: secret.py 프로젝트: fancyKai/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()
예제 #8
0
파일: jobs.py 프로젝트: andrewlukoshko/vdsm
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()
예제 #9
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)
예제 #10
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)
예제 #11
0
파일: api.py 프로젝트: andrewlukoshko/vdsm
    def wrapper(self, *args, **kwargs):

        _log.debug("START %s args=%s kwargs=%s", func.__name__, args, kwargs)
        try:
            ret = func(self, *args, **kwargs)
        except Exception as e:
            _log.exception("FINISH %s error=%s", func.__name__, e)
            if not isinstance(e, exception.VdsmException):
                e = exception.GeneralException(str(e))
            return e.response()

        _log.debug("FINISH %s response=%s", func.__name__, ret)

        if ret is None:
            return response.success()
        else:
            return response.success(**ret)
예제 #12
0
파일: jobs.py 프로젝트: fancyKai/vdsm
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()
예제 #13
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)
예제 #14
0
파일: jobs.py 프로젝트: borisroman/vdsm
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()
예제 #15
0
파일: api.py 프로젝트: rexhsu/vdsm
    def wrapper(self, *args, **kwargs):

        _log.debug("START %s args=%s kwargs=%s", func.__name__, args, kwargs)
        try:
            ret = func(self, *args, **kwargs)
        except Exception as e:
            _log.exception("FINISH %s error=%s", func.__name__, e)
            if not isinstance(e, exception.VdsmException):
                e = exception.GeneralException(str(e))
            return e.response()

        _log.debug("FINISH %s response=%s", func.__name__, ret)

        if ret is None:
            return response.success()
        else:
            return response.success(**ret)
예제 #16
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)
예제 #17
0
파일: jobs.py 프로젝트: borisroman/vdsm
def delete(job_id):
    try:
        job = get(job_id)
        job.validate_not_running()
        _delete(job_id)
    except ClientError as e:
        logging.info('Cannot delete job, error: %s', e)
        return response.error(e.name)
    return response.success()
예제 #18
0
파일: jobs.py 프로젝트: fancyKai/vdsm
def delete(job_id):
    try:
        job = get(job_id)
        job.validate_not_active()
        _delete(job_id)
    except ClientError as e:
        logging.info('Cannot delete job, error: %s', e)
        return response.error(e.name)
    return response.success()
예제 #19
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)
예제 #20
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)
예제 #21
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)
예제 #22
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)
예제 #23
0
파일: v2v.py 프로젝트: yingyun001/vdsm
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)
예제 #24
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)
예제 #25
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()
예제 #26
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)
예제 #27
0
파일: v2v.py 프로젝트: fancyKai/vdsm
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)
    _add_disks_ovf_info(vm, root, ns)
    _add_networks_ovf_info(vm, root, ns)

    return response.success(vmList=vm)
예제 #28
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)
    _add_disks_ovf_info(vm, root, ns)
    _add_networks_ovf_info(vm, root, ns)

    return response.success(vmList=vm)
예제 #29
0
    def _callMethod(self, methodName, *args):
        try:
            method = _COMMAND_CONVERTER[methodName]
        except KeyError as e:
            raise Exception("Attempt to call function: %s with "
                            "arguments: %s error: %s" %
                            (methodName, args, e))

        req = JsonRpcRequest(method, args, reqId=str(uuid4()))
        responses = self._client.call(req)
        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 resp.result and resp.result is not True:
            # None is translated to True inside our JSONRPC implementation
            return response.success(**resp.result)

        return response.success()
예제 #30
0
 def test_register_clear(self):
     self.connection.secrets = {
         "uuid1": vmfakelib.Secret(self.connection, "uuid1", "ceph",
                                   "ovirt/name1", None),
         "uuid2": vmfakelib.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)
예제 #31
0
 def test_register_clear(self):
     self.connection.secrets = {
         "uuid1":
         vmfakelib.Secret(self.connection, "uuid1", "ceph", "ovirt/name1",
                          None),
         "uuid2":
         vmfakelib.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)
예제 #32
0
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()
예제 #33
0
파일: secret.py 프로젝트: fancyKai/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()
예제 #34
0
    def test_success_with_args(self):
        res = response.success(a=1, b=2)

        self.assertEqual(res, {"status": doneCode, "a": 1, "b": 2})
예제 #35
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])
예제 #36
0
    def test_success(self):
        res = response.success()

        self.assertEqual(res, {"status": doneCode})
예제 #37
0
 def createVm(self, vmParams, vmRecover=False):
     self.vmRequests[vmParams['vmId']] = (vmParams, vmRecover)
     return response.success(vmList={})
예제 #38
0
파일: v2v.py 프로젝트: kanalun/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()
예제 #39
0
파일: v2v.py 프로젝트: fancyKai/vdsm
def convert_ova(ova_path, vminfo, job_id, irs):
    job = ImportVm.from_ova(ova_path, vminfo, job_id, irs)
    job.start()
    _add_job(job_id, job)
    return response.success()
예제 #40
0
    def test_success_with_args(self):
        res = response.success(a=1, b=2)

        self.assertEqual(res, {"status": doneCode, "a": 1, "b": 2})
예제 #41
0
파일: v2v.py 프로젝트: fancyKai/vdsm
def convert_ova(ova_path, vminfo, job_id, irs):
    job = ImportVm.from_ova(ova_path, vminfo, job_id, irs)
    job.start()
    _add_job(job_id, job)
    return response.success()
예제 #42
0
    def test_success(self):
        res = response.success()

        self.assertEqual(res, {"status": doneCode})
예제 #43
0
파일: jobsTests.py 프로젝트: fancyKai/vdsm
 def test_delete_inactive_job(self, status):
     job = TestingJob()
     job._status = status
     jobs.add(job)
     self.assertEqual(response.success(), jobs.delete(job.id))
예제 #44
0
 def test_success_without_return(self):
     res = self.vm.succeed()
     self.assertEquals(res, response.success())
예제 #45
0
 def __init__(self, *args, **kwargs):
     self.status = response.success()
     self._alive = False
예제 #46
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])
예제 #47
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()