Browse Source
1. What is the problem? Tricircle now is dedicated for networking automation across Neutron. Some tables used in APIs gateway should be removed, like aggregation table, pod binding table, etc. They should not reside in the Tricircle any more. Other tables containing old meanings but are still in use should be renamed for better understanding. We can see the blueprint[1] for further explanation. 2. What is the solution to the problem? The data models, tables and APIs about aggregation, pod binding, etc. should be removed. After the pod binding table is removed, the az_hint used for external network creation is hard to match. So special handle needs to be implemented. Other tables will have vague meaning after this splitting, but they still take effective in the Tricircle, So they should be renamed for better understanding. What's more, the pod_name in the pod table is renamed to region_name, which coordinates better with its availability zone. 1)Tables to be removed: *aggregates *aggregate_metadata *instance_types *instance_type_projects *instance_type_extra_specs *key_pairs *pod_binding 2)Tables need to be renamed: *cascaded_pod_service_configuration (new name: cached_endpoints) *cascaded_pods (new name: pods) *cascaded_pods_resource_routing (new name: resource_routings) *job (new name: async_jobs) 3. What the features need to be implemented to the Tricircle to realize the solution? After the pod binding table is removed, the az_hint used for external network creation is hard to match. New features will be implemented to solve this problem. [1] https://blueprints.launchpad.net/tricircle/+spec/clean-legacy-tables Change-Id: I025b4fb48c70abf424bd458fac0dc888e5fa19fdchanges/25/412325/11
42 changed files with 508 additions and 1906 deletions
@ -1,178 +0,0 @@
|
||||
# Copyright 2015 Huawei Technologies Co., Ltd. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
||||
# implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
from oslo_log import log as logging |
||||
from oslo_utils import uuidutils |
||||
|
||||
from tricircle.common.i18n import _LE |
||||
|
||||
from tricircle.db import api as db_api |
||||
from tricircle.db import core |
||||
from tricircle.db import models |
||||
|
||||
LOG = logging.getLogger(__name__) |
||||
|
||||
|
||||
def create_ag_az(context, ag_name, az_name): |
||||
aggregate = core.create_resource(context, models.Aggregate, |
||||
{'name': ag_name}) |
||||
core.create_resource( |
||||
context, models.AggregateMetadata, |
||||
{'key': 'availability_zone', |
||||
'value': az_name, |
||||
'aggregate_id': aggregate['id']}) |
||||
extra_fields = { |
||||
'availability_zone': az_name, |
||||
'metadata': {'availability_zone': az_name} |
||||
} |
||||
aggregate.update(extra_fields) |
||||
return aggregate |
||||
|
||||
|
||||
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 |
||||
|
||||
|
||||
def get_ag_by_name(context, ag_name): |
||||
filters = [{'key': 'name', |
||||
'comparator': 'eq', |
||||
'value': ag_name}] |
||||
aggregates = get_all_ag(context, filters) |
||||
if aggregates is not None: |
||||
if len(aggregates) == 1: |
||||
return aggregates[0] |
||||
|
||||
return None |
||||
|
||||
|
||||
def delete_ag(context, aggregate_id): |
||||
core.delete_resources(context, models.AggregateMetadata, |
||||
[{'key': 'aggregate_id', |
||||
'comparator': 'eq', |
||||
'value': aggregate_id}]) |
||||
core.delete_resource(context, models.Aggregate, aggregate_id) |
||||
return |
||||
|
||||
|
||||
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 |
||||
|
||||
|
||||
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 az_name and pod['az_name'] == az_name: |
||||
return pod, pod['pod_az_name'] |
||||
elif az_name == '' and pod['az_name'] != '': |
||||
# if the az_name is not specified, a defult bottom |
||||
# pod will be selected |
||||
return pod, pod['pod_az_name'] |
||||
else: |
||||
pass |
||||
|
||||
# TODO(joehuang): schedule one dynamically in the future |
||||
if az_name != '': |
||||
filters = [{'key': 'az_name', 'comparator': 'eq', 'value': az_name}] |
||||
else: |
||||
filters = None |
||||
|
||||
# if az_name is valid, select a pod under this az_name |
||||
# if az_name is '', select the first valid bottom pod. |
||||
# change to dynamic schedluing in the future |
||||
pods = db_api.list_pods(context, filters=filters) |
||||
for pod in pods: |
||||
if pod['pod_name'] != '' and pod['az_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'], |
||||
'is_binding': True}) |
||||
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 |
||||
|
||||
|
||||
def list_pods_by_tenant(context, tenant_id): |
||||
|
||||
pod_bindings = core.query_resource(context, |
||||
models.PodBinding, |
||||
[{'key': 'tenant_id', |
||||
'comparator': 'eq', |
||||
'value': tenant_id}], |
||||
[]) |
||||
|
||||
pods = [] |
||||
if pod_bindings: |
||||
for pod_b in pod_bindings: |
||||
pod = core.get_resource(context, |
||||
models.Pod, |
||||
pod_b['pod_id']) |
||||
pods.append(pod) |
||||
|
||||
return pods |