本文整理汇总了Python中networkapi.ip.models.Ip.get_by_octs_and_environment_vip方法的典型用法代码示例。如果您正苦于以下问题:Python Ip.get_by_octs_and_environment_vip方法的具体用法?Python Ip.get_by_octs_and_environment_vip怎么用?Python Ip.get_by_octs_and_environment_vip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkapi.ip.models.Ip
的用法示例。
在下文中一共展示了Ip.get_by_octs_and_environment_vip方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_post
# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import get_by_octs_and_environment_vip [as 别名]
def handle_post(self, request, user, *args, **kwargs):
'''Handles POST requests to check an IPv4 or Ipv6 for vip request.
URL: ip/checkvipip/
'''
self.log.info('Check a Ipv4 or Ipv6 for Vip')
try:
# 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:
msg = u'There is no value to the networkapi tag of XML request.'
self.log.error(msg)
return self.response_error(3, msg)
ip_map = networkapi_map.get('ip_map')
if ip_map is None:
msg = u'There is no value to the ip tag of XML request.'
self.log.error(msg)
return self.response_error(3, msg)
# Get XML data
ip = ip_map.get('ip')
id_evip = ip_map.get('id_evip')
# User permission
if not has_perm(user, AdminPermission.IPS, AdminPermission.READ_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
return self.not_authorized()
# Valid ip id
if ip is None:
self.log.error(u'Parameter ip is invalid. Value: %s.', ip)
raise InvalidValueError(None, 'ip', ip)
# Valid evip id
if not is_valid_int_greater_zero_param(id_evip):
raise InvalidValueError(None, 'id_evip', id_evip)
# Business Rules
evip = EnvironmentVip.get_by_pk(id_evip)
ip_list = ip.split(".")
if len(ip_list) == 1:
if not is_valid_ipv6(ip):
self.log.error(u'Parameter ip is invalid. Value: %s.', ip)
raise InvalidValueError(None, 'ip', ip)
if len(evip.networkipv6_set.all()) <= 0:
raise NetworkNotInEvip(
'IPv6', 'Não há rede no ambiente vip fornecido')
ip_list = ip.split(":")
ip_checked = Ipv6.get_by_octs_and_environment_vip(ip_list[0], ip_list[1], ip_list[
2], ip_list[3], ip_list[4], ip_list[5], ip_list[6], ip_list[7], id_evip)
ip_ok = False
for ip_equip in ip_checked.ipv6equipament_set.all():
if ip_equip.equipamento.tipo_equipamento == TipoEquipamento.get_tipo_balanceador():
ip_ok = True
break
if not ip_ok:
raise IpNotAvailableError(
None, "Ipv6 indisponível para o Ambiente Vip: %s, pois não existe equipamento do Tipo Balanceador relacionado a este Ip." % evip.show_environment_vip())
else:
if not is_valid_ipv4(ip):
self.log.error(u'Parameter ip is invalid. Value: %s.', ip)
raise InvalidValueError(None, 'ip', ip)
if len(evip.networkipv4_set.all()) <= 0:
raise NetworkNotInEvip(
'IPv4', 'Não há rede no ambiente vip fornecido')
ip_checked = Ip.get_by_octs_and_environment_vip(
ip_list[0], ip_list[1], ip_list[2], ip_list[3], id_evip)
ip_ok = False
for ip_equip in ip_checked.ipequipamento_set.all():
if ip_equip.equipamento.tipo_equipamento == TipoEquipamento.get_tipo_balanceador():
ip_ok = True
break
#.........这里部分代码省略.........