本文整理汇总了Python中tricircle.db.core.query_resource函数的典型用法代码示例。如果您正苦于以下问题:Python query_resource函数的具体用法?Python query_resource怎么用?Python query_resource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了query_resource函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_one
def get_one(self, _id):
# NOTE(zhiyuan) this function handles two kinds of requests
# GET /flavors/flavor_id
# GET /flavors/detail
context = t_context.extract_context_from_environ()
if _id == 'detail':
with context.session.begin():
flavors = core.query_resource(context, models.InstanceTypes,
[], [])
for flavor in flavors:
flavor['id'] = flavor['flavorid']
del flavor['flavorid']
return {'flavors': flavors}
else:
with context.session.begin():
flavors = core.query_resource(context, models.InstanceTypes,
[{'key': 'flavorid',
'comparator': 'eq',
'value': _id}], [])
if not flavors:
pecan.abort(404, 'Flavor not found')
return
flavor = flavors[0]
flavor['id'] = flavor['flavorid']
del flavor['flavorid']
return {'flavor': flavor}
开发者ID:Ronghui,项目名称:tricircle,代码行数:26,代码来源:flavor.py
示例2: get_all_ag
def get_all_ag(context, filters=None, sorts=None):
aggregates = core.query_resource(context,
models.Aggregate,
filters or [],
sorts or [])
metadatas = core.query_resource(
context, models.AggregateMetadata,
[{'key': 'key',
'comparator': 'eq',
'value': 'availability_zone'}], [])
agg_meta_map = {}
for metadata in metadatas:
agg_meta_map[metadata['aggregate_id']] = metadata
for aggregate in aggregates:
extra_fields = {
'availability_zone': '',
'metadata': {}
}
if aggregate['id'] in agg_meta_map:
metadata = agg_meta_map[aggregate['id']]
extra_fields['availability_zone'] = metadata['value']
extra_fields['metadata'] = {
'availability_zone': metadata['value']}
aggregate.update(extra_fields)
return aggregates
开发者ID:Ronghui,项目名称:tricircle,代码行数:27,代码来源:az_ag.py
示例3: _check_routes
def _check_routes(self):
for res in (TOP_NETS, TOP_SUBNETS, BOTTOM_NETS, BOTTOM_SUBNETS):
self.assertEqual(1, len(res))
self.assertEqual(2, len(TOP_PORTS))
self.assertEqual(2, len(BOTTOM_PORTS))
with self.context.session.begin():
routes = core.query_resource(self.context,
models.ResourceRouting, [], [])
self.assertEqual(4, len(routes))
actual = [[], [], [], []]
for region in ('t_region', 'b_region'):
actual[0].append(self.controller._get_client(
region).list_resources('network', self.context, [])[0]['id'])
actual[1].append(self.controller._get_client(
region).list_resources('subnet', self.context, [])[0]['id'])
t_ports = self.controller._get_client(
region).list_resources('port', self.context, [])
if 'device_id' in t_ports[0]:
actual[2].append(t_ports[0]['id'])
actual[3].append(t_ports[1]['id'])
else:
actual[2].append(t_ports[1]['id'])
actual[3].append(t_ports[0]['id'])
expect = [[route['top_id'], route['bottom_id']] for route in routes]
self.assertItemsEqual(expect, actual)
开发者ID:Ronghui,项目名称:tricircle,代码行数:26,代码来源:test_server.py
示例4: 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
示例5: 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
示例6: get_bottom_mappings_by_tenant_pod
def get_bottom_mappings_by_tenant_pod(context,
tenant_id,
pod_id,
resource_type):
"""Get resource routing for specific tenant and pod
:param context: context object
:param tenant_id: tenant id to look up
:param pod_id: pod to look up
:param resource_type: specific resource
:return: a dic {top_id : route}
"""
route_filters = [{'key': 'pod_id',
'comparator': 'eq',
'value': pod_id},
{'key': 'project_id',
'comparator': 'eq',
'value': tenant_id},
{'key': 'resource_type',
'comparator': 'eq',
'value': resource_type}]
routings = {}
with context.session.begin():
routes = core.query_resource(
context, models.ResourceRouting, route_filters, [])
for _route in routes:
if not _route['bottom_id']:
continue
routings[_route['top_id']] = _route
return routings
开发者ID:LongXQ,项目名称:tricircle,代码行数:30,代码来源:api.py
示例7: 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
示例8: get_all
def get_all(self):
context = t_context.extract_context_from_environ()
with context.session.begin():
flavors = core.query_resource(context, models.InstanceTypes,
[], [])
return {'flavors': [dict(
[('id', flavor['flavorid']),
('name', flavor['name'])]) for flavor in flavors]}
开发者ID:Ronghui,项目名称:tricircle,代码行数:8,代码来源:flavor.py
示例9: get_or_create_route
def get_or_create_route(t_ctx, q_ctx,
project_id, pod, ele, _type, list_ele_method):
# use configuration option later
route_expire_threshold = 30
_id = ele['id']
with t_ctx.session.begin():
routes = core.query_resource(
t_ctx, models.ResourceRouting,
[{'key': 'top_id', 'comparator': 'eq', 'value': _id},
{'key': 'pod_id', 'comparator': 'eq',
'value': pod['pod_id']},
{'key': 'resource_type', 'comparator': 'eq',
'value': _type}], [])
if routes:
route = routes[0]
if route['bottom_id']:
return route, ALL_DONE
else:
route_time = route['updated_at'] or route['created_at']
current_time = datetime.datetime.utcnow()
delta = current_time - route_time
if delta.seconds > route_expire_threshold:
# NOTE(zhiyuan) cannot directly remove the route, we have
# a race here that other worker is updating this route, we
# need to check if the corresponding element has been
# created by other worker
eles = list_ele_method(t_ctx, q_ctx, pod, ele, _type)
if eles:
route['bottom_id'] = eles[0]['id']
core.update_resource(t_ctx,
models.ResourceRouting,
route['id'], route)
return route, RES_DONE
try:
core.delete_resource(t_ctx,
models.ResourceRouting,
route['id'])
except db_exc.ResourceNotFound:
pass
try:
# NOTE(zhiyuan) try/except block inside a with block will cause
# problem, so move them out of the block and manually handle the
# session context
t_ctx.session.begin()
route = core.create_resource(t_ctx, models.ResourceRouting,
{'top_id': _id,
'pod_id': pod['pod_id'],
'project_id': project_id,
'resource_type': _type})
t_ctx.session.commit()
return route, NONE_DONE
except db_exc.DBDuplicateEntry:
t_ctx.session.rollback()
return None, NONE_DONE
finally:
t_ctx.session.close()
开发者ID:LongXQ,项目名称:tricircle,代码行数:57,代码来源:lock_handle.py
示例10: get_running_job
def get_running_job(context, _type, resource_id):
jobs = core.query_resource(
context, models.AsyncJob,
[{'key': 'resource_id', 'comparator': 'eq', 'value': resource_id},
{'key': 'status', 'comparator': 'eq', 'value': constants.JS_Running},
{'key': 'type', 'comparator': 'eq', 'value': _type}], [])
if jobs:
return jobs[0]
else:
return None
开发者ID:LongXQ,项目名称:tricircle,代码行数:10,代码来源:api.py
示例11: get_latest_job
def get_latest_job(context, status, _type, resource_id):
jobs = core.query_resource(
context, models.AsyncJob,
[{'key': 'status', 'comparator': 'eq', 'value': status},
{'key': 'type', 'comparator': 'eq', 'value': _type},
{'key': 'resource_id', 'comparator': 'eq', 'value': resource_id}],
[('timestamp', False)])
if jobs:
return jobs[0]
else:
return None
开发者ID:LongXQ,项目名称:tricircle,代码行数:11,代码来源:api.py
示例12: test_delete
def test_delete(self, mock_context):
mock_context.return_value = self.context
kw = {'pod': {'region_name': 'BottomPod', 'az_name': 'TopAZ'}}
pod_id = self.controller.post(**kw)['pod']['pod_id']
self.controller.delete(pod_id)
with self.context.session.begin():
pods = core.query_resource(self.context, models.Pod,
[{'key': 'region_name',
'comparator': 'eq',
'value': 'BottomPod'}], [])
self.assertEqual(0, len(pods))
开发者ID:LongXQ,项目名称:tricircle,代码行数:12,代码来源:test_pod.py
示例13: _get_top_region
def _get_top_region(self, ctx):
top_region_name = ''
try:
with ctx.session.begin():
pods = core.query_resource(ctx,
models.Pod, [], [])
for pod in pods:
if pod['az_name'] == '' and pod['pod_name'] != '':
return pod['pod_name']
except Exception:
return top_region_name
return top_region_name
开发者ID:Ronghui,项目名称:tricircle,代码行数:13,代码来源:pod.py
示例14: delete_pre_created_resource_mapping
def delete_pre_created_resource_mapping(context, name):
with context.session.begin():
entries = core.query_resource(
context, models.ResourceRouting,
filters=[{'key': 'top_id', 'comparator': 'eq',
'value': name}], sorts=[])
if entries:
core.delete_resources(
context, models.ResourceRouting,
filters=[{'key': 'top_id', 'comparator': 'eq',
'value': entries[0]['bottom_id']}])
core.delete_resource(context, models.ResourceRouting,
entries[0]['id'])
开发者ID:LongXQ,项目名称:tricircle,代码行数:13,代码来源:api.py
示例15: test_delete_mappings_by_bottom_id
def test_delete_mappings_by_bottom_id(self):
self._create_pod(0, 'test_az_uuid_0')
self._create_pod(1, 'test_az_uuid_1')
self._create_pod(2, 'test_az_uuid_2')
self._create_resource_mappings()
bottom_id = 'bottom_uuid_1'
api.delete_mappings_by_bottom_id(self.context, bottom_id)
filters = [{'key': 'bottom_id', 'comparator': 'eq',
'value': bottom_id}]
routing = core.query_resource(
self.context, models.ResourceRouting, filters, [])
self.assertEqual(len(routing), 0)
开发者ID:LongXQ,项目名称:tricircle,代码行数:13,代码来源:test_api.py
示例16: delete
def delete(self, _id):
context = t_context.extract_context_from_environ()
with context.session.begin():
flavors = core.query_resource(context, models.InstanceTypes,
[{'key': 'flavorid',
'comparator': 'eq',
'value': _id}], [])
if not flavors:
pecan.abort(404, 'Flavor not found')
return
core.delete_resource(context,
models.InstanceTypes, flavors[0]['id'])
pecan.response.status = 202
return
开发者ID:Ronghui,项目名称:tricircle,代码行数:14,代码来源:flavor.py
示例17: get_one_ag
def get_one_ag(context, aggregate_id):
aggregate = core.get_resource(context, models.Aggregate, aggregate_id)
metadatas = core.query_resource(
context, models.AggregateMetadata,
[{'key': 'key', 'comparator': 'eq',
'value': 'availability_zone'},
{'key': 'aggregate_id', 'comparator': 'eq',
'value': aggregate['id']}], [])
if metadatas:
aggregate['availability_zone'] = metadatas[0]['value']
aggregate['metadata'] = {
'availability_zone': metadatas[0]['value']}
else:
aggregate['availability_zone'] = ''
aggregate['metadata'] = {}
return aggregate
开发者ID:Ronghui,项目名称:tricircle,代码行数:16,代码来源:az_ag.py
示例18: get_pod_by_top_id
def get_pod_by_top_id(context, _id):
"""Get pod resource from pod table by top id of resource
:param context: context object
:param _id: the top id of resource
:returns: pod resource
"""
route_filters = [{'key': 'top_id', 'comparator': 'eq', 'value': _id}]
with context.session.begin():
routes = core.query_resource(
context, models.ResourceRouting, route_filters, [])
if not routes or len(routes) != 1:
return None
route = routes[0]
if not route['bottom_id']:
return None
return core.get_resource(context, models.Pod, route['pod_id'])
开发者ID:LongXQ,项目名称:tricircle,代码行数:17,代码来源:api.py
示例19: test_job_handle
def test_job_handle(self):
job_type = 'fake_resource'
@xmanager._job_handle(job_type)
def fake_handle(self, ctx, payload):
pass
fake_id = 'fake_id'
fake_project_id = uuidutils.generate_uuid()
payload = {job_type: fake_id}
db_api.new_job(self.context, fake_project_id, job_type, fake_id)
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,代码行数:17,代码来源:test_xmanager.py
示例20: get_all
def get_all(self):
context = t_context.extract_context_from_environ()
if not t_context.is_admin_context(context):
pecan.abort(400, _('Admin role required to list bindings'))
return
try:
with context.session.begin():
pod_bindings = core.query_resource(context,
models.PodBinding,
[], [])
except Exception:
pecan.abort(500, _('Fail to list tenant pod bindings'))
return
return {'pod_bindings': pod_bindings}
开发者ID:Ronghui,项目名称:tricircle,代码行数:17,代码来源:pod.py
注:本文中的tricircle.db.core.query_resource函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论