diff --git a/api-ref/source/instances.inc b/api-ref/source/instances.inc index 2be3519bb6..38c388649a 100644 --- a/api-ref/source/instances.inc +++ b/api-ref/source/instances.inc @@ -260,6 +260,9 @@ Response Parameters - server_id: server_id - volume_id: volume_id - encrypted_rpc_messaging: encrypted_rpc_messaging + - access: access + - access.is_public: access_is_public + - access.allowed_cidrs: access_allowed_cidrs Response Example diff --git a/trove/db/sqlalchemy/migrate_repo/schema.py b/trove/db/sqlalchemy/migrate_repo/schema.py index ecc58f064a..9f7b0b368e 100644 --- a/trove/db/sqlalchemy/migrate_repo/schema.py +++ b/trove/db/sqlalchemy/migrate_repo/schema.py @@ -63,6 +63,11 @@ class Float(sqlalchemy.types.Float): super(Float, self).__init__(*args, **kwargs) +class Json(sqlalchemy.types.JSON): + def __init__(self, *args, **kwargs): + super(Json, self).__init__(*args, **kwargs) + + def create_tables(tables): for table in tables: logger.info("creating table %(table)s", {'table': table}) diff --git a/trove/db/sqlalchemy/migrate_repo/versions/046_add_access_to_instance.py b/trove/db/sqlalchemy/migrate_repo/versions/046_add_access_to_instance.py new file mode 100644 index 0000000000..eac819e113 --- /dev/null +++ b/trove/db/sqlalchemy/migrate_repo/versions/046_add_access_to_instance.py @@ -0,0 +1,28 @@ +# Copyright 2020 Catalyst Cloud +# All Rights Reserved. +# +# 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 sqlalchemy.schema import Column +from sqlalchemy.schema import MetaData + +from trove.db.sqlalchemy.migrate_repo.schema import Json +from trove.db.sqlalchemy.migrate_repo.schema import Table + + +def upgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + + instances = Table('instances', meta, autoload=True) + instances.create_column(Column('access', Json(), nullable=True)) diff --git a/trove/instance/models.py b/trove/instance/models.py index e1624df0bb..6875d0b480 100644 --- a/trove/instance/models.py +++ b/trove/instance/models.py @@ -489,6 +489,13 @@ class SimpleInstance(object): def encrypted_rpc_messaging(self): return True if self.db_info.encrypted_key is not None else False + @property + def access(self): + if hasattr(self.db_info, 'access'): + return self.db_info.access + else: + return None + class DetailInstance(SimpleInstance): """A detailed view of an Instance. @@ -1260,7 +1267,7 @@ class Instance(BuiltInstance): configuration_id=configuration_id, slave_of_id=slave_of_id, cluster_id=cluster_id, shard_id=shard_id, type=instance_type, - region_id=region_name) + region_id=region_name, access=access) instance_id = db_info.id instance_name = name LOG.debug(f"Creating new instance {instance_id}") @@ -1836,7 +1843,7 @@ class DBInstance(dbmodels.DatabaseModelBase): 'volume_size', 'tenant_id', 'server_status', 'deleted', 'deleted_at', 'datastore_version_id', 'configuration_id', 'slave_of_id', 'cluster_id', - 'shard_id', 'type', 'region_id', 'encrypted_key'] + 'shard_id', 'type', 'region_id', 'encrypted_key', 'access'] _table_name = 'instances' def __init__(self, task_status, **kwargs): diff --git a/trove/instance/service.py b/trove/instance/service.py index 8542b024a1..1ed9ad41b5 100644 --- a/trove/instance/service.py +++ b/trove/instance/service.py @@ -250,11 +250,11 @@ class InstanceController(wsgi.Controller): LOG.debug("req : '%s'\n\n", req) context = req.environ[wsgi.CONTEXT_KEY] - server = models.load_instance_with_info(models.DetailInstance, - context, id) - self.authorize_instance_action(context, 'show', server) + instance = models.load_instance_with_info(models.DetailInstance, + context, id) + self.authorize_instance_action(context, 'show', instance) return wsgi.Result( - views.InstanceDetailView(server, req=req).data(), 200 + views.InstanceDetailView(instance, req=req).data(), 200 ) def delete(self, req, tenant_id, id): diff --git a/trove/instance/views.py b/trove/instance/views.py index 4f1dc2a064..1456344b49 100644 --- a/trove/instance/views.py +++ b/trove/instance/views.py @@ -38,7 +38,8 @@ class InstanceView(object): "links": self._build_links(), "flavor": self._build_flavor_info(), "datastore": {"type": None, "version": None}, - "region": self.instance.region_name + "region": self.instance.region_name, + "access": {} } if self.instance.datastore_version: instance_dict['datastore'] = { @@ -66,6 +67,9 @@ class InstanceView(object): if self.instance.slaves: instance_dict['replicas'] = self._build_slaves_info() + if self.instance.access: + instance_dict['access'] = self.instance.access + LOG.debug(instance_dict) return {"instance": instance_dict}