diff options
| author | Stephen Finucane <sfinucan@redhat.com> | 2020-10-13 15:35:21 +0100 |
|---|---|---|
| committer | Stephen Finucane <sfinucan@redhat.com> | 2020-10-13 15:35:21 +0100 |
| commit | ab0b1fe885ee0a210a58008b631521025be7f3eb (patch) | |
| tree | 53acc613a08e2aaeaa14691c803645a8d2e5f739 /openstackclient/compute | |
| parent | 375fe315255535ad0a6451aa0d9270ca5c3ba3b9 (diff) | |
| download | python-openstackclient-ab0b1fe885ee0a210a58008b631521025be7f3eb.tar.gz | |
Validate 'server group create --policy' option
We were documenting that some of these policies were only supported with
specific microversions, however, we weren't actually enforcing that,
leading to a poor user experience. Correct this.
Change-Id: Ic3c555226a220efd9b0f27edffccf6c4c95c2747
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Diffstat (limited to 'openstackclient/compute')
| -rw-r--r-- | openstackclient/compute/v2/server_group.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/openstackclient/compute/v2/server_group.py b/openstackclient/compute/v2/server_group.py index 1af6e28d..a3363244 100644 --- a/openstackclient/compute/v2/server_group.py +++ b/openstackclient/compute/v2/server_group.py @@ -56,12 +56,18 @@ class CreateServerGroup(command.ShowOne): parser.add_argument( '--policy', metavar='<policy>', + choices=[ + 'affinity', + 'anti-affinity', + 'soft-affinity', + 'soft-anti-affinity', + ], default='affinity', - help=_("Add a policy to <name> " - "('affinity' or 'anti-affinity', " - "defaults to 'affinity'). Specify --os-compute-api-version " - "2.15 or higher for the 'soft-affinity' or " - "'soft-anti-affinity' policy.") + help=_( + "Add a policy to <name> " + "Specify --os-compute-api-version 2.15 or higher for the " + "'soft-affinity' or 'soft-anti-affinity' policy." + ) ) return parser @@ -69,9 +75,18 @@ class CreateServerGroup(command.ShowOne): compute_client = self.app.client_manager.compute info = {} + if parsed_args.policy in ('soft-affinity', 'soft-anti-affinity'): + if compute_client.api_version < api_versions.APIVersion('2.15'): + msg = _( + '--os-compute-api-version 2.15 or greater is required to ' + 'support the %s policy' + ) + raise exceptions.CommandError(msg % parsed_args.policy) + policy_arg = {'policies': [parsed_args.policy]} if compute_client.api_version >= api_versions.APIVersion("2.64"): policy_arg = {'policy': parsed_args.policy} + server_group = compute_client.server_groups.create( name=parsed_args.name, **policy_arg) |
