本文整理汇总了Python中networkapi.requisicaovips.models.RequisicaoVips.heathcheck_exist方法的典型用法代码示例。如果您正苦于以下问题:Python RequisicaoVips.heathcheck_exist方法的具体用法?Python RequisicaoVips.heathcheck_exist怎么用?Python RequisicaoVips.heathcheck_exist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkapi.requisicaovips.models.RequisicaoVips
的用法示例。
在下文中一共展示了RequisicaoVips.heathcheck_exist方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_put
# 需要导入模块: from networkapi.requisicaovips.models import RequisicaoVips [as 别名]
# 或者: from networkapi.requisicaovips.models.RequisicaoVips import heathcheck_exist [as 别名]
def handle_put(self, request, user, *args, **kwargs):
"""
Handles PUT requests to change the VIP's healthcheck.
URL: vip/<id_vip>/healthcheck
"""
self.log.info("Change VIP's healthcheck")
try:
# Commons Validations
# 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
vip_id = kwargs.get("id_vip")
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)
# 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"Healthcheck can not be changed because VIP has not yet been created.")
raise RequestVipsNotBeenCreatedError(None)
# Vip equipments permission
if vip.ip is not None:
for ip_equipment in vip.ip.ipequipamento_set.all():
if not has_perm(
user,
AdminPermission.VIP_ALTER_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)
if vip.ipv6 is not None:
for ip_equipment in vip.ipv6.ipv6equipament_set.all():
if not has_perm(
user,
AdminPermission.VIP_ALTER_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)
# Business Validations
# Load XML data
xml_map, attrs_map = loads(request.raw_post_data)
# 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.")
# Get XML data
healthcheck_type = upper(str(vip_map["healthcheck_type"]))
healthcheck = vip_map["healthcheck"]
id_healthcheck_expect = vip_map["id_healthcheck_expect"]
vars = vip.variables_to_map()
environment_vip = EnvironmentVip.get_by_values(
vars.get("finalidade"), vars.get("cliente"), vars.get("ambiente")
)
healthcheck_is_valid = RequisicaoVips.heathcheck_exist(healthcheck_type, environment_vip.id)
# healthcheck_type exist'
if not healthcheck_is_valid:
self.log.error(u"The healthcheck_type parameter not exist.")
raise InvalidValueError(
u"The healthcheck_type parameter not exist.", "healthcheck_type", healthcheck_type
)
# If healthcheck_type is not HTTP id_healthcheck_expect and
#.........这里部分代码省略.........