summaryrefslogtreecommitdiff
path: root/openstackclient/image
diff options
context:
space:
mode:
authorchengkunye <chengkun@unitedstack.com>2015-07-16 17:32:42 +0800
committerSteve Martinelli <stevemar@ca.ibm.com>2015-07-20 10:38:42 -0700
commit7bb459837bf8023cbc71cbf41007f8aa4c4725fb (patch)
treedbd44e8ff55d7889fd8988a7613a2a061f2a5d47 /openstackclient/image
parent1af89f757c1edf44067de964cb6ca8dffbb1969e (diff)
downloadpython-openstackclient-7bb459837bf8023cbc71cbf41007f8aa4c4725fb.tar.gz
add image member commands for image API
This commit adds the following commands: image project add image project remove Closes-Bug: 1402420 Change-Id: I07954e9fa43a3ad6078dd939ecedf9f038299e7b
Diffstat (limited to 'openstackclient/image')
-rw-r--r--openstackclient/image/v2/image.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py
index 3dd98338..30485202 100644
--- a/openstackclient/image/v2/image.py
+++ b/openstackclient/image/v2/image.py
@@ -27,6 +27,49 @@ 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.identity import common
+
+
+class AddProjectToImage(show.ShowOne):
+ """Associate project with image"""
+
+ log = logging.getLogger(__name__ + ".AddProjectToImage")
+
+ def get_parser(self, prog_name):
+ parser = super(AddProjectToImage, self).get_parser(prog_name)
+ parser.add_argument(
+ "image",
+ metavar="<image>",
+ help="Image to share (name or ID)",
+ )
+ parser.add_argument(
+ "project",
+ metavar="<project>",
+ help="Project to associate with image (name or ID)",
+ )
+ common.add_project_domain_option_to_parser(parser)
+ return parser
+
+ def take_action(self, parsed_args):
+ self.log.debug("take_action(%s)", parsed_args)
+
+ image_client = self.app.client_manager.image
+ identity_client = self.app.client_manager.identity
+
+ project_id = common.find_project(identity_client,
+ parsed_args.project,
+ parsed_args.project_domain).id
+
+ image_id = utils.find_resource(
+ image_client.images,
+ parsed_args.image).id
+
+ image_member = image_client.image_members.create(
+ image_id,
+ project_id,
+ )
+
+ return zip(*sorted(six.iteritems(image_member._info)))
class DeleteImage(command.Command):
@@ -192,6 +235,43 @@ class ListImage(lister.Lister):
)
+class RemoveProjectImage(command.Command):
+ """Disassociate project with image"""
+
+ log = logging.getLogger(__name__ + ".RemoveProjectImage")
+
+ def get_parser(self, prog_name):
+ parser = super(RemoveProjectImage, self).get_parser(prog_name)
+ parser.add_argument(
+ "image",
+ metavar="<image>",
+ help="Image to unshare (name or ID)",
+ )
+ parser.add_argument(
+ "project",
+ metavar="<project>",
+ help="Project to disassociate with image (name or ID)",
+ )
+ common.add_project_domain_option_to_parser(parser)
+ return parser
+
+ def take_action(self, parsed_args):
+ self.log.debug("take_action(%s)", parsed_args)
+
+ image_client = self.app.client_manager.image
+ identity_client = self.app.client_manager.identity
+
+ project_id = common.find_project(identity_client,
+ parsed_args.project,
+ parsed_args.project_domain).id
+
+ image_id = utils.find_resource(
+ image_client.images,
+ parsed_args.image).id
+
+ image_client.image_members.delete(image_id, project_id)
+
+
class SaveImage(command.Command):
"""Save an image locally"""