本文整理汇总了Python中networkapi.ip.models.Ip.descricao方法的典型用法代码示例。如果您正苦于以下问题:Python Ip.descricao方法的具体用法?Python Ip.descricao怎么用?Python Ip.descricao使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkapi.ip.models.Ip
的用法示例。
在下文中一共展示了Ip.descricao方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: inserir_equip
# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import descricao [as 别名]
def inserir_equip(user, variablestochangecore, rede_id):
ip = Ip()
ip.descricao = None
ip.oct1, ip.oct2, ip.oct3, ip.oct4 = str(variablestochangecore["IPCORE"]).split('.')
equip = Equipamento.get_by_name(variablestochangecore["EQUIP_NAME"])
rede = NetworkIPv4.get_by_pk(rede_id)
ip.save_ipv4(equip.id, user, rede)
if ip.id is None:
raise RackAplError (None, None, "Erro ao inserir os equipamentos")
# Delete vlan's cache
destroy_cache_function([rede.vlan_id])
list_id_equip = []
list_id_equip.append(equip.id)
destroy_cache_function(list_id_equip, True)
return 0
示例2: handle_post
# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import descricao [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 descricao [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" % (
#.........这里部分代码省略.........
示例4: handle_post
# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import descricao [as 别名]
def handle_post(self, request, user, *args, **kwargs):
'''Handles POST requests to add an IP and associate it to an equipment.
URL: ipv4/
'''
self.log.info('Add an IP and associate it to an equipment')
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')
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_equipment')
network_ipv4_id = ip_map.get('id_network_ipv4')
description = ip_map.get('description')
# 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)
# Description can NOT be greater than 100
if not is_valid_string_maxsize(description, 100) or not is_valid_string_minsize(description, 3):
self.log.error(
u'Parameter descricao is invalid. Value: %s.', description)
raise InvalidValueError(None, 'descricao', 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()
ip.descricao = description
# Persist
ip.create(user, equip_id, network_ipv4_id, True)
# Generate return map
ip_map = dict()
ip_map['id'] = ip.id
ip_map['id_redeipv4'] = ip.networkipv4.id
ip_map['oct4'] = ip.oct4
ip_map['oct3'] = ip.oct3
ip_map['oct2'] = ip.oct2
ip_map['oct1'] = ip.oct1
ip_map['descricao'] = ip.descricao
return self.response(dumps_networkapi({'ip': ip_map}))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
示例5: insert_ip
# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import descricao [as 别名]
def insert_ip(ip_map, user):
'''Insere um IP e o relacionamento entre o IP e o equipamento.
@param ip_map: Map com as chaves: id_equipamento, id_vlan e descricao
@param user: Usuário autenticado na API.
@return Em caso de erro retorna a tupla: (código da mensagem de erro, argumento01, argumento02, ...)
Em caso de sucesso retorna a tupla: (0, <mapa com os dados do IP>)
@raise VlanNotFoundError: VLAN não cadastrada.
@raise VlanError: Falha ao pesquisar a VLAN.
@raise EquipamentoNotFoundError: Equipamento não cadastrado.
@raise EquipamentoError: Falha ao pesquisar o Equipamento.
@raise IpNotAvailableError: Não existe um IP disponível para a VLAN.
@raise IpError: Falha ao inserir no banco de dados.
@raise UserNotAuthorizedError: Usuário sem autorização para executar a operação.
'''
log = logging.getLogger('insert_ip')
equip_id = ip_map.get('id_equipamento')
if not is_valid_int_greater_zero_param(equip_id):
log.error(
u'The equip_id parameter is not a valid value: %s.', equip_id)
raise InvalidValueError(None, 'equip_id', equip_id)
else:
equip_id = int(equip_id)
if not has_perm(user,
AdminPermission.IPS,
AdminPermission.WRITE_OPERATION,
None,
equip_id,
AdminPermission.EQUIP_WRITE_OPERATION):
raise UserNotAuthorizedError(
None, u'Usuário não tem permissão para executar a operação.')
vlan_id = ip_map.get('id_vlan')
if not is_valid_int_greater_zero_param(vlan_id):
log.error(u'The vlan_id parameter is not a valid value: %s.', vlan_id)
raise InvalidValueError(None, 'vlan_id', vlan_id)
else:
vlan_id = int(vlan_id)
desc_ip = ip_map.get('descricao')
if desc_ip is not None:
if not is_valid_string_maxsize(desc_ip, 100) or not is_valid_string_minsize(desc_ip, 3):
log.error(u'Parameter desc_ip is invalid. Value: %s.', desc_ip)
raise InvalidValueError(None, 'desc_ip', desc_ip)
ip = Ip()
ip.descricao = desc_ip
ip.create(user, equip_id, vlan_id, False)
ip_map = dict()
ip_map['id'] = ip.id
ip_map['id_redeipv4'] = ip.networkipv4.id
ip_map['oct4'] = ip.oct4
ip_map['oct3'] = ip.oct3
ip_map['oct2'] = ip.oct2
ip_map['oct1'] = ip.oct1
ip_map['descricao'] = ip.descricao
return 0, ip_map
示例6: handle_post
# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import descricao [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
#.........这里部分代码省略.........