• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python api.subnet_create函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中quark.db.api.subnet_create函数的典型用法代码示例。如果您正苦于以下问题:Python subnet_create函数的具体用法?Python subnet_create怎么用?Python subnet_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_get_subnets_cidr_set

 def test_get_subnets_cidr_set(self):
     network = db_api.network_create(self.context)
     db_api.subnet_create(
         self.context,
         network=network, cidr=self.cidr)
     self.context.session.flush()
     ipset = null_routes.get_subnets_cidr_set(self.context, [network.id])
     self.assertEqual(ipset, netaddr.IPSet(netaddr.IPNetwork(self.cidr)))
开发者ID:Anonymike,项目名称:quark,代码行数:8,代码来源:test_null_routes.py


示例2: _stubs

 def _stubs(self, network, subnets):
     self.ipam = quark.ipam.QuarkIpamANY()
     with self.context.session.begin():
         net_mod = db_api.network_create(self.context, **network)
         for subnet in subnets:
             subnet["network"] = net_mod
             db_api.subnet_create(self.context, **subnet)
     yield net_mod
开发者ID:Anonymike,项目名称:quark,代码行数:8,代码来源:test_pagination.py


示例3: _stubs

 def _stubs(self, network, subnet):
     self.ipam = quark.ipam.QuarkIpamANY()
     with self.context.session.begin():
         net_mod = db_api.network_create(self.context, **network)
         subnet["network"] = net_mod
         sub1 = db_api.subnet_create(self.context, **subnet)
         subnet["id"] = 2
         sub2 = db_api.subnet_create(self.context, do_not_use=True, **subnet)
     yield net_mod, sub1, sub2
开发者ID:thomasem,项目名称:quark,代码行数:9,代码来源:test_subnets.py


示例4: _stubs

 def _stubs(self, network, subnet, dealloc=True):
     self.plugin = quark.plugin.Plugin()
     self.ipam = quark.ipam.QuarkIpamANY()
     with self.context.session.begin():
         net_mod = db_api.network_create(self.context, **network)
         subnet["network"] = net_mod
         db_api.subnet_create(self.context, **subnet)
         ip_addr = self.ipam.allocate_ip_address(self.context, net_mod["id"], 0, 0)
         if dealloc:
             self.ipam._deallocate_ip_address(self.context, ip_addr[0])
     yield net_mod
开发者ID:blamarvt,项目名称:quark,代码行数:11,代码来源:test_networks.py


示例5: _fixtures

    def _fixtures(self, models):

        self.ipam = quark.ipam.QuarkIpamANY()
        net = dict(name="public", tenant_id='fake')
        net_mod = db_api.network_create(self.context, **net)
        with self.context.session.begin():
            for model in models:
                policy_mod = db_api.ip_policy_create(
                    self.context, **model['ip_policy'])
                model['subnet']["network"] = net_mod
                model['subnet']["ip_policy"] = policy_mod
                db_api.subnet_create(self.context, **model['subnet'])
        yield net_mod
开发者ID:Cerberus98,项目名称:quark,代码行数:13,代码来源:test_api.py


示例6: _stubs

    def _stubs(self):
        with mock.patch("neutron.common.rpc.get_notifier"), \
                mock.patch("neutron.quota.QUOTAS.limit_check"):
            mac = {'mac_address_range': dict(cidr="AA:BB:CC")}
            self.context.is_admin = True
            macrng_api.create_mac_address_range(self.context, mac)
            self.context.is_admin = False
            network_info = dict(name="public", tenant_id="fake",
                                network_plugin="BASE",
                                ipam_strategy="ANY")
            network_info = {"network": network_info}
            network = network_api.create_network(self.context, network_info)
            subnet = db_api.subnet_create(self.context, tenant_id="fake",
                                          cidr="192.168.10.0/24",
                                          network_id=network['id'])

            fixed_ips = [dict(subnet_id=subnet['id'], enabled=True,
                         ip_address=self.addr)]
            port = dict(port=dict(network_id=network['id'],
                                  tenant_id=self.context.tenant_id,
                                  device_id=2,
                                  fixed_ips=fixed_ips))
            port_api.create_port(self.context, port)
            self.context.is_admin = True
            filters = {"deallocated": "both"}
            ip = ip_addr.get_ip_addresses(self.context, **filters)
            self.context.is_admin = False
        yield ip[0]
开发者ID:Anonymike,项目名称:quark,代码行数:28,代码来源:test_ip_addresses.py


示例7: test_subnet_update_set_alloc_pool_cache_concurrency

    def test_subnet_update_set_alloc_pool_cache_concurrency(self):
        subnet = {"cidr": "192.168.10.0/24"}
        subnet_db = db_api.subnet_create(self.context, **subnet)
        self.context.session.flush()

        # establish second session
        old_session = self.context.session
        self.context._session = None

        subnet_to_delete = db_api.subnet_find(
            self.context, id=subnet_db.id, scope=db_api.ONE)
        db_api.subnet_delete(self.context, subnet_to_delete)
        self.context.session.flush()

        # restore first session
        self.context._session = old_session

        try:
            db_api.subnet_update_set_alloc_pool_cache(
                self.context, subnet_db, {"foo": "bar"})
            self.context.session.flush()
        except exc.StaleDataError as e:
            self.fail("Did not expect StaleDataError exception: {0}".format(e))
        self.assertEqual(subnet_db["_allocation_pool_cache"],
                         "{\"foo\": \"bar\"}")
开发者ID:Anonymike,项目名称:quark,代码行数:25,代码来源:test_subnets.py


示例8: create_subnet

def create_subnet(context, subnet):
    """Create a subnet.

    Create a subnet which represents a range of IP addresses
    that can be allocated to devices

    : param context: neutron api request context
    : param subnet: dictionary describing the subnet, with keys
        as listed in the RESOURCE_ATTRIBUTE_MAP object in
        neutron/api/v2/attributes.py.  All keys will be populated.
    """
    LOG.info("create_subnet for tenant %s" % context.tenant_id)
    net_id = subnet["subnet"]["network_id"]

    net = db_api.network_find(context, id=net_id, scope=db_api.ONE)
    if not net:
        raise exceptions.NetworkNotFound(net_id=net_id)

    sub_attrs = subnet["subnet"]

    _validate_subnet_cidr(context, net_id, sub_attrs["cidr"])

    cidr = netaddr.IPNetwork(sub_attrs["cidr"])
    gateway_ip = utils.pop_param(sub_attrs, "gateway_ip", str(cidr[1]))
    dns_ips = utils.pop_param(sub_attrs, "dns_nameservers", [])
    host_routes = utils.pop_param(sub_attrs, "host_routes", [])
    allocation_pools = utils.pop_param(sub_attrs, "allocation_pools", [])
    sub_attrs["network"] = net

    new_subnet = db_api.subnet_create(context, **sub_attrs)

    default_route = None
    for route in host_routes:
        netaddr_route = netaddr.IPNetwork(route["destination"])
        if netaddr_route.value == routes.DEFAULT_ROUTE.value:
            default_route = route
            gateway_ip = default_route["nexthop"]
        new_subnet["routes"].append(db_api.route_create(
            context, cidr=route["destination"], gateway=route["nexthop"]))

    if default_route is None:
        new_subnet["routes"].append(db_api.route_create(
            context, cidr=str(routes.DEFAULT_ROUTE), gateway=gateway_ip))

    for dns_ip in dns_ips:
        new_subnet["dns_nameservers"].append(db_api.dns_create(
            context, ip=netaddr.IPAddress(dns_ip)))

    if allocation_pools:
        exclude = netaddr.IPSet([cidr])
        for p in allocation_pools:
            x = netaddr.IPSet(netaddr.IPRange(p["start"], p["end"]))
            exclude = exclude - x
        new_subnet["ip_policy"] = db_api.ip_policy_create(context,
                                                          exclude=exclude)
    subnet_dict = v._make_subnet_dict(new_subnet,
                                      default_route=routes.DEFAULT_ROUTE)
    subnet_dict["gateway_ip"] = gateway_ip
    return subnet_dict
开发者ID:kilogram,项目名称:quark,代码行数:59,代码来源:subnets.py


示例9: _stubs

 def _stubs(self):
     with self.context.session.begin():
         subnet = db_api.subnet_create(self.context,
                                       cidr="192.168.0.0/24")
         db_api.ip_address_create(self.context,
                                  address=self.addr,
                                  subnet_id=subnet["id"])
     yield
开发者ID:quadewarren,项目名称:quark,代码行数:8,代码来源:test_ip_addresses.py


示例10: insert_subnet

 def insert_subnet(self, network_db, cidr, do_not_use=False):
     subnet = {"network": network_db,
               "cidr": cidr,
               "ip_version": netaddr.IPNetwork(cidr).version,
               "do_not_use": do_not_use}
     subnet_db = db_api.subnet_create(self.context, **subnet)
     self.context.session.flush()
     return subnet_db
开发者ID:Anonymike,项目名称:quark,代码行数:8,代码来源:test_db_ip_reallocate.py


示例11: _stubs

 def _stubs(self, network, subnet):
     self.ipam = quark.ipam.QuarkIpamANY()
     with self.context.session.begin():
         net_mod = db_api.network_create(self.context, **network)
         subnet["network"] = net_mod
         sub_mod = db_api.subnet_create(self.context, **subnet)
     yield net_mod
     with self.context.session.begin():
         db_api.subnet_delete(self.context, sub_mod)
         db_api.network_delete(self.context, net_mod)
开发者ID:blamarvt,项目名称:quark-1,代码行数:10,代码来源:test_ipam.py


示例12: _stubs

 def _stubs(self, network, subnet):
     self.ipam = quark.ipam.QuarkIpamANY()
     with self.context.session.begin():
         next_ip = subnet.pop("next_auto_assign_ip", 0)
         net_mod = db_api.network_create(self.context, **network)
         subnet["network"] = net_mod
         sub_mod = db_api.subnet_create(self.context, **subnet)
         # NOTE(asadoughi): update after cidr constructor has been invoked
         db_api.subnet_update(self.context,
                              sub_mod,
                              next_auto_assign_ip=next_ip)
     yield net_mod
开发者ID:mohanraj1311,项目名称:quark,代码行数:12,代码来源:test_ipam.py


示例13: _stubs

    def _stubs(self, network, subnet, dealloc=True):
        self.plugin = quark.plugin.Plugin()
        self.ipam = quark.ipam.QuarkIpamANY()
        with self.context.session.begin():
            net_mod = db_api.network_create(self.context, **network)
            subnet["network"] = net_mod
            next_auto = subnet.pop("next_auto_assign_ip", 0)
            sub_mod = db_api.subnet_create(self.context, **subnet)
            db_api.subnet_update(self.context, sub_mod, next_auto_assign_ip=next_auto)

        ip_addr = []
        self.ipam.allocate_ip_address(self.context, ip_addr, net_mod["id"], 0, 0)
        if dealloc:
            self.ipam.deallocate_ip_address(self.context, ip_addr[0])
        yield net_mod
开发者ID:kshortwindham,项目名称:quark,代码行数:15,代码来源:test_networks.py


示例14: test_create_locks_address_doesnt_exist

    def test_create_locks_address_doesnt_exist(self):
        network = db_api.network_create(self.context)
        subnet = db_api.subnet_create(
            self.context,
            network=network,
            cidr=self.cidr,
            ip_version=4)
        self.context.session.flush()

        addresses = netaddr.IPSet(netaddr.IPNetwork(self.sub_cidr))
        null_routes.create_locks(self.context, [network.id], addresses)
        address = db_api.ip_address_find(
            self.context, subnet_id=subnet.id, scope=db_api.ONE)
        self.assertIsNotNone(address)
        self.assertIsNotNone(address.lock_id)
开发者ID:Anonymike,项目名称:quark,代码行数:15,代码来源:test_null_routes.py


示例15: setUp

    def setUp(self):
        super(BaseFloatingIPTest, self).setUp()
        self.public_net_id = "00000000-0000-0000-0000-000000000000"
        net_stat = '{"%s": {}}' % self.public_net_id
        cfg.CONF.set_override('default_net_strategy', net_stat, group='QUARK')
        old_strat = db_api.STRATEGY

        def reset_strategy():
            db_api.STRATEGY = old_strat

        db_api.STRATEGY = network_strategy.JSONStrategy()
        self.addCleanup(reset_strategy)
        admin_ctx = context.get_admin_context()
        self._setup_mock_requests()
        self.plugin = quark.plugin.Plugin()
        mac = {'mac_address_range': dict(cidr="AA:BB:CC")}
        macrng_api.create_mac_address_range(admin_ctx, mac)
        with admin_ctx.session.begin():
            tenant = 'rackspace'
            floating_net = dict(name='publicnet', tenant_id=tenant,
                                id=self.public_net_id)
            self.floating_network = db_api.network_create(
                self.context, **floating_net)
            self.pub_net_cidr = "10.1.1.0/24"
            floating_subnet = dict(id=self.public_net_id,
                                   cidr=self.pub_net_cidr,
                                   ip_policy=None, tenant_id=tenant,
                                   segment_id='floating_ip',
                                   network_id=self.floating_network.id)
            self.floating_subnet = db_api.subnet_create(
                self.context, **floating_subnet)
        user_net = dict(name='user_network', tenant_id='fake')
        self.user_network = self.plugin.create_network(
            self.context, {'network': user_net})
        user_subnet = dict(cidr="192.168.1.0/24",
                           ip_policy=None, tenant_id="fake",
                           network_id=self.user_network['id'])
        self.user_subnet = self.plugin.create_subnet(
            self.context, {'subnet': user_subnet})
        user_port1 = dict(name='user_port1',
                          network_id=self.user_network['id'])
        self.user_port1 = self.plugin.create_port(
            self.context, {'port': user_port1})
        user_port2 = dict(name='user_port2',
                          network_id=self.user_network['id'])
        self.user_port2 = self.plugin.create_port(
            self.context, {'port': user_port2})
开发者ID:Anonymike,项目名称:quark,代码行数:47,代码来源:test_floating_ips.py


示例16: create_network

def create_network(context, network):
    """Create a network.

    Create a network which represents an L2 network segment which
    can have a set of subnets and ports associated with it.
    : param context: neutron api request context
    : param network: dictionary describing the network, with keys
        as listed in the RESOURCE_ATTRIBUTE_MAP object in
        neutron/api/v2/attributes.py.  All keys will be populated.
    """
    LOG.info("create_network for tenant %s" % context.tenant_id)

    # Generate a uuid that we're going to hand to the backend and db
    net_uuid = uuidutils.generate_uuid()

    # TODO(mdietz) this will be the first component registry hook, but
    #             lets make it work first
    pnet_type, phys_net, seg_id = _adapt_provider_nets(context, network)
    net_attrs = network["network"]

    # NOTE(mdietz) I think ideally we would create the providernet
    # elsewhere as a separate driver step that could be
    # kept in a plugin and completely removed if desired. We could
    # have a pre-callback/observer on the netdriver create_network
    # that gathers any additional parameters from the network dict
    net_driver.create_network(
        context, net_attrs["name"], network_id=net_uuid, phys_type=pnet_type, phys_net=phys_net, segment_id=seg_id
    )

    subs = net_attrs.pop("subnets", [])

    net_attrs["id"] = net_uuid
    net_attrs["tenant_id"] = context.tenant_id
    new_net = db_api.network_create(context, **net_attrs)

    new_subnets = []
    for sub in subs:
        sub["subnet"]["network_id"] = new_net["id"]
        sub["subnet"]["tenant_id"] = context.tenant_id
        s = db_api.subnet_create(context, **sub["subnet"])
        new_subnets.append(s)
    new_net["subnets"] = new_subnets

    if not security_groups.get_security_groups(context, filters={"id": security_groups.DEFAULT_SG_UUID}):
        security_groups._create_default_security_group(context)
    return v._make_network_dict(new_net)
开发者ID:kilogram,项目名称:quark,代码行数:46,代码来源:networks.py


示例17: _fixtures

    def _fixtures(self, models):

        self.ipam = quark.ipam.QuarkIpamANY()
        net = dict(name="public", tenant_id='fake')
        net_mod = db_api.network_create(self.context, **net)
        with self.context.session.begin():
            for model in models:
                policy_mod = db_api.ip_policy_create(
                    self.context, **model['ip_policy'])
                model['subnet']["network"] = net_mod
                model['subnet']["ip_policy"] = policy_mod
                next_ip = model['subnet'].pop("next_auto_assign_ip", 0)
                sub_mod = db_api.subnet_create(self.context, **model['subnet'])
                # NOTE(amir): update after cidr constructor has been invoked
                db_api.subnet_update(self.context,
                                     sub_mod,
                                     next_auto_assign_ip=next_ip)
        yield net_mod
开发者ID:lmaycotte,项目名称:quark,代码行数:18,代码来源:test_ipam.py


示例18: _stubs

 def _stubs(self, network, subnets, ipam_strategy):
     self.ipam = ipam_strategy
     with self.context.session.begin():
         net_mod = db_api.network_create(self.context, **network)
         next_ip = []
         sub_mod = []
         for sub in subnets:
             next_ip.append(sub.pop("next_auto_assign_ip", 0))
             sub["network"] = net_mod
             sub_mod.append(db_api.subnet_create(self.context, **sub))
         for sub, ip_next in zip(sub_mod, next_ip):
             # NOTE(asadoughi): update after cidr constructor has been
             # invoked
             db_api.subnet_update(self.context,
                                  sub,
                                  next_auto_assign_ip=ip_next)
     yield net_mod, sub_mod
     with self.context.session.begin():
         for sub in sub_mod:
             db_api.subnet_delete(self.context, sub)
         db_api.network_delete(self.context, net_mod)
开发者ID:lmaycotte,项目名称:quark,代码行数:21,代码来源:test_ipam.py


示例19: _stubs

    def _stubs(self, network, subnet, address, lock=False):
        self.ipam = quark.ipam.QuarkIpamANY()
        with self.context.session.begin():
            next_ip = subnet.pop("next_auto_assign_ip", 0)
            net_mod = db_api.network_create(self.context, **network)
            subnet["network"] = net_mod
            sub_mod = db_api.subnet_create(self.context, **subnet)

            address["network_id"] = net_mod["id"]
            address["subnet_id"] = sub_mod["id"]
            ip = db_api.ip_address_create(self.context, **address)
            address.pop("address")
            ip = db_api.ip_address_update(self.context, ip, **address)

            # NOTE(asadoughi): update after cidr constructor has been invoked
            db_api.subnet_update(self.context,
                                 sub_mod,
                                 next_auto_assign_ip=next_ip)

        if lock:
            db_api.lock_holder_create(self.context, ip,
                                      name="testlock", type="ip_address")
        yield net_mod
开发者ID:Cerberus98,项目名称:quark,代码行数:23,代码来源:test_ipam.py


示例20: create_network

    def create_network(self, context, network):
        """Create a network.

        Create a network which represents an L2 network segment which
        can have a set of subnets and ports associated with it.
        : param context: quantum api request context
        : param network: dictionary describing the network, with keys
            as listed in the RESOURCE_ATTRIBUTE_MAP object in
            quantum/api/v2/attributes.py.  All keys will be populated.
        """
        LOG.info("create_network for tenant %s" % context.tenant_id)
        # Generate a uuid that we're going to hand to the backend and db
        net_uuid = uuidutils.generate_uuid()

        #NOTE(mdietz): probably want to abstract this out as we're getting
        #              too tied to the implementation here
        self.net_driver.create_network(context,
                                       network["network"]["name"],
                                       network_id=net_uuid)

        subnets = []
        if network["network"].get("subnets"):
            subnets = network["network"].pop("subnets")

        network["network"]["id"] = net_uuid
        network["network"]["tenant_id"] = context.tenant_id
        new_net = db_api.network_create(context, **network["network"])

        new_subnets = []
        for sub in subnets:
            sub["subnet"]["network_id"] = new_net["id"]
            sub["subnet"]["tenant_id"] = context.tenant_id
            s = db_api.subnet_create(context, **sub["subnet"])
            new_subnets.append(s)
        new_net["subnets"] = new_subnets
        return self._make_network_dict(new_net)
开发者ID:ugoring,项目名称:quark,代码行数:36,代码来源:plugin.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python api.subnet_find函数代码示例发布时间:2022-05-26
下一篇:
Python api.security_group_find函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap