本文整理汇总了Python中suds.WebFault方法的典型用法代码示例。如果您正苦于以下问题:Python suds.WebFault方法的具体用法?Python suds.WebFault怎么用?Python suds.WebFault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类suds
的用法示例。
在下文中一共展示了suds.WebFault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _call
# 需要导入模块: import suds [as 别名]
# 或者: from suds import WebFault [as 别名]
def _call(self, function_name, args=None, kwargs=None):
args = args or []
kwargs = kwargs or {}
func = getattr(self.client.service, function_name)
# TODO: parse response, return something actually useful
try:
return func(*args, **kwargs)
except WebFault as e:
# Detect whether the failure is due to an invalid session, and if
# possible, try to refresh the access token.
if (hasattr(e, 'fault') and
e.fault.faultcode == 'sf:INVALID_SESSION_ID' and
self.rest_client):
token = self.rest_client._refresh_token()
if token:
self._set_session_header(token['access_token'])
return func(*args, **kwargs)
raise
示例2: generate_dict
# 需要导入模块: import suds [as 别名]
# 或者: from suds import WebFault [as 别名]
def generate_dict(api_obj, fields):
result_dict = {}
lists = []
supported_fields = []
if api_obj.get_list():
for field in fields:
try:
api_response = getattr(api_obj, "get_" + field)()
except (MethodNotFound, WebFault):
pass
else:
lists.append(api_response)
supported_fields.append(field)
for i, j in enumerate(api_obj.get_list()):
temp = {}
temp.update([(item[0], item[1][i]) for item in zip(supported_fields, lists)])
result_dict[j] = temp
return result_dict
示例3: get_fault
# 需要导入模块: import suds [as 别名]
# 或者: from suds import WebFault [as 别名]
def get_fault(self, reply):
"""
Extract the fault from the specified soap reply. If I{faults} is True,
an exception is raised. Otherwise, the I{unmarshalled} fault L{Object}
is returned. This method is called when the server raises a
I{web fault}.
@param reply: A soap reply message.
@type reply: str
@return: A fault object.
@rtype: tuple ( L{Element}, L{Object} )
"""
reply = self.replyfilter(reply)
sax = Parser()
faultroot = sax.parse(string=reply)
soapenv = faultroot.getChild('Envelope')
soapbody = soapenv.getChild('Body')
fault = soapbody.getChild('Fault')
unmarshaller = self.unmarshaller(False)
p = unmarshaller.process(fault)
if self.options().faults:
raise WebFault(p, faultroot)
return (faultroot, p.detail)
示例4: _update_real_server_port_status
# 需要导入模块: import suds [as 别名]
# 或者: from suds import WebFault [as 别名]
def _update_real_server_port_status(self, new_member):
try:
address = new_member['address']
protocol_port = new_member['protocol_port']
new_admin_state_up = new_member.get('admin_state_up')
rs_server_port = self._adx_server_port(address, protocol_port)
reply = (self.slb_service
.getRealServerPortConfiguration(rs_server_port))
rs_port_conf_seq = (self.slb_factory.create
('ArrayOfRealServerPortConfigurationSequence'))
reply.rsPortConfig.serverPort = rs_server_port
reply.rsPortConfig.adminState = new_admin_state_up
rs_port_conf_list = [reply.rsPortConfig]
rs_port_conf_seq.RealServerPortConfigurationSequence = rs_port_conf_list
(self.slb_service
.setRealServersPortConfiguration(rs_port_conf_seq))
except suds.WebFault as e:
raise adx_exception.ConfigError(msg=e.message)
示例5: _update_real_server_properties
# 需要导入模块: import suds [as 别名]
# 或者: from suds import WebFault [as 别名]
def _update_real_server_properties(self, new_member):
try:
address = new_member['address']
new_weight = new_member.get('weight')
rs_server = self._adx_server(address)
reply = (self.slb_service
.getRealServerConfiguration(rs_server))
rs_conf_seq = (self.slb_factory.create
('ArrayOfRealServerConfigurationSequence'))
reply.rsConfig.leastConnectionWeight = new_weight
# Work Around to fix bug in WSDL
reply.rsConfig.byteRateThresold = None
rs_conf_list = list()
rs_conf_list.append(reply.rsConfig)
rs_conf_seq.RealServerConfigurationSequence = rs_conf_list
(self.slb_service
.setRealServersConfiguration(rs_conf_seq))
except suds.WebFault as e:
raise adx_exception.ConfigError(msg=e.message)
示例6: bind_member_to_vip
# 需要导入模块: import suds [as 别名]
# 或者: from suds import WebFault [as 别名]
def bind_member_to_vip(self, member, vip):
rs_ip_address = member['address']
rs_port = member['protocol_port']
rs_name = member.get('name', rs_ip_address)
vs_ip_address = vip['address']
vs_port = vip['protocol_port']
vs_name = vip['name']
try:
vs_server_port = self._adx_server_port(
vs_ip_address, vs_port, vs_name)
rs_server_port = self._adx_server_port(
rs_ip_address, rs_port, rs_name)
(self.slb_service
.bindRealServerPortToVipPort(vs_server_port, rs_server_port))
except suds.WebFault as e:
raise adx_exception.ConfigError(msg=e.message)
示例7: unbind_member_from_vip
# 需要导入模块: import suds [as 别名]
# 或者: from suds import WebFault [as 别名]
def unbind_member_from_vip(self, member, vip):
rs_ip_address = member['address']
rs_name = rs_ip_address
rs_name = member.get('name', rs_ip_address)
rs_port = member['protocol_port']
vs_ip_address = vip['address']
vs_port = vip['protocol_port']
vs_name = vip['name']
try:
vs_server_port = self._adx_server_port(
vs_ip_address, vs_port, vs_name)
rs_server_port = self._adx_server_port(
rs_ip_address, rs_port, rs_name)
(self.slb_service
.unbindRealServerPortFromVipPort(vs_server_port, rs_server_port))
# Need to check alternate solutions rather than sleep
# Is 5 seconds good enough ?
time.sleep(5)
except suds.WebFault as e:
raise adx_exception.ConfigError(msg=e.message)
示例8: set_predictor_on_virtual_server
# 需要导入模块: import suds [as 别名]
# 或者: from suds import WebFault [as 别名]
def set_predictor_on_virtual_server(self, vip):
try:
server = self._adx_server(vip['address'], vip['name'])
lb_method = vip['lb_method']
predictor_method_configuration = (self.slb_factory.create
('PredictorMethodConfiguration'))
predictor = ADX_PREDICTOR_MAP.get(lb_method)
if predictor:
predictor_method_configuration.predictor = predictor
else:
error_message = ('Load Balancing Method/Predictor %s '
'not supported') % (lb_method)
LOG.error(error_message)
raise adx_exception.UnsupportedFeature(msg=error_message)
(self.slb_service
.setPredictorOnVirtualServer(server,
predictor_method_configuration))
except suds.WebFault as e:
raise adx_exception.ConfigError(msg=e.message)
示例9: delete_vip
# 需要导入模块: import suds [as 别名]
# 或者: from suds import WebFault [as 别名]
def delete_vip(self, vip):
address = vip['address']
port = vip['protocol_port']
vs_server_port = self._adx_server_port(address, port)
vip_port_count = self._get_server_port_count(address, True)
try:
self.slb_service.deleteVirtualServerPort(vs_server_port)
except suds.WebFault:
pass
try:
if vip_port_count <= 2:
self.slb_service.deleteVirtualServer(vs_server_port.srvr)
except suds.WebFault as e:
raise adx_exception.ConfigError(msg=e.message)
示例10: delete_health_monitor
# 需要导入模块: import suds [as 别名]
# 或者: from suds import WebFault [as 别名]
def delete_health_monitor(self, healthmonitor):
name = healthmonitor['id']
monitor_type = healthmonitor['type']
if monitor_type in ['HTTP', 'HTTPS', 'TCP']:
if not self._does_port_policy_exist(healthmonitor):
LOG.debug('Health Monitor %s does not '
'exist on the device', name)
return
if not self._is_port_policy_in_use(name):
try:
(self.slb_service
.deletePortPolicy(name))
except suds.WebFault as e:
raise adx_exception.ConfigError(msg=e.message)
elif monitor_type == 'PING':
m = 'Delete of PING Monitor not supported'
LOG.error(m)
raise adx_exception.UnsupportedFeature(msg=m)
示例11: test_reply_error_with_detail_with_fault
# 需要导入模块: import suds [as 别名]
# 或者: from suds import WebFault [as 别名]
def test_reply_error_with_detail_with_fault(monkeypatch):
monkeypatch.delitem(locals(), "e", False)
client = testutils.client_from_wsdl(_wsdl__simple_f, faults=True)
for http_status in (http_client.OK, http_client.INTERNAL_SERVER_ERROR):
inject = dict(reply=_fault_reply__with_detail, status=http_status)
e = pytest.raises(suds.WebFault, client.service.f, __inject=inject)
try:
e = e.value
_test_fault(e.fault, True)
assert e.document.__class__ is suds.sax.document.Document
assert str(e) == "Server raised fault: 'Dummy error.'"
finally:
del e # explicitly break circular reference chain in Python 3
inject = dict(reply=_fault_reply__with_detail,
status=http_client.BAD_REQUEST, description="quack-quack")
e = pytest.raises(Exception, client.service.f, __inject=inject).value
try:
assert e.__class__ is Exception
assert e.args[0][0] == http_client.BAD_REQUEST
assert e.args[0][1] == "quack-quack"
finally:
del e # explicitly break circular reference chain in Python 3
示例12: test_reply_error_without_detail_with_fault
# 需要导入模块: import suds [as 别名]
# 或者: from suds import WebFault [as 别名]
def test_reply_error_without_detail_with_fault(monkeypatch):
monkeypatch.delitem(locals(), "e", False)
client = testutils.client_from_wsdl(_wsdl__simple_f, faults=True)
for http_status in (http_client.OK, http_client.INTERNAL_SERVER_ERROR):
inject = dict(reply=_fault_reply__without_detail, status=http_status)
e = pytest.raises(suds.WebFault, client.service.f, __inject=inject)
try:
e = e.value
_test_fault(e.fault, False)
assert e.document.__class__ is suds.sax.document.Document
assert str(e) == "Server raised fault: 'Dummy error.'"
finally:
del e # explicitly break circular reference chain in Python 3
inject = dict(reply=_fault_reply__with_detail,
status=http_client.BAD_REQUEST, description="quack-quack")
e = pytest.raises(Exception, client.service.f, __inject=inject).value
try:
assert e.__class__ is Exception
assert e.args[0][0] == http_client.BAD_REQUEST
assert e.args[0][1] == "quack-quack"
finally:
del e # explicitly break circular reference chain in Python 3
示例13: test_request_handler_with_empty_web_fault_doc
# 需要导入模块: import suds [as 别名]
# 或者: from suds import WebFault [as 别名]
def test_request_handler_with_empty_web_fault_doc(self):
def side_effect(mo, **kwargs):
fault = mock.Mock(faultstring="MyFault")
raise suds.WebFault(fault, None)
svc_obj = service.Service()
service_mock = svc_obj.client.service
setattr(service_mock, 'powerOn', side_effect)
ex = self.assertRaises(exceptions.VimFaultException,
svc_obj.powerOn,
'VirtualMachine')
self.assertEqual([], ex.fault_list)
self.assertEqual({}, ex.details)
self.assertEqual("MyFault", ex.msg)
示例14: raiseZoneNotFound
# 需要导入模块: import suds [as 别名]
# 或者: from suds import WebFault [as 别名]
def raiseZoneNotFound(self):
fault = MockFault(str('102'), '102 is zone not found')
document = {}
raise WebFault(fault, document)
示例15: raiseInvalidAuth
# 需要导入模块: import suds [as 别名]
# 或者: from suds import WebFault [as 别名]
def raiseInvalidAuth(self):
fault = MockFault(str('200'), '200 is invalid auth')
document = {}
raise WebFault(fault, document)