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


Python Prefix.save方法代码示例

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


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

示例1: add_prefix

# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import save [as 别名]
 def add_prefix(self, prefix, type, description):
     p = Prefix()
     p.prefix = prefix
     p.type = type
     p.description = description
     p.save()
     return p
开发者ID:sohonet,项目名称:NIPAP,代码行数:9,代码来源:nipaptest.py

示例2: test_add_prefix

# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import save [as 别名]
 def test_add_prefix(self):
     """ We should NOT be able to execute add_prefix as read-only user
     """
     p = Prefix()
     p.prefix = '1.3.3.7'
     with self.assertRaises(NipapAuthorizationError):
         p.save()
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:9,代码来源:nipap-ro.py

示例3: test_edit_prefix

# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import save [as 别名]
 def test_edit_prefix(self):
     """ We should NOT be able to execute edit_prefix as read-only user
     """
     p = Prefix()
     p.id = 123
     with self.assertRaises(NipapAuthorizationError):
         p.save()
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:9,代码来源:nipap-ro.py

示例4: test_country_code_length

# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import save [as 别名]
    def test_country_code_length(self):
        """ Make sure only two character country codes are allowed
        """
        p = Prefix()
        p.prefix = '1.3.3.0/24'
        p.type = 'assignment'
        # try to input one character - should fail - this will be a INSERT operation
        p.country = 'a'
        with self.assertRaisesRegexp(NipapValueError, 'Please enter a two letter country code according to ISO 3166-1 alpha-2'):
            p.save()

        # try to input one character - should fail - this will be an UPDATE operation
        p.country = 'a'
        with self.assertRaisesRegexp(NipapValueError, 'Please enter a two letter country code according to ISO 3166-1 alpha-2'):
            p.save()

        # try to input three character - should fail
        p.country = 'aaa'
        with self.assertRaisesRegexp(NipapValueError, 'Please enter a two letter country code according to ISO 3166-1 alpha-2'):
            p.save()

        # try to input a number character - should fail
        p.country = 'a1'
        with self.assertRaisesRegexp(NipapValueError, 'Please enter a two letter country code according to ISO 3166-1 alpha-2'):
            p.save()

        # try to input two character - should succeed
        p.country = 'se'
        p.save()

        # output should be capitalized
        self.assertEqual('SE', p.country)
开发者ID:Cougar,项目名称:NIPAP,代码行数:34,代码来源:nipaptest.py

示例5: save_hosts

# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import save [as 别名]
def save_hosts():
    for host in hosts:
        try:
            host.save()
            continue
        except:
            pass

        r = Prefix().search({"operator": "contains", "val1": "prefix", "val2": host.prefix})
        for p in r["result"]:
            try:
                p.type = "assignment"
                p.tags["guessed"] = 1
                p.save()
            except:
                pass

        try:
            host.save()
            continue
        except:
            pass

        # this is a last and probably wrong attempt
        # to fix the bad data in infoblox.
        p = Prefix()
        p.type = "assignment"
        p.description = "AUTO: host container (import)"
        p.tags["auto"] = 1
        ip = ipaddr.IPNetwork(host.prefix)
        p.prefix = str(ip.supernet(prefixlen_diff=1).network) + "/127"
        p.save()
        host.save()
开发者ID:genokan,项目名称:NIPAP,代码行数:35,代码来源:infoblox-import.py

示例6: add_prefix_from_pool

# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import save [as 别名]
    def add_prefix_from_pool(self, pool, family, description):
        p = Prefix()
        args = {}
        args['from-pool'] = pool
        args['family'] = family
        p.type = pool.default_type

        p.save(args)
        return p
开发者ID:Cougar,项目名称:NIPAP,代码行数:11,代码来源:nipaptest.py

示例7: add_prefix

# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import save [as 别名]
 def add_prefix(self, prefix, type, description, tags=None):
     if tags is None:
         tags = []
     p = Prefix()
     p.prefix = prefix
     p.type = type
     p.description = description
     p.tags = tags
     p.save()
     return p
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:12,代码来源:upgrade-before.py

示例8: add_prefix

# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import save [as 别名]
    def add_prefix(self, prefix, type, description, tags=[], pool_id=None):

        p = Prefix()
        p.prefix = prefix
        p.type = type
        p.description = description
        p.tags = tags
        if pool_id:
            pool = Pool.get(pool_id)
            p.pool = pool
        p.save()
        return p
开发者ID:Cougar,项目名称:NIPAP,代码行数:14,代码来源:nipaptest.py

示例9: add_prefix

# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import save [as 别名]
def add_prefix(arg, opts):
    """ Add prefix to NIPAP
    """

    s = get_schema()

    p = Prefix()
    p.schema = s
    p.prefix = opts.get('prefix')
    p.type = opts.get('type')
    p.description = opts.get('description')
    p.node = opts.get('node')
    p.country = opts.get('country')
    p.order_id = opts.get('order_id')
    p.vrf = opts.get('vrf')
    p.alarm_priority = opts.get('alarm_priority')
    p.comment = opts.get('comment')
    p.monitor = _str_to_bool(opts.get('monitor'))

    args = {}
    if 'from-pool' in opts:
        res = Pool.list(s, { 'name': opts['from-pool'] })
        if len(res) == 0:
            print >> sys.stderr, "No pool named %s found." % opts['from-pool']
            sys.exit(1)

        args['from-pool'] = res[0]

    if 'from-prefix' in opts:
        args['from-prefix'] = [ opts['from-prefix'], ]

    if 'prefix-length' in opts:
        args['prefix_length'] = int(opts['prefix-length'])

    if 'family' in opts:
        family = opts['family']
        if opts['family'] == 'ipv4':
            family = 4
        elif opts['family'] == 'ipv6':
            family = 6

        args['family'] = family


    try:
        p.save(args)
    except NipapError, e:
        print >> sys.stderr, "Could not add prefix to NIPAP: %s" % e.message
        sys.exit(1)
开发者ID:tobbakko,项目名称:NIPAP,代码行数:51,代码来源:nipap_cli.py

示例10: parse_line

# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import save [as 别名]
    def parse_line(self, line):
        """ Parse one line
        """

        try:
            # text params, ie params from the text file
            tp = self.split_columns(line)
        except CommentLine:
            # just ignore comments
            return

        if tp['prefix_type'] == 'reservation':  # reservations / aggregates
            print "Reservation:", tp['prefix'], tp['description']
            p = Prefix()
            p.schema = self.schema
            p.prefix = tp['prefix']
            p.type = 'reservation'
            p.description = tp['description']
            p.monitor = True
            p.alarm_priority = 'low'
            p.authoritative_source = 'nw'
            p.save({})
            return

        elif tp['node'] == '.' and tp['description'] == '.':
            # ignore prefixes without description or node set
            return

        elif tp['prefix_length'] == 32:   # loopback
            # if it's a loopback, the covering prefix will be a reservation and we can just insert an assignment.
            # if this insert fails, it means the parent prefix is an assignment and we instead insert a host
            try:
                p = Prefix()
                p.schema = self.schema
                p.prefix = tp['prefix']
                # loopbacks are always of type 'assignment'
                p.type = 'assignment'
                p.node = tp['node']
                p.description = tp['description']
                p.monitor = True
                p.alarm_priority = tp['alarm_priority']
                p.authoritative_source = 'nw'
                p.save({})
                print "Loopback:", tp['prefix']
                return
            except:
                p = Prefix()
                p.schema = self.schema
                p.prefix = tp['prefix']
                # loopbacks are always of type 'assignment'
                p.type = 'host'
                p.node = tp['node']
                p.description = tp['description']
                p.monitor = True
                p.alarm_priority = tp['alarm_priority']
                p.authoritative_source = 'nw'
                p.save({})
                print "Host:", tp['prefix']
                return

        elif tp['prefix_length'] == 30 or tp['prefix_length'] == 31:   # link network
            octets = tp['address'].split('.')
            prefix_node1 = None
            prefix_node2 = None
            if tp['prefix_length'] == 30:
                prefix_node1 = '.'.join(octets[:3] + [str( int(octets[3]) + 1 )] ) + '/32'
                prefix_node2 = '.'.join(octets[:3] + [str( int(octets[3]) + 2 )] ) + '/32'
            else:
                prefix_node1 = '.'.join(octets) + '/32'
                prefix_node2 = '.'.join(octets[:3] + [str( int(octets[3]) + 1 )] ) + '/32'

            #m = re.match('(ETHER_KAP|ETHER_PORT|IP-KAP|IP-PORT|IP-SIPNET|IP-SNIX|IPSUR|L2L|RED-IPPORT|SNIX|SWIP|[email protected]|T2V-DIGTV|T2V-SUR)[0-9]{4,}', tp['order_id'])
            m = re.match('.*[0-9]{6}$', tp['order_id'])
            if m is not None or tp['type'] == 'CUSTOMER':
                print "Customer link", tp['prefix'], ':', tp['description']
                p = Prefix()
                p.schema = self.schema
                p.prefix = tp['prefix']
                p.type = 'assignment'
                p.description = tp['description']
                p.alarm_priority = tp['alarm_priority']
                p.authoritative_source = 'nw'
                if tp['order_id'] != '.':
                    p.order_id = tp['order_id']
                p.save({})

                # insert node1 and node2
                p1 = Prefix()
                p1.schema = self.schema
                p1.prefix = prefix_node1
                p1.type = 'host'
                p1.description = 'Some PE router'
                p1.authoritative_source = 'nw'
                p1.save({})

                p2 = Prefix()
                p2.schema = self.schema
                p2.prefix = prefix_node2
                p2.type = 'host'
                p2.node = tp['node']
#.........这里部分代码省略.........
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:103,代码来源:text-import.py


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