summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIccha Sethi <iccha.sethi@rackspace.com>2014-05-07 10:58:38 -0500
committerIccha Sethi <iccha.sethi@rackspace.com>2014-05-08 11:08:48 -0500
commit84de6ee1a0eff940aa770bcbf0c802424da21e85 (patch)
treeec4e2573e1a95d704ec2594e437c1a55d22ae1b8
parenta0ec47b9957b31d165bafa76f99b3c8d90c2bb77 (diff)
downloadpython-troveclient-84de6ee1a0eff940aa770bcbf0c802424da21e85.tar.gz
Allow users the ability to update the instance name
Implements: blueprint update-instance-name This review provides the user the ability to update the instance name or/and configuration using the trove client. Change-Id: If404d4d47c83ca36d7a08ed2a8f1f8dddb7ed677
-rw-r--r--troveclient/tests/test_instances.py11
-rw-r--r--troveclient/v1/instances.py14
-rw-r--r--troveclient/v1/shell.py20
3 files changed, 45 insertions, 0 deletions
diff --git a/troveclient/tests/test_instances.py b/troveclient/tests/test_instances.py
index 69f61f8..c3c95e4 100644
--- a/troveclient/tests/test_instances.py
+++ b/troveclient/tests/test_instances.py
@@ -177,6 +177,17 @@ class InstancesTest(testtools.TestCase):
resp.status_code = 500
self.assertRaises(Exception, self.instances.modify, 'instance1')
+ def test_edit(self):
+ resp = mock.Mock()
+ resp.status_code = 204
+ body = None
+ self.instances.api.client.patch = mock.Mock(return_value=(resp, body))
+ self.instances.edit(123)
+ self.instances.edit(123, 321)
+ self.instances.edit(123, 321, 'name-1234')
+ resp.status_code = 500
+ self.assertRaises(Exception, self.instances.edit, 'instance1')
+
def test_configuration(self):
def side_effect_func(path, inst):
return path, inst
diff --git a/troveclient/v1/instances.py b/troveclient/v1/instances.py
index ed44464..4a73655 100644
--- a/troveclient/v1/instances.py
+++ b/troveclient/v1/instances.py
@@ -96,6 +96,20 @@ class Instances(base.ManagerWithFind):
resp, body = self.api.client.put(url, body=body)
common.check_for_exceptions(resp, body, url)
+ def edit(self, instance_id, configuration=None, name=None):
+ body = {
+ "instance": {
+ }
+ }
+ if configuration is not None:
+ body["instance"]["configuration"] = configuration
+ if name is not None:
+ body["instance"]["name"] = name
+
+ url = "/instances/%s" % instance_id
+ resp, body = self.api.client.patch(url, body=body)
+ common.check_for_exceptions(resp, body, url)
+
def list(self, limit=None, marker=None):
"""
Get a list of all instances.
diff --git a/troveclient/v1/shell.py b/troveclient/v1/shell.py
index 990b555..d6d94e6 100644
--- a/troveclient/v1/shell.py
+++ b/troveclient/v1/shell.py
@@ -147,6 +147,26 @@ def do_delete(cs, args):
cs.instances.delete(args.instance)
+@utils.arg('instance',
+ metavar='<instance>',
+ type=str,
+ help='UUID of the instance.')
+@utils.arg('--name',
+ metavar='<name>',
+ type=str,
+ default=None,
+ help='Name of the instance.')
+@utils.arg('--configuration',
+ metavar='<configuration>',
+ type=str,
+ default=None,
+ help='ID of the configuration reference to attach.')
+@utils.service_type('database')
+def do_update(cs, args):
+ """Updates an instance name or configuration."""
+ cs.instances.edit(args.instance, args.configuration, args.name)
+
+
@utils.arg('name',
metavar='<name>',
type=str,