本文整理汇总了Python中networkapi.requisicaovips.models.RequisicaoVips.is_valid_values_reals_priority方法的典型用法代码示例。如果您正苦于以下问题:Python RequisicaoVips.is_valid_values_reals_priority方法的具体用法?Python RequisicaoVips.is_valid_values_reals_priority怎么用?Python RequisicaoVips.is_valid_values_reals_priority使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkapi.requisicaovips.models.RequisicaoVips
的用法示例。
在下文中一共展示了RequisicaoVips.is_valid_values_reals_priority方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_put
# 需要导入模块: from networkapi.requisicaovips.models import RequisicaoVips [as 别名]
# 或者: from networkapi.requisicaovips.models.RequisicaoVips import is_valid_values_reals_priority [as 别名]
def handle_put(self, request, user, *args, **kwargs):
"""Treat PUT requests to change reals_priority list of VIP.
URLs: /vip/<id_vip>/priority/
"""
self.log.info("Change list the reals_priority to VIP")
try:
vip_id = kwargs.get('id_vip')
# Load XML data
xml_map, attrs_map = loads(
request.raw_post_data, ['reals_priority'])
# XML data format
networkapi_map = xml_map.get('networkapi')
if networkapi_map is None:
return self.response_error(3, u'There is no value to the networkapi tag of XML request.')
vip_map = networkapi_map.get('vip')
if vip_map is None:
return self.response_error(3, u'There is no value to the vip tag of XML request.')
# User permission
if not has_perm(user, AdminPermission.VIP_ALTER_SCRIPT, AdminPermission.WRITE_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
raise UserNotAuthorizedError(None)
# Valid Vip ID
if not is_valid_int_greater_zero_param(vip_id):
self.log.error(
u'The vip_id parameter is not a valid value: %s.', vip_id)
raise InvalidValueError(None, 'vip_id', vip_id)
# Valid reals_prioritys
reals_prioritys_map = vip_map.get('reals_prioritys')
if (reals_prioritys_map is not None):
reals_priority_map = reals_prioritys_map.get('reals_priority')
if (reals_priority_map is not None):
# Valid values of reals_priority
for reals_priority in reals_priority_map:
if not is_valid_int_greater_equal_zero_param(reals_priority):
self.log.error(
u'The reals_priority parameter is not a valid value: %s.', reals_priority)
raise InvalidValueError(
None, 'reals_priority', reals_priority)
if len(reals_priority_map) > 0:
vip_map = RequisicaoVips.is_valid_values_reals_priority(
reals_priority_map)
else:
self.log.error(
u'The reals_priority_map parameter is not a valid value: %s.', reals_priority_map)
raise InvalidValueError(
None, 'reals_priority_map', reals_priority_map)
else:
self.log.error(
u'The reals_priority parameter is not a valid value: %s.', reals_priority_map)
raise InvalidValueError(
None, 'reals_priority', reals_priority_map)
else:
self.log.error(
u'The reals_prioritys parameter is not a valid value: %s.', reals_prioritys_map)
raise InvalidValueError(
None, 'reals_prioritys', reals_prioritys_map)
# Existing Vip ID
vip = RequisicaoVips.get_by_pk(vip_id)
with distributedlock(LOCK_VIP % vip_id):
vip_old = clone(vip)
# Vip must be created
if not vip.vip_criado:
self.log.error(
u'Priority can not be changed because VIP has not yet been created.')
raise RequestVipsNotBeenCreatedError(None)
# Vip equipments permission
for ip_equipment in vip.ip.ipequipamento_set.all():
if not has_perm(user, AdminPermission.VIP_CREATE_SCRIPT, AdminPermission.WRITE_OPERATION, None, ip_equipment.equipamento_id, AdminPermission.EQUIP_UPDATE_CONFIG_OPERATION):
self.log.error(
u'Groups of equipment registered with the IP of the VIP request is not allowed of acess.')
raise EquipmentGroupsNotAuthorizedError(None)
variables_map = vip.variables_to_map()
# Valid list reals_server
"""if len(variables_map.get('reals').get('real')) != len(vip_map.get('reals_prioritys').get('reals_priority')):
self.log.error(u'List the Reals_priority is higher or lower than list the real_server.')
return self.response_error(272)"""
variables_map['reals_prioritys'] = vip_map.get(
'reals_prioritys')
#.........这里部分代码省略.........