compute: Add 'server group create --rule' option
This closes the remaining gap with the 2.64 compute API microversion. Change-Id: Ia42b23d813b7af6ddb1a41f4e9bdc8a6160b908c Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import logging
|
|||||||
|
|
||||||
from novaclient import api_versions
|
from novaclient import api_versions
|
||||||
from osc_lib.cli import format_columns
|
from osc_lib.cli import format_columns
|
||||||
|
from osc_lib.cli import parseractions
|
||||||
from osc_lib.command import command
|
from osc_lib.command import command
|
||||||
from osc_lib import exceptions
|
from osc_lib import exceptions
|
||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
@@ -30,8 +31,9 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
_formatters = {
|
_formatters = {
|
||||||
'policies': format_columns.ListColumn,
|
|
||||||
'members': format_columns.ListColumn,
|
'members': format_columns.ListColumn,
|
||||||
|
'policies': format_columns.ListColumn,
|
||||||
|
'rules': format_columns.DictColumn,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -68,7 +70,19 @@ class CreateServerGroup(command.ShowOne):
|
|||||||
"Add a policy to <name> "
|
"Add a policy to <name> "
|
||||||
"Specify --os-compute-api-version 2.15 or higher for the "
|
"Specify --os-compute-api-version 2.15 or higher for the "
|
||||||
"'soft-affinity' or 'soft-anti-affinity' policy."
|
"'soft-affinity' or 'soft-anti-affinity' policy."
|
||||||
)
|
),
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--rule',
|
||||||
|
metavar='<key=value>',
|
||||||
|
action=parseractions.KeyValueAction,
|
||||||
|
default={},
|
||||||
|
dest='rules',
|
||||||
|
help=_(
|
||||||
|
"A rule for the policy. Currently, only the "
|
||||||
|
"'max_server_per_host' rule is supported for the "
|
||||||
|
"'anti-affinity' policy."
|
||||||
|
),
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@@ -84,12 +98,24 @@ class CreateServerGroup(command.ShowOne):
|
|||||||
)
|
)
|
||||||
raise exceptions.CommandError(msg % parsed_args.policy)
|
raise exceptions.CommandError(msg % parsed_args.policy)
|
||||||
|
|
||||||
policy_arg = {'policies': [parsed_args.policy]}
|
if parsed_args.rules:
|
||||||
if compute_client.api_version >= api_versions.APIVersion("2.64"):
|
if compute_client.api_version < api_versions.APIVersion('2.64'):
|
||||||
policy_arg = {'policy': parsed_args.policy}
|
msg = _(
|
||||||
|
'--os-compute-api-version 2.64 or greater is required to '
|
||||||
|
'support the --rule option'
|
||||||
|
)
|
||||||
|
raise exceptions.CommandError(msg)
|
||||||
|
|
||||||
|
if compute_client.api_version < api_versions.APIVersion('2.64'):
|
||||||
|
kwargs = {'policies': [parsed_args.policy]}
|
||||||
|
else:
|
||||||
|
kwargs = {
|
||||||
|
'policy': parsed_args.policy,
|
||||||
|
'rules': parsed_args.rules or None,
|
||||||
|
}
|
||||||
|
|
||||||
server_group = compute_client.server_groups.create(
|
server_group = compute_client.server_groups.create(
|
||||||
name=parsed_args.name, **policy_arg)
|
name=parsed_args.name, **kwargs)
|
||||||
|
|
||||||
info.update(server_group._info)
|
info.update(server_group._info)
|
||||||
|
|
||||||
@@ -161,31 +187,33 @@ class ListServerGroup(command.Lister):
|
|||||||
if compute_client.api_version >= api_versions.APIVersion("2.64"):
|
if compute_client.api_version >= api_versions.APIVersion("2.64"):
|
||||||
policy_key = 'Policy'
|
policy_key = 'Policy'
|
||||||
|
|
||||||
|
columns = (
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
policy_key.lower(),
|
||||||
|
)
|
||||||
|
column_headers = (
|
||||||
|
'ID',
|
||||||
|
'Name',
|
||||||
|
policy_key,
|
||||||
|
)
|
||||||
if parsed_args.long:
|
if parsed_args.long:
|
||||||
column_headers = columns = (
|
columns += (
|
||||||
'ID',
|
'members',
|
||||||
'Name',
|
'project_id',
|
||||||
policy_key,
|
'user_id',
|
||||||
|
)
|
||||||
|
column_headers += (
|
||||||
'Members',
|
'Members',
|
||||||
'Project Id',
|
'Project Id',
|
||||||
'User Id',
|
'User Id',
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
column_headers = columns = (
|
|
||||||
'ID',
|
|
||||||
'Name',
|
|
||||||
policy_key,
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
column_headers,
|
column_headers,
|
||||||
(
|
(
|
||||||
utils.get_item_properties(
|
utils.get_item_properties(
|
||||||
s, columns,
|
s, columns, formatters=_formatters,
|
||||||
formatters={
|
|
||||||
'Policies': format_columns.ListColumn,
|
|
||||||
'Members': format_columns.ListColumn,
|
|
||||||
}
|
|
||||||
) for s in data
|
) for s in data
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@@ -152,28 +152,55 @@ class TestServerGroupCreate(TestServerGroup):
|
|||||||
'--os-compute-api-version 2.15 or greater is required',
|
'--os-compute-api-version 2.15 or greater is required',
|
||||||
str(ex))
|
str(ex))
|
||||||
|
|
||||||
def test_server_group_create_v264(self):
|
def test_server_group_create_with_rules(self):
|
||||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||||
'2.64')
|
'2.64')
|
||||||
|
|
||||||
arglist = [
|
arglist = [
|
||||||
'--policy', 'soft-anti-affinity',
|
'--policy', 'soft-anti-affinity',
|
||||||
|
'--rule', 'max_server_per_host=2',
|
||||||
'affinity_group',
|
'affinity_group',
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
('policy', 'soft-anti-affinity'),
|
('policy', 'soft-anti-affinity'),
|
||||||
|
('rules', {'max_server_per_host': '2'}),
|
||||||
('name', 'affinity_group'),
|
('name', 'affinity_group'),
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
self.server_groups_mock.create.assert_called_once_with(
|
self.server_groups_mock.create.assert_called_once_with(
|
||||||
name=parsed_args.name,
|
name=parsed_args.name,
|
||||||
policy=parsed_args.policy,
|
policy=parsed_args.policy, # should be 'policy', not 'policies'
|
||||||
|
rules=parsed_args.rules,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertCountEqual(self.columns, columns)
|
self.assertCountEqual(self.columns, columns)
|
||||||
self.assertCountEqual(self.data, data)
|
self.assertCountEqual(self.data, data)
|
||||||
|
|
||||||
|
def test_server_group_create_with_rules_pre_v264(self):
|
||||||
|
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||||
|
'2.63')
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
'--policy', 'soft-anti-affinity',
|
||||||
|
'--rule', 'max_server_per_host=2',
|
||||||
|
'affinity_group',
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('policy', 'soft-anti-affinity'),
|
||||||
|
('rules', {'max_server_per_host': '2'}),
|
||||||
|
('name', 'affinity_group'),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
ex = self.assertRaises(
|
||||||
|
exceptions.CommandError,
|
||||||
|
self.cmd.take_action,
|
||||||
|
parsed_args)
|
||||||
|
self.assertIn(
|
||||||
|
'--os-compute-api-version 2.64 or greater is required',
|
||||||
|
str(ex))
|
||||||
|
|
||||||
|
|
||||||
class TestServerGroupDelete(TestServerGroup):
|
class TestServerGroupDelete(TestServerGroup):
|
||||||
|
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Add support for ``--rule`` option for ``server group create``.
|
Reference in New Issue
Block a user