Skip to content

Commit cf2de9a

Browse files
author
Dean Troyer
committed
Change --owner to --project in image commands
* image create and image set now use --project to specify an alternate project to own the image * --owner is still silently accepted but deprecated, add warning messages * --project and --owner are mutually exclusive to prevent precedence issues Closes Bug: 1527833 Change-Id: Iccb1a1d9175ef9b5edcd79d294607db12641c1f0
1 parent 8654e3e commit cf2de9a

6 files changed

Lines changed: 204 additions & 52 deletions

File tree

doc/source/command-objects/image.rst

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ Create/upload an image
1919
[--store <store>]
2020
[--container-format <container-format>]
2121
[--disk-format <disk-format>]
22-
[--owner <project>]
2322
[--size <size>]
2423
[--min-disk <disk-gb>]
2524
[--min-ram <ram-mb>]
@@ -33,7 +32,7 @@ Create/upload an image
3332
[--public | --private]
3433
[--property <key=value> [...] ]
3534
[--tag <tag> [...] ]
36-
[--project-domain <project-domain>]
35+
[--project <project> [--project-domain <project-domain>]]
3736
<image-name>
3837
3938
.. option:: --id <id>
@@ -54,10 +53,6 @@ Create/upload an image
5453
5554
Image disk format (default: raw)
5655
57-
.. option:: --owner <project>
58-
59-
Image owner project name or ID
60-
6156
.. option:: --size <size>
6257
6358
Image size, in bytes (only used with --location and --copy-from)
@@ -128,11 +123,18 @@ Create/upload an image
128123
129124
.. versionadded:: 2
130125
126+
.. option:: --project <project>
127+
128+
Set an alternate project on this image (name or ID).
129+
Previously known as `--owner`.
130+
131131
.. option:: --project-domain <project-domain>
132132
133133
Domain the project belongs to (name or ID).
134134
This can be used in case collisions between project names exist.
135135
136+
.. versionadded:: 2
137+
136138
.. describe:: <image-name>
137139
138140
New image name
@@ -225,7 +227,6 @@ Set image properties
225227
226228
os image set
227229
[--name <name>]
228-
[--owner <project>]
229230
[--min-disk <disk-gb>]
230231
[--min-ram <disk-ram>]
231232
[--container-format <container-format>]
@@ -250,17 +251,13 @@ Set image properties
250251
[--os-version <os-version>]
251252
[--ramdisk-id <ramdisk-id>]
252253
[--activate|--deactivate]
253-
[--project-domain <project-domain>]
254+
[--project <project> [--project-domain <project-domain>]]
254255
<image>
255256
256257
.. option:: --name <name>
257258
258259
New image name
259260
260-
.. option:: --owner <project>
261-
262-
New image owner project (name or ID)
263-
264261
.. option:: --min-disk <disk-gb>
265262
266263
Minimum disk size needed to boot image, in gigabytes
@@ -407,11 +404,18 @@ Set image properties
407404
408405
.. versionadded:: 2
409406
407+
.. option:: --project <project>
408+
409+
Set an alternate project on this image (name or ID).
410+
Previously known as `--owner`.
411+
410412
.. option:: --project-domain <project-domain>
411413
412414
Domain the project belongs to (name or ID).
413415
This can be used in case collisions between project names exist.
414416
417+
.. versionadded:: 2
418+
415419
.. describe:: <image>
416420
417421
Image to modify (name or ID)

openstackclient/image/v1/image.py

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from openstackclient.api import utils as api_utils
3636
from openstackclient.common import parseractions
3737
from openstackclient.common import utils
38+
from openstackclient.i18n import _ # noqa
3839

3940

4041
DEFAULT_CONTAINER_FORMAT = 'bare'
@@ -92,11 +93,6 @@ def get_parser(self, prog_name):
9293
help="Image disk format "
9394
"(default: %s)" % DEFAULT_DISK_FORMAT,
9495
)
95-
parser.add_argument(
96-
"--owner",
97-
metavar="<project>",
98-
help="Image owner project name or ID",
99-
)
10096
parser.add_argument(
10197
"--size",
10298
metavar="<size>",
@@ -178,12 +174,32 @@ def get_parser(self, prog_name):
178174
help="Set a property on this image "
179175
"(repeat option to set multiple properties)",
180176
)
177+
# NOTE(dtroyer): --owner is deprecated in Jan 2016 in an early
178+
# 2.x release. Do not remove before Jan 2017
179+
# and a 3.x release.
180+
project_group = parser.add_mutually_exclusive_group()
181+
project_group.add_argument(
182+
"--project",
183+
metavar="<project>",
184+
help="Set an alternate project on this image (name or ID)",
185+
)
186+
project_group.add_argument(
187+
"--owner",
188+
metavar="<project>",
189+
help=argparse.SUPPRESS,
190+
)
181191
return parser
182192

183193
def take_action(self, parsed_args):
184194
self.log.debug("take_action(%s)", parsed_args)
185195
image_client = self.app.client_manager.image
186196

197+
if getattr(parsed_args, 'owner', None) is not None:
198+
self.log.warning(_(
199+
'The --owner option is deprecated, '
200+
'please use --project instead.'
201+
))
202+
187203
# Build an attribute dict from the parsed args, only include
188204
# attributes that were actually set on the command line
189205
kwargs = {}
@@ -198,6 +214,12 @@ def take_action(self, parsed_args):
198214
# Only include a value in kwargs for attributes that are
199215
# actually present on the command line
200216
kwargs[attr] = val
217+
218+
# Special case project option back to API attribute name 'owner'
219+
val = getattr(parsed_args, 'project', None)
220+
if val:
221+
kwargs['owner'] = val
222+
201223
# Handle exclusive booleans with care
202224
# Avoid including attributes in kwargs if an option is not
203225
# present on the command line. These exclusive booleans are not
@@ -383,7 +405,7 @@ def take_action(self, parsed_args):
383405
'Status',
384406
'Visibility',
385407
'Protected',
386-
'Owner',
408+
'Project',
387409
'Properties',
388410
)
389411
else:
@@ -476,11 +498,6 @@ def get_parser(self, prog_name):
476498
metavar="<name>",
477499
help="New image name",
478500
)
479-
parser.add_argument(
480-
"--owner",
481-
metavar="<project>",
482-
help="New image owner project (name or ID)",
483-
)
484501
parser.add_argument(
485502
"--min-disk",
486503
metavar="<disk-gb>",
@@ -590,12 +607,32 @@ def get_parser(self, prog_name):
590607
metavar="<checksum>",
591608
help="Image hash used for verification",
592609
)
610+
# NOTE(dtroyer): --owner is deprecated in Jan 2016 in an early
611+
# 2.x release. Do not remove before Jan 2017
612+
# and a 3.x release.
613+
project_group = parser.add_mutually_exclusive_group()
614+
project_group.add_argument(
615+
"--project",
616+
metavar="<project>",
617+
help="Set an alternate project on this image (name or ID)",
618+
)
619+
project_group.add_argument(
620+
"--owner",
621+
metavar="<project>",
622+
help=argparse.SUPPRESS,
623+
)
593624
return parser
594625

595626
def take_action(self, parsed_args):
596627
self.log.debug("take_action(%s)", parsed_args)
597628
image_client = self.app.client_manager.image
598629

630+
if getattr(parsed_args, 'owner', None) is not None:
631+
self.log.warning(_(
632+
'The --owner option is deprecated, '
633+
'please use --project instead.'
634+
))
635+
599636
kwargs = {}
600637
copy_attrs = ('name', 'owner', 'min_disk', 'min_ram', 'properties',
601638
'container_format', 'disk_format', 'size', 'store',
@@ -607,6 +644,12 @@ def take_action(self, parsed_args):
607644
# Only include a value in kwargs for attributes that are
608645
# actually present on the command line
609646
kwargs[attr] = val
647+
648+
# Special case project option back to API attribute name 'owner'
649+
val = getattr(parsed_args, 'project', None)
650+
if val:
651+
kwargs['owner'] = val
652+
610653
# Handle exclusive booleans with care
611654
# Avoid including attributes in kwargs if an option is not
612655
# present on the command line. These exclusive booleans are not

openstackclient/image/v2/image.py

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from openstackclient.common import exceptions
2929
from openstackclient.common import parseractions
3030
from openstackclient.common import utils
31+
from openstackclient.i18n import _ # noqa
3132
from openstackclient.identity import common
3233

3334

@@ -147,11 +148,6 @@ def get_parser(self, prog_name):
147148
help="Image disk format "
148149
"(default: %s)" % DEFAULT_DISK_FORMAT,
149150
)
150-
parser.add_argument(
151-
"--owner",
152-
metavar="<owner>",
153-
help="Image owner project name or ID",
154-
)
155151
parser.add_argument(
156152
"--min-disk",
157153
metavar="<disk-gb>",
@@ -220,6 +216,20 @@ def get_parser(self, prog_name):
220216
help="Set a tag on this image "
221217
"(repeat option to set multiple tags)",
222218
)
219+
# NOTE(dtroyer): --owner is deprecated in Jan 2016 in an early
220+
# 2.x release. Do not remove before Jan 2017
221+
# and a 3.x release.
222+
project_group = parser.add_mutually_exclusive_group()
223+
project_group.add_argument(
224+
"--project",
225+
metavar="<project>",
226+
help="Set an alternate project on this image (name or ID)",
227+
)
228+
project_group.add_argument(
229+
"--owner",
230+
metavar="<project>",
231+
help=argparse.SUPPRESS,
232+
)
223233
common.add_project_domain_option_to_parser(parser)
224234
for deadopt in self.deadopts:
225235
parser.add_argument(
@@ -246,15 +256,15 @@ def take_action(self, parsed_args):
246256
kwargs = {}
247257
copy_attrs = ('name', 'id',
248258
'container_format', 'disk_format',
249-
'min_disk', 'min_ram',
250-
'tags', 'owner')
259+
'min_disk', 'min_ram', 'tags')
251260
for attr in copy_attrs:
252261
if attr in parsed_args:
253262
val = getattr(parsed_args, attr, None)
254263
if val:
255264
# Only include a value in kwargs for attributes that
256265
# are actually present on the command line
257266
kwargs[attr] = val
267+
258268
# properties should get flattened into the general kwargs
259269
if getattr(parsed_args, 'properties', None):
260270
for k, v in six.iteritems(parsed_args.properties):
@@ -275,6 +285,21 @@ def take_action(self, parsed_args):
275285
if parsed_args.private:
276286
kwargs['visibility'] = 'private'
277287

288+
# Handle deprecated --owner option
289+
project_arg = parsed_args.project
290+
if parsed_args.owner:
291+
project_arg = parsed_args.owner
292+
self.log.warning(_(
293+
'The --owner option is deprecated, '
294+
'please use --project instead.'
295+
))
296+
if project_arg:
297+
kwargs['owner'] = common.find_project(
298+
identity_client,
299+
project_arg,
300+
parsed_args.project_domain,
301+
).id
302+
278303
# open the file first to ensure any failures are handled before the
279304
# image is created
280305
fp = gc_utils.get_data_file(parsed_args)
@@ -458,7 +483,7 @@ def take_action(self, parsed_args):
458483
'Status',
459484
'Visibility',
460485
'Protected',
461-
'Owner',
486+
'Project',
462487
'Tags',
463488
)
464489
else:
@@ -598,11 +623,6 @@ def get_parser(self, prog_name):
598623
metavar="<name>",
599624
help="New image name"
600625
)
601-
parser.add_argument(
602-
"--owner",
603-
metavar="<project>",
604-
help="New image owner project (name or ID)",
605-
)
606626
parser.add_argument(
607627
"--min-disk",
608628
type=int,
@@ -713,6 +733,20 @@ def get_parser(self, prog_name):
713733
action="store_true",
714734
help="Activate the image",
715735
)
736+
# NOTE(dtroyer): --owner is deprecated in Jan 2016 in an early
737+
# 2.x release. Do not remove before Jan 2017
738+
# and a 3.x release.
739+
project_group = parser.add_mutually_exclusive_group()
740+
project_group.add_argument(
741+
"--project",
742+
metavar="<project>",
743+
help="Set an alternate project on this image (name or ID)",
744+
)
745+
project_group.add_argument(
746+
"--owner",
747+
metavar="<project>",
748+
help=argparse.SUPPRESS,
749+
)
716750
common.add_project_domain_option_to_parser(parser)
717751
for deadopt in self.deadopts:
718752
parser.add_argument(
@@ -738,7 +772,7 @@ def take_action(self, parsed_args):
738772
copy_attrs = ('architecture', 'container_format', 'disk_format',
739773
'file', 'instance_id', 'kernel_id', 'locations',
740774
'min_disk', 'min_ram', 'name', 'os_distro', 'os_version',
741-
'owner', 'prefix', 'progress', 'ramdisk_id', 'tags')
775+
'prefix', 'progress', 'ramdisk_id', 'tags')
742776
for attr in copy_attrs:
743777
if attr in parsed_args:
744778
val = getattr(parsed_args, attr, None)
@@ -767,6 +801,21 @@ def take_action(self, parsed_args):
767801
if parsed_args.private:
768802
kwargs['visibility'] = 'private'
769803

804+
# Handle deprecated --owner option
805+
project_arg = parsed_args.project
806+
if parsed_args.owner:
807+
project_arg = parsed_args.owner
808+
self.log.warning(_(
809+
'The --owner option is deprecated, '
810+
'please use --project instead.'
811+
))
812+
if project_arg:
813+
kwargs['owner'] = common.find_project(
814+
identity_client,
815+
project_arg,
816+
parsed_args.project_domain,
817+
).id
818+
770819
# Checks if anything that requires getting the image
771820
if not (kwargs or parsed_args.deactivate or parsed_args.activate):
772821
self.log.warning("No arguments specified")
@@ -790,13 +839,6 @@ def take_action(self, parsed_args):
790839
# Tags should be extended, but duplicates removed
791840
kwargs['tags'] = list(set(image.tags).union(set(parsed_args.tags)))
792841

793-
if parsed_args.owner:
794-
kwargs['owner'] = common.find_project(
795-
identity_client,
796-
parsed_args.owner,
797-
parsed_args.project_domain,
798-
).id
799-
800842
try:
801843
image = image_client.images.update(image.id, **kwargs)
802844
except Exception as e:

0 commit comments

Comments
 (0)