Skip to content

Commit 960004d

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add 'openstack server create --use-config-drive'"
2 parents f50bd40 + 12f1e56 commit 960004d

3 files changed

Lines changed: 44 additions & 14 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -707,12 +707,30 @@ def get_parser(self, prog_name):
707707
default={},
708708
help=_('Hints for the scheduler (optional extension)'),
709709
)
710-
parser.add_argument(
710+
config_drive_group = parser.add_mutually_exclusive_group()
711+
config_drive_group.add_argument(
712+
'--use-config-drive',
713+
action='store_true',
714+
dest='config_drive',
715+
help=_("Enable config drive."),
716+
)
717+
config_drive_group.add_argument(
718+
'--no-config-drive',
719+
action='store_false',
720+
dest='config_drive',
721+
help=_("Disable config drive."),
722+
)
723+
# TODO(stephenfin): Drop support in the next major version bump after
724+
# Victoria
725+
config_drive_group.add_argument(
711726
'--config-drive',
712727
metavar='<config-drive-volume>|True',
713728
default=False,
714-
help=_('Use specified volume as the config drive, '
715-
'or \'True\' to use an ephemeral drive'),
729+
help=_(
730+
"**Deprecated** Use specified volume as the config drive, "
731+
"or 'True' to use an ephemeral drive. Replaced by "
732+
"'--use-config-drive'."
733+
),
716734
)
717735
parser.add_argument(
718736
'--min',
@@ -1013,16 +1031,19 @@ def _match_image(image_api, wanted_properties):
10131031
else:
10141032
hints[key] = values
10151033

1016-
# What does a non-boolean value for config-drive do?
1017-
# --config-drive argument is either a volume id or
1018-
# 'True' (or '1') to use an ephemeral volume
1019-
if str(parsed_args.config_drive).lower() in ("true", "1"):
1020-
config_drive = True
1021-
elif str(parsed_args.config_drive).lower() in ("false", "0",
1022-
"", "none"):
1023-
config_drive = None
1034+
if isinstance(parsed_args.config_drive, bool):
1035+
# NOTE(stephenfin): The API doesn't accept False as a value :'(
1036+
config_drive = parsed_args.config_drive or None
10241037
else:
1025-
config_drive = parsed_args.config_drive
1038+
# TODO(stephenfin): Remove when we drop support for
1039+
# '--config-drive'
1040+
if str(parsed_args.config_drive).lower() in ("true", "1"):
1041+
config_drive = True
1042+
elif str(parsed_args.config_drive).lower() in ("false", "0",
1043+
"", "none"):
1044+
config_drive = None
1045+
else:
1046+
config_drive = parsed_args.config_drive
10261047

10271048
boot_kwargs = dict(
10281049
meta=parsed_args.property,

openstackclient/tests/unit/compute/v2/test_server.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ def test_server_create_with_options(self):
857857
'--key-name', 'keyname',
858858
'--property', 'Beta=b',
859859
'--security-group', 'securitygroup',
860+
'--use-config-drive',
860861
'--hint', 'a=b',
861862
'--hint', 'a=c',
862863
self.new_server.name,
@@ -868,7 +869,7 @@ def test_server_create_with_options(self):
868869
('property', {'Beta': 'b'}),
869870
('security_group', ['securitygroup']),
870871
('hint', {'a': ['b', 'c']}),
871-
('config_drive', False),
872+
('config_drive', True),
872873
('server_name', self.new_server.name),
873874
]
874875
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -900,7 +901,7 @@ def test_server_create_with_options(self):
900901
block_device_mapping_v2=[],
901902
nics=[],
902903
scheduler_hints={'a': ['b', 'c']},
903-
config_drive=None,
904+
config_drive=True,
904905
)
905906
# ServerManager.create(name, image, flavor, **kwargs)
906907
self.servers_mock.create.assert_called_with(
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
deprecations:
3+
- |
4+
The ``--config-drive`` option on the ``openstack server create`` command
5+
has been deprecated in favour of the ``--use-config-drive`` and
6+
``--no-config-drive`` arguments. The ``--config-drive`` option expected
7+
either a string or bool-like argument, but the nova API has only supported
8+
boolean values since API v2.1 was introduced.

0 commit comments

Comments
 (0)