summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-04-21 17:18:01 +0000
committerGerrit Code Review <review@openstack.org>2016-04-21 17:18:01 +0000
commita0a29df3e67b29880e62e1974dde18a4993f2aa1 (patch)
tree58ad26cdd9a7f3615c889f2dc97e7cf5d45c3354
parentd0ff8b6db2a5af79d12307fdcd85b52fc2a4e11f (diff)
parent48ebc49f201baea443146a8d1c3b6cbde3b2f297 (diff)
downloadpython-openstackclient-a0a29df3e67b29880e62e1974dde18a4993f2aa1.tar.gz
Merge "Add new share and default parms to subnet pool cmds"
-rw-r--r--doc/source/command-objects/subnet-pool.rst27
-rw-r--r--openstackclient/network/v2/subnet_pool.py42
-rw-r--r--openstackclient/tests/network/v2/test_subnet_pool.py86
-rw-r--r--releasenotes/notes/bug-1544586-0fe19a567d3e31fc.yaml6
4 files changed, 161 insertions, 0 deletions
diff --git a/doc/source/command-objects/subnet-pool.rst b/doc/source/command-objects/subnet-pool.rst
index 3b7d0e91..867153ef 100644
--- a/doc/source/command-objects/subnet-pool.rst
+++ b/doc/source/command-objects/subnet-pool.rst
@@ -19,6 +19,8 @@ Create subnet pool
[--max-prefix-length <max-prefix-length>]
[--project <project> [--project-domain <project-domain>]]
[--address-scope <address-scope>]
+ [--default | --no-default]
+ [--share | --no-share]
<name>
.. option:: --pool-prefix <pool-prefix>
@@ -52,6 +54,22 @@ Create subnet pool
Set address scope associated with the subnet pool (name or ID),
prefixes must be unique across address scopes
+.. option:: --default
+
+ Set this as a default subnet pool
+
+.. option:: --no-default
+
+ Set this as a non-default subnet pool
+
+.. option:: --share
+
+ Set this subnet pool as shared
+
+.. option:: --no-share
+
+ Set this subnet pool as not shared
+
.. _subnet_pool_create-name:
.. describe:: <name>
@@ -103,6 +121,7 @@ Set subnet pool properties
[--min-prefix-length <min-prefix-length>]
[--max-prefix-length <max-prefix-length>]
[--address-scope <address-scope> | --no-address-scope]
+ [--default | --no-default]
<subnet-pool>
.. option:: --name <name>
@@ -135,6 +154,14 @@ Set subnet pool properties
Remove address scope associated with the subnet pool
+.. option:: --default
+
+ Set this as a default subnet pool
+
+.. option:: --no-default
+
+ Set this as a non-default subnet pool
+
.. _subnet_pool_set-subnet-pool:
.. describe:: <subnet-pool>
diff --git a/openstackclient/network/v2/subnet_pool.py b/openstackclient/network/v2/subnet_pool.py
index 482b5ecf..688dd2ca 100644
--- a/openstackclient/network/v2/subnet_pool.py
+++ b/openstackclient/network/v2/subnet_pool.py
@@ -55,6 +55,16 @@ def _get_attrs(client_manager, parsed_args):
if 'no_address_scope' in parsed_args and parsed_args.no_address_scope:
attrs['address_scope_id'] = None
+ if parsed_args.default:
+ attrs['is_default'] = True
+ if parsed_args.no_default:
+ attrs['is_default'] = False
+
+ if 'share' in parsed_args and parsed_args.share:
+ attrs['shared'] = True
+ if 'no_share' in parsed_args and parsed_args.no_share:
+ attrs['shared'] = False
+
# "subnet pool set" command doesn't support setting project.
if 'project' in parsed_args and parsed_args.project is not None:
identity_client = client_manager.identity
@@ -97,6 +107,20 @@ def _add_prefix_options(parser):
)
+def _add_default_options(parser):
+ default_group = parser.add_mutually_exclusive_group()
+ default_group.add_argument(
+ '--default',
+ action='store_true',
+ help=_("Set this as a default subnet pool"),
+ )
+ default_group.add_argument(
+ '--no-default',
+ action='store_true',
+ help=_("Set this as a non-default subnet pool"),
+ )
+
+
class CreateSubnetPool(command.ShowOne):
"""Create subnet pool"""
@@ -121,6 +145,18 @@ class CreateSubnetPool(command.ShowOne):
"(name or ID), prefixes must be unique across address "
"scopes")
)
+ _add_default_options(parser)
+ shared_group = parser.add_mutually_exclusive_group()
+ shared_group.add_argument(
+ '--share',
+ action='store_true',
+ help=_("Set this subnet pool as shared"),
+ )
+ shared_group.add_argument(
+ '--no-share',
+ action='store_true',
+ help=_("Set this subnet pool as not shared"),
+ )
return parser
def take_action(self, parsed_args):
@@ -176,6 +212,8 @@ class ListSubnetPool(command.Lister):
'Prefixes',
'Default Prefix Length',
'Address Scope',
+ 'Default Subnet Pool',
+ 'Shared',
)
columns = (
'id',
@@ -183,6 +221,8 @@ class ListSubnetPool(command.Lister):
'prefixes',
'default_prefixlen',
'address_scope_id',
+ 'is_default',
+ 'shared',
)
else:
headers = (
@@ -232,6 +272,8 @@ class SetSubnetPool(command.Command):
action='store_true',
help=_("Remove address scope associated with the subnet pool")
)
+ _add_default_options(parser)
+
return parser
def take_action(self, parsed_args):
diff --git a/openstackclient/tests/network/v2/test_subnet_pool.py b/openstackclient/tests/network/v2/test_subnet_pool.py
index cbb32fc3..369a8b11 100644
--- a/openstackclient/tests/network/v2/test_subnet_pool.py
+++ b/openstackclient/tests/network/v2/test_subnet_pool.py
@@ -221,6 +221,32 @@ class TestCreateSubnetPool(TestSubnetPool):
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
+ def test_create_default_and_shared_options(self):
+ arglist = [
+ '--pool-prefix', '10.0.10.0/24',
+ '--default',
+ '--share',
+ self._subnet_pool.name,
+ ]
+ verifylist = [
+ ('prefixes', ['10.0.10.0/24']),
+ ('default', True),
+ ('share', True),
+ ('name', self._subnet_pool.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = (self.cmd.take_action(parsed_args))
+
+ self.network.create_subnet_pool.assert_called_once_with(**{
+ 'is_default': True,
+ 'name': self._subnet_pool.name,
+ 'prefixes': ['10.0.10.0/24'],
+ 'shared': True,
+ })
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, data)
+
class TestDeleteSubnetPool(TestSubnetPool):
@@ -267,6 +293,8 @@ class TestListSubnetPool(TestSubnetPool):
columns_long = columns + (
'Default Prefix Length',
'Address Scope',
+ 'Default Subnet Pool',
+ 'Shared',
)
data = []
@@ -285,6 +313,8 @@ class TestListSubnetPool(TestSubnetPool):
utils.format_list(pool.prefixes),
pool.default_prefixlen,
pool.address_scope_id,
+ pool.is_default,
+ pool.shared,
))
def setUp(self):
@@ -474,6 +504,62 @@ class TestSetSubnetPool(TestSubnetPool):
self.assertRaises(tests_utils.ParserException, self.check_parser,
self.cmd, arglist, verifylist)
+ def test_set_default(self):
+ arglist = [
+ '--default',
+ self._subnet_pool.name,
+ ]
+ verifylist = [
+ ('default', True),
+ ('subnet_pool', self._subnet_pool.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ attrs = {
+ 'is_default': True
+ }
+ self.network.update_subnet_pool.assert_called_once_with(
+ self._subnet_pool, **attrs)
+ self.assertIsNone(result)
+
+ def test_set_no_default(self):
+ arglist = [
+ '--no-default',
+ self._subnet_pool.name,
+ ]
+ verifylist = [
+ ('no_default', True),
+ ('subnet_pool', self._subnet_pool.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ attrs = {
+ 'is_default': False,
+ }
+ self.network.update_subnet_pool.assert_called_once_with(
+ self._subnet_pool, **attrs)
+ self.assertIsNone(result)
+
+ def test_set_no_default_conflict(self):
+ arglist = [
+ '--default',
+ '--no-default',
+ self._subnet_pool.name,
+ ]
+ verifylist = [
+ ('default', True),
+ ('no_default', True),
+ ('subnet_pool', self._subnet_pool.name),
+ ]
+
+ # Exclusive arguments will conflict here.
+ self.assertRaises(tests_utils.ParserException, self.check_parser,
+ self.cmd, arglist, verifylist)
+
class TestShowSubnetPool(TestSubnetPool):
diff --git a/releasenotes/notes/bug-1544586-0fe19a567d3e31fc.yaml b/releasenotes/notes/bug-1544586-0fe19a567d3e31fc.yaml
new file mode 100644
index 00000000..fb73325e
--- /dev/null
+++ b/releasenotes/notes/bug-1544586-0fe19a567d3e31fc.yaml
@@ -0,0 +1,6 @@
+---
+features:
+ - Add ``--share`` and ``--default`` options to ``subnet pool create``
+ and ``--default`` option to ``subnet pool set``
+ [Bug `1544586 <https://bugs.launchpad.net/python-openstackclient/+bug/1544586>`_]
+ [Bug `1544591 <https://bugs.launchpad.net/python-openstackclient/+bug/1544591>`_]