Merge "replace windows line endings with unix line endings"
This commit is contained in:
commit
fdfb2ffe97
|
@ -1,35 +1,35 @@
|
||||||
# Copyright 2017 SZZT Co., Ltd.
|
# Copyright 2017 SZZT Co., Ltd.
|
||||||
# All Rights Reserved
|
# All Rights Reserved
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# 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
|
# not use this file except in compliance with the License. You may obtain
|
||||||
# a copy of the License at
|
# a copy of the License at
|
||||||
#
|
#
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import sqlalchemy as sql
|
import sqlalchemy as sql
|
||||||
|
|
||||||
|
|
||||||
def upgrade(migrate_engine):
|
def upgrade(migrate_engine):
|
||||||
meta = sql.MetaData()
|
meta = sql.MetaData()
|
||||||
meta.bind = migrate_engine
|
meta.bind = migrate_engine
|
||||||
|
|
||||||
recycle_resources = sql.Table(
|
recycle_resources = sql.Table(
|
||||||
'deleting_resources', meta,
|
'deleting_resources', meta,
|
||||||
sql.Column('resource_id', sql.String(length=127), nullable=False),
|
sql.Column('resource_id', sql.String(length=127), nullable=False),
|
||||||
sql.Column('resource_type', sql.String(length=64), nullable=False),
|
sql.Column('resource_type', sql.String(length=64), nullable=False),
|
||||||
sql.Column('deleted_at', sql.DateTime),
|
sql.Column('deleted_at', sql.DateTime),
|
||||||
mysql_engine='InnoDB',
|
mysql_engine='InnoDB',
|
||||||
mysql_charset='utf8')
|
mysql_charset='utf8')
|
||||||
|
|
||||||
recycle_resources.create()
|
recycle_resources.create()
|
||||||
|
|
||||||
|
|
||||||
def downgrade(migrate_engine):
|
def downgrade(migrate_engine):
|
||||||
raise NotImplementedError('downgrade not support')
|
raise NotImplementedError('downgrade not support')
|
||||||
|
|
|
@ -1,88 +1,88 @@
|
||||||
# Copyright 2015 Huawei Technologies Co., Ltd.
|
# Copyright 2015 Huawei Technologies Co., Ltd.
|
||||||
# All Rights Reserved
|
# All Rights Reserved
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# 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
|
# not use this file except in compliance with the License. You may obtain
|
||||||
# a copy of the License at
|
# a copy of the License at
|
||||||
#
|
#
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from neutron.db import models_v2
|
from neutron.db import models_v2
|
||||||
from neutron_lib import exceptions
|
from neutron_lib import exceptions
|
||||||
from sqlalchemy import sql
|
from sqlalchemy import sql
|
||||||
|
|
||||||
import tricircle.common.constants as t_constants
|
import tricircle.common.constants as t_constants
|
||||||
import tricircle.common.context as t_context
|
import tricircle.common.context as t_context
|
||||||
import tricircle.common.exceptions as t_exceptions
|
import tricircle.common.exceptions as t_exceptions
|
||||||
import tricircle.db.api as db_api
|
import tricircle.db.api as db_api
|
||||||
from tricircle.db import core
|
from tricircle.db import core
|
||||||
from tricircle.db import models
|
from tricircle.db import models
|
||||||
|
|
||||||
|
|
||||||
def check_resource_not_in_deleting(context, dict_para):
|
def check_resource_not_in_deleting(context, dict_para):
|
||||||
t_ctx = t_context.get_context_from_neutron_context(context)
|
t_ctx = t_context.get_context_from_neutron_context(context)
|
||||||
with t_ctx.session.begin():
|
with t_ctx.session.begin():
|
||||||
resource_filters = []
|
resource_filters = []
|
||||||
for key in dict_para.keys():
|
for key in dict_para.keys():
|
||||||
resource_filters.append({'key': key,
|
resource_filters.append({'key': key,
|
||||||
'comparator': 'eq',
|
'comparator': 'eq',
|
||||||
'value': dict_para[key]})
|
'value': dict_para[key]})
|
||||||
|
|
||||||
deleting_resource = core.query_resource(t_ctx,
|
deleting_resource = core.query_resource(t_ctx,
|
||||||
models.DeletingResources,
|
models.DeletingResources,
|
||||||
resource_filters, [])
|
resource_filters, [])
|
||||||
|
|
||||||
if len(deleting_resource):
|
if len(deleting_resource):
|
||||||
if hasattr(context, "USER_AGENT") and \
|
if hasattr(context, "USER_AGENT") and \
|
||||||
context.USER_AGENT == t_constants.LOCAL:
|
context.USER_AGENT == t_constants.LOCAL:
|
||||||
raise t_exceptions.ResourceNotFound(
|
raise t_exceptions.ResourceNotFound(
|
||||||
models.DeletingResources, dict_para['resource_id'])
|
models.DeletingResources, dict_para['resource_id'])
|
||||||
else:
|
else:
|
||||||
raise t_exceptions.ResourceIsInDeleting()
|
raise t_exceptions.ResourceIsInDeleting()
|
||||||
|
|
||||||
|
|
||||||
def check_network_not_in_use(self, context, t_ctx, network_id):
|
def check_network_not_in_use(self, context, t_ctx, network_id):
|
||||||
# use a different name to avoid override _ensure_entwork_not_in_use
|
# use a different name to avoid override _ensure_entwork_not_in_use
|
||||||
subnets = self._get_subnets_by_network(context, network_id)
|
subnets = self._get_subnets_by_network(context, network_id)
|
||||||
auto_delete_port_names = []
|
auto_delete_port_names = []
|
||||||
|
|
||||||
for subnet in subnets:
|
for subnet in subnets:
|
||||||
subnet_id = subnet['id']
|
subnet_id = subnet['id']
|
||||||
region_names = [e[0] for e in t_ctx.session.query(
|
region_names = [e[0] for e in t_ctx.session.query(
|
||||||
sql.distinct(models.Pod.region_name)).join(
|
sql.distinct(models.Pod.region_name)).join(
|
||||||
models.ResourceRouting,
|
models.ResourceRouting,
|
||||||
models.Pod.pod_id == models.ResourceRouting.pod_id).filter(
|
models.Pod.pod_id == models.ResourceRouting.pod_id).filter(
|
||||||
models.ResourceRouting.top_id == subnet_id)]
|
models.ResourceRouting.top_id == subnet_id)]
|
||||||
auto_delete_port_names.extend([t_constants.interface_port_name % (
|
auto_delete_port_names.extend([t_constants.interface_port_name % (
|
||||||
region_name, subnet_id) for region_name in region_names])
|
region_name, subnet_id) for region_name in region_names])
|
||||||
dhcp_port_name = t_constants.dhcp_port_name % subnet_id
|
dhcp_port_name = t_constants.dhcp_port_name % subnet_id
|
||||||
snat_port_name = t_constants.snat_port_name % subnet_id
|
snat_port_name = t_constants.snat_port_name % subnet_id
|
||||||
auto_delete_port_names.append(dhcp_port_name)
|
auto_delete_port_names.append(dhcp_port_name)
|
||||||
auto_delete_port_names.append(snat_port_name)
|
auto_delete_port_names.append(snat_port_name)
|
||||||
|
|
||||||
if not auto_delete_port_names:
|
if not auto_delete_port_names:
|
||||||
# pre-created port not found, any ports left need to be deleted
|
# pre-created port not found, any ports left need to be deleted
|
||||||
# before deleting network
|
# before deleting network
|
||||||
non_auto_delete_ports = context.session.query(
|
non_auto_delete_ports = context.session.query(
|
||||||
models_v2.Port.id).filter_by(network_id=network_id)
|
models_v2.Port.id).filter_by(network_id=network_id)
|
||||||
if non_auto_delete_ports.count():
|
if non_auto_delete_ports.count():
|
||||||
raise exceptions.NetworkInUse(net_id=network_id)
|
raise exceptions.NetworkInUse(net_id=network_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
t_pod = db_api.get_top_pod(t_ctx)
|
t_pod = db_api.get_top_pod(t_ctx)
|
||||||
auto_delete_port_ids = [e[0] for e in t_ctx.session.query(
|
auto_delete_port_ids = [e[0] for e in t_ctx.session.query(
|
||||||
models.ResourceRouting.bottom_id).filter_by(
|
models.ResourceRouting.bottom_id).filter_by(
|
||||||
pod_id=t_pod['pod_id'], resource_type=t_constants.RT_PORT).filter(
|
pod_id=t_pod['pod_id'], resource_type=t_constants.RT_PORT).filter(
|
||||||
models.ResourceRouting.top_id.in_(auto_delete_port_names))]
|
models.ResourceRouting.top_id.in_(auto_delete_port_names))]
|
||||||
|
|
||||||
non_auto_delete_ports = context.session.query(
|
non_auto_delete_ports = context.session.query(
|
||||||
models_v2.Port.id).filter_by(network_id=network_id).filter(
|
models_v2.Port.id).filter_by(network_id=network_id).filter(
|
||||||
~models_v2.Port.id.in_(auto_delete_port_ids))
|
~models_v2.Port.id.in_(auto_delete_port_ids))
|
||||||
if non_auto_delete_ports.count():
|
if non_auto_delete_ports.count():
|
||||||
raise exceptions.NetworkInUse(net_id=network_id)
|
raise exceptions.NetworkInUse(net_id=network_id)
|
||||||
|
|
Loading…
Reference in New Issue