Merge "[Subnet pool] Add 'subnet pool create' command support"

This commit is contained in:
Jenkins 2016-03-10 00:38:26 +00:00 committed by Gerrit Code Review
commit c6e46aa8da
5 changed files with 176 additions and 4 deletions

View File

@ -4,6 +4,43 @@ subnet pool
Network v2
subnet pool create
------------------
Create subnet pool
.. program:: subnet pool create
.. code:: bash
os subnet pool create
[--pool-prefix <pool-prefix> [...]]
[--default-prefix-length <default-prefix-length>]
[--min-prefix-length <min-prefix-length>]
[--max-prefix-length <max-prefix-length>]
<name>
.. option:: --pool-prefix <pool-prefix>
Set subnet pool prefixes (in CIDR notation).
Repeat this option to set multiple prefixes.
.. option:: --default-prefix-length <default-prefix-length>
Set subnet pool default prefix length
.. option:: --min-prefix-length <min-prefix-length>
Set subnet pool minimum prefix length
.. option:: --max-prefix-length <max-prefix-length>
Set subnet pool maximum prefix length
.. _subnet_pool_create-name:
.. describe:: <name>
Name of the new subnet pool
subnet pool delete
------------------

View File

@ -77,6 +77,29 @@ def _add_prefix_options(parser):
)
class CreateSubnetPool(command.ShowOne):
"""Create subnet pool"""
def get_parser(self, prog_name):
parser = super(CreateSubnetPool, self).get_parser(prog_name)
parser.add_argument(
'name',
metavar="<name>",
help='Name of the new subnet pool'
)
_add_prefix_options(parser)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
attrs = _get_attrs(parsed_args)
obj = client.create_subnet_pool(**attrs)
columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters=_formatters)
return (columns, data)
class DeleteSubnetPool(command.Command):
"""Delete subnet pool"""

View File

@ -734,15 +734,15 @@ class FakeSubnetPool(object):
'id': 'subnet-pool-id-' + uuid.uuid4().hex,
'name': 'subnet-pool-name-' + uuid.uuid4().hex,
'prefixes': ['10.0.0.0/24', '10.1.0.0/24'],
'default_prefixlen': 8,
'default_prefixlen': '8',
'address_scope_id': 'address-scope-id-' + uuid.uuid4().hex,
'tenant_id': 'project-id-' + uuid.uuid4().hex,
'is_default': False,
'shared': False,
'max_prefixlen': 32,
'min_prefixlen': 8,
'max_prefixlen': '32',
'min_prefixlen': '8',
'default_quota': None,
'ip_version': 4,
'ip_version': '4',
}
# Overwrite default attributes.

View File

@ -30,6 +30,117 @@ class TestSubnetPool(network_fakes.TestNetworkV2):
self.network = self.app.client_manager.network
class TestCreateSubnetPool(TestSubnetPool):
# The new subnet pool to create.
_subnet_pool = network_fakes.FakeSubnetPool.create_one_subnet_pool()
columns = (
'address_scope_id',
'default_prefixlen',
'default_quota',
'id',
'ip_version',
'is_default',
'max_prefixlen',
'min_prefixlen',
'name',
'prefixes',
'project_id',
'shared',
)
data = (
_subnet_pool.address_scope_id,
_subnet_pool.default_prefixlen,
_subnet_pool.default_quota,
_subnet_pool.id,
_subnet_pool.ip_version,
_subnet_pool.is_default,
_subnet_pool.max_prefixlen,
_subnet_pool.min_prefixlen,
_subnet_pool.name,
utils.format_list(_subnet_pool.prefixes),
_subnet_pool.project_id,
_subnet_pool.shared,
)
def setUp(self):
super(TestCreateSubnetPool, self).setUp()
self.network.create_subnet_pool = mock.Mock(
return_value=self._subnet_pool)
# Get the command object to test
self.cmd = subnet_pool.CreateSubnetPool(self.app, self.namespace)
def test_create_no_options(self):
arglist = []
verifylist = []
# Missing required args should bail here
self.assertRaises(tests_utils.ParserException, self.check_parser,
self.cmd, arglist, verifylist)
def test_create_default_options(self):
arglist = [
'--pool-prefix', '10.0.10.0/24',
self._subnet_pool.name,
]
verifylist = [
('prefixes', ['10.0.10.0/24']),
('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_with(**{
'prefixes': ['10.0.10.0/24'],
'name': self._subnet_pool.name,
})
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
def test_create_prefixlen_options(self):
arglist = [
'--default-prefix-length', self._subnet_pool.default_prefixlen,
'--max-prefix-length', self._subnet_pool.max_prefixlen,
'--min-prefix-length', self._subnet_pool.min_prefixlen,
self._subnet_pool.name,
]
verifylist = [
('default_prefix_length', self._subnet_pool.default_prefixlen),
('max_prefix_length', self._subnet_pool.max_prefixlen),
('min_prefix_length', self._subnet_pool.min_prefixlen),
('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_with(**{
'default_prefix_length': self._subnet_pool.default_prefixlen,
'max_prefix_length': self._subnet_pool.max_prefixlen,
'min_prefix_length': self._subnet_pool.min_prefixlen,
'name': self._subnet_pool.name,
})
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
def test_create_len_negative(self):
arglist = [
self._subnet_pool.name,
'--min-prefix-length', '-16',
]
verifylist = [
('subnet_pool', self._subnet_pool.name),
('min_prefix_length', '-16'),
]
self.assertRaises(argparse.ArgumentTypeError, self.check_parser,
self.cmd, arglist, verifylist)
class TestDeleteSubnetPool(TestSubnetPool):
# The subnet pool to delete.

View File

@ -355,6 +355,7 @@ openstack.network.v2 =
subnet_list = openstackclient.network.v2.subnet:ListSubnet
subnet_show = openstackclient.network.v2.subnet:ShowSubnet
subnet_pool_create = openstackclient.network.v2.subnet_pool:CreateSubnetPool
subnet_pool_delete = openstackclient.network.v2.subnet_pool:DeleteSubnetPool
subnet_pool_list = openstackclient.network.v2.subnet_pool:ListSubnetPool
subnet_pool_set = openstackclient.network.v2.subnet_pool:SetSubnetPool