本文整理汇总了Python中networkapi.ip.models.Ip.list_by_network方法的典型用法代码示例。如果您正苦于以下问题:Python Ip.list_by_network方法的具体用法?Python Ip.list_by_network怎么用?Python Ip.list_by_network使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkapi.ip.models.Ip
的用法示例。
在下文中一共展示了Ip.list_by_network方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_get
# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import list_by_network [as 别名]
def handle_get(self, request, user, *args, **kwargs):
"""Handles GET requests to list all network IPv4 by network ipv4 id.
URLs: ip/id_network_ipv4/id_rede
"""
try:
# Commons Validations
# 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):
raise InvalidValueError(None, 'id_rede', id_network)
# Business Rules
NetworkIPv4.get_by_pk(id_network)
ips = Ip.list_by_network(id_network)
try:
len(ips)
except Exception, e:
raise InvalidValueError(None, 'id_rede', id_network)
if ips is None or len(ips) <= 0:
raise IpNotFoundError(305, id_network)
EquipIps = []
mapa = dict()
# lista = []
try:
for ip in ips:
EquipIps = []
equipsIp = IpEquipamento.list_by_ip(ip.id)
for eIp in equipsIp:
EquipIps.append(eIp)
mapa[ip.id] = EquipIps
# lista.append(mapa)
except IpEquipmentNotFoundError:
EquipIps.append(None)
except IpError:
EquipIps.append(None)
network_map = dict()
list_ips = []
for ip in ips:
lequips = []
ip_maps = dict()
ip_maps = model_to_dict(ip)
for equip in mapa.get(ip.id):
equip = Equipamento.get_by_pk(equip.equipamento.id)
lequips.append(model_to_dict(equip))
ip_maps['equipamento'] = lequips
list_ips.append(ip_maps)
network_map['ips'] = list_ips
# Return XML
return self.response(dumps_networkapi(network_map))