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


Python core.create_resource函数代码示例

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


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

示例1: _test_create_security_group_rule

    def _test_create_security_group_rule(self, plugin, q_ctx, t_ctx, pod_id,
                                         top_sgs, bottom1_sgs):
        t_sg_id = uuidutils.generate_uuid()
        t_rule_id = uuidutils.generate_uuid()
        b_sg_id = uuidutils.generate_uuid()
        project_id = 'test_prject_id'
        t_sg = {'id': t_sg_id, 'name': 'test', 'description': '',
                'tenant_id': project_id,
                'security_group_rules': []}
        b_sg = {'id': b_sg_id, 'name': t_sg_id, 'description': '',
                'tenant_id': project_id,
                'security_group_rules': []}
        top_sgs.append(t_sg)
        bottom1_sgs.append(b_sg)
        route = {
            'top_id': t_sg_id,
            'pod_id': pod_id,
            'bottom_id': b_sg_id,
            'resource_type': constants.RT_SG}
        with t_ctx.session.begin():
            core.create_resource(t_ctx, models.ResourceRouting, route)

        rule = {
            'security_group_rule': self._build_test_rule(
                t_rule_id, t_sg_id, project_id, '10.0.0.0/24')}
        plugin.create_security_group_rule(q_ctx, rule)

        self.assertEqual(1, len(bottom1_sgs[0]['security_group_rules']))
        b_rule = bottom1_sgs[0]['security_group_rules'][0]
        self.assertEqual(b_sg_id, b_rule['security_group_id'])
开发者ID:LongXQ,项目名称:tricircle,代码行数:30,代码来源:test_security_groups.py

示例2: _test_handle_remote_group_invalid_input

    def _test_handle_remote_group_invalid_input(self, plugin, q_ctx, t_ctx,
                                                pod_id, top_sgs, top_rules,
                                                bottom1_sgs):
        t_sg1_id = uuidutils.generate_uuid()
        t_sg2_id = uuidutils.generate_uuid()
        t_rule1_id = uuidutils.generate_uuid()
        t_rule2_id = uuidutils.generate_uuid()
        b_sg_id = uuidutils.generate_uuid()
        project_id = 'test_prject_id'
        t_rule1 = self._build_test_rule(
            t_rule1_id, t_sg1_id, project_id, None, t_sg1_id)
        t_rule2 = self._build_test_rule(
            t_rule2_id, t_sg1_id, project_id, None, t_sg2_id)
        t_sg = {'id': t_sg1_id, 'name': 'test', 'description': '',
                'tenant_id': project_id,
                'security_group_rules': []}
        b_sg = {'id': b_sg_id, 'name': t_sg1_id, 'description': '',
                'tenant_id': project_id,
                'security_group_rules': []}
        top_sgs.append(t_sg)
        top_rules.append(t_rule1)
        bottom1_sgs.append(b_sg)
        route = {
            'top_id': t_sg1_id,
            'pod_id': pod_id,
            'bottom_id': b_sg_id,
            'resource_type': constants.RT_SG}
        with t_ctx.session.begin():
            core.create_resource(t_ctx, models.ResourceRouting, route)

        self.assertRaises(exceptions.RemoteGroupNotSupported,
                          plugin.create_security_group_rule, q_ctx,
                          {'security_group_rule': t_rule2})
        self.assertRaises(exceptions.RemoteGroupNotSupported,
                          plugin.delete_security_group_rule, q_ctx, t_rule1_id)
开发者ID:LongXQ,项目名称:tricircle,代码行数:35,代码来源:test_security_groups.py

示例3: test_get_bottom_mappings_by_top_id

 def test_get_bottom_mappings_by_top_id(self):
     for i in xrange(3):
         pod = {'pod_id': 'test_pod_uuid_%d' % i,
                'pod_name': 'test_pod_%d' % i,
                'az_name': 'test_az_uuid_%d' % i}
         api.create_pod(self.context, pod)
     route1 = {
         'top_id': 'top_uuid',
         'pod_id': 'test_pod_uuid_0',
         'resource_type': 'port'}
     route2 = {
         'top_id': 'top_uuid',
         'pod_id': 'test_pod_uuid_1',
         'bottom_id': 'bottom_uuid_1',
         'resource_type': 'port'}
     route3 = {
         'top_id': 'top_uuid',
         'pod_id': 'test_pod_uuid_2',
         'bottom_id': 'bottom_uuid_2',
         'resource_type': 'neutron'}
     routes = [route1, route2, route3]
     with self.context.session.begin():
         for route in routes:
             core.create_resource(
                 self.context, models.ResourceRouting, route)
     mappings = api.get_bottom_mappings_by_top_id(self.context,
                                                  'top_uuid', 'port')
     self.assertEqual('test_pod_uuid_1', mappings[0][0]['pod_id'])
     self.assertEqual('bottom_uuid_1', mappings[0][1])
