From d6c9b7f198b94ef05c96dc72fc71d34f019e9350 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 10 Dec 2020 14:13:47 +0000 Subject: [PATCH] compute: Shuffle options for 'server create' argparse doesn't sort options by name, meaning we can use the opportunity to group closely related options together. Do that. Change-Id: I6714c8db1a549bd4206d2282d2876a406af65aa2 Signed-off-by: Stephen Finucane --- openstackclient/compute/v2/server.py | 198 ++++++++++++++------------- 1 file changed, 102 insertions(+), 96 deletions(-) diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 15a5084d0d..7e17d0d043 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -621,6 +621,12 @@ class CreateServer(command.ShowOne): metavar='', help=_('New server name'), ) + parser.add_argument( + '--flavor', + metavar='', + required=True, + help=_('Create server with this flavor (name or ID)'), + ) disk_group = parser.add_mutually_exclusive_group( required=True, ) @@ -629,12 +635,17 @@ class CreateServer(command.ShowOne): metavar='', help=_('Create server boot disk from this image (name or ID)'), ) + # TODO(stephenfin): Is this actually useful? Looks like a straight port + # from 'nova boot --image-with'. Perhaps we should deprecate this. disk_group.add_argument( '--image-property', metavar='', action=parseractions.KeyValueAction, dest='image_properties', - help=_("Image property to be matched"), + help=_( + "Create server using the image that matches the specified " + "property. Property must match exactly one property." + ), ) disk_group.add_argument( '--volume', @@ -649,17 +660,101 @@ class CreateServer(command.ShowOne): 'volume.' ), ) + parser.add_argument( + '--boot-from-volume', + metavar='', + type=int, + help=_( + 'When used in conjunction with the ``--image`` or ' + '``--image-property`` option, this option automatically ' + 'creates a block device mapping with a boot index of 0 ' + 'and tells the compute service to create a volume of the ' + 'given size (in GB) from the specified image and use it ' + 'as the root disk of the server. The root volume will not ' + 'be deleted when the server is deleted. This option is ' + 'mutually exclusive with the ``--volume`` option.' + ) + ) + parser.add_argument( + '--block-device-mapping', + metavar='', + action=parseractions.KeyValueAction, + default={}, + # NOTE(RuiChen): Add '\n' to the end of line to improve formatting; + # see cliff's _SmartHelpFormatter for more details. + help=_( + 'Create a block device on the server.\n' + 'Block device mapping in the format\n' + '=:::\n' + ': block device name, like: vdb, xvdc ' + '(required)\n' + ': Name or ID of the volume, volume snapshot or image ' + '(required)\n' + ': volume, snapshot or image; default: volume ' + '(optional)\n' + ': volume size if create from image or snapshot ' + '(optional)\n' + ': true or false; default: false ' + '(optional)\n' + ), + ) + parser.add_argument( + '--network', + metavar="", + action='append', + dest='nic', + type=_prefix_checked_value('net-id='), + # NOTE(RuiChen): Add '\n' to the end of line to improve formatting; + # see cliff's _SmartHelpFormatter for more details. + help=_( + "Create a NIC on the server and connect it to network. " + "Specify option multiple times to create multiple NICs. " + "This is a wrapper for the '--nic net-id=' " + "parameter that provides simple syntax for the standard " + "use case of connecting a new server to a given network. " + "For more advanced use cases, refer to the '--nic' " + "parameter." + ), + ) + parser.add_argument( + '--port', + metavar="", + action='append', + dest='nic', + type=_prefix_checked_value('port-id='), + help=_( + "Create a NIC on the server and connect it to port. " + "Specify option multiple times to create multiple NICs. " + "This is a wrapper for the '--nic port-id=' " + "parameter that provides simple syntax for the standard " + "use case of connecting a new server to a given port. For " + "more advanced use cases, refer to the '--nic' parameter." + ), + ) + parser.add_argument( + '--nic', + metavar="", + action='append', + help=_( + "Create a NIC on the server. " + "Specify option multiple times to create multiple NICs. " + "Either net-id or port-id must be provided, but not both. " + "net-id: attach NIC to network with this UUID, " + "port-id: attach NIC to port with this UUID, " + "v4-fixed-ip: IPv4 fixed address for NIC (optional), " + "v6-fixed-ip: IPv6 fixed address for NIC (optional), " + "none: (v2.37+) no network is attached, " + "auto: (v2.37+) the compute service will automatically " + "allocate a network. Specifying a --nic of auto or none " + "cannot be used with any other --nic value." + ), + ) parser.add_argument( '--password', metavar='', help=_("Set the password to this server"), ) - parser.add_argument( - '--flavor', - metavar='', - required=True, - help=_('Create server with this flavor (name or ID)'), - ) parser.add_argument( '--security-group', metavar='', @@ -736,95 +831,6 @@ class CreateServer(command.ShowOne): '(supported by --os-compute-api-version 2.74 or above)' ), ) - parser.add_argument( - '--boot-from-volume', - metavar='', - type=int, - help=_( - 'When used in conjunction with the ``--image`` or ' - '``--image-property`` option, this option automatically ' - 'creates a block device mapping with a boot index of 0 ' - 'and tells the compute service to create a volume of the ' - 'given size (in GB) from the specified image and use it ' - 'as the root disk of the server. The root volume will not ' - 'be deleted when the server is deleted. This option is ' - 'mutually exclusive with the ``--volume`` option.' - ) - ) - parser.add_argument( - '--block-device-mapping', - metavar='', - action=parseractions.KeyValueAction, - default={}, - # NOTE(RuiChen): Add '\n' at the end of line to put each item in - # the separated line, avoid the help message looks - # messy, see _SmartHelpFormatter in cliff. - help=_( - 'Create a block device on the server.\n' - 'Block device mapping in the format\n' - '=:::\n' - ': block device name, like: vdb, xvdc ' - '(required)\n' - ': Name or ID of the volume, volume snapshot or image ' - '(required)\n' - ': volume, snapshot or image; default: volume ' - '(optional)\n' - ': volume size if create from image or snapshot ' - '(optional)\n' - ': true or false; default: false ' - '(optional)\n' - ), - ) - parser.add_argument( - '--nic', - metavar="", - action='append', - help=_( - "Create a NIC on the server. " - "Specify option multiple times to create multiple NICs. " - "Either net-id or port-id must be provided, but not both. " - "net-id: attach NIC to network with this UUID, " - "port-id: attach NIC to port with this UUID, " - "v4-fixed-ip: IPv4 fixed address for NIC (optional), " - "v6-fixed-ip: IPv6 fixed address for NIC (optional), " - "none: (v2.37+) no network is attached, " - "auto: (v2.37+) the compute service will automatically " - "allocate a network. Specifying a --nic of auto or none " - "cannot be used with any other --nic value." - ), - ) - parser.add_argument( - '--network', - metavar="", - action='append', - dest='nic', - type=_prefix_checked_value('net-id='), - help=_( - "Create a NIC on the server and connect it to network. " - "Specify option multiple times to create multiple NICs. " - "This is a wrapper for the '--nic net-id=' " - "parameter that provides simple syntax for the standard " - "use case of connecting a new server to a given network. " - "For more advanced use cases, refer to the '--nic' " - "parameter." - ), - ) - parser.add_argument( - '--port', - metavar="", - action='append', - dest='nic', - type=_prefix_checked_value('port-id='), - help=_( - "Create a NIC on the server and connect it to port. " - "Specify option multiple times to create multiple NICs. " - "This is a wrapper for the '--nic port-id=' " - "parameter that provides simple syntax for the standard " - "use case of connecting a new server to a given port. For " - "more advanced use cases, refer to the '--nic' parameter." - ), - ) parser.add_argument( '--hint', metavar='',