diff --git a/lower-constraints.txt b/lower-constraints.txt index fac497a3c..0a453dae2 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -49,7 +49,7 @@ msgpack-python==0.4.0 munch==2.1.0 netaddr==0.7.18 netifaces==0.10.4 -openstacksdk==0.44.0 +openstacksdk==0.48.0 os-service-types==1.7.0 os-testr==1.0.0 osc-lib==2.0.0 diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index 53ce560dc..b068ddafd 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -324,6 +324,14 @@ class CreateImage(command.ShowOne): metavar="", help=_("Set an alternate project on this image (name or ID)"), ) + parser.add_argument( + "--import", + dest="use_import", + action="store_true", + help=_( + "Force the use of glance image import instead of" + " direct upload") + ) common.add_project_domain_option_to_parser(parser) for deadopt in self.deadopts: parser.add_argument( @@ -388,6 +396,9 @@ class CreateImage(command.ShowOne): parsed_args.project_domain, ).id + if parsed_args.use_import: + kwargs['use_import'] = True + # open the file first to ensure any failures are handled before the # image is created. Get the file name (if it is file, and not stdin) # for easier further handling. diff --git a/openstackclient/tests/unit/image/v2/test_image.py b/openstackclient/tests/unit/image/v2/test_image.py index a021cfc7f..310f6b763 100644 --- a/openstackclient/tests/unit/image/v2/test_image.py +++ b/openstackclient/tests/unit/image/v2/test_image.py @@ -271,6 +271,28 @@ class TestImageCreate(TestImage): exceptions.CommandError, self.cmd.take_action, parsed_args) + @mock.patch('sys.stdin', side_effect=[None]) + def test_image_create_import(self, raw_input): + + arglist = [ + '--import', + self.new_image.name, + ] + verifylist = [ + ('name', self.new_image.name), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = self.cmd.take_action(parsed_args) + + # ImageManager.create(name=, **) + self.client.create_image.assert_called_with( + name=self.new_image.name, + container_format=image.DEFAULT_CONTAINER_FORMAT, + disk_format=image.DEFAULT_DISK_FORMAT, + use_import=True + ) + class TestAddProjectToImage(TestImage): diff --git a/releasenotes/notes/add-image-import-flag-899869dc5a92aea7.yaml b/releasenotes/notes/add-image-import-flag-899869dc5a92aea7.yaml new file mode 100644 index 000000000..fbd29bcd8 --- /dev/null +++ b/releasenotes/notes/add-image-import-flag-899869dc5a92aea7.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Added ``--import`` flag to ``openstack image create`` to allow + the user to force use of the image import codepath. diff --git a/requirements.txt b/requirements.txt index b1421a831..2b7976e59 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ pbr!=2.1.0,>=2.0.0 # Apache-2.0 six>=1.10.0 # MIT cliff!=2.9.0,>=2.8.0 # Apache-2.0 -openstacksdk>=0.44.0 # Apache-2.0 +openstacksdk>=0.48.0 # Apache-2.0 osc-lib>=2.0.0 # Apache-2.0 oslo.i18n>=3.15.3 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0