开发者ID:Ronghui,项目名称:tricircle,代码行数:29,代码来源:test_api.py

示例4: get_pod_by_az_tenant

def get_pod_by_az_tenant(context, az_name, tenant_id):
    pod_bindings = core.query_resource(context,
                                       models.PodBinding,
                                       [{'key': 'tenant_id',
                                         'comparator': 'eq',
                                         'value': tenant_id}],
                                       [])
    for pod_b in pod_bindings:
        pod = core.get_resource(context,
                                models.Pod,
                                pod_b['pod_id'])
        if pod['az_name'] == az_name:
            return pod, pod['pod_az_name']

    # TODO(joehuang): schedule one dynamically in the future
    filters = [{'key': 'az_name', 'comparator': 'eq', 'value': az_name}]
    pods = db_api.list_pods(context, filters=filters)
    for pod in pods:
        if pod['pod_name'] != '':
            try:
                with context.session.begin():
                    core.create_resource(
                        context, models.PodBinding,
                        {'id': uuidutils.generate_uuid(),
                         'tenant_id': tenant_id,
                         'pod_id': pod['pod_id']})
                    return pod, pod['pod_az_name']
            except Exception as e:
                LOG.error(_LE('Fail to create pod binding: %(exception)s'),
                          {'exception': e})
                return None, None

    return None, None
开发者ID:Ronghui,项目名称:tricircle,代码行数:33,代码来源:az_ag.py

示例5: test_job_run_expire

    def test_job_run_expire(self):
        @xmanager._job_handle('fake_resource')
        def fake_handle(self, ctx, payload):
            pass

        fake_id = uuidutils.generate_uuid()
        payload = {'fake_resource': fake_id}
        expired_job = {
            'id': uuidutils.generate_uuid(),
            'type': 'fake_resource',
            'timestamp': datetime.datetime.now() - datetime.timedelta(0, 120),
            'status': constants.JS_Running,
            'resource_id': fake_id,
            'extra_id': constants.SP_EXTRA_ID
        }
        core.create_resource(self.context, models.Job, expired_job)
        fake_handle(None, self.context, payload=payload)

        jobs = core.query_resource(self.context, models.Job, [], [])
        expected_status = ['New', 'Fail', 'Success']
        job_status = [job['status'] for job in jobs]
        self.assertItemsEqual(expected_status, job_status)

        for i in xrange(3):
            self.assertEqual(fake_id, jobs[i]['resource_id'])
            self.assertEqual('fake_resource', jobs[i]['type'])
开发者ID:Ronghui,项目名称:tricircle,代码行数:26,代码来源:test_xmanager.py

示例6: _prepare_snat_test

 def _prepare_snat_test(self, top_router_id):
     ext_network = {'id': 'ext_network_id',
                    'router:external': True}
     ext_subnet = {
         'id': 'ext_subnet_id',
         'network_id': ext_network['id'],
         'cidr': '162.3.124.0/24',
         'gateway_ip': '162.3.124.1'
     }
     for router in TOP_ROUTER:
         if router['id'] == top_router_id:
             router['external_gateway_info'] = {
                 'network_id': ext_network['id']}
     router = {'id': 'ns_router_id'}
     for subnet in BOTTOM2_SUBNET:
         if 'bridge' in subnet['id']:
             bridge_subnet = subnet
     bridge_port = {
         'network_id': bridge_subnet['network_id'],
         'device_id': router['id'],
         'device_owner': 'network:router_interface',
         'fixed_ips': [{'subnet_id': bridge_subnet['id'],
                        'ip_address': bridge_subnet['gateway_ip']}]
     }
     BOTTOM2_NETWORK.append(ext_network)
     BOTTOM2_SUBNET.append(ext_subnet)
     BOTTOM2_PORT.append(bridge_port)
     BOTTOM2_ROUTER.append(router)
     route = {'top_id': top_router_id, 'bottom_id': router['id'],
              'pod_id': 'pod_id_2', 'resource_type': constants.RT_NS_ROUTER}
     with self.context.session.begin():
         core.create_resource(self.context, models.ResourceRouting, route)
     return bridge_subnet['gateway_ip'], router['id']
开发者ID:LongXQ,项目名称:tricircle,代码行数:33,代码来源:test_xmanager.py

示例7: test_job_run_expire

    def test_job_run_expire(self):
        job_type = 'fake_resource'

        @xmanager._job_handle(job_type)
        def fake_handle(self, ctx, payload):
            pass

        fake_id = uuidutils.generate_uuid()
        fake_project_id = uuidutils.generate_uuid()
        payload = {job_type: fake_id}
        db_api.new_job(self.context, fake_project_id, job_type, fake_id)
        expired_job = {
            'id': uuidutils.generate_uuid(),
            'type': job_type,
            'timestamp': datetime.datetime.now() - datetime.timedelta(0, 200),
            'status': constants.JS_Running,
            'resource_id': fake_id,
            'extra_id': constants.SP_EXTRA_ID
        }
        core.create_resource(self.context, models.AsyncJob, expired_job)
        fake_handle(None, self.context, payload=payload)

        logs = core.query_resource(self.context, models.AsyncJobLog, [], [])

        self.assertEqual(fake_id, logs[0]['resource_id'])
        self.assertEqual(job_type, logs[0]['type'])
开发者ID:LongXQ,项目名称:tricircle,代码行数:26,代码来源:test_xmanager.py

示例8: _prepare_port_test

    def _prepare_port_test(self, tenant_id, ctx, pod_name, net_id):
        t_port_id = uuidutils.generate_uuid()
        t_port = {
            'id': t_port_id,
            'network_id': net_id
        }
        TOP_PORTS.append(DotDict(t_port))
        b_port = {
            'id': t_port_id,
            'network_id': net_id
        }
        if pod_name == 'pod_1':
            BOTTOM1_PORTS.append(DotDict(b_port))
        else:
            BOTTOM2_PORTS.append(DotDict(b_port))

        pod_id = 'pod_id_1' if pod_name == 'pod_1' else 'pod_id_2'
        core.create_resource(ctx, models.ResourceRouting,
                             {'top_id': t_port_id,
                              'bottom_id': t_port_id,
                              'pod_id': pod_id,
                              'project_id': tenant_id,
                              'resource_type': constants.RT_PORT})

        return t_port_id
开发者ID:openstack,项目名称:tricircle,代码行数:25,代码来源:test_central_sfc_plugin.py

示例9: _test_delete_security_group_rule_exception

    def _test_delete_security_group_rule_exception(self, plugin, q_ctx, t_ctx,
                                                   pod_id, top_sgs, top_rules,
                                                   bottom1_sgs):
        t_sg_id = uuidutils.generate_uuid()
        t_rule_id = uuidutils.generate_uuid()
        b_sg_id = uuidutils.generate_uuid()
        project_id = 'test_prject_id'
        t_rule = self._build_test_rule(
            t_rule_id, t_sg_id, project_id, '10.0.1.0/24')
        b_rule = self._build_test_rule(
            t_rule_id, b_sg_id, project_id, '10.0.1.0/24')
        t_sg = {'id': t_sg_id, 'name': 'test', 'description': '',
                'tenant_id': project_id,
                'security_group_rules': [t_rule]}
        b_sg = {'id': b_sg_id, 'name': t_sg_id, 'description': '',
                'tenant_id': project_id,
                'security_group_rules': [b_rule]}
        top_sgs.append(t_sg)
        top_rules.append(t_rule)
        bottom1_sgs.append(b_sg)
        route = {
            'top_id': t_sg_id,
            'pod_id': pod_id,
            'bottom_id': b_sg_id,
            'resource_type': constants.RT_SG}
        with t_ctx.session.begin():
            core.create_resource(t_ctx, models.ResourceRouting, route)

        self.assertRaises(exceptions.BottomPodOperationFailure,
                          plugin.delete_security_group_rule, q_ctx, t_rule_id)
开发者ID:LongXQ,项目名称:tricircle,代码行数:30,代码来源:test_security_groups.py

