本文整理汇总了Python中networkapi.vlan.models.TipoRede.get_by_pk方法的典型用法代码示例。如果您正苦于以下问题:Python TipoRede.get_by_pk方法的具体用法?Python TipoRede.get_by_pk怎么用?Python TipoRede.get_by_pk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkapi.vlan.models.TipoRede
的用法示例。
在下文中一共展示了TipoRede.get_by_pk方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_alter_valid
# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import get_by_pk [as 别名]
def test_alter_valid(self):
mock = self.mock_valid_alter()
response = self.alter(self.ID_ALTER_VALID, {self.XML_KEY: mock})
valid_response(response)
nt = TipoRede.get_by_pk(self.ID_ALTER_VALID)
self.valid_attr(mock, model_to_dict(nt))
示例2: test_save_valid
# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import get_by_pk [as 别名]
def test_save_valid(self):
mock = self.mock_valid()
response = self.save({self.XML_KEY: mock})
valid_response(response)
content = valid_content(response, self.XML_KEY)
nt = TipoRede.get_by_pk(content["id"])
self.valid_attr(mock, model_to_dict(nt))
示例3: criar_rede
# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import get_by_pk [as 别名]
def criar_rede(user, tipo_rede, variablestochangecore1, vlan, active=1):
tiporede = TipoRede()
net_id = tiporede.get_by_name(tipo_rede)
network_type = tiporede.get_by_pk(net_id.id)
network_ip = NetworkIPv4()
network_ip.oct1, network_ip.oct2, network_ip.oct3, network_ip.oct4 = str(variablestochangecore1.get("REDE_IP")).split('.')
network_ip.block = variablestochangecore1.get("REDE_MASK")
network_ip.mask_oct1, network_ip.mask_oct2, network_ip.mask_oct3, network_ip.mask_oct4 = str(variablestochangecore1.get("NETMASK")).split('.')
network_ip.broadcast = variablestochangecore1.get("BROADCAST")
network_ip.vlan = vlan
network_ip.network_type = network_type
network_ip.ambient_vip = None
network_ip.active = active
destroy_cache_function([vlan.id])
network_ip.save()
return network_ip
示例4: handle_delete
# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import get_by_pk [as 别名]
def handle_delete(self, request, user, *args, **kwargs):
"""Treat DELETE request to remove network type
URL: /net_type/<id_net_type>/
"""
try:
# Check permission
if not has_perm(user, AdminPermission.NETWORK_TYPE_MANAGEMENT, AdminPermission.WRITE_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
return self.not_authorized()
# Get URL args
id_net_type = kwargs.get('id_net_type')
if not is_valid_int_greater_zero_param(id_net_type):
self.log.error(
u'Parameter %s is invalid. Value: %s.', 'id_net_type', id_net_type)
raise InvalidValueError(None, 'id_net_type', id_net_type)
net_type = TipoRede.get_by_pk(id_net_type)
with distributedlock(LOCK_TYPE_NETWORK % id_net_type):
# Check if network type is used by vlan
if net_type.networkipv4_set.count() > 0 or net_type.networkipv6_set.count() > 0:
self.log.error(u'Network type used by network.')
raise NetTypeUsedByNetworkError(
None, u'Network type used by network.')
try:
net_type.delete(user)
except Exception, e:
self.log.error(u'Failed to remove network type.')
raise VlanError(e, u'Failed to remove network type.')
# Return empty response
return self.response(dumps_networkapi({}))
示例5: criar_rede_ipv6
# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import get_by_pk [as 别名]
def criar_rede_ipv6(user, tipo_rede, variablestochangecore1, vlan, active=1):
tiporede = TipoRede()
net_id = tiporede.get_by_name(tipo_rede)
network_type = tiporede.get_by_pk(net_id.id)
network_ip = NetworkIPv6()
network_ip.vlan = vlan
network_ip.network_type = network_type
network_ip.ambient_vip = None
network_ip.active = active
network_ip.block = variablestochangecore1.get("REDE_MASK")
while str(variablestochangecore1.get("REDE_IP")).endswith(":"):
variablestochangecore1['REDE_IP'] = variablestochangecore1['REDE_IP'][:-1]
while str(variablestochangecore1.get("NETMASK")).endswith(":"):
variablestochangecore1['NETMASK'] = variablestochangecore1['NETMASK'][:-1]
len_ip_ipv6 = len(str(variablestochangecore1.get("REDE_IP")).split(':'))
len_mask = len(str(variablestochangecore1.get("NETMASK")).split(':'))
while(8-len_ip_ipv6>0):#8-6=2--8-7=1--8-8=0
len_ip_ipv6 = len_ip_ipv6 + 1
variablestochangecore1['REDE_IP'] = variablestochangecore1.get("REDE_IP")+":0"
while(8-len_mask>0):
len_mask = len_mask + 1
variablestochangecore1['NETMASK'] = variablestochangecore1.get("NETMASK")+":0"
network_ip.block1, network_ip.block2, network_ip.block3, network_ip.block4, network_ip.block5, network_ip.block6, network_ip.block7, network_ip.block8 = str(variablestochangecore1.get("REDE_IP")).split(':')
network_ip.mask1, network_ip.mask2, network_ip.mask3, network_ip.mask4, network_ip.mask5, network_ip.mask6, network_ip.mask7, network_ip.mask8 = str(variablestochangecore1.get("NETMASK")).split(':')
destroy_cache_function([vlan.id])
network_ip.save()
return network_ip
示例6: network_ipv4_add
# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import get_by_pk [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)
示例7: handle_post
# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import get_by_pk [as 别名]
def handle_post(self, request, user, *args, **kwargs):
"""
Handles POST requests to allocate a new VLAN.
URL: vlan/
"""
self.log.info('Allocate new VLAN')
try:
# Commons Validations
# User permission
if not has_perm(user, AdminPermission.VLAN_MANAGEMENT, AdminPermission.WRITE_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
return self.not_authorized()
# 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)
vlan_map = networkapi_map.get('vlan')
if vlan_map is None:
msg = u'There is no value to the vlan tag of XML request.'
self.log.error(msg)
return self.response_error(3, msg)
# Get XML data
environment = vlan_map.get('id_ambiente')
network_type = vlan_map.get('id_tipo_rede')
name = vlan_map.get('nome')
description = vlan_map.get('descricao')
environment_vip = vlan_map.get('id_ambiente_vip')
vrf = vlan_map.get('vrf')
# Name must NOT be none and 50 is the maxsize
if not is_valid_string_minsize(name, 3) or not is_valid_string_maxsize(name, 50):
self.log.error(u'Parameter nome is invalid. Value: %s.', name)
raise InvalidValueError(None, 'nome', name)
# Description can NOT be greater than 200
if not is_valid_string_minsize(description, 3, False) or not is_valid_string_maxsize(description, 200, False):
self.log.error(
u'Parameter descricao is invalid. Value: %s.', description)
raise InvalidValueError(None, 'descricao', description)
# vrf can NOT be greater than 100
if not is_valid_string_maxsize(vrf, 100, False):
self.log.error(
u'Parameter vrf is invalid. Value: %s.', vrf)
raise InvalidValueError(None, 'vrf', vrf)
# Environment
# Valid environment ID
if not is_valid_int_greater_zero_param(environment):
self.log.error(
u'Parameter id_ambiente is invalid. Value: %s.', environment)
raise InvalidValueError(None, 'id_ambiente', environment)
# Find environment by ID to check if it exist
env = Ambiente.get_by_pk(environment)
# 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
# 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 = TipoRede.get_by_pk(network_type)
# Business Rules
# New Vlan
#.........这里部分代码省略.........
示例8: handle_post
# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import get_by_pk [as 别名]
def handle_post(self, request, user, *args, **kwargs):
"""Treat POST requests to add new Environment Configuration Prefix
URL: environment/configuration/add
"""
try:
self._validate_permission(user)
xml_map, _ = loads(request.raw_post_data)
networkapi_map = xml_map.get('networkapi')
self._validate_xml_networkapi(networkapi_map)
network_map = networkapi_map.get('ambiente')
self._validate_xml_network(network_map)
# Get XML data
network = network_map.get('network')
id_environment = network_map.get('id_environment')
ip_version = network_map.get('ip_version')
network_type = network_map.get('network_type')
prefix = network_map.get('prefix')
self._validate_network(network, prefix)
self._validate_environment_id(id_environment)
self._validate_ip_version(ip_version)
self._validate_network_type(network_type)
self._validate_prefix_by_net_type(prefix, ip_version)
environment = Ambiente().get_by_pk(id_environment)
network_type = TipoRede.get_by_pk(network_type)
ip_config = IPConfig()
ip_config.subnet = network
ip_config.new_prefix = prefix
ip_config.type = ip_version
ip_config.network_type = network_type
ip_config.save()
config_environment = ConfigEnvironment()
config_environment.environment = environment
config_environment.ip_config = ip_config
config_environment.save()
return self.response(dumps_networkapi({'network': network_map}))
except PermissionError:
return self.not_authorized()
except AmbienteNotFoundError, e:
return self.response_error(112)
示例9: handle_post
# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import get_by_pk [as 别名]
def handle_post(self, request, user, *args, **kwargs):
'''Handles POST requests to edit an Network.
URL: network/edit/
'''
self.log.info('Edit an Network')
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)
net_map = networkapi_map.get('net')
if net_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_network = net_map.get('id_network')
ip_type = net_map.get('ip_type')
id_net_type = net_map.get('id_net_type')
id_env_vip = net_map.get('id_env_vip')
# Valid id_network
if not is_valid_int_greater_zero_param(id_network):
self.log.error(
u'Parameter id_network is invalid. Value: %s.', id_network)
raise InvalidValueError(None, 'id_network', id_network)
# Valid ip_type
if not is_valid_int_param(ip_type):
self.log.error(
u'Parameter ip_type is invalid. Value: %s.', ip_type)
raise InvalidValueError(None, 'ip_type', ip_type)
list_choice = [0, 1]
# Valid ip_type choice
if int(ip_type) not in list_choice:
self.log.error(
u'Parameter ip_type is invalid. Value: %s.', ip_type)
raise InvalidValueError(None, 'ip_type', ip_type)
# Valid id_net_type
if not is_valid_int_greater_zero_param(id_net_type):
self.log.error(
u'Parameter id_net_type is invalid. Value: %s.', id_net_type)
raise InvalidValueError(None, 'id_net_type', id_net_type)
# Valid id_env_vip
if id_env_vip is not None:
if not is_valid_int_greater_zero_param(id_env_vip):
self.log.error(
u'Parameter id_env_vip is invalid. Value: %s.', id_env_vip)
raise InvalidValueError(None, 'id_env_vip', id_env_vip)
# User permission
if not has_perm(user, AdminPermission.VLAN_MANAGEMENT, AdminPermission.WRITE_OPERATION):
raise UserNotAuthorizedError(
None, u'User does not have permission to perform the operation.')
# Business Rules
if (id_env_vip is not None):
id_env_vip = EnvironmentVip.get_by_pk(id_env_vip)
id_net_type = TipoRede.get_by_pk(id_net_type)
# New network_tyoe
# EDIT NETWORK IP4
if int(ip_type) == 0:
net = NetworkIPv4.get_by_pk(id_network)
with distributedlock(LOCK_NETWORK_IPV4 % id_network):
if id_env_vip is not None:
if net.ambient_vip is None or net.ambient_vip.id != id_env_vip.id:
network = IPNetwork(
'%d.%d.%d.%d/%d' % (net.oct1, net.oct2, net.oct3, net.oct4, net.block))
# Find all networks related to environment vip
nets = NetworkIPv4.objects.select_related().filter(
ambient_vip__id=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 ip
# range as related the environment vip
if network in networks:
raise NetworkIpAddressNotAvailableError(
#.........这里部分代码省略.........
示例10: handle_put
# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import get_by_pk [as 别名]
def handle_put(self, request, user, *args, **kwargs):
"""Treat PUT requests to edit network types.
URL: /net_type/<id_net_type>/
"""
try:
# Check permission
if not has_perm(user, AdminPermission.NETWORK_TYPE_MANAGEMENT, AdminPermission.WRITE_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
return self.not_authorized()
# Get URL args
id_net_type = kwargs.get('id_net_type')
if not is_valid_int_greater_zero_param(id_net_type):
self.log.error(
u'Parameter %s is invalid. Value: %s.', 'id_net_type', id_net_type)
raise InvalidValueError(None, 'id_net_type', id_net_type)
# Get XML data
xml_map, attrs_map = loads(request.raw_post_data)
# Get networkapi tag map
networkapi_map = xml_map.get('networkapi')
if networkapi_map is None:
return self.response_error(3, u'There is no networkapi tag from request XML.')
# Get net_type tag map
net_type_map = networkapi_map.get('net_type')
if net_type_map is None:
return self.response_error(3, u'There is no net_type tag from request XML.')
# Valid name attribute
name = net_type_map.get('name')
if not is_valid_string_minsize(name, 3) or not is_valid_string_maxsize(name, 100):
self.log.error(
u'Parameter %s is invalid. Value: %s.', 'name', name)
raise InvalidValueError(None, 'name', name)
net_type = TipoRede.get_by_pk(id_net_type)
with distributedlock(LOCK_TYPE_NETWORK % id_net_type):
try:
if name.lower() != net_type.tipo_rede.lower():
TipoRede.get_by_name(name)
raise NetworkTypeNameDuplicatedError(
None, u'Network type with name %s already exists' % name)
except NetworkTypeNotFoundError:
pass
net_type.tipo_rede = name
try:
net_type.save(user)
except Exception, e:
self.log.error(u'Failed to edit network type.')
raise VlanError(e, u'Failed to edit network type.')
# Return empty response
return self.response(dumps_networkapi({}))
示例11: handle_post
# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import get_by_pk [as 别名]
def handle_post(self, request, user, *args, **kwargs):
"""Treat POST requests to add new Network
URL: network/add/
"""
try:
# Commons Validations
# User permission
if not has_perm(user, AdminPermission.VLAN_MANAGEMENT, AdminPermission.WRITE_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
return self.not_authorized()
# 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)
network_map = networkapi_map.get('network')
if network_map is None:
msg = u'There is no value to the vlan tag of XML request.'
self.log.error(msg)
return self.response_error(3, msg)
# Get XML data
network = network_map.get('network')
id_vlan = network_map.get('id_vlan')
network_type = network_map.get('id_network_type')
environment_vip = network_map.get('id_environment_vip')
# Valid Network
try:
net = IPNetwork(network)
except ValueError, e:
raise InvalidValueError(None, 'network', network)
# VLAN
# Valid vlan ID
if not is_valid_int_greater_zero_param(id_vlan):
raise InvalidValueError(None, 'id_vlan', id_vlan)
# Find vlan by ID to check if it exist
vlan = Vlan().get_by_pk(id_vlan)
# Network Type
# Valid network_type ID
if not is_valid_int_greater_zero_param(network_type):
raise InvalidValueError(None, 'id_network_type', network_type)
# Find network_type by ID to check if it exist
net_type = 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):
raise InvalidValueError(
None, 'id_environment_vip', environment_vip)
evips = EnvironmentVip.objects.all()
evip_list = EnvironmentVip.available_evips(
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
#.........这里部分代码省略.........
示例12: network_ipv6_add
# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import get_by_pk [as 别名]
def network_ipv6_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 = 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 NetworkIPv6
network_ipv6 = NetworkIPv6()
vlan_map = network_ipv6.add_network_ipv6(
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 ipv6 on all equipment
# that is configured as a router for the environment related to
# network
ipv6 = Ipv6.get_first_available_ip6(vlan_map['vlan']['id_network'])
ipv6 = str(ipv6).split(':')
ipv6_model = Ipv6()
ipv6_model.block1 = ipv6[0]
ipv6_model.block2 = ipv6[1]
ipv6_model.block3 = ipv6[2]
ipv6_model.block4 = ipv6[3]
ipv6_model.block5 = ipv6[4]
ipv6_model.block6 = ipv6[5]
ipv6_model.block7 = ipv6[6]
ipv6_model.block8 = ipv6[7]
ipv6_model.networkipv6_id = vlan_map['vlan']['id_network']
ipv6_model.save()
if len(list_equip_routers_ambient) > 1:
multiple_ips = True
else:
multiple_ips = False
for equip in list_equip_routers_ambient:
Ipv6Equipament().create(
user, ipv6_model.id, equip.equipamento.id)
if multiple_ips:
router_ip = Ipv6.get_first_available_ip6(vlan_map['vlan']['id_network'], True)
ipv6_model2 = Ipv6()
ipv6_model2.block1 = router_ip[0]
ipv6_model2.block2 = router_ip[1]
ipv6_model2.block3 = router_ip[2]
ipv6_model2.block4 = router_ip[3]
ipv6_model2.block5 = router_ip[4]
ipv6_model2.block6 = router_ip[5]
ipv6_model2.block7 = router_ip[6]
ipv6_model2.block8 = router_ip[7]
ipv6_model2.networkipv6_id = vlan_map['vlan']['id_network']
ipv6_model2.save()
Ipv6Equipament().create(user, ipv6_model2.id, equip.equipamento.id)
# Return XML
return self.response(dumps_networkapi(vlan_map))
except XMLError, e:
self.log.error(u'Error reading the XML request.')
return self.response_error(3, e)