diff options
| author | Zuul <zuul@review.opendev.org> | 2020-11-13 08:53:57 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2020-11-13 08:53:57 +0000 |
| commit | f28390ee5ddf83c0dfbf886b7e99c192fa7f4ecc (patch) | |
| tree | 9b5e95d315a4669a526fe1eb9163f45e6a3a0413 /troveclient/osc | |
| parent | 20566017e5c5c4c5b2ebf3629c062f8f2521e0c7 (diff) | |
| parent | c04e299b1d503f2ce67730398b9585a196616e51 (diff) | |
| download | python-troveclient-f28390ee5ddf83c0dfbf886b7e99c192fa7f4ecc.tar.gz | |
Merge "Revert "Remove flavor API""
Diffstat (limited to 'troveclient/osc')
| -rw-r--r-- | troveclient/osc/v1/database_flavors.py | 97 | ||||
| -rw-r--r-- | troveclient/osc/v1/database_instances.py | 17 |
2 files changed, 110 insertions, 4 deletions
diff --git a/troveclient/osc/v1/database_flavors.py b/troveclient/osc/v1/database_flavors.py new file mode 100644 index 0000000..5fb513e --- /dev/null +++ b/troveclient/osc/v1/database_flavors.py @@ -0,0 +1,97 @@ +# 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. + +"""Database v1 Flavors action implementations""" + +from osc_lib.command import command +from osc_lib import utils +import six + +from troveclient import exceptions +from troveclient.i18n import _ + + +def set_attributes_for_print_detail(flavor): + info = flavor._info.copy() + # Get rid of those ugly links + if info.get('links'): + del(info['links']) + + # Fallback to str_id for flavors, where necessary + if hasattr(flavor, 'str_id'): + info['id'] = flavor.id + del(info['str_id']) + return info + + +class ListDatabaseFlavors(command.Lister): + + _description = _("List database flavors") + columns = ['ID', 'Name', 'RAM', 'vCPUs', 'Disk', 'Ephemeral'] + + def get_parser(self, prog_name): + parser = super(ListDatabaseFlavors, self).get_parser(prog_name) + parser.add_argument( + '--datastore-type', + dest='datastore_type', + metavar='<datastore-type>', + help=_('Type of the datastore. For eg: mysql.') + ) + parser.add_argument( + '--datastore-version-id', + dest='datastore_version_id', + metavar='<datastore-version-id>', + help=_('ID of the datastore version.') + ) + return parser + + def take_action(self, parsed_args): + db_flavors = self.app.client_manager.database.flavors + if parsed_args.datastore_type and parsed_args.datastore_version_id: + flavors = db_flavors.list_datastore_version_associated_flavors( + datastore=parsed_args.datastore_type, + version_id=parsed_args.datastore_version_id) + elif (not parsed_args.datastore_type and not + parsed_args.datastore_version_id): + flavors = db_flavors.list() + else: + raise exceptions.MissingArgs(['datastore-type', + 'datastore-version-id']) + + # Fallback to str_id where necessary. + _flavors = [] + for f in flavors: + if not f.id and hasattr(f, 'str_id'): + f.id = f.str_id + _flavors.append(utils.get_item_properties(f, self.columns)) + + return self.columns, _flavors + + +class ShowDatabaseFlavor(command.ShowOne): + _description = _("Shows details of a database flavor") + + def get_parser(self, prog_name): + parser = super(ShowDatabaseFlavor, self).get_parser(prog_name) + parser.add_argument( + 'flavor', + metavar='<flavor>', + help=_('ID or name of the flavor'), + ) + return parser + + def take_action(self, parsed_args): + db_flavors = self.app.client_manager.database.flavors + flavor = utils.find_resource(db_flavors, + parsed_args.flavor) + flavor = set_attributes_for_print_detail(flavor) + return zip(*sorted(six.iteritems(flavor))) diff --git a/troveclient/osc/v1/database_instances.py b/troveclient/osc/v1/database_instances.py index bf81b8b..c99b776 100644 --- a/troveclient/osc/v1/database_instances.py +++ b/troveclient/osc/v1/database_instances.py @@ -247,7 +247,8 @@ class CreateDatabaseInstance(command.ShowOne): '--flavor', metavar='<flavor>', type=str, - help=_("A flavor ID."), + help=_("Flavor to create the instance (name or ID). Flavor is not " + "required when creating replica instances."), ) parser.add_argument( '--size', @@ -376,8 +377,16 @@ class CreateDatabaseInstance(command.ShowOne): db_instances = database.instances if not parsed_args.replica_of and not parsed_args.flavor: - raise exceptions.CommandError( - _("Please specify a flavor")) + raise exceptions.CommandError(_("Please specify a flavor")) + + if parsed_args.replica_of and parsed_args.flavor: + print("Warning: Flavor is ignored for creating replica.") + + if not parsed_args.replica_of: + flavor_id = osc_utils.find_resource( + database.flavors, parsed_args.flavor).id + else: + flavor_id = None volume = None if parsed_args.size is not None and parsed_args.size <= 0: @@ -444,7 +453,7 @@ class CreateDatabaseInstance(command.ShowOne): instance = db_instances.create( parsed_args.name, - flavor_id=parsed_args.flavor, + flavor_id=flavor_id, volume=volume, databases=databases, users=users, |