示例10: _prepare_flow_classifier_test

    def _prepare_flow_classifier_test(self, project_id, t_ctx, pod_name,
                                      index, src_port_id, create_bottom):
        t_fc_id = uuidutils.generate_uuid()
        b_fc_id = uuidutils.generate_uuid()

        top_fc = {
            "source_port_range_min": None,
            "destination_ip_prefix": None,
            "protocol": None,
            "description": "",
            "l7_parameters": {},
            "source_port_range_max": None,
            "id": t_fc_id,
            "name": "t_fc_%s" % index,
            "ethertype": "IPv4",
            "tenant_id": project_id,
            "source_ip_prefix": "1.0.0.0/24",
            "logical_destination_port": None,
            "destination_port_range_min": None,
            "destination_port_range_max": None,
            "project_id": project_id,
            "logical_source_port": src_port_id}

        TOP_FLOWCLASSIFIERS.append(DotDict(top_fc))
        if create_bottom:
            btm_fc = {
                "source_port_range_min": None,
                "destination_ip_prefix": None,
                "protocol": None,
                "description": "",
                "l7_parameters": {},
                "source_port_range_max": None,
                "id": b_fc_id,
                "name": "b_fc_%s" % index,
                "ethertype": "IPv4",
                "tenant_id": project_id,
                "source_ip_prefix": "1.0.0.0/24",
                "logical_destination_port": None,
                "destination_port_range_min": None,
                "destination_port_range_max": None,
                "project_id": project_id,
                "logical_source_port": src_port_id}
            if pod_name == 'pod_1':
                BOTTOM1_FLOWCLASSIFIERS.append(DotDict(btm_fc))
            else:
                BOTTOM2_FLOWCLASSIFIERS.append(DotDict(btm_fc))

            pod_id = 'pod_id_1' if pod_name == 'pod_1' else 'pod_id_2'
            core.create_resource(t_ctx, models.ResourceRouting,
                                 {'top_id': t_fc_id,
                                  'bottom_id': b_fc_id,
                                  'pod_id': pod_id,
                                  'project_id': project_id,
                                  'resource_type':
                                      constants.RT_FLOW_CLASSIFIER})

        return t_fc_id, b_fc_id
开发者ID:openstack,项目名称:tricircle,代码行数:57,代码来源:test_central_sfc_plugin.py

示例11: _prepare_net_test

 def _prepare_net_test(self, project_id, ctx, pod_name):
     t_net_id = uuidutils.generate_uuid()
     pod_id = 'pod_id_1' if pod_name == 'pod_1' else 'pod_id_2'
     core.create_resource(ctx, models.ResourceRouting,
                          {'top_id': t_net_id,
                           'bottom_id': t_net_id,
                           'pod_id': pod_id,
                           'project_id': project_id,
                           'resource_type': constants.RT_NETWORK})
     return t_net_id
开发者ID:openstack,项目名称:tricircle,代码行数:10,代码来源:test_central_sfc_plugin.py

示例12: _prepare_server

 def _prepare_server(self, pod):
     t_server_id = uuidutils.generate_uuid()
     b_server_id = t_server_id
     with self.context.session.begin():
         core.create_resource(
             self.context, models.ResourceRouting,
             {'top_id': t_server_id, 'bottom_id': b_server_id,
              'pod_id': pod['pod_id'], 'project_id': self.project_id,
              'resource_type': constants.RT_SERVER})
     return t_server_id
开发者ID:dingboopt,项目名称:tricircle,代码行数:10,代码来源:test_action.py

