Add flavor resource aggregates support

1. Allow to specify resource aggregates when creating a flavor.
2. Replace --resources with --resource.

Change-Id: I6d41d02b5ec1881d662a578a1380a223a27df055
This commit is contained in:
Zhenguo Niu 2017-09-14 17:15:41 +08:00
parent a473f6a541
commit c3d71e14cc
3 changed files with 21 additions and 10 deletions

View File

@ -62,12 +62,19 @@ class CreateFlavor(command.ShowOne):
help=_("Flavor description"), help=_("Flavor description"),
) )
parser.add_argument( parser.add_argument(
"--resources", "--resource",
metavar="<key=value>", metavar="<key=value>",
action=parseractions.KeyValueAction, action=parseractions.KeyValueAction,
help=_("Resources to add to this flavor " help=_("Resource to add to this flavor "
"(repeat option to set multiple resources)") "(repeat option to set multiple resources)")
) )
parser.add_argument(
"--resource-aggregate",
metavar="<key=value>",
action=parseractions.KeyValueAction,
help=_("Aggregate metadata to add to this flavor "
"(repeat option to set multiple aggregate metadata)")
)
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
@ -83,7 +90,8 @@ class CreateFlavor(command.ShowOne):
data = bc_client.flavor.create( data = bc_client.flavor.create(
name=parsed_args.name, name=parsed_args.name,
description=parsed_args.description, description=parsed_args.description,
resources=parsed_args.resources, resource=parsed_args.resource,
resource_aggregate=parsed_args.resource_aggregate,
is_public=is_public, is_public=is_public,
disabled=parsed_args.disabled, disabled=parsed_args.disabled,
) )

View File

@ -60,11 +60,11 @@ class TestFlavorCreate(TestFlavor):
def test_flavor_create(self, mock_create): def test_flavor_create(self, mock_create):
arglist = [ arglist = [
'flavor1', 'flavor1',
'--resources', 'k1=v1' '--resource', 'k1=v1'
] ]
verifylist = [ verifylist = [
('name', 'flavor1'), ('name', 'flavor1'),
('resources', {'k1': 'v1'}), ('resource', {'k1': 'v1'}),
] ]
mock_create.return_value = self.fake_flavor mock_create.return_value = self.fake_flavor
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -152,11 +152,11 @@ class TestFlavorCreate(TestFlavor):
def test_flavor_create_with_resources(self, mock_update, mock_get, def test_flavor_create_with_resources(self, mock_update, mock_get,
mock_create): mock_create):
arglist = [ arglist = [
'--resources', 'k1=v1', '--resource', 'k1=v1',
'flavor1', 'flavor1',
] ]
verifylist = [ verifylist = [
('resources', {'k1': 'v1'}), ('resource', {'k1': 'v1'}),
('name', 'flavor1'), ('name', 'flavor1'),
] ]
mock_create.return_value = self.fake_flavor mock_create.return_value = self.fake_flavor

View File

@ -23,7 +23,8 @@ class Flavor(base.Resource):
class FlavorManager(base.ManagerWithFind): class FlavorManager(base.ManagerWithFind):
resource_class = Flavor resource_class = Flavor
def create(self, name, resources, is_public, disabled, description=None): def create(self, name, resource, resource_aggregate, is_public,
disabled, description=None):
url = '/flavors' url = '/flavors'
data = { data = {
'name': name, 'name': name,
@ -31,8 +32,10 @@ class FlavorManager(base.ManagerWithFind):
'is_public': is_public, 'is_public': is_public,
'disabled': disabled, 'disabled': disabled,
} }
if resources: if resource:
data['resources'] = resources data['resources'] = resource
if resource_aggregate:
data['resource_aggregates'] = resource_aggregate
return self._create(url, data=data) return self._create(url, data=data)
def delete(self, flavor): def delete(self, flavor):