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


Python Network.broadcast_long方法代码示例

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


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

示例1: search_free

# 需要导入模块: from ipcalc import Network [as 别名]
# 或者: from ipcalc.Network import broadcast_long [as 别名]
 def search_free(vrf, network, statuses):
     """
     Free blocks recursive search
     :param vrf: VRF
     :type vrf: Vrf
     :param network:  Network
     :type network: Network
     """
     f_ip = network.ip
     l_ip = network.broadcast_long()
     size = network.size()
     blocked_size = \
         vrf.prefixes().filter(status__in=statuses, first_ip_dec__gte=f_ip, last_ip_dec__lte=l_ip).aggregate(
             sum_size=Sum('size'))['sum_size']
     if not blocked_size:
         blocked_size = 0
     if size == blocked_size:
         return []
     elif blocked_size == 0:
         if vrf.prefixes().filter(first_ip_dec__lte=f_ip, last_ip_dec__gte=l_ip):
             parent = vrf.prefixes().filter(first_ip_dec__lte=f_ip, last_ip_dec__gte=l_ip).last()
         else:
             parent = None
         if size == 1:
             create_url = '{0}?prefix={1}'.format(reverse_lazy('ipam.host4_add', kwargs={'vrf': vrf.name}),
                                                  network.dq)
         else:
             create_url = '{0}?prefix={1}'.format(reverse_lazy('ipam.prefix4_add', kwargs={'vrf': vrf.name}),
                                                  network)
         return [{'prefix': str(network), 'parent': parent, 'create_url': create_url}]
     else:
         net_1 = Network('{0}/{1}'.format(network.to_tuple()[0], network.to_tuple()[1] + 1))
         net_2 = Network('{0}/{1}'.format(IP(net_1.broadcast_long() + 1).dq, network.subnet() + 1))
         return search_free(vrf, net_1, statuses) + search_free(vrf, net_2, statuses)
开发者ID:k-vinogradov,项目名称:noclite,代码行数:36,代码来源:views.py

示例2: prefixes_lower

# 需要导入模块: from ipcalc import Network [as 别名]
# 或者: from ipcalc.Network import broadcast_long [as 别名]
    def prefixes_lower(self, root_only=False, networks_only=False, hosts_only=False, statuses=None,
                       ignore_stored_values=False):
        if self.id and root_only and not ignore_stored_values:
            args = {}
            if networks_only:
                args['size__gt'] = 1
            elif hosts_only:
                args['size'] = 1
            if statuses:
                args['status__in'] = statuses
            return self.child if len(args) == 0 else self.child.filter(**args)

        network = Network(str(self.prefix))
        f_ip = network.ip
        l_ip = network.broadcast_long()
        qs = self.vrf.prefixes(
            networks_only=networks_only,
            hosts_only=hosts_only,
            statuses=statuses).filter(first_ip_dec__gte=f_ip, last_ip_dec__lte=l_ip)
        if ignore_stored_values:
            # TODO Add check with ignoring stored data
            pass
        else:
            if self.id:
                qs = qs.exclude(id=self.id)
            if root_only:
                return qs.filter(parent=self.find_parent())
            else:
                return qs
开发者ID:k-vinogradov,项目名称:noclite,代码行数:31,代码来源:models.py

示例3: prefixes_upper

# 需要导入模块: from ipcalc import Network [as 别名]
# 或者: from ipcalc.Network import broadcast_long [as 别名]
 def prefixes_upper(self, networks_only=False, hosts_only=False, statuses=None):
     network = Network(str(self.prefix))
     f_ip = network.ip
     l_ip = network.broadcast_long()
     if self.id:
         return self.vrf.prefixes(networks_only=networks_only, hosts_only=hosts_only, statuses=statuses).filter(
             first_ip_dec__lte=f_ip, last_ip_dec__gte=l_ip, size__gt=network.size()).exclude(id=self.id)
     else:
         return self.vrf.prefixes(networks_only=networks_only, hosts_only=hosts_only, statuses=statuses).filter(
             first_ip_dec__lte=f_ip, last_ip_dec__gte=l_ip, size__gt=network.size())
开发者ID:k-vinogradov,项目名称:noclite,代码行数:12,代码来源:models.py

示例4: search

# 需要导入模块: from ipcalc import Network [as 别名]
# 或者: from ipcalc.Network import broadcast_long [as 别名]
def search(user, search_args):
    """

    :param user: User
    :type user: django.contrib.auth.models.User
    :param search_args: String list
    :type search_args: list
    :return: List of results: {title, utl, description, module}
    """
    if not user.has_perms(['ipam.view', ]):
        return []
    else:
        ip = None
        string_args = []
        ip_reg_exp = re.compile('(\d{1,3}\.)\d{1,3}(/\d{1,3})?')
        for line in search_args:
            if ip_reg_exp.match(line) and not ip:
                ip = line if '/' in line else line + '/32'
            else:
                string_args.append(line)

        objects = []

        # Search Prefix4
        qs = Prefix4.objects.all()
        if ip:
            network = Network(ip)
            f_ip = network.ip
            l_ip = network.broadcast_long()
            qs = qs.filter(first_ip_dec__lte=f_ip, last_ip_dec__gte=l_ip)
            for s in string_args:
                qs = qs.filter(Q(description__icontains=s) | Q(status__icontains=s) | Q(domain__icontains=s) | Q(
                    host_name__icontains=s))
            if qs:
                objects.append(qs.last())
        qs = Prefix4.objects.all()
        for s in search_args:
            qs = qs.filter(Q(description__icontains=s) | Q(status__icontains=s) | Q(domain__icontains=s) | Q(
                host_name__icontains=s) | Q(prefix__icontains=s))
        for prefix in qs:
            if prefix not in objects:
                objects.append(prefix)

        qs = Vrf.objects.all()
        for s in search_args:
            qs = qs.filter(Q(description__icontains=s) | Q(rd__icontains=s) | Q(name__icontains=s))
        for vrf in qs:
            if vrf not in objects:
                objects.append(vrf)

        return [{'title': str(o), 'url': o.get_absolute_url(), 'description': o.description, 'module': 'IPAM'} for o in
                objects]
开发者ID:k-vinogradov,项目名称:noclite,代码行数:54,代码来源:contrib.py

示例5: prefixes

# 需要导入模块: from ipcalc import Network [as 别名]
# 或者: from ipcalc.Network import broadcast_long [as 别名]
    def prefixes(self, root_only=False, networks_only=False, hosts_only=False, statuses=None, subnet=None,
                 recursion=False):
        """
        Return QuerySet with VRF's prefixes
        :param root_only: return top-level's prefixes only
        :type root_only: bool
        :param networks_only: return networks only (without hosts)
        :type networks_only: bool
        :param hosts_only: return hosts only (without networks)
        :type hosts_only: bool
        :param statuses: statuses list for filter
        :type statuses: list
        :param recursion: Include children VRFs
        :type recursion: bool
        :return: QuerySet
        :rtype: django.db.models.QuerySet
        """

        args = {}
        if statuses:
            args['status__in'] = statuses
        if root_only:
            args['parent'] = None
        if networks_only:
            args['size__gt'] = 1
        elif hosts_only:
            args['size'] = 1
        if subnet:
            network = Network(subnet)
            args['first_ip_dec__gte'] = network.ip
            args['last_ip_dec__lte'] = network.broadcast_long()
        if recursion:
            args['vrf__in'] = self.recursive_children()
            return Prefix4.objects.filter(**args)
        else:
            return self.prefixes_list if len(args) == 0 else self.prefixes_list.filter(**args)
开发者ID:k-vinogradov,项目名称:noclite,代码行数:38,代码来源:models.py


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