当前位置: 首页>>代码示例>>Python>>正文


Python Vlan.delete_v3方法代码示例

本文整理汇总了Python中networkapi.vlan.models.Vlan.delete_v3方法的典型用法代码示例。如果您正苦于以下问题:Python Vlan.delete_v3方法的具体用法?Python Vlan.delete_v3怎么用?Python Vlan.delete_v3使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkapi.vlan.models.Vlan的用法示例。


在下文中一共展示了Vlan.delete_v3方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_delete

# 需要导入模块: from networkapi.vlan.models import Vlan [as 别名]
# 或者: from networkapi.vlan.models.Vlan import delete_v3 [as 别名]

#.........这里部分代码省略.........

        try:

            # 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.')
                raise UserNotAuthorizedError(None)

            # Load URL param
            id_vlan = kwargs.get('id_vlan')

            # Valid vlan id
            if not is_valid_int_greater_zero_param(id_vlan):
                self.log.error(
                    u'The id_vlan parameter is not a valid value: %s.', 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)

            # Delete vlan's cache
            destroy_cache_function([id_vlan])

            # Delete equipment's cache
            equip_id_list = []

            for netv4 in vlan.networkipv4_set.all():
                for ipv4 in netv4.ip_set.all():

                    server_pool_member_list = ServerPoolMember.objects.filter(
                        ip=ipv4)

                    if server_pool_member_list.count() != 0:

                        # IP associated with Server Pool
                        server_pool_name_list = set()

                        for member in server_pool_member_list:
                            item = '{}: {}'.format(
                                member.server_pool.id, member.server_pool.identifier)
                            server_pool_name_list.add(item)

                        server_pool_name_list = list(server_pool_name_list)
                        server_pool_identifiers = ', '.join(
                            server_pool_name_list)

                        ip_formated = mount_ipv4_string(ipv4)
                        vlan_name = vlan.nome
                        network_ip = mount_ipv4_string(netv4)

                        raise IpCantRemoveFromServerPool({'ip': ip_formated, 'vlan_name': vlan_name, 'network_ip': network_ip, 'server_pool_identifiers': server_pool_identifiers},
                                                         'Não foi possível excluir a vlan %s pois ela possui a rede %s e essa rede possui o ip %s contido nela, e esse ip esta sendo usado nos Server Pools (id:identifier) %s' %
                                                         (vlan_name, network_ip, ip_formated, server_pool_identifiers))

                    for ip_equip in ipv4.ipequipamento_set.all():
                        equip_id_list.append(ip_equip.equipamento_id)

            for netv6 in vlan.networkipv6_set.all():
                for ip in netv6.ipv6_set.all():

                    server_pool_member_list = ServerPoolMember.objects.filter(
                        ipv6=ip)

                    if server_pool_member_list.count() != 0:

                        # IP associated with Server Pool
                        server_pool_name_list = set()

                        for member in server_pool_member_list:
                            item = '{}: {}'.format(
                                member.server_pool.id, member.server_pool.identifier)
                            server_pool_name_list.add(item)

                        server_pool_name_list = list(server_pool_name_list)
                        server_pool_identifiers = ', '.join(
                            server_pool_name_list)

                        ip_formated = mount_ipv6_string(ip)
                        vlan_name = vlan.nome
                        network_ip = mount_ipv6_string(netv6)

                        raise IpCantRemoveFromServerPool({'ip': ip_formated, 'vlan_name': vlan_name, 'network_ip': network_ip, 'server_pool_identifiers': server_pool_identifiers},
                                                         'Não foi possível excluir a vlan %s pois ela possui a rede %s e essa rede possui o ip %s contido nela, e esse ip esta sendo usado nos Server Pools (id:identifier) %s' %
                                                         (vlan_name, network_ip, ip_formated, server_pool_identifiers))

                    for ip_equip in ip.ipv6equipament_set.all():
                        equip_id_list.append(ip_equip.equipamento_id)

            destroy_cache_function(equip_id_list, True)

            with distributedlock(LOCK_VLAN % id_vlan):

                # Remove Vlan
                vlan.delete_v3()

                return self.response(dumps_networkapi({}))

        except IpCantRemoveFromServerPool, e:
            return self.response_error(387, e.cause.get('vlan_name'), e.cause.get('network_ip'), e.cause.get('ip'), e.cause.get('server_pool_identifiers'))
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:104,代码来源:VlanDeallocateResource.py


注:本文中的networkapi.vlan.models.Vlan.delete_v3方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。