From 04ef8a41acbd45ef03253240934fa07ec170d7f4 Mon Sep 17 00:00:00 2001
From: Reedip <reedip.banerjee@nectechnologies.in>
Date: Tue, 8 Aug 2017 09:23:44 +0530
Subject: [PATCH] Allow PD as Subnetpool during Subnet creations

This commit now allows user to specify 'prefix_delegation'
as a Subnetpool during Subnet creation by using the new
--use-prefix-delegation option so that the IPv6
prefixes can be delegated to routers set up by the
cloud admins.

Change-Id: I67e5d81c4155db2e3c5c41ee1df77f2d77a17689
Closes-Bug: #1513894
---
 doc/source/cli/command-objects/subnet.rst            | 7 ++++++-
 openstackclient/network/v2/subnet.py                 | 7 +++++++
 releasenotes/notes/bug-1513894-6d2f05db6e1df744.yaml | 6 ++++++
 3 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 releasenotes/notes/bug-1513894-6d2f05db6e1df744.yaml

diff --git a/doc/source/cli/command-objects/subnet.rst b/doc/source/cli/command-objects/subnet.rst
index c228dc207d..0a56ccf18b 100644
--- a/doc/source/cli/command-objects/subnet.rst
+++ b/doc/source/cli/command-objects/subnet.rst
@@ -18,7 +18,7 @@ Create new subnet
 
     openstack subnet create
         [--project <project> [--project-domain <project-domain>]]
-        [--subnet-pool <subnet-pool> | --use-default-subnet-pool [--prefix-length <prefix-length>]]
+        [--subnet-pool <subnet-pool> | --use-default-subnet-pool [--prefix-length <prefix-length>] | --use-prefix-delegation]
         [--subnet-range <subnet-range>]
         [--allocation-pool start=<ip-address>,end=<ip-address>]
         [--dhcp | --no-dhcp]
@@ -48,6 +48,11 @@ Create new subnet
 
     Subnet pool from which this subnet will obtain a CIDR (name or ID)
 
+.. option:: --use-prefix-delegation
+
+    Use 'prefix-delegation' if IP is IPv6 format and IP would be delegated
+    externally
+
 .. option:: --use-default-subnet-pool
 
     Use default subnet pool for :option:`--ip-version`
diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py
index b96dff7f94..c71358a52f 100644
--- a/openstackclient/network/v2/subnet.py
+++ b/openstackclient/network/v2/subnet.py
@@ -186,6 +186,8 @@ def _get_attrs(client_manager, parsed_args, is_create=True):
             subnet_pool = client.find_subnet_pool(parsed_args.subnet_pool,
                                                   ignore_missing=False)
             attrs['subnetpool_id'] = subnet_pool.id
+        if parsed_args.use_prefix_delegation:
+            attrs['subnetpool_id'] = "prefix_delegation"
         if parsed_args.use_default_subnet_pool:
             attrs['use_default_subnet_pool'] = True
         if parsed_args.prefix_length is not None:
@@ -260,6 +262,11 @@ class CreateSubnet(command.ShowOne):
             help=_("Subnet pool from which this subnet will obtain a CIDR "
                    "(Name or ID)")
         )
+        subnet_pool_group.add_argument(
+            '--use-prefix-delegation',
+            help=_("Use 'prefix-delegation' if IP is IPv6 format "
+                   "and IP would be delegated externally")
+        )
         subnet_pool_group.add_argument(
             '--use-default-subnet-pool',
             action='store_true',
diff --git a/releasenotes/notes/bug-1513894-6d2f05db6e1df744.yaml b/releasenotes/notes/bug-1513894-6d2f05db6e1df744.yaml
new file mode 100644
index 0000000000..a7d750557c
--- /dev/null
+++ b/releasenotes/notes/bug-1513894-6d2f05db6e1df744.yaml
@@ -0,0 +1,6 @@
+---
+features:
+  - |
+    Add ``--use-prefix-delegation`` option to the ``subnet create`` command to
+    specify 'Prefix Delegation' as a subnetpool when creating subnets.
+    [Bug `1513894 <https://bugs.launchpad.net/bugs/1513894>`_]