示例13: _test_handle_network_dhcp_port

    def _test_handle_network_dhcp_port(self, dhcp_ip):
        t_pod, b_pod = self._prepare_pod()

        top_net_id = 'top_net_id'
        bottom_net_id = 'bottom_net_id'
        top_subnet_id = 'top_subnet_id'
        bottom_subnet_id = 'bottom_subnet_id'
        t_net = {'id': top_net_id}
        b_net = {'id': bottom_net_id}
        t_subnet = {'id': top_subnet_id,
                    'network_id': top_net_id,
                    'ip_version': 4,
                    'cidr': '10.0.0.0/24',
                    'gateway_ip': '10.0.0.1',
                    'allocation_pools': {'start': '10.0.0.2',
                                         'end': '10.0.0.254'},
                    'enable_dhcp': True}
        b_subnet = {'id': bottom_subnet_id,
                    'network_id': bottom_net_id,
                    'ip_version': 4,
                    'cidr': '10.0.0.0/24',
                    'gateway_ip': '10.0.0.1',
                    'allocation_pools': {'start': '10.0.0.2',
                                         'end': '10.0.0.254'},
                    'enable_dhcp': True}
        b_dhcp_port = {'id': 'bottom_dhcp_port_id',
                       'network_id': bottom_net_id,
                       'fixed_ips': [
                           {'subnet_id': bottom_subnet_id,
                            'ip_address': dhcp_ip}
                       ],
                       'mac_address': 'fa:16:3e:96:41:0a',
                       'binding:profile': {},
                       'device_id': 'reserved_dhcp_port',
                       'device_owner': 'network:dhcp'}
        TOP_NETS.append(t_net)
        TOP_SUBNETS.append(t_subnet)
        BOTTOM_NETS.append(b_net)
        BOTTOM_SUBNETS.append(b_subnet)
        BOTTOM_PORTS.append(b_dhcp_port)
        with self.context.session.begin():
            core.create_resource(
                self.context, models.ResourceRouting,
                {'top_id': top_net_id, 'bottom_id': bottom_net_id,
                 'pod_id': b_pod['pod_id'], 'project_id': self.project_id,
                 'resource_type': 'network'})
            core.create_resource(
                self.context, models.ResourceRouting,
                {'top_id': top_subnet_id, 'bottom_id': bottom_subnet_id,
                 'pod_id': b_pod['pod_id'], 'project_id': self.project_id,
                 'resource_type': 'subnet'})
        self.controller._handle_network(self.context,
                                        b_pod, t_net, [t_subnet])
        self._check_routes()
开发者ID:Ronghui,项目名称:tricircle,代码行数:54,代码来源:test_server.py

示例14: test_resource_routing_unique_key

 def test_resource_routing_unique_key(self):
     pod = {'pod_id': 'test_pod1_uuid',
            'pod_name': 'test_pod1',
            'az_name': 'test_az1_uuid'}
     api.create_pod(self.context, pod)
     routing = {'top_id': 'top_uuid',
                'pod_id': 'test_pod1_uuid',
                'resource_type': 'port'}
     with self.context.session.begin():
         core.create_resource(self.context, models.ResourceRouting, routing)
     self.assertRaises(oslo_db.exception.DBDuplicateEntry,
                       core.create_resource,
                       self.context, models.ResourceRouting, routing)
开发者ID:Ronghui,项目名称:tricircle,代码行数:13,代码来源:test_models.py

示例15: _prepare_port_pair_group_test

    def _prepare_port_pair_group_test(self, project_id, t_ctx, pod_name, index,
                                      t_pp_ids, create_bottom, b_pp_ids):
        t_ppg_id = uuidutils.generate_uuid()
        b_ppg_id = uuidutils.generate_uuid()

        t_client = FakeClient()
        b_client = FakeClient(pod_name)
        t_pps = [t_client.get_resource(
            'port_pair', t_ctx, e) for e in t_pp_ids]
        if create_bottom:
            b_pps = [b_client.get_resource(
                'port_pair', t_ctx, e) for e in b_pp_ids]

        top_ppg = {
            "group_id": 1,
            "description": "",
            "tenant_id": project_id,
            "port_pair_group_parameters": {"lb_fields": []},
            "port_pairs": t_pps,
            "project_id": project_id,
            "id": t_ppg_id,
            "name": 'top_ppg_%d' % index,
            "tap_enabled": False}
        TOP_PORTPAIRGROUPS.append(DotDict(top_ppg))
        if create_bottom:
            btm_ppg = {
                "group_id": 1,
                "description": "",
                "tenant_id": project_id,
                "port_pair_group_parameters": {"lb_fields": []},
                "port_pairs": b_pps,
                "project_id": project_id,
                "id": b_ppg_id,
                "name": 'btm_ppg_%d' % index,
                "tap_enabled": False}
            if pod_name == 'pod_1':
                BOTTOM1_PORTPAIRGROUPS.append(DotDict(btm_ppg))
            else:
                BOTTOM2_PORTPAIRGROUPS.append(DotDict(btm_ppg))

            pod_id = 'pod_id_1' if pod_name == 'pod_1' else 'pod_id_2'
            core.create_resource(t_ctx, models.ResourceRouting,
                                 {'top_id': t_ppg_id,
                                  'bottom_id': b_ppg_id,
                                  'pod_id': pod_id,
                                  'project_id': project_id,
                                  'resource_type':
                                      constants.RT_PORT_PAIR_GROUP})

        return t_ppg_id, b_ppg_id
开发者ID:openstack,项目名称:tricircle,代码行数:50,代码来源:test_central_sfc_plugin.py


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