本文整理汇总了Python中networkapi.ip.models.Ip.oct4方法的典型用法代码示例。如果您正苦于以下问题:Python Ip.oct4方法的具体用法?Python Ip.oct4怎么用?Python Ip.oct4使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkapi.ip.models.Ip
的用法示例。
在下文中一共展示了Ip.oct4方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: network_ipv4_add
# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import oct4 [as 别名]
def network_ipv4_add(self, user, vlan_id, network_type, environment_vip, prefix=None):
try:
# Valid vlan ID
if not is_valid_int_greater_zero_param(vlan_id):
self.log.error(
u'Parameter id_vlan is invalid. Value: %s.', vlan_id)
raise InvalidValueError(None, 'id_vlan', vlan_id)
# Network Type
# Valid network_type ID
"""
if not is_valid_int_greater_zero_param(network_type):
self.log.error(
u'Parameter id_tipo_rede is invalid. Value: %s.', network_type)
raise InvalidValueError(None, 'id_tipo_rede', network_type)
"""
# Find network_type by ID to check if it exist
net = None
if network_type:
net = TipoRede.get_by_pk(network_type)
# Environment Vip
if environment_vip is not None:
# Valid environment_vip ID
if not is_valid_int_greater_zero_param(environment_vip):
self.log.error(
u'Parameter id_ambiente_vip is invalid. Value: %s.', environment_vip)
raise InvalidValueError(
None, 'id_ambiente_vip', environment_vip)
# Find Environment VIP by ID to check if it exist
evip = EnvironmentVip.get_by_pk(environment_vip)
else:
evip = None
# Business Rules
# New NetworkIPv4
network_ipv4 = NetworkIPv4()
vlan_map = network_ipv4.add_network_ipv4(user, vlan_id, net, evip, prefix)
list_equip_routers_ambient = EquipamentoAmbiente.get_routers_by_environment(vlan_map['vlan']['id_ambiente'])
if list_equip_routers_ambient:
# Add Adds the first available ipv4 on all equipment
# that is configured as a router for the environment related to
# network
ip = Ip.get_first_available_ip(vlan_map['vlan']['id_network'])
ip = str(ip).split('.')
ip_model = Ip()
ip_model.oct1 = ip[0]
ip_model.oct2 = ip[1]
ip_model.oct3 = ip[2]
ip_model.oct4 = ip[3]
ip_model.networkipv4_id = network_ipv4.id
ip_model.save()
if len(list_equip_routers_ambient) > 1:
multiple_ips = True
else:
multiple_ips = False
for equip in list_equip_routers_ambient:
IpEquipamento().create(user, ip_model.id, equip.equipamento.id)
if multiple_ips:
router_ip = Ip.get_first_available_ip(vlan_map['vlan']['id_network'], True)
router_ip = str(router_ip).split('.')
ip_model2 = Ip()
ip_model2.oct1 = router_ip[0]
ip_model2.oct2 = router_ip[1]
ip_model2.oct3 = router_ip[2]
ip_model2.oct4 = router_ip[3]
ip_model2.networkipv4_id = vlan_map['vlan']['id_network']
ip_model2.save()
IpEquipamento().create(user, ip_model2.id, equip.equipamento.id)
# Return XML
return self.response(dumps_networkapi(vlan_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 oct4 [as 别名]
def handle_post(self, request, user, *args, **kwargs):
"""Handles POST requests to edit an IP.
URL: ipv4/edit/
"""
self.log.info('Edit an IP')
try:
# 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
id_ip = ip_map.get('id_ip')
description = ip_map.get('descricao')
ip4 = ip_map.get('ip4')
# Valid id_ip
if not is_valid_int_greater_zero_param(id_ip):
self.log.error(
u'Parameter id_ip is invalid. Value: %s.', id_ip)
raise InvalidValueError(None, 'id_ip', id_ip)
if not is_valid_string_maxsize(ip4, 15):
self.log.error(u'Parameter ip4 is invalid. Value: %s.', ip4)
raise InvalidValueError(None, 'ip4', description)
# Valid description
if description is not None:
if not is_valid_string_maxsize(description, 100) or not is_valid_string_minsize(description, 3):
self.log.error(
u'Parameter description is invalid. Value: %s.', description)
raise InvalidValueError(None, 'description', description)
# User permission
if not has_perm(user, AdminPermission.IPS, AdminPermission.WRITE_OPERATION):
raise UserNotAuthorizedError(
None, u'User does not have permission to perform the operation.')
# Business Rules
# New IP
ip = Ip()
ip = ip.get_by_pk(id_ip)
with distributedlock(LOCK_IPV4 % id_ip):
# se Houver erro no ip informado para retorna-lo na mensagem
ip_error = ip4
# verificação se foi passado algo errado no ip
ip4 = ip4.split('.')
for oct in ip4:
if not is_valid_int_param(oct):
raise InvalidValueError(None, 'ip4', ip_error)
# Ip passado de forma invalida
if len(ip4) is not 4:
raise IndexError
ip.descricao = description
ip.oct1 = ip4[0]
ip.oct2 = ip4[1]
ip.oct3 = ip4[2]
ip.oct4 = ip4[3]
# Persist
ip.edit_ipv4(user)
return self.response(dumps_networkapi({}))
except UserNotAuthorizedError:
return self.not_authorized()
except IndexError:
msg = 'Invalid IP %s' % ip_error
return self.response_error(150, msg)
except IpNotFoundError, e:
return self.response_error(150, e.message)
示例3: handle_post
# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import oct4 [as 别名]
#.........这里部分代码省略.........
vlan.acl_file_name = acl_file
vlan.acl_file_name_v6 = acl_file_v6
vlan.num_vlan = number
vlan.nome = name
vlan.descricao = description
vlan.ambiente = ambiente
vlan.ativada = 0
vlan.acl_valida = 0
vlan.acl_valida_v6 = 0
vlan.insert_vlan(user)
if network_ipv4:
network_ipv4 = NetworkIPv4()
vlan_map = network_ipv4.add_network_ipv4(
user, vlan.id, None, None, None)
list_equip_routers_ambient = EquipamentoAmbiente.objects.select_related('equipamento').filter(
ambiente=vlan.ambiente.id, is_router=True)
if list_equip_routers_ambient:
# Add Adds the first available ipv4 on all equipment
# that is configured as a router for the environment related to
# network
ip = Ip.get_first_available_ip(network_ipv4.id)
ip = str(ip).split('.')
ip_model = Ip()
ip_model.oct1 = ip[0]
ip_model.oct2 = ip[1]
ip_model.oct3 = ip[2]
ip_model.oct4 = ip[3]
ip_model.networkipv4_id = network_ipv4.id
ip_model.save(user)
if len(list_equip_routers_ambient) > 1 and network_ipv4.block < 30:
multiple_ips = True
else:
multiple_ips = False
for equip in list_equip_routers_ambient:
IpEquipamento().create(user, ip_model.id, equip.equipamento.id)
if multiple_ips:
router_ip = Ip.get_first_available_ip(
network_ipv4.id, True)
router_ip = str(router_ip).split('.')
ip_model2 = Ip()
ip_model2.oct1 = router_ip[0]
ip_model2.oct2 = router_ip[1]
ip_model2.oct3 = router_ip[2]
ip_model2.oct4 = router_ip[3]
ip_model2.networkipv4_id = network_ipv4.id
ip_model2.save(user)
IpEquipamento().create(user, ip_model2.id, equip.equipamento.id)
if network_ipv6:
network_ipv6 = NetworkIPv6()
vlan_map = network_ipv6.add_network_ipv6(
user, vlan.id, None, None, None)
list_equip_routers_ambient = EquipamentoAmbiente.objects.filter(
ambiente=vlan.ambiente.id, is_router=True)
示例4: handle_post
# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import oct4 [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" % (
#.........这里部分代码省略.........
示例5: handle_post
# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import oct4 [as 别名]
def handle_post(self, request, user, *args, **kwargs):
'''Handles POST requests to add an IP and associate it to an equipment.
URL: ipv4/save/
'''
self.log.info('Add an IP and associate it to an equipment')
try:
# 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
equip_id = ip_map.get('id_equip')
network_ipv4_id = ip_map.get('id_net')
description = ip_map.get('descricao')
ip4 = ip_map.get('ip4')
# Valid equip_id
if not is_valid_int_greater_zero_param(equip_id):
self.log.error(
u'Parameter equip_id is invalid. Value: %s.', equip_id)
raise InvalidValueError(None, 'equip_id', equip_id)
# Valid network_ipv4_id
if not is_valid_int_greater_zero_param(network_ipv4_id):
self.log.error(
u'Parameter network_ipv4_id is invalid. Value: %s.', network_ipv4_id)
raise InvalidValueError(
None, 'network_ipv4_id', network_ipv4_id)
# Valid ip size
if not is_valid_string_maxsize(ip4, 15):
self.log.error(u'Parameter ip4 is invalid. Value: %s.', ip4)
raise InvalidValueError(None, 'ip4', ip4)
# Description can NOT be greater than 100
if description is not None:
if not is_valid_string_maxsize(description, 100) or not is_valid_string_minsize(description, 3):
self.log.error(
u'Parameter description is invalid. Value: %s.', description)
raise InvalidValueError(None, 'description', description)
# User permission
if not has_perm(user,
AdminPermission.IPS,
AdminPermission.WRITE_OPERATION,
None,
equip_id,
AdminPermission.EQUIP_WRITE_OPERATION):
raise UserNotAuthorizedError(
None, u'User does not have permission to perform the operation.')
# Business Rules
# New IP
ip = Ip()
net = NetworkIPv4.get_by_pk(network_ipv4_id)
with distributedlock(LOCK_NETWORK_IPV4 % network_ipv4_id):
# se Houver erro no ip informado para retorna-lo na mensagem
ip_error = ip4
# verificação se foi passado algo errado no ip
ip4 = ip4.split(".")
for oct in ip4:
if not is_valid_int_param(oct):
raise InvalidValueError(None, 'ip4', ip_error)
#raise IndexError
# Ip passado de forma invalida
if len(ip4) is not 4:
raise IndexError
ip.descricao = description
ip.oct1 = ip4[0]
ip.oct2 = ip4[1]
ip.oct3 = ip4[2]
ip.oct4 = ip4[3]
equip = Equipamento.get_by_pk(equip_id)
listaVlansDoEquip = []
for ipequip in equip.ipequipamento_set.all():
vlan = ipequip.ip.networkipv4.vlan
#.........这里部分代码省略.........
示例6: handle_post
# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import oct4 [as 别名]
#.........这里部分代码省略.........
EnvironmentVip(), evips, int(id_vlan))
# Check if the chose environment is in the same environment
if any(int(environment_vip) == item['id'] for item in evip_list):
# Find Environment VIP by ID to check if it exist
env_vip = EnvironmentVip.get_by_pk(environment_vip)
else:
raise InvalidValueError(
None, 'id_environment_vip', environment_vip)
else:
env_vip = None
# Check unchecked exception
blocks, network, version = break_network(network)
expl = split(
net.network.exploded, "." if version == IP_VERSION.IPv4[0] else ":")
expl.append(str(net.prefixlen))
if blocks != expl:
raise InvalidValueError(None, 'rede', network)
# Business Rules
if version == IP_VERSION.IPv4[0]:
# Find all networks related to environment
nets = NetworkIPv4.objects.select_related().filter(
vlan__ambiente__id=vlan.ambiente.id)
# Cast to API class
networks = set([IPv4Network(
'%d.%d.%d.%d/%d' % (net_ip.oct1, net_ip.oct2, net_ip.oct3, net_ip.oct4, net_ip.block)) for net_ip in nets])
# If network selected not in use
if net in networks:
raise NetworkIPv4AddressNotAvailableError(
None, u'Unavailable address to create a NetworkIPv4.')
if env_vip is not None:
# Find all networks related to environment vip
nets = NetworkIPv4.objects.select_related().filter(
ambient_vip__id=env_vip.id)
# Cast to API class
networks = set([IPv4Network(
'%d.%d.%d.%d/%d' % (net_ip.oct1, net_ip.oct2, net_ip.oct3, net_ip.oct4, net_ip.block)) for net_ip in nets])
# If there is already a network with the same range ip as
# related the environment vip
if net in networks:
raise NetworkIpAddressNotAvailableError(
None, u'Unavailable address to create a NetworkIPv4.')
# # Filter case 1 - Adding new network with same ip range to another network on other environment ##
# Get environments with networks with the same ip range
nets = NetworkIPv4.objects.filter(
oct1=expl[0], oct2=expl[1], oct3=expl[2], oct4=expl[3], block=expl[4])
env_ids = list()
for net_ip in nets:
env_ids.append(net_ip.vlan.ambiente.id)
# If other network with same ip range exists
if len(env_ids) > 0: