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


Python VRF.get方法代码示例

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


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

示例1: remove

# 需要导入模块: from pynipap import VRF [as 别名]
# 或者: from pynipap.VRF import get [as 别名]
    def remove(self, id):
        """ Removes a VRF.
        """

        v = VRF.get(int(id))
        v.remove()

        redirect(url(controller="vrf", action="list"))
开发者ID:genokan,项目名称:NIPAP,代码行数:10,代码来源:vrf.py

示例2: edit_vrf

# 需要导入模块: from pynipap import VRF [as 别名]
# 或者: from pynipap.VRF import get [as 别名]
    def edit_vrf(self, id):
        """ Edit a VRF.
        """

        try:
            v = VRF.get(int(id))
        except NipapError, e:
            return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:fredsod,项目名称:NIPAP,代码行数:10,代码来源:xhr.py

示例3: edit_prefix

# 需要导入模块: from pynipap import VRF [as 别名]
# 或者: from pynipap.VRF import get [as 别名]
    def edit_prefix(self, id):
        """ Edit a prefix.
        """

        try:
            p = Prefix.get(int(id))

            # extract attributes
            if 'prefix' in request.json:
                p.prefix = validate_string(request.json, 'prefix')
            if 'type' in request.json:
                p.type = validate_string(request.json, 'type')
            if 'description' in request.json:
                p.description = validate_string(request.json, 'description')
            if 'expires' in request.json:
                p.expires = validate_string(request.json, 'expires')
            if 'comment' in request.json:
                p.comment = validate_string(request.json, 'comment')
            if 'node' in request.json:
                p.node = validate_string(request.json, 'node')
            if 'status' in request.json:
                p.status = validate_string(request.json, 'status')

            if 'pool' in request.json:
                if request.json['pool'] is None:
                    p.pool = None
                else:
                    try:
                        p.pool = Pool.get(int(request.json['pool']))
                    except NipapError, e:
                        return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})

            if 'alarm_priority' in request.json:
                p.alarm_priority = validate_string(request.json, 'alarm_priority')
            if 'monitor' in request.json:
                if request.json['monitor'] == 'true':
                    p.monitor = True
                else:
                    p.monitor = False

            if 'country' in request.json:
                p.country = validate_string(request.json, 'country')
            if 'order_id' in request.json:
                p.order_id = validate_string(request.json, 'order_id')
            if 'customer_id' in request.json:
                p.customer_id = validate_string(request.json, 'customer_id')

            if 'vrf' in request.json:

                try:
                    if request.json['vrf'] is None or len(unicode(request.json['vrf'])) == 0:
                        p.vrf = None
                    else:
                        p.vrf = VRF.get(int(request.json['vrf']))
                except ValueError:
                    return json.dumps({'error': 1, 'message': "Invalid VRF ID '%s'" % request.json['vrf']})
                except NipapError, e:
                    return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:fredsod,项目名称:NIPAP,代码行数:60,代码来源:xhr.py

示例4: remove_vrf

# 需要导入模块: from pynipap import VRF [as 别名]
# 或者: from pynipap.VRF import get [as 别名]
    def remove_vrf(self, id):
        """ Remove a VRF.
        """

        try:
            vrf = VRF.get(int(id))
            vrf.remove()

        except NipapError, e:
            return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:fredsod,项目名称:NIPAP,代码行数:12,代码来源:xhr.py

示例5: test_stats2

# 需要导入模块: from pynipap import VRF [as 别名]
# 或者: from pynipap.VRF import get [as 别名]
    def test_stats2(self):
        """ Check stats are correct when adding and removing prefixes
        """
        th = TestHelper()

        # add some top level prefixes to the default VRF
        p1 = th.add_prefix('1.0.0.0/24', 'reservation', 'test')
        p2 = th.add_prefix('1.0.0.128/25', 'assignment', 'test')
        p3 = th.add_prefix('2001:db8:1::/48', 'reservation', 'test')
        p4 = th.add_prefix('2001:db8:1:1::/64', 'reservation', 'test')

        # check stats for VRF
        res = VRF.get(0)
        # ipv4
        self.assertEqual(2, res.num_prefixes_v4)
        self.assertEqual(256, res.total_addresses_v4)
        self.assertEqual(128, res.used_addresses_v4)
        self.assertEqual(128, res.free_addresses_v4)
        # ipv6
        self.assertEqual(2, res.num_prefixes_v6)
        self.assertEqual(1208925819614629174706176, res.total_addresses_v6)
        self.assertEqual(18446744073709551616, res.used_addresses_v6)
        self.assertEqual(1208907372870555465154560, res.free_addresses_v6)

        # remove some prefixes
        p1.remove()
        p3.remove()

        # check stats for VRF
        res = VRF.get(0)
        # ipv4
        self.assertEqual(1, res.num_prefixes_v4)
        self.assertEqual(128, res.total_addresses_v4)
        self.assertEqual(0, res.used_addresses_v4)
        self.assertEqual(128, res.free_addresses_v4)
        # ipv6
        self.assertEqual(1, res.num_prefixes_v6)
        self.assertEqual(18446744073709551616, res.total_addresses_v6)
        self.assertEqual(0, res.used_addresses_v6)
        self.assertEqual(18446744073709551616, res.free_addresses_v6)
开发者ID:Cougar,项目名称:NIPAP,代码行数:42,代码来源:nipaptest.py

示例6: test_stats1

# 需要导入模块: from pynipap import VRF [as 别名]
# 或者: from pynipap.VRF import get [as 别名]
    def test_stats1(self):
        """ Check stats are correct when adding and removing prefixes
        """
        th = TestHelper()

        # add some top level prefixes to the default VRF
        p1 = th.add_prefix('1.0.0.0/24', 'reservation', 'test')
        p2 = th.add_prefix('2.0.0.0/24', 'reservation', 'test')
        p3 = th.add_prefix('2001:db8:1::/48', 'reservation', 'test')
        p4 = th.add_prefix('2001:db8:2::/48', 'reservation', 'test')

        # check stats for VRF
        res = VRF.get(0)
        # ipv4
        self.assertEqual(2, res.num_prefixes_v4)
        self.assertEqual(512, res.total_addresses_v4)
        self.assertEqual(0, res.used_addresses_v4)
        self.assertEqual(512, res.free_addresses_v4)
        # ipv6
        self.assertEqual(2, res.num_prefixes_v6)
        self.assertEqual(2417851639229258349412352, res.total_addresses_v6)
        self.assertEqual(0, res.used_addresses_v6)
        self.assertEqual(2417851639229258349412352, res.free_addresses_v6)

        # remove some prefixes
        p1.remove()
        p3.remove()

        # check stats for VRF
        res = VRF.get(0)
        # ipv4
        self.assertEqual(1, res.num_prefixes_v4)
        self.assertEqual(256, res.total_addresses_v4)
        self.assertEqual(0, res.used_addresses_v4)
        self.assertEqual(256, res.free_addresses_v4)
        # ipv6
        self.assertEqual(1, res.num_prefixes_v6)
        self.assertEqual(1208925819614629174706176, res.total_addresses_v6)
        self.assertEqual(0, res.used_addresses_v6)
        self.assertEqual(1208925819614629174706176, res.free_addresses_v6)
开发者ID:Cougar,项目名称:NIPAP,代码行数:42,代码来源:nipaptest.py

示例7: add_current_vrf

# 需要导入模块: from pynipap import VRF [as 别名]
# 或者: from pynipap.VRF import get [as 别名]
    def add_current_vrf(self):
        """ Add VRF to filter list session variable
        """

        vrf_id = request.params.get('vrf_id')

        if vrf_id is not None:

            if vrf_id == 'null':
                vrf = VRF()
            else:
                vrf = VRF.get(int(vrf_id))

            session['current_vrfs'][vrf_id] = { 'id': vrf.id, 'rt': vrf.rt,
                    'name': vrf.name, 'description': vrf.description }
            session.save()

        return json.dumps(session.get('current_vrfs', {}))
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:20,代码来源:xhr.py

示例8: add_prefix

# 需要导入模块: from pynipap import VRF [as 别名]
# 或者: from pynipap.VRF import get [as 别名]
    def add_prefix(self):
        """ Add prefix according to the specification.

            The following keys can be used:

            vrf             ID of VRF to place the prefix in
            prefix          the prefix to add if already known
            family          address family (4 or 6)
            description     A short description
            expires         Expiry time of assignment
            comment         Longer comment
            node            Hostname of node
            type            Type of prefix; reservation, assignment, host
            status          Status of prefix; assigned, reserved, quarantine
            pool            ID of pool
            country         Country where the prefix is used
            order_id        Order identifier
            customer_id     Customer identifier
            vlan            VLAN ID
            alarm_priority  Alarm priority of prefix
            monitor         If the prefix should be monitored or not

            from-prefix     A prefix the prefix is to be allocated from
            from-pool       A pool (ID) the prefix is to be allocated from
            prefix_length   Prefix length of allocated prefix
        """

        p = Prefix()

        # Sanitize input parameters
        if 'vrf' in request.json:
            try:
                if request.json['vrf'] is None or len(unicode(request.json['vrf'])) == 0:
                    p.vrf = None
                else:
                    p.vrf = VRF.get(int(request.json['vrf']))
            except ValueError:
                return json.dumps({'error': 1, 'message': "Invalid VRF ID '%s'" % request.json['vrf']})
            except NipapError, e:
                return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:fredsod,项目名称:NIPAP,代码行数:42,代码来源:xhr.py

示例9: edit

# 需要导入模块: from pynipap import VRF [as 别名]
# 或者: from pynipap.VRF import get [as 别名]
    def edit(self, id):
        """ Edit a VRF
        """

        c.action = "edit"
        c.edit_vrf = VRF.get(int(id))

        # Did we have any action passed to us?
        if "action" in request.params:

            if request.params["action"] == "edit":
                if request.params["rt"].strip() == "":
                    c.edit_vrf.rt = None
                else:
                    c.edit_vrf.rt = request.params["rt"].strip()

                if request.params["name"].strip() == "":
                    c.edit_vrf.name = None
                else:
                    c.edit_vrf.name = request.params["name"].strip()
                c.edit_vrf.description = request.params["description"]
                c.edit_vrf.save()

        return render("/vrf_edit.html")
开发者ID:genokan,项目名称:NIPAP,代码行数:26,代码来源:vrf.py

示例10: edit_prefix

# 需要导入模块: from pynipap import VRF [as 别名]
# 或者: from pynipap.VRF import get [as 别名]
    def edit_prefix(self, id):
        """ Edit a prefix.
        """

        try:
            p = Prefix.get(int(id))

            # extract attributes
            if 'prefix' in request.params:
                p.prefix = request.params['prefix']

            if 'type' in request.params:
                p.type = request.params['type'].strip()

            if 'description' in request.params:
                if request.params['description'].strip() == '':
                    p.description = None
                else:
                    p.description = request.params['description'].strip()

            if 'expires' in request.params:
                if request.params['expires'].strip() == '':
                    p.expires = None
                else:
                    p.expires = request.params['expires'].strip(' "')

            if 'comment' in request.params:
                if request.params['comment'].strip() == '':
                    p.comment = None
                else:
                    p.comment = request.params['comment'].strip()

            if 'node' in request.params:
                if request.params['node'].strip() == '':
                    p.node = None
                else:
                    p.node = request.params['node'].strip()

            if 'status' in request.params:
                p.status = request.params['status'].strip()

            if 'pool' in request.params:
                if request.params['pool'].strip() == '':
                    p.pool = None
                else:
                    try:
                        p.pool = Pool.get(int(request.params['pool']))
                    except NipapError, e:
                        return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})

            if 'alarm_priority' in request.params:
                p.alarm_priority = request.params['alarm_priority'].strip()

            if 'monitor' in request.params:
                if request.params['monitor'] == 'true':
                    p.monitor = True
                else:
                    p.monitor = False

            if 'country' in request.params:
                if request.params['country'].strip() == '':
                    p.country = None
                else:
                    p.country = request.params['country'].strip()

            if 'order_id' in request.params:
                if request.params['order_id'].strip() == '':
                    p.order_id = None
                else:
                    p.order_id = request.params['order_id'].strip()

            if 'customer_id' in request.params:
                if request.params['customer_id'].strip() == '':
                    p.customer_id = None
                else:
                    p.customer_id = request.params['customer_id'].strip()

            if 'vrf' in request.params:

                try:
                    if request.params['vrf'] is None or len(request.params['vrf']) == 0:
                        p.vrf = None
                    else:
                        p.vrf = VRF.get(int(request.params['vrf']))
                except ValueError:
                    return json.dumps({'error': 1, 'message': "Invalid VRF ID '%s'" % request.params['vrf']})
                except NipapError, e:
                    return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:90,代码来源:xhr.py

示例11: test_list_vrf

# 需要导入模块: from pynipap import VRF [as 别名]
# 或者: from pynipap.VRF import get [as 别名]
 def test_list_vrf(self):
     """ We should be able to execute list_vrf as read-only user
     """
     v = VRF.get(0)
     self.assertEqual(v.id, 0)
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:7,代码来源:nipap-ro.py

示例12: test_find_free_prefix

# 需要导入模块: from pynipap import VRF [as 别名]
# 或者: from pynipap.VRF import get [as 别名]
 def test_find_free_prefix(self):
     """ We should be able to execute find_free_prefix as read-only user
     """
     v = VRF.get(0)
     p = Prefix.find_free(v, { 'from-prefix': ['1.3.3.0/24'],
         'prefix_length': 27 })
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:8,代码来源:nipap-ro.py


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