From 3a8efba2b8d462f06227ad4347263ba20eb05fca Mon Sep 17 00:00:00 2001
From: Venkata Siva Vijayendra Bhamidipati <vbhamidipati@ebaysf.com>
Date: Tue, 4 Mar 2014 10:17:47 -0800
Subject: [PATCH] Frist commit to add tag create CLI.

---
 neutronclient/neutron/v2_0/neutrontags/__init__.py |  2 +
 neutronclient/neutron/v2_0/neutrontags/tag.py      | 47 ++++++++++++++++++++++
 neutronclient/shell.py                             |  3 +-
 neutronclient/v2_0/client.py                       |  8 ++++
 4 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100644 neutronclient/neutron/v2_0/neutrontags/__init__.py
 create mode 100644 neutronclient/neutron/v2_0/neutrontags/tag.py

diff --git a/neutronclient/neutron/v2_0/neutrontags/__init__.py b/neutronclient/neutron/v2_0/neutrontags/__init__.py
new file mode 100644
index 0000000..b199b1d
--- /dev/null
+++ b/neutronclient/neutron/v2_0/neutrontags/__init__.py
@@ -0,0 +1,2 @@
+# __init__.py
+# For tag extension.
diff --git a/neutronclient/neutron/v2_0/neutrontags/tag.py b/neutronclient/neutron/v2_0/neutrontags/tag.py
new file mode 100644
index 0000000..53080c2
--- /dev/null
+++ b/neutronclient/neutron/v2_0/neutrontags/tag.py
@@ -0,0 +1,47 @@
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+#
+
+import argparse
+import logging
+import traceback
+
+from neutronclient.neutron import v2_0 as neutronV20
+from neutronclient.openstack.common.gettextutils import _
+
+
+class CreateTag(neutronV20.CreateCommand):
+    """Create a tag."""
+
+    resource = 'tag'
+    log = logging.getLogger(__name__ + '.CreateTag')
+
+    def add_known_arguments(self, parser):
+        parser.add_argument(
+            '--name',
+            help=_('Name of the tag'))
+        parser.add_argument(
+            '--key',
+            help=_('Key of tag'))
+        parser.add_argument(
+            '--value',
+            help=_('Value of tag'))
+
+    def args2body(self, parsed_args):
+        body = {'tag': {
+            'name': parsed_args.name,
+            'key': parsed_args.key,
+            'value' : parsed_args.value} }
+        neutronV20.update_dict(parsed_args, body['tag'],
+                               ['tenant_id'])
+        return body
diff --git a/neutronclient/shell.py b/neutronclient/shell.py
index 9aead6a..96a0622 100644
--- a/neutronclient/shell.py
+++ b/neutronclient/shell.py
@@ -60,6 +60,7 @@ from neutronclient.neutron.v2_0.vpn import ikepolicy
 from neutronclient.neutron.v2_0.vpn import ipsec_site_connection
 from neutronclient.neutron.v2_0.vpn import ipsecpolicy
 from neutronclient.neutron.v2_0.vpn import vpnservice
+from neutronclient.neutron.v2_0.neutrontags import tag
 from neutronclient.openstack.common.gettextutils import _
 from neutronclient.openstack.common import strutils
 from neutronclient.version import __version__
@@ -266,6 +267,7 @@ COMMAND_V2 = {
     'nuage-netpartition-show': netpartition.ShowNetPartition,
     'nuage-netpartition-create': netpartition.CreateNetPartition,
     'nuage-netpartition-delete': netpartition.DeleteNetPartition,
+    'tag-create' : tag.CreateTag,
 }
 
 COMMANDS = {'2.0': COMMAND_V2}
@@ -624,7 +626,6 @@ class NeutronShell(app.App):
         * set up API versions
         * validate authentication info
         """
-
         super(NeutronShell, self).initialize_app(argv)
 
         self.api_version = {'network': self.api_version}
diff --git a/neutronclient/v2_0/client.py b/neutronclient/v2_0/client.py
index 4098c1d..80a756b 100644
--- a/neutronclient/v2_0/client.py
+++ b/neutronclient/v2_0/client.py
@@ -220,6 +220,8 @@ class Client(object):
     firewall_path = "/fw/firewalls/%s"
     net_partitions_path = "/net-partitions"
     net_partition_path = "/net-partitions/%s"
+    tags_path = "/tags"
+    tag_path = "/tags/%s"
 
     # API has no way to report plurals, so we have to hard code them
     EXTED_PLURALS = {'routers': 'router',
@@ -1131,6 +1133,12 @@ class Client(object):
         """Delete the network partition."""
         return self.delete(self.net_partition_path % netpartition)
 
+    @APIParamsCall
+    def create_tag(self, body=None):
+        """Creates a new tag."""
+        return self.post(self.tags_path, body=body)
+
+
     def __init__(self, **kwargs):
         """Initialize a new client for the Neutron v2.0 API."""
         super(Client, self).__init__()
-- 
1.8.3.2

