Change --owner to --project in image commands · Doswind/python-openstackclient@cf2de9a · GitHub
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

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

0 commit comments

Comments
 (0)