summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorBrad Behle <behle@us.ibm.com>2016-04-18 21:22:24 -0500
committerBrad Behle <behle@us.ibm.com>2016-04-20 20:12:02 -0500
commit48ebc49f201baea443146a8d1c3b6cbde3b2f297 (patch)
tree00c4502be903ec0b5142a9c2abeb73d5206a4164 /openstackclient
parent3f2ed7d19f53b0950152e4f233797f13627f4986 (diff)
downloadpython-openstackclient-48ebc49f201baea443146a8d1c3b6cbde3b2f297.tar.gz
Add new share and default parms to subnet pool cmds
Add the "share" and "default" parms to subnet pool create command. Add the "default" and "no-default" parms to subnet pool set command. Note that "share" can not be modified once subnet pool has been created, so do not add this to the set command. Change-Id: I1eecad69527a1cde7fb234669f4aff2be2db491e Partial-Bug: #1544591 Partial-Bug: #1544586
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/network/v2/subnet_pool.py42
-rw-r--r--openstackclient/tests/network/v2/test_subnet_pool.py86
2 files changed, 128 insertions, 0 deletions
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):