Add resize-instance to OSC

This change adds database support to the python-openstackclient
project for the resize-instance command

The trove command resize-instance is now:
    openstack database instance resize flavor

Change-Id: I58f8a6ebf8f715c5cc67ce67a36f87d720056ffe
Partially-Implements: blueprint trove-support-in-python-openstackclient
This commit is contained in:
caishan 2018-01-16 02:14:21 -08:00
parent 21c9085c71
commit 3747c17e18
4 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
features:
- |
The command ``trove resize-instance`` is now available to use in
the python-openstackclient CLI as ``openstack database instance resize flavor``

View File

@ -57,6 +57,7 @@ openstack.database.v1 =
database_instance_delete = troveclient.osc.v1.database_instances:DeleteDatabaseInstance
database_instance_list = troveclient.osc.v1.database_instances:ListDatabaseInstances
database_instance_reset_status = troveclient.osc.v1.database_instances:ResetDatabaseInstanceStatus
database_instance_resize_flavor = troveclient.osc.v1.database_instances:ResizeDatabaseInstanceFlavor
database_instance_show = troveclient.osc.v1.database_instances:ShowDatabaseInstance
database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits
database_root_disable = troveclient.osc.v1.database_root:DisableDatabaseRoot

View File

@ -387,3 +387,35 @@ class ResetDatabaseInstanceStatus(command.Command):
instance = osc_utils.find_resource(db_instances,
parsed_args.instance)
db_instances.reset_status(instance)
class ResizeDatabaseInstanceFlavor(command.Command):
_description = _("Resize an instance with a new flavor")
def get_parser(self, prog_name):
parser = super(ResizeDatabaseInstanceFlavor, self).get_parser(
prog_name
)
parser.add_argument(
'instance',
metavar='<instance>',
type=str,
help=_('ID or name of the instance')
)
parser.add_argument(
'flavor_id',
metavar='<flavor_id>',
type=str,
help=_('New flavor of the instance')
)
return parser
def take_action(self, parsed_args):
db_instances = self.app.client_manager.database.instances
db_flavor = self.app.client_manager.database.flavors
instance = osc_utils.find_resource(db_instances,
parsed_args.instance)
flavor = osc_utils.find_resource(db_flavor,
parsed_args.flavor_id)
db_instances.resize_instance(instance, flavor)

View File

@ -183,3 +183,21 @@ class TestDatabaseInstanceResetStatus(TestInstances):
result = self.cmd.take_action(parsed_args)
self.instance_client.reset_status.assert_called_with('instance1')
self.assertIsNone(result)
class TestDatabaseInstanceResizeFlavor(TestInstances):
def setUp(self):
super(TestDatabaseInstanceResizeFlavor, self).setUp()
self.cmd = database_instances.ResizeDatabaseInstanceFlavor(self.app,
None)
@mock.patch.object(utils, 'find_resource')
def test_instance_resize_flavor(self, mock_find):
args = ['instance1', 'flavor_id']
mock_find.side_effect = ['instance1', 'flavor_id']
parsed_args = self.check_parser(self.cmd, args, [])
result = self.cmd.take_action(parsed_args)
self.instance_client.resize_instance.assert_called_with('instance1',
'flavor_id')
self.assertIsNone(result)