From 5ad59968ac4257c76aec9bd62c417fe8b5403608 Mon Sep 17 00:00:00 2001
From: NiallBunting <niall.bunting@hp.com>
Date: Fri, 25 Sep 2015 13:21:01 +0000
Subject: [PATCH] Add --owner to `image create`

This adds --owner to `image create`. This is backwards compatable with v1.

Change-Id: I9e79cf880c91a1386419db729818d23dfe632179
Depends-On: I8d572a070bbb04dccdd051b8e0ad199c5754746e
---
 doc/source/command-objects/image.rst         |  2 --
 openstackclient/image/v2/image.py            | 10 +++++++---
 openstackclient/tests/image/v2/test_image.py |  6 ++++--
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/doc/source/command-objects/image.rst b/doc/source/command-objects/image.rst
index c3fe77a10b..d4b9916221 100644
--- a/doc/source/command-objects/image.rst
+++ b/doc/source/command-objects/image.rst
@@ -57,8 +57,6 @@ Create/upload an image
 
     Image owner project name or ID
 
-    *Image version 1 only.*
-
 .. option:: --size <size>
 
     Image size, in bytes (only used with --location and --copy-from)
diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py
index 7d8b14124a..6fd6c74e30 100644
--- a/openstackclient/image/v2/image.py
+++ b/openstackclient/image/v2/image.py
@@ -112,7 +112,7 @@ class CreateImage(show.ShowOne):
     """Create/upload an image"""
 
     log = logging.getLogger(__name__ + ".CreateImage")
-    deadopts = ('owner', 'size', 'location', 'copy-from', 'checksum', 'store')
+    deadopts = ('size', 'location', 'copy-from', 'checksum', 'store')
 
     def get_parser(self, prog_name):
         parser = super(CreateImage, self).get_parser(prog_name)
@@ -120,7 +120,6 @@ class CreateImage(show.ShowOne):
         # TODO(bunting): There are additional arguments that v1 supported
         # that v2 either doesn't support or supports weirdly.
         # --checksum - could be faked clientside perhaps?
-        # --owner - could be set as an update after the put?
         # --location - maybe location add?
         # --size - passing image size is actually broken in python-glanceclient
         # --copy-from - does not exist in v2
@@ -149,6 +148,11 @@ class CreateImage(show.ShowOne):
             help="Image disk format "
                  "(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>",
@@ -229,7 +233,7 @@ class CreateImage(show.ShowOne):
         copy_attrs = ('name', 'id',
                       'container_format', 'disk_format',
                       'min_disk', 'min_ram',
-                      'tags')
+                      'tags', 'owner')
         for attr in copy_attrs:
             if attr in parsed_args:
                 val = getattr(parsed_args, attr, None)
diff --git a/openstackclient/tests/image/v2/test_image.py b/openstackclient/tests/image/v2/test_image.py
index 4ce854759b..b35fda798e 100644
--- a/openstackclient/tests/image/v2/test_image.py
+++ b/openstackclient/tests/image/v2/test_image.py
@@ -112,6 +112,7 @@ class TestImageCreate(TestImage):
             '--disk-format', 'fs',
             '--min-disk', '10',
             '--min-ram', '4',
+            '--owner', '123456',
             '--protected',
             '--private',
             image_fakes.image_name,
@@ -121,6 +122,7 @@ class TestImageCreate(TestImage):
             ('disk_format', 'fs'),
             ('min_disk', 10),
             ('min_ram', 4),
+            ('owner', '123456'),
             ('protected', True),
             ('unprotected', False),
             ('public', False),
@@ -139,6 +141,7 @@ class TestImageCreate(TestImage):
             disk_format='fs',
             min_disk=10,
             min_ram=4,
+            owner='123456',
             protected=True,
             visibility='private',
         )
@@ -213,11 +216,10 @@ class TestImageCreate(TestImage):
     def test_image_create_dead_options(self):
 
         arglist = [
-            '--owner', 'nobody',
+            '--store', 'somewhere',
             image_fakes.image_name,
         ]
         verifylist = [
-            ('owner', 'nobody'),
             ('name', image_fakes.image_name),
         ]
         parsed_args = self.check_parser(self.cmd, arglist, verifylist)