diff options
| author | Dean Troyer <dtroyer@gmail.com> | 2015-12-18 14:16:45 -0600 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2016-01-15 09:24:48 -0600 |
| commit | cf2de9af79cedd51ca080f5a6521997c05647418 (patch) | |
| tree | fa476461d5fe4ae4edb7008ec71c070425f93d87 /openstackclient/image | |
| parent | 8654e3e366166372c8f114ad9463dbceb599cd3d (diff) | |
| download | python-openstackclient-cf2de9af79cedd51ca080f5a6521997c05647418.tar.gz | |
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
Diffstat (limited to 'openstackclient/image')
| -rw-r--r-- | openstackclient/image/v1/image.py | 65 | ||||
| -rw-r--r-- | openstackclient/image/v2/image.py | 84 |
2 files changed, 117 insertions, 32 deletions
diff --git a/openstackclient/image/v1/image.py b/openstackclient/image/v1/image.py index 0382501e..c18f3fc7 100644 --- a/openstackclient/image/v1/image.py +++ b/openstackclient/image/v1/image.py @@ -35,6 +35,7 @@ from glanceclient.common import utils as gc_utils from openstackclient.api import utils as api_utils from openstackclient.common import parseractions from openstackclient.common import utils +from openstackclient.i18n import _ # noqa DEFAULT_CONTAINER_FORMAT = 'bare' @@ -93,11 +94,6 @@ class CreateImage(show.ShowOne): "(default: %s)" % DEFAULT_DISK_FORMAT, ) parser.add_argument( - "--owner", - metavar="<project>", - help="Image owner project name or ID", - ) - parser.add_argument( "--size", metavar="<size>", help="Image size, in bytes (only used with --location and" @@ -178,12 +174,32 @@ class CreateImage(show.ShowOne): help="Set a property on this image " "(repeat option to set multiple properties)", ) + # NOTE(dtroyer): --owner is deprecated in Jan 2016 in an early + # 2.x release. Do not remove before Jan 2017 + # and a 3.x release. + project_group = parser.add_mutually_exclusive_group() + project_group.add_argument( + "--project", + metavar="<project>", + help="Set an alternate project on this image (name or ID)", + ) + project_group.add_argument( + "--owner", + metavar="<project>", + help=argparse.SUPPRESS, + ) return parser def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) image_client = self.app.client_manager.image + if getattr(parsed_args, 'owner', None) is not None: + self.log.warning(_( + 'The --owner option is deprecated, ' + 'please use --project instead.' + )) + # Build an attribute dict from the parsed args, only include # attributes that were actually set on the command line kwargs = {} @@ -198,6 +214,12 @@ class CreateImage(show.ShowOne): # Only include a value in kwargs for attributes that are # actually present on the command line kwargs[attr] = val + + # Special case project option back to API attribute name 'owner' + val = getattr(parsed_args, 'project', None) + if val: + kwargs['owner'] = val + # Handle exclusive booleans with care # Avoid including attributes in kwargs if an option is not # present on the command line. These exclusive booleans are not @@ -383,7 +405,7 @@ class ListImage(lister.Lister): 'Status', 'Visibility', 'Protected', - 'Owner', + 'Project', 'Properties', ) else: @@ -477,11 +499,6 @@ class SetImage(command.Command): help="New image name", ) parser.add_argument( - "--owner", - metavar="<project>", - help="New image owner project (name or ID)", - ) - parser.add_argument( "--min-disk", metavar="<disk-gb>", type=int, @@ -590,12 +607,32 @@ class SetImage(command.Command): metavar="<checksum>", help="Image hash used for verification", ) + # NOTE(dtroyer): --owner is deprecated in Jan 2016 in an early + # 2.x release. Do not remove before Jan 2017 + # and a 3.x release. + project_group = parser.add_mutually_exclusive_group() + project_group.add_argument( + "--project", + metavar="<project>", + help="Set an alternate project on this image (name or ID)", + ) + project_group.add_argument( + "--owner", + metavar="<project>", + help=argparse.SUPPRESS, + ) return parser def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) image_client = self.app.client_manager.image + if getattr(parsed_args, 'owner', None) is not None: + self.log.warning(_( + 'The --owner option is deprecated, ' + 'please use --project instead.' + )) + kwargs = {} copy_attrs = ('name', 'owner', 'min_disk', 'min_ram', 'properties', 'container_format', 'disk_format', 'size', 'store', @@ -607,6 +644,12 @@ class SetImage(command.Command): # Only include a value in kwargs for attributes that are # actually present on the command line kwargs[attr] = val + + # Special case project option back to API attribute name 'owner' + val = getattr(parsed_args, 'project', None) + if val: + kwargs['owner'] = val + # Handle exclusive booleans with care # Avoid including attributes in kwargs if an option is not # present on the command line. These exclusive booleans are not diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index ad536ba2..3c1faf59 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -28,6 +28,7 @@ from openstackclient.api import utils as api_utils from openstackclient.common import exceptions from openstackclient.common import parseractions from openstackclient.common import utils +from openstackclient.i18n import _ # noqa from openstackclient.identity import common @@ -148,11 +149,6 @@ class CreateImage(show.ShowOne): "(default: %s)" % DEFAULT_DISK_FORMAT, ) parser.add_argument( - "--owner", - metavar="<owner>", - help="Image owner project name or ID", - ) - parser.add_argument( "--min-disk", metavar="<disk-gb>", type=int, @@ -220,6 +216,20 @@ class CreateImage(show.ShowOne): help="Set a tag on this image " "(repeat option to set multiple tags)", ) + # NOTE(dtroyer): --owner is deprecated in Jan 2016 in an early + # 2.x release. Do not remove before Jan 2017 + # and a 3.x release. + project_group = parser.add_mutually_exclusive_group() + project_group.add_argument( + "--project", + metavar="<project>", + help="Set an alternate project on this image (name or ID)", + ) + project_group.add_argument( + "--owner", + metavar="<project>", + help=argparse.SUPPRESS, + ) common.add_project_domain_option_to_parser(parser) for deadopt in self.deadopts: parser.add_argument( @@ -246,8 +256,7 @@ class CreateImage(show.ShowOne): kwargs = {} copy_attrs = ('name', 'id', 'container_format', 'disk_format', - 'min_disk', 'min_ram', - 'tags', 'owner') + 'min_disk', 'min_ram', 'tags') for attr in copy_attrs: if attr in parsed_args: val = getattr(parsed_args, attr, None) @@ -255,6 +264,7 @@ class CreateImage(show.ShowOne): # Only include a value in kwargs for attributes that # are actually present on the command line kwargs[attr] = val + # properties should get flattened into the general kwargs if getattr(parsed_args, 'properties', None): for k, v in six.iteritems(parsed_args.properties): @@ -275,6 +285,21 @@ class CreateImage(show.ShowOne): if parsed_args.private: kwargs['visibility'] = 'private' + # Handle deprecated --owner option + project_arg = parsed_args.project + if parsed_args.owner: + project_arg = parsed_args.owner + self.log.warning(_( + 'The --owner option is deprecated, ' + 'please use --project instead.' + )) + if project_arg: + kwargs['owner'] = common.find_project( + identity_client, + project_arg, + parsed_args.project_domain, + ).id + # open the file first to ensure any failures are handled before the # image is created fp = gc_utils.get_data_file(parsed_args) @@ -458,7 +483,7 @@ class ListImage(lister.Lister): 'Status', 'Visibility', 'Protected', - 'Owner', + 'Project', 'Tags', ) else: @@ -599,11 +624,6 @@ class SetImage(command.Command): help="New image name" ) parser.add_argument( - "--owner", - metavar="<project>", - help="New image owner project (name or ID)", - ) - parser.add_argument( "--min-disk", type=int, metavar="<disk-gb>", @@ -713,6 +733,20 @@ class SetImage(command.Command): action="store_true", help="Activate the image", ) + # NOTE(dtroyer): --owner is deprecated in Jan 2016 in an early + # 2.x release. Do not remove before Jan 2017 + # and a 3.x release. + project_group = parser.add_mutually_exclusive_group() + project_group.add_argument( + "--project", + metavar="<project>", + help="Set an alternate project on this image (name or ID)", + ) + project_group.add_argument( + "--owner", + metavar="<project>", + help=argparse.SUPPRESS, + ) common.add_project_domain_option_to_parser(parser) for deadopt in self.deadopts: parser.add_argument( @@ -738,7 +772,7 @@ class SetImage(command.Command): copy_attrs = ('architecture', 'container_format', 'disk_format', 'file', 'instance_id', 'kernel_id', 'locations', 'min_disk', 'min_ram', 'name', 'os_distro', 'os_version', - 'owner', 'prefix', 'progress', 'ramdisk_id', 'tags') + 'prefix', 'progress', 'ramdisk_id', 'tags') for attr in copy_attrs: if attr in parsed_args: val = getattr(parsed_args, attr, None) @@ -767,6 +801,21 @@ class SetImage(command.Command): if parsed_args.private: kwargs['visibility'] = 'private' + # Handle deprecated --owner option + project_arg = parsed_args.project + if parsed_args.owner: + project_arg = parsed_args.owner + self.log.warning(_( + 'The --owner option is deprecated, ' + 'please use --project instead.' + )) + if project_arg: + kwargs['owner'] = common.find_project( + identity_client, + project_arg, + parsed_args.project_domain, + ).id + # Checks if anything that requires getting the image if not (kwargs or parsed_args.deactivate or parsed_args.activate): self.log.warning("No arguments specified") @@ -790,13 +839,6 @@ class SetImage(command.Command): # Tags should be extended, but duplicates removed kwargs['tags'] = list(set(image.tags).union(set(parsed_args.tags))) - if parsed_args.owner: - kwargs['owner'] = common.find_project( - identity_client, - parsed_args.owner, - parsed_args.project_domain, - ).id - try: image = image_client.images.update(image.id, **kwargs) except Exception as e: |
