Merge "Allow users the ability to update the instance name"

This commit is contained in:
Jenkins 2014-05-27 11:28:00 +00:00 committed by Gerrit Code Review
commit 21646a49dc
3 changed files with 45 additions and 0 deletions

View File

@ -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

View File

@ -86,6 +86,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.

View File

@ -148,6 +148,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,