當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。