當前位置: 首頁>>代碼示例>>Python>>正文


Python Vlan.delete方法代碼示例

本文整理匯總了Python中networkapi.vlan.models.Vlan.delete方法的典型用法代碼示例。如果您正苦於以下問題:Python Vlan.delete方法的具體用法?Python Vlan.delete怎麽用?Python Vlan.delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在networkapi.vlan.models.Vlan的用法示例。


在下文中一共展示了Vlan.delete方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: remover_vlan_so

# 需要導入模塊: from networkapi.vlan.models import Vlan [as 別名]
# 或者: from networkapi.vlan.models.Vlan import delete [as 別名]
def remover_vlan_so(user, rack):

    nome = "OOB_SO_"+rack.nome

    vlan = Vlan()
    try:
        vlan = vlan.get_by_name(nome)
        vlan.delete()
    except:
        pass
開發者ID:marcelometal,項目名稱:GloboNetworkAPI,代碼行數:12,代碼來源:RackDeleteResource.py

示例2: handle_delete

# 需要導入模塊: from networkapi.vlan.models import Vlan [as 別名]
# 或者: from networkapi.vlan.models.Vlan import delete [as 別名]
    def handle_delete(self, request, user, *args, **kwargs):
        """Treat requests DELETE to deallocate all relationships between Vlan.

        URL: vlan/<id_vlan>/deallocate/
        """

        self.log.info("Deallocate all relationships between Vlan.")

        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(user)

                return self.response(dumps_networkapi({}))

#.........這裏部分代碼省略.........
開發者ID:andrewsmedina,項目名稱:GloboNetworkAPI,代碼行數:103,代碼來源:VlanDeallocateResource.py


注:本文中的networkapi.vlan.models.Vlan.delete方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。