From e8be3b64c1956b58fa0a5b6d460c8bf07085951c Mon Sep 17 00:00:00 2001
From: Steve Martinelli <stevemar@ca.ibm.com>
Date: Tue, 6 Jan 2015 01:43:49 -0500
Subject: [PATCH] Command doc: mapping

Also tweaked the code for `mapping set` as it was previously
using cliff Show instead of cliff Command.

Change-Id: I0ea1383a9f2dddf4b2f717b2aa16bbd60ab1720c
---
 doc/source/command-objects/mapping.rst | 91 ++++++++++++++++++++++++++
 doc/source/commands.rst                |  1 +
 openstackclient/identity/v3/mapping.py | 39 ++++++-----
 3 files changed, 113 insertions(+), 18 deletions(-)
 create mode 100644 doc/source/command-objects/mapping.rst

diff --git a/doc/source/command-objects/mapping.rst b/doc/source/command-objects/mapping.rst
new file mode 100644
index 0000000000..5c7535bd1c
--- /dev/null
+++ b/doc/source/command-objects/mapping.rst
@@ -0,0 +1,91 @@
+=======
+mapping
+=======
+
+Identity v3
+
+`Requires: OS-FEDERATION extension`
+
+mapping create
+--------------
+
+Create new mapping
+
+.. program:: mapping create
+.. code:: bash
+
+    os mapping create
+        --rules <filename>
+        <name>
+
+.. option:: --rules <filename>
+
+    Filename that contains a set of mapping rules (required)
+
+.. _mapping_create-mapping:
+.. describe:: <name>
+
+    New mapping name (must be unique)
+
+mapping delete
+--------------
+
+Delete a mapping
+
+.. program:: mapping delete
+.. code:: bash
+
+    os mapping delete
+        <mapping>
+
+.. _mapping_delete-mapping:
+.. describe:: <mapping>
+
+    Mapping to delete
+
+mapping list
+------------
+
+List mappings
+
+.. program:: mapping list
+.. code:: bash
+
+    os mapping list
+
+mapping set
+-----------
+
+Set mapping properties
+
+.. program:: mapping set
+.. code:: bash
+
+    os mapping set
+        [--rules <filename>]
+        <mapping>
+
+.. option:: --rules <filename>
+
+    Filename that contains a new set of mapping rules
+
+.. _mapping_set-mapping:
+.. describe:: <mapping>
+
+    Mapping to modify
+
+mapping show
+------------
+
+Display mapping details
+
+.. program:: mapping show
+.. code:: bash
+
+    os mapping show
+        <mapping>
+
+.. _mapping_show-mapping:
+.. describe:: <mapping>
+
+    Mapping to display
diff --git a/doc/source/commands.rst b/doc/source/commands.rst
index bb3db18755..8976fc029a 100644
--- a/doc/source/commands.rst
+++ b/doc/source/commands.rst
@@ -93,6 +93,7 @@ referring to both Compute and Volume quotas.
 * ``ip floating``: Compute, Network - a public IP address that can be mapped to a server
 * ``keypair``: (**Compute**) an SSH public key
 * ``limits``: (**Compute**, **Volume**) resource usage limits
+* ``mapping``: (**Identity**) a definition to translate identity provider attributes to Identity concepts
 * ``module``: internal - installed Python modules in the OSC process
 * ``network``: Network - a virtual network for connecting servers and other resources
 * ``object``: (**Object Store**) a single file in the Object Store
diff --git a/openstackclient/identity/v3/mapping.py b/openstackclient/identity/v3/mapping.py
index c530a40439..a1f60438f6 100644
--- a/openstackclient/identity/v3/mapping.py
+++ b/openstackclient/identity/v3/mapping.py
@@ -80,7 +80,7 @@ class _RulesReader(object):
 
 
 class CreateMapping(show.ShowOne, _RulesReader):
-    """Create new federation mapping"""
+    """Create new mapping"""
 
     log = logging.getLogger(__name__ + '.CreateMapping')
 
@@ -89,12 +89,12 @@ class CreateMapping(show.ShowOne, _RulesReader):
         parser.add_argument(
             'mapping',
             metavar='<name>',
-            help='New mapping (must be unique)',
+            help='New mapping name (must be unique)',
         )
         parser.add_argument(
             '--rules',
-            metavar='<rules>', required=True,
-            help='Filename with rules',
+            metavar='<filename>', required=True,
+            help='Filename that contains a set of mapping rules (required)',
         )
         return parser
 
@@ -112,7 +112,7 @@ class CreateMapping(show.ShowOne, _RulesReader):
 
 
 class DeleteMapping(command.Command):
-    """Delete federation mapping"""
+    """Delete a mapping"""
 
     log = logging.getLogger(__name__ + '.DeleteMapping')
 
@@ -120,7 +120,7 @@ class DeleteMapping(command.Command):
         parser = super(DeleteMapping, self).get_parser(prog_name)
         parser.add_argument(
             'mapping',
-            metavar='<name>',
+            metavar='<mapping>',
             help='Mapping to delete',
         )
         return parser
@@ -134,7 +134,7 @@ class DeleteMapping(command.Command):
 
 
 class ListMapping(lister.Lister):
-    """List federation mappings"""
+    """List mappings"""
     log = logging.getLogger(__name__ + '.ListMapping')
 
     def take_action(self, parsed_args):
@@ -149,8 +149,8 @@ class ListMapping(lister.Lister):
         return (columns, items)
 
 
-class SetMapping(show.ShowOne, _RulesReader):
-    """Update federation mapping"""
+class SetMapping(command.Command, _RulesReader):
+    """Set mapping properties"""
 
     log = logging.getLogger(__name__ + '.SetMapping')
 
@@ -159,12 +159,12 @@ class SetMapping(show.ShowOne, _RulesReader):
         parser.add_argument(
             'mapping',
             metavar='<name>',
-            help='Mapping to update.',
+            help='Mapping to modify',
         )
         parser.add_argument(
             '--rules',
-            metavar='<rules>', required=True,
-            help='Filename with rules',
+            metavar='<filename>',
+            help='Filename that contains a new set of mapping rules',
         )
         return parser
 
@@ -172,19 +172,22 @@ class SetMapping(show.ShowOne, _RulesReader):
         self.log.debug('take_action(%s)' % parsed_args)
         identity_client = self.app.client_manager.identity
 
+        if not parsed_args.rules:
+            self.app.log.error("No changes requested")
+            return
+
         rules = self._read_rules(parsed_args.rules)
 
         mapping = identity_client.federation.mappings.update(
             mapping=parsed_args.mapping,
             rules=rules)
 
-        info = {}
-        info.update(mapping._info)
-        return zip(*sorted(six.iteritems(info)))
+        mapping._info.pop('links', None)
+        return zip(*sorted(six.iteritems(mapping._info)))
 
 
 class ShowMapping(show.ShowOne):
-    """Show federation mapping details"""
+    """Display mapping details"""
 
     log = logging.getLogger(__name__ + '.ShowMapping')
 
@@ -192,8 +195,8 @@ class ShowMapping(show.ShowOne):
         parser = super(ShowMapping, self).get_parser(prog_name)
         parser.add_argument(
             'mapping',
-            metavar='<name>',
-            help='Mapping to show',
+            metavar='<mapping>',
+            help='Mapping to display',
         )
         return parser