Add name argument to aggregate commands
Fixes #Bug 1202901 This patch adds name arguments to the following subcommands: * aggregate-update * aggregate-delete * aggregate-set-metadata * aggregate-add-host * aggregate-remove-host * aggregate-details Change-Id: I93f44a12b6d5a91b448f6f8d238311d58bf40c01
This commit is contained in:
parent
f702c25d43
commit
4025b7e5e3
novaclient
@ -865,45 +865,84 @@ class ShellTest(utils.TestCase):
|
||||
self.assert_called('POST', '/os-aggregates', body, pos=-2)
|
||||
self.assert_called('GET', '/os-aggregates/1', pos=-1)
|
||||
|
||||
def test_aggregate_delete(self):
|
||||
def test_aggregate_delete_by_id(self):
|
||||
self.run_command('aggregate-delete 1')
|
||||
self.assert_called('DELETE', '/os-aggregates/1')
|
||||
|
||||
def test_aggregate_update(self):
|
||||
def test_aggregate_delete_by_name(self):
|
||||
self.run_command('aggregate-delete test')
|
||||
self.assert_called('DELETE', '/os-aggregates/1')
|
||||
|
||||
def test_aggregate_update_by_id(self):
|
||||
self.run_command('aggregate-update 1 new_name')
|
||||
body = {"aggregate": {"name": "new_name"}}
|
||||
self.assert_called('PUT', '/os-aggregates/1', body, pos=-2)
|
||||
self.assert_called('GET', '/os-aggregates/1', pos=-1)
|
||||
|
||||
def test_aggregate_update_with_availability_zone(self):
|
||||
def test_aggregate_update_by_name(self):
|
||||
self.run_command('aggregate-update test new_name')
|
||||
body = {"aggregate": {"name": "new_name"}}
|
||||
self.assert_called('PUT', '/os-aggregates/1', body, pos=-2)
|
||||
self.assert_called('GET', '/os-aggregates/1', pos=-1)
|
||||
|
||||
def test_aggregate_update_with_availability_zone_by_id(self):
|
||||
self.run_command('aggregate-update 1 foo new_zone')
|
||||
body = {"aggregate": {"name": "foo", "availability_zone": "new_zone"}}
|
||||
self.assert_called('PUT', '/os-aggregates/1', body, pos=-2)
|
||||
self.assert_called('GET', '/os-aggregates/1', pos=-1)
|
||||
|
||||
def test_aggregate_set_metadata(self):
|
||||
def test_aggregate_update_with_availability_zone_by_name(self):
|
||||
self.run_command('aggregate-update test foo new_zone')
|
||||
body = {"aggregate": {"name": "foo", "availability_zone": "new_zone"}}
|
||||
self.assert_called('PUT', '/os-aggregates/1', body, pos=-2)
|
||||
self.assert_called('GET', '/os-aggregates/1', pos=-1)
|
||||
|
||||
def test_aggregate_set_metadata_by_id(self):
|
||||
self.run_command('aggregate-set-metadata 1 foo=bar delete_key')
|
||||
body = {"set_metadata": {"metadata": {"foo": "bar",
|
||||
"delete_key": None}}}
|
||||
self.assert_called('POST', '/os-aggregates/1/action', body, pos=-2)
|
||||
self.assert_called('GET', '/os-aggregates/1', pos=-1)
|
||||
|
||||
def test_aggregate_add_host(self):
|
||||
def test_aggregate_set_metadata_by_name(self):
|
||||
self.run_command('aggregate-set-metadata test foo=bar delete_key')
|
||||
body = {"set_metadata": {"metadata": {"foo": "bar",
|
||||
"delete_key": None}}}
|
||||
self.assert_called('POST', '/os-aggregates/1/action', body, pos=-2)
|
||||
self.assert_called('GET', '/os-aggregates/1', pos=-1)
|
||||
|
||||
def test_aggregate_add_host_by_id(self):
|
||||
self.run_command('aggregate-add-host 1 host1')
|
||||
body = {"add_host": {"host": "host1"}}
|
||||
self.assert_called('POST', '/os-aggregates/1/action', body, pos=-2)
|
||||
self.assert_called('GET', '/os-aggregates/1', pos=-1)
|
||||
|
||||
def test_aggregate_remove_host(self):
|
||||
def test_aggregate_add_host_by_name(self):
|
||||
self.run_command('aggregate-add-host test host1')
|
||||
body = {"add_host": {"host": "host1"}}
|
||||
self.assert_called('POST', '/os-aggregates/1/action', body, pos=-2)
|
||||
self.assert_called('GET', '/os-aggregates/1', pos=-1)
|
||||
|
||||
def test_aggregate_remove_host_by_id(self):
|
||||
self.run_command('aggregate-remove-host 1 host1')
|
||||
body = {"remove_host": {"host": "host1"}}
|
||||
self.assert_called('POST', '/os-aggregates/1/action', body, pos=-2)
|
||||
self.assert_called('GET', '/os-aggregates/1', pos=-1)
|
||||
|
||||
def test_aggregate_details(self):
|
||||
def test_aggregate_remove_host_by_name(self):
|
||||
self.run_command('aggregate-remove-host test host1')
|
||||
body = {"remove_host": {"host": "host1"}}
|
||||
self.assert_called('POST', '/os-aggregates/1/action', body, pos=-2)
|
||||
self.assert_called('GET', '/os-aggregates/1', pos=-1)
|
||||
|
||||
def test_aggregate_details_by_id(self):
|
||||
self.run_command('aggregate-details 1')
|
||||
self.assert_called('GET', '/os-aggregates/1')
|
||||
|
||||
def test_aggregate_details_by_name(self):
|
||||
self.run_command('aggregate-details test')
|
||||
self.assert_called('GET', '/os-aggregates')
|
||||
|
||||
def test_live_migration(self):
|
||||
self.run_command('live-migration sample-server hostname')
|
||||
self.assert_called('POST', '/servers/1234/action',
|
||||
|
@ -2405,6 +2405,11 @@ def do_agent_modify(cs, args):
|
||||
utils.print_dict(result._info)
|
||||
|
||||
|
||||
def _find_aggregate(cs, aggregate):
|
||||
"""Get a aggregate by name or ID."""
|
||||
return utils.find_resource(cs.aggregates, aggregate)
|
||||
|
||||
|
||||
def do_aggregate_list(cs, args):
|
||||
"""Print a list of all aggregates."""
|
||||
aggregates = cs.aggregates.list()
|
||||
@ -2424,14 +2429,17 @@ def do_aggregate_create(cs, args):
|
||||
_print_aggregate_details(aggregate)
|
||||
|
||||
|
||||
@utils.arg('id', metavar='<id>', help='Aggregate id to delete.')
|
||||
@utils.arg('aggregate', metavar='<aggregate>',
|
||||
help='Name or ID of aggregate to delete.')
|
||||
def do_aggregate_delete(cs, args):
|
||||
"""Delete the aggregate by its id."""
|
||||
cs.aggregates.delete(args.id)
|
||||
print("Aggregate %s has been successfully deleted." % args.id)
|
||||
"""Delete the aggregate."""
|
||||
aggregate = _find_aggregate(cs, args.aggregate)
|
||||
cs.aggregates.delete(aggregate)
|
||||
print("Aggregate %s has been successfully deleted." % aggregate.id)
|
||||
|
||||
|
||||
@utils.arg('id', metavar='<id>', help='Aggregate id to update.')
|
||||
@utils.arg('aggregate', metavar='<aggregate>',
|
||||
help='Name or ID of aggregate to update.')
|
||||
@utils.arg('name', metavar='<name>', help='Name of aggregate.')
|
||||
@utils.arg('availability_zone',
|
||||
metavar='<availability-zone>',
|
||||
@ -2440,16 +2448,18 @@ def do_aggregate_delete(cs, args):
|
||||
help='The availability zone of the aggregate.')
|
||||
def do_aggregate_update(cs, args):
|
||||
"""Update the aggregate's name and optionally availability zone."""
|
||||
aggregate = _find_aggregate(cs, args.aggregate)
|
||||
updates = {"name": args.name}
|
||||
if args.availability_zone:
|
||||
updates["availability_zone"] = args.availability_zone
|
||||
|
||||
aggregate = cs.aggregates.update(args.id, updates)
|
||||
print("Aggregate %s has been successfully updated." % args.id)
|
||||
aggregate = cs.aggregates.update(aggregate.id, updates)
|
||||
print("Aggregate %s has been successfully updated." % aggregate.id)
|
||||
_print_aggregate_details(aggregate)
|
||||
|
||||
|
||||
@utils.arg('id', metavar='<id>', help='Aggregate id to update.')
|
||||
@utils.arg('aggregate', metavar='<aggregate>',
|
||||
help='Name or ID of aggregate to update.')
|
||||
@utils.arg('metadata',
|
||||
metavar='<key=value>',
|
||||
nargs='+',
|
||||
@ -2458,35 +2468,39 @@ def do_aggregate_update(cs, args):
|
||||
help='Metadata to add/update to aggregate')
|
||||
def do_aggregate_set_metadata(cs, args):
|
||||
"""Update the metadata associated with the aggregate."""
|
||||
aggregate = _find_aggregate(cs, args.aggregate)
|
||||
metadata = _extract_metadata(args)
|
||||
aggregate = cs.aggregates.set_metadata(args.id, metadata)
|
||||
print("Aggregate %s has been successfully updated." % args.id)
|
||||
aggregate = cs.aggregates.set_metadata(aggregate.id, metadata)
|
||||
print("Aggregate %s has been successfully updated." % aggregate.id)
|
||||
_print_aggregate_details(aggregate)
|
||||
|
||||
|
||||
@utils.arg('id', metavar='<id>', help='Aggregate id.')
|
||||
@utils.arg('aggregate', metavar='<aggregate>', help='Name or ID of aggregate.')
|
||||
@utils.arg('host', metavar='<host>', help='The host to add to the aggregate.')
|
||||
def do_aggregate_add_host(cs, args):
|
||||
"""Add the host to the specified aggregate."""
|
||||
aggregate = cs.aggregates.add_host(args.id, args.host)
|
||||
print("Aggregate %s has been successfully updated." % args.id)
|
||||
aggregate = _find_aggregate(cs, args.aggregate)
|
||||
aggregate = cs.aggregates.add_host(aggregate.id, args.host)
|
||||
print("Aggregate %s has been successfully updated." % aggregate.id)
|
||||
_print_aggregate_details(aggregate)
|
||||
|
||||
|
||||
@utils.arg('id', metavar='<id>', help='Aggregate id.')
|
||||
@utils.arg('aggregate', metavar='<aggregate>', help='Name or ID of aggregate.')
|
||||
@utils.arg('host', metavar='<host>',
|
||||
help='The host to remove from the aggregate.')
|
||||
def do_aggregate_remove_host(cs, args):
|
||||
"""Remove the specified host from the specified aggregate."""
|
||||
aggregate = cs.aggregates.remove_host(args.id, args.host)
|
||||
print("Aggregate %s has been successfully updated." % args.id)
|
||||
aggregate = _find_aggregate(cs, args.aggregate)
|
||||
aggregate = cs.aggregates.remove_host(aggregate.id, args.host)
|
||||
print("Aggregate %s has been successfully updated." % aggregate.id)
|
||||
_print_aggregate_details(aggregate)
|
||||
|
||||
|
||||
@utils.arg('id', metavar='<id>', help='Aggregate id.')
|
||||
@utils.arg('aggregate', metavar='<aggregate>', help='Name or ID of aggregate.')
|
||||
def do_aggregate_details(cs, args):
|
||||
"""Show details of the specified aggregate."""
|
||||
_print_aggregate_details(cs.aggregates.get(args.id))
|
||||
aggregate = _find_aggregate(cs, args.aggregate)
|
||||
_print_aggregate_details(aggregate)
|
||||
|
||||
|
||||
def _print_aggregate_details(aggregate):
|
||||
|
Loading…
x
Reference in New Issue
Block a user