本文整理汇总了Python中networkapi.ip.models.Ip.get_available_ip方法的典型用法代码示例。如果您正苦于以下问题:Python Ip.get_available_ip方法的具体用法?Python Ip.get_available_ip怎么用?Python Ip.get_available_ip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkapi.ip.models.Ip
的用法示例。
在下文中一共展示了Ip.get_available_ip方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_get
# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import get_available_ip [as 别名]
def handle_get(self, request, user, *args, **kwargs):
'''Handles GET requests get an IP4 available.
URL: ip/availableip4/ip_rede
'''
self.log.info('Get an IP4 available')
try:
# 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()
# Business Validations
# Valid id access
id_network = kwargs.get('id_rede')
if not is_valid_int_greater_zero_param(id_network):
self.log.error(
u'Parameter id_rede is invalid. Value: %s.', id_network)
raise InvalidValueError(None, 'id_rede', id_network)
# Business Rules
ip = Ip.get_available_ip(id_network)
list_ip = []
list_ip.append(ip)
network_map = dict()
map_aux = dict()
map_aux['ip'] = list_ip
network_map['ip'] = map_aux
# Business Rules
return self.response(dumps_networkapi(network_map))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
示例2: handle_post
# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import get_available_ip [as 别名]
def handle_post(self, request, user, *args, **kwargs):
'''Handles GET requests get an IP4 available for vip_request by evip_id.
URL: ip/availableip6/vip/id_evip/
'''
self.log.info('Get an IP4 available for vip_request')
try:
# User permission
if not has_perm(user, AdminPermission.IPS, AdminPermission.WRITE_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
return self.not_authorized()
# Load XML data
xml_map, attrs_map = loads(request.raw_post_data)
# XML data format
networkapi_map = xml_map.get('networkapi')
ip_map = networkapi_map.get('ip_map')
# Get XML data
id_evip = ip_map.get('id_evip')
name = ip_map.get('name')
if not is_valid_int_greater_zero_param(id_evip):
self.log.error(
u'Parameter id_evip is invalid. Value: %s.', id_evip)
raise InvalidValueError(None, 'id_evip', id_evip)
# Business Rules
evip = EnvironmentVip.get_by_pk(id_evip)
ipv4 = Ip()
len_network = len(evip.networkipv4_set.all())
raise_not_found_balanceamento = False
if (len_network <= 0):
raise NetworkNotInEvip(
None, 'Não há rede no ambiente vip fornecido')
cont_network = 0
cont_balanceador_not_found = 0
for net in evip.networkipv4_set.all():
balanceador_found_flag = False
cont_network = cont_network + 1
list_ips_equips = list()
try:
ip_available = ipv4.get_available_ip(net.id)
ip_new = Ip()
ip_available = ip_available.exploded
ip_available = ip_available.split(".")
ip_new.oct1 = ip_available[0]
ip_new.oct2 = ip_available[1]
ip_new.oct3 = ip_available[2]
ip_new.oct4 = ip_available[3]
ip_new.descricao = name
for env_equipment in net.vlan.ambiente.equipamentoambiente_set.all():
equipment = env_equipment.equipamento
if equipment.tipo_equipamento == TipoEquipamento.get_tipo_balanceador():
if equipment.id not in list_ips_equips:
list_ips_equips.append(equipment.id)
if ip_new.id is None:
ip_new.save_ipv4(equipment.id, user, net)
else:
new_ip_equip = IpEquipamento()
new_ip_equip.ip = ip_new
new_ip_equip.equipamento = equipment
new_ip_equip.save(user)
balanceador_found_flag = True
if not balanceador_found_flag:
cont_balanceador_not_found = cont_balanceador_not_found + \
1
else:
break
if cont_balanceador_not_found == len_network:
raise_not_found_balanceamento = True
raise IpNotAvailableError(None, "Não há ipv4 disponivel para as redes associdas com o Ambiente Vip: %s - %s - %s, pois não existe equipamentos do Tipo Balanceador nessas redes." % (
evip.finalidade_txt, evip.cliente_txt, evip.ambiente_p44_txt))
except (IpNotAvailableError, IpRangeAlreadyAssociation), e:
cont_balanceador_not_found = cont_balanceador_not_found + 1
if raise_not_found_balanceamento:
raise IpNotAvailableError(None, e.message)
elif len_network == cont_network:
raise IpNotAvailableError(None, "Não há ipv4 disponivel para as redes associdas com o Ambiente Vip: %s - %s - %s" % (
#.........这里部分代码省略.........