当前位置: 首页>>代码示例>>Python>>正文


Python xmlrpc_client.Fault方法代码示例

本文整理汇总了Python中six.moves.xmlrpc_client.Fault方法的典型用法代码示例。如果您正苦于以下问题:Python xmlrpc_client.Fault方法的具体用法?Python xmlrpc_client.Fault怎么用?Python xmlrpc_client.Fault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six.moves.xmlrpc_client的用法示例。


在下文中一共展示了xmlrpc_client.Fault方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: xenapi_request

# 需要导入模块: from six.moves import xmlrpc_client [as 别名]
# 或者: from six.moves.xmlrpc_client import Fault [as 别名]
def xenapi_request(self, methodname, params):
        if methodname.startswith('login'):
            self._login(methodname, params)
            return None
        elif methodname == 'logout' or methodname == 'session.logout':
            self._logout()
            return None
        else:
            retry_count = 0
            while retry_count < 3:
                full_params = (self._session,) + params
                result = _parse_result(getattr(self, methodname)(*full_params))
                if result == _RECONNECT_AND_RETRY:
                    retry_count += 1
                    if self.last_login_method:
                        self._login(self.last_login_method,
                                    self.last_login_params)
                    else:
                        raise xmlrpc_client.Fault(401, 'You must log in')
                else:
                    return result
            raise xmlrpc_client.Fault(
                500, 'Tried 3 times to get a valid session, but failed') 
开发者ID:candlepin,项目名称:virt-who,代码行数:25,代码来源:XenAPI.py

示例2: _parse_result

# 需要导入模块: from six.moves import xmlrpc_client [as 别名]
# 或者: from six.moves.xmlrpc_client import Fault [as 别名]
def _parse_result(result):
    if not isinstance(result, dict) or 'Status' not in result:
        raise xmlrpc_client.Fault(500, 'Missing Status in response from server' + result)
    if result['Status'] == 'Success':
        if 'Value' in result:
            return result['Value']
        else:
            raise xmlrpc_client.Fault(500,
                                  'Missing Value in response from server')
    else:
        if 'ErrorDescription' in result:
            if result['ErrorDescription'][0] == 'SESSION_INVALID':
                return _RECONNECT_AND_RETRY
            elif result['ErrorDescription'][0] == 'HOST_IS_SLAVE':
                raise NewMaster(result['ErrorDescription'][0], result['ErrorDescription'][1])
            else:
                raise Failure(result['ErrorDescription'])
        else:
            raise xmlrpc_client.Fault(
                500, 'Missing ErrorDescription in response from server')


# Based upon _Method from xmlrpclib. 
开发者ID:candlepin,项目名称:virt-who,代码行数:25,代码来源:XenAPI.py

示例3: virt_notify

# 需要导入模块: from six.moves import xmlrpc_client [as 别名]
# 或者: from six.moves.xmlrpc_client import Fault [as 别名]
def virt_notify(self, system_id, plan):
        if system_id != TEST_SYSTEM_ID:
            raise xmlrpc_client.Fault(-9, "Wrong system id")

        if plan[0] != [0, 'exists', 'system', {'uuid': '0000000000000000', 'identity': 'host'}]:
            raise Exception("Wrong value for virt_notify: invalid format of first entry")
        if plan[1] != [0, 'crawl_began', 'system', {}]:
            raise Exception("Wrong value for virt_notify: invalid format of second entry")
        if plan[-1] != [0, 'crawl_ended', 'system', {}]:
            raise Exception("Wrong value for virt_notify: invalid format of last entry")
        for item in plan[2:-1]:
            if item[0] != 0:
                raise Exception("Wrong value for virt_notify: invalid format first item of an entry")
            if item[1] != 'exists':
                raise Exception("Wrong value for virt_notify: invalid format second item of an entry")
            if item[2] != 'domain':
                raise Exception("Wrong value for virt_notify: invalid format third item of an entry")
            if not item[3]['uuid'].startswith("guest"):
                raise Exception("Wrong value for virt_notify: invalid format uuid item")
        return 0 
开发者ID:candlepin,项目名称:virt-who,代码行数:22,代码来源:test_satellite.py

示例4: dumps

# 需要导入模块: from six.moves import xmlrpc_client [as 别名]
# 或者: from six.moves.xmlrpc_client import Fault [as 别名]
def dumps(self, obj):

        try:
            # Marshaller has a specific handling of Fault instance. It is given without modification
            if isinstance(obj, xmlrpc_client.Fault):
                return self.marshaller.dumps(obj)

            # xmlrpc_client.Marshaller expects a list of objects to dumps.
            # It will output a '<params></params>' block and loops onto given objects to inject, for each one,
            # a '<param><value><type>X</type></value></param>' block.
            # This is not the return defined in XML-RPC standard, see http://xmlrpc.scripting.com/spec.html:
            # "The body of the response is a single XML structure, a <methodResponse>, which can contain
            # a single <params> which contains a single <param> which contains a single <value>."
            #
            # So, to make sure the return value always contain a single '<param><value><type>X</type></value></param>',
            # we dumps it as an array of a single value.
            return self.marshaller.dumps([obj])

        except Exception as e:
            raise RPCInternalError('Unable to serialize result as valid XML: ' + str(e)) 
开发者ID:alorence,项目名称:django-modern-rpc,代码行数:22,代码来源:xmlhandler.py

示例5: _validate_request

# 需要导入模块: from six.moves import xmlrpc_client [as 别名]
# 或者: from six.moves.xmlrpc_client import Fault [as 别名]
def _validate_request(self, proc=None):
        '''Validates request and simulates errors when not valid'''

        # Password not part of URL if connecting via socket
        transport_password = self.transport.password if self.transport else ""

        # `host` is optional connecting via socket
        transport_socket = self.transport.serverurl if self.transport else ""

        # if 'socket_file' in self.url:
        if 'invalid_host' in self.url or 'invalid_socket' in transport_socket:
            # Simulate connecting to an invalid host/port in order to
            # raise `socket.error: [Errno 111] Connection refused`
            socket().connect(('localhost', 38837))
        elif 'invalid_pass' in self.url or 'invalid_pass' in transport_password:
            # Simulate xmlrpc exception for invalid credentials
            raise xmlrpclib.ProtocolError(self.url[7:], 401, 'Unauthorized', None)
        elif proc is not None and 'invalid' in proc:
            # Simulate xmlrpc exception for process not found
            raise xmlrpclib.Fault(10, 'BAD_NAME') 
开发者ID:DataDog,项目名称:integrations-core,代码行数:22,代码来源:test_supervisord_unit.py

示例6: _login

# 需要导入模块: from six.moves import xmlrpc_client [as 别名]
# 或者: from six.moves.xmlrpc_client import Fault [as 别名]
def _login(self, method, params):
        result = _parse_result(getattr(self, 'session.%s' % method)(*params))
        if result == _RECONNECT_AND_RETRY:
            raise xmlrpc_client.Fault(
                500, 'Received SESSION_INVALID when logging in')
        self._session = result
        self.last_login_method = method
        self.last_login_params = params
        self.API_version = self._get_api_version() 
开发者ID:candlepin,项目名称:virt-who,代码行数:11,代码来源:XenAPI.py

示例7: result_error

# 需要导入模块: from six.moves import xmlrpc_client [as 别名]
# 或者: from six.moves.xmlrpc_client import Fault [as 别名]
def result_error(self, exception, http_response_cls=HttpResponse):

        raw_response = '<?xml version="1.0"?>'
        raw_response += '<methodResponse>'
        raw_response += self.dumps(xmlrpc_client.Fault(exception.code, exception.message))
        raw_response += '</methodResponse>'

        return self.xml_http_response(raw_response, http_response_cls=http_response_cls) 
开发者ID:alorence,项目名称:django-modern-rpc,代码行数:10,代码来源:xmlhandler.py

示例8: __init__

# 需要导入模块: from six.moves import xmlrpc_client [as 别名]
# 或者: from six.moves.xmlrpc_client import Fault [as 别名]
def __init__(self, fault_instance):
        self._fault = fault_instance
        msg = (u"A fault occured\n"
               u"Fault code: %s\n"
               u"Fault string: %s\n"
               u"" % (ustr(fault_instance.faultCode),
                      ustr(fault_instance.faultString)))
        msg = msg.encode('utf-8')
        super(XMLRPCError, self).__init__(msg) 
开发者ID:katyukha,项目名称:odoo-rpc-client,代码行数:11,代码来源:xmlrpc.py

示例9: fault

# 需要导入模块: from six.moves import xmlrpc_client [as 别名]
# 或者: from six.moves.xmlrpc_client import Fault [as 别名]
def fault(self):
        """ Return xmlrpclib.Fault instance related to this error
        """
        return self._fault 
开发者ID:katyukha,项目名称:odoo-rpc-client,代码行数:6,代码来源:xmlrpc.py

示例10: __call__

# 需要导入模块: from six.moves import xmlrpc_client [as 别名]
# 或者: from six.moves.xmlrpc_client import Fault [as 别名]
def __call__(self, *args):
        try:
            res = self.__method(*args)
        except xmlrpclib.Fault as fault:
            raise XMLRPCError(fault)
        return res 
开发者ID:katyukha,项目名称:odoo-rpc-client,代码行数:8,代码来源:xmlrpc.py

示例11: _get_bugzilla_bug

# 需要导入模块: from six.moves import xmlrpc_client [as 别名]
# 或者: from six.moves.xmlrpc_client import Fault [as 别名]
def _get_bugzilla_bug(bug_id):
    """Fetch bug ``bug_id``.

    :param int bug_id: The ID of a bug in the Bugzilla database.
    :return: A FRIGGIN UNDOCUMENTED python-bugzilla THING.
    :raises BugFetchError: If an error occurs while fetching the bug. For
        example, a network timeout occurs or the bug does not exist.

    """
    # Is bug ``bug_id`` in the cache?
    if bug_id in _bugzilla:
        LOGGER.debug('Bugzilla bug {0} found in cache.'.format(bug_id))
    else:
        LOGGER.info('Bugzilla bug {0} not in cache. Fetching.'.format(bug_id))
        # Make a network connection to the Bugzilla server.
        try:
            bz_conn = bugzilla.RHBugzilla()
            bz_conn.connect(BUGZILLA_URL)
        except (TypeError, ValueError):
            raise BugFetchError(
                'Could not connect to {0}'.format(BUGZILLA_URL)
            )
        # Fetch the bug and place it in the cache.
        try:
            _bugzilla[bug_id] = bz_conn.getbugsimple(bug_id)
        except Fault as err:
            raise BugFetchError(
                'Could not fetch bug. Error: {0}'.format(err.faultString)
            )
        except ExpatError as err:
            raise BugFetchError(
                'Could not interpret bug. Error: {0}'
                .format(ErrorString(err.code))
            )

    return _bugzilla[bug_id] 
开发者ID:SatelliteQE,项目名称:automation-tools,代码行数:38,代码来源:bz.py

示例12: hypervisorCheckIn

# 需要导入模块: from six.moves import xmlrpc_client [as 别名]
# 或者: from six.moves.xmlrpc_client import Fault [as 别名]
def hypervisorCheckIn(self, report, options=None):
        mapping = report.association
        self._connect(report.config)

        hypervisor_count = len(mapping['hypervisors'])
        guest_count = sum(len(hypervisor.guestIds) for hypervisor in mapping['hypervisors'])
        self.logger.info("Sending update in hosts-to-guests mapping: %d hypervisors and %d guests found", hypervisor_count, guest_count)
        serialized_mapping = {'hypervisors': [h.toDict() for h in mapping['hypervisors']]}
        self.logger.debug("Host-to-guest mapping: %s", json.dumps(serialized_mapping, indent=4))
        if len(mapping) == 0:
            self.logger.info("no hypervisors found, not sending data to satellite")

        for hypervisor in mapping['hypervisors']:
            self.logger.debug("Loading systemid for %s", hypervisor.hypervisorId)
            hypervisor_systemid = self._load_hypervisor(hypervisor.hypervisorId,
                                                        hypervisor_type=report.config['type'])

            self.logger.debug("Building plan for hypervisor %s: %s", hypervisor.hypervisorId, hypervisor.guestIds)
            plan = self._assemble_plan(hypervisor.guestIds, hypervisor.hypervisorId,
                                       hypervisor_type=report.config['type'])

            try:
                try:
                    self.logger.debug("Sending plan: %s", plan)
                    self.server_xmlrpc.registration.virt_notify(hypervisor_systemid["system_id"], plan)
                except xmlrpc_client.Fault as e:
                    if e.faultCode == -9:
                        self.logger.warn("System was deleted from Satellite 5, reregistering")
                        hypervisor_systemid = self._load_hypervisor(hypervisor.hypervisorId,
                                                                    hypervisor_type=report.config['type'], force=True)
                        self.server_xmlrpc.registration.virt_notify(hypervisor_systemid["system_id"], plan)
            except Exception as e:
                self.logger.exception("Unable to send host/guest association to the satellite:")
                raise SatelliteError("Unable to send host/guest association to the satellite: %s" % str(e))

        self.logger.info("Mapping for config \"%s\" updated", report.config.name)
        report.state = AbstractVirtReport.STATE_FINISHED

        # TODO: figure out what to populate here
        result = {}
        for type in ['failedUpdate', 'created', 'updated']:
            result[type] = []

        return result 
开发者ID:candlepin,项目名称:virt-who,代码行数:46,代码来源:satellite.py


注:本文中的six.moves.xmlrpc_client.Fault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。