Skip to content

Commit c8ecba2

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "image: Fix the default description of image visibility"
2 parents c29e057 + a3730af commit c8ecba2

File tree

1 file changed

+73
-90
lines changed

1 file changed

+73
-90
lines changed

openstackclient/image/v2/image.py

Lines changed: 73 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,67 @@ def get_data_from_stdin():
163163
return None
164164

165165

166+
def _add_is_protected_args(parser):
167+
protected_group = parser.add_mutually_exclusive_group()
168+
protected_group.add_argument(
169+
"--protected",
170+
action="store_true",
171+
dest="is_protected",
172+
default=None,
173+
help=_("Prevent image from being deleted"),
174+
)
175+
protected_group.add_argument(
176+
"--unprotected",
177+
action="store_false",
178+
dest="is_protected",
179+
default=None,
180+
help=_("Allow image to be deleted (default)"),
181+
)
182+
183+
184+
def _add_visibility_args(parser):
185+
public_group = parser.add_mutually_exclusive_group()
186+
public_group.add_argument(
187+
"--public",
188+
action="store_const",
189+
const="public",
190+
dest="visibility",
191+
help=_("Image is accessible and visisble to all users"),
192+
)
193+
public_group.add_argument(
194+
"--private",
195+
action="store_const",
196+
const="private",
197+
dest="visibility",
198+
help=_(
199+
"Image is only accessible by the owner "
200+
"(default until --os-image-api-version 2.5)"
201+
),
202+
)
203+
public_group.add_argument(
204+
"--community",
205+
action="store_const",
206+
const="community",
207+
dest="visibility",
208+
help=_(
209+
"Image is accessible by all users but does not appear in the "
210+
"default image list of any user except the owner "
211+
"(requires --os-image-api-version 2.5 or later)"
212+
),
213+
)
214+
public_group.add_argument(
215+
"--shared",
216+
action="store_const",
217+
const="shared",
218+
dest="visibility",
219+
help=_(
220+
"Image is only accessible by the owner and image members "
221+
"(requires --os-image-api-version 2.5 or later) "
222+
"(default since --os-image-api-version 2.5)"
223+
),
224+
)
225+
226+
166227
class AddProjectToImage(command.ShowOne):
167228
_description = _("Associate project with image")
168229

@@ -322,50 +383,8 @@ def get_parser(self, prog_name):
322383
"Only use in combination with --sign-key-path"
323384
),
324385
)
325-
protected_group = parser.add_mutually_exclusive_group()
326-
protected_group.add_argument(
327-
"--protected",
328-
action="store_true",
329-
dest="is_protected",
330-
default=None,
331-
help=_("Prevent image from being deleted"),
332-
)
333-
protected_group.add_argument(
334-
"--unprotected",
335-
action="store_false",
336-
dest="is_protected",
337-
default=None,
338-
help=_("Allow image to be deleted (default)"),
339-
)
340-
public_group = parser.add_mutually_exclusive_group()
341-
public_group.add_argument(
342-
"--public",
343-
action="store_const",
344-
const="public",
345-
dest="visibility",
346-
help=_("Image is accessible to the public"),
347-
)
348-
public_group.add_argument(
349-
"--private",
350-
action="store_const",
351-
const="private",
352-
dest="visibility",
353-
help=_("Image is inaccessible to the public (default)"),
354-
)
355-
public_group.add_argument(
356-
"--community",
357-
action="store_const",
358-
const="community",
359-
dest="visibility",
360-
help=_("Image is accessible to the community"),
361-
)
362-
public_group.add_argument(
363-
"--shared",
364-
action="store_const",
365-
const="shared",
366-
dest="visibility",
367-
help=_("Image can be shared"),
368-
)
386+
_add_is_protected_args(parser)
387+
_add_visibility_args(parser)
369388
parser.add_argument(
370389
"--property",
371390
dest="properties",
@@ -726,14 +745,20 @@ def get_parser(self, prog_name):
726745
action="store_const",
727746
const="community",
728747
dest="visibility",
729-
help=_("List only community images"),
748+
help=_(
749+
"List only community images "
750+
"(requires --os-image-api-version 2.5 or later)"
751+
),
730752
)
731753
public_group.add_argument(
732754
"--shared",
733755
action="store_const",
734756
const="shared",
735757
dest="visibility",
736-
help=_("List only shared images"),
758+
help=_(
759+
"List only shared images "
760+
"(requires --os-image-api-version 2.5 or later)"
761+
),
737762
)
738763
public_group.add_argument(
739764
"--all",
@@ -1110,50 +1135,8 @@ def get_parser(self, prog_name):
11101135
help=_("Image disk format. The supported options are: %s")
11111136
% ', '.join(DISK_CHOICES),
11121137
)
1113-
protected_group = parser.add_mutually_exclusive_group()
1114-
protected_group.add_argument(
1115-
"--protected",
1116-
action="store_true",
1117-
dest="is_protected",
1118-
default=None,
1119-
help=_("Prevent image from being deleted"),
1120-
)
1121-
protected_group.add_argument(
1122-
"--unprotected",
1123-
action="store_false",
1124-
dest="is_protected",
1125-
default=None,
1126-
help=_("Allow image to be deleted (default)"),
1127-
)
1128-
public_group = parser.add_mutually_exclusive_group()
1129-
public_group.add_argument(
1130-
"--public",
1131-
action="store_const",
1132-
const="public",
1133-
dest="visibility",
1134-
help=_("Image is accessible to the public"),
1135-
)
1136-
public_group.add_argument(
1137-
"--private",
1138-
action="store_const",
1139-
const="private",
1140-
dest="visibility",
1141-
help=_("Image is inaccessible to the public (default)"),
1142-
)
1143-
public_group.add_argument(
1144-
"--community",
1145-
action="store_const",
1146-
const="community",
1147-
dest="visibility",
1148-
help=_("Image is accessible to the community"),
1149-
)
1150-
public_group.add_argument(
1151-
"--shared",
1152-
action="store_const",
1153-
const="shared",
1154-
dest="visibility",
1155-
help=_("Image can be shared"),
1156-
)
1138+
_add_is_protected_args(parser)
1139+
_add_visibility_args(parser)
11571140
parser.add_argument(
11581141
"--property",
11591142
dest="properties",

0 commit comments

Comments
 (0)