diff --git a/neutronclient/neutron/v2_0/subnetpool.py b/neutronclient/neutron/v2_0/subnetpool.py index 54926b0..0631a19 100644 --- a/neutronclient/neutron/v2_0/subnetpool.py +++ b/neutronclient/neutron/v2_0/subnetpool.py @@ -45,7 +45,7 @@ class ListSubnetPool(neutronV20.ListCommand): resource = 'subnetpool' list_columns = ['id', 'name', 'prefixes', - 'default_prefixlen'] + 'default_prefixlen', 'address-scope'] pagination_support = True sorting_support = True @@ -70,12 +70,25 @@ class CreateSubnetPool(neutronV20.CreateCommand): parser.add_argument( 'name', help=_('Name of subnetpool to create.')) + parser.add_argument( + '--address-scope', + metavar='ADDRSCOPE', + help=_('ID or name of the address scope with which the subnetpool ' + 'is associated. Prefixes must be unique across address ' + 'scopes')) def args2body(self, parsed_args): body = {'subnetpool': {'prefixes': parsed_args.prefixes}} updatable_args2body(parsed_args, body) if parsed_args.shared: body['subnetpool']['shared'] = True + + # Parse and update for "address-scope" option + if parsed_args.address_scope: + _addrscope_id = neutronV20.find_resourceid_by_name_or_id( + self.get_client(), 'address-scope', + parsed_args.address_scope) + body['subnetpool']['address_scope_id'] = _addrscope_id return body @@ -94,8 +107,28 @@ class UpdateSubnetPool(neutronV20.UpdateCommand): add_updatable_arguments(parser) parser.add_argument('--name', help=_('Name of subnetpool to update.')) + addrscope_args = parser.add_mutually_exclusive_group() + addrscope_args.add_argument('--address-scope', + metavar='ADDRSCOPE', + help=_('ID or name of the address scope ' + 'with which the subnetpool is ' + 'associated. Prefixes must be ' + 'unique across address scopes')) + addrscope_args.add_argument('--no-address-scope', + action='store_true', + help=_('Detach subnetpool from the ' + 'address scope')) def args2body(self, parsed_args): body = {'subnetpool': {}} updatable_args2body(parsed_args, body, for_create=False) + + # Parse and update for "address-scope" option/s + if parsed_args.no_address_scope: + body['subnetpool']['address_scope_id'] = None + elif parsed_args.address_scope: + _addrscope_id = neutronV20.find_resourceid_by_name_or_id( + self.get_client(), 'address-scope', + parsed_args.address_scope) + body['subnetpool']['address_scope_id'] = _addrscope_id return body diff --git a/neutronclient/tests/unit/test_cli20_subnetpool.py b/neutronclient/tests/unit/test_cli20_subnetpool.py index 782d74d..9873e84 100644 --- a/neutronclient/tests/unit/test_cli20_subnetpool.py +++ b/neutronclient/tests/unit/test_cli20_subnetpool.py @@ -75,6 +75,26 @@ class CLITestV20SubnetPoolJSON(test_cli20.CLITestV20Base): self._test_create_resource(resource, cmd, name, myid, args, position_names, position_values) + def test_create_subnetpool_with_addrscope(self): + """Create subnetpool: myname in addrscope: foo-address-scope""" + resource = 'subnetpool' + cmd = subnetpool.CreateSubnetPool(test_cli20.MyApp(sys.stdout), None) + name = 'myname' + myid = 'myid' + min_prefixlen = 30 + prefix1 = '11.11.11.0/24' + prefix2 = '12.12.12.0/24' + address_scope = 'foo-address-scope' + args = [name, '--min-prefixlen', str(min_prefixlen), + '--pool-prefix', prefix1, '--pool-prefix', prefix2, + '--address-scope', address_scope] + position_names = ['name', 'min_prefixlen', 'prefixes', + 'address_scope_id'] + position_values = [name, min_prefixlen, [prefix1, prefix2], + address_scope] + self._test_create_resource(resource, cmd, name, myid, args, + position_names, position_values) + def test_list_subnetpool_pagination(self): cmd = subnetpool.ListSubnetPool(test_cli20.MyApp(sys.stdout), None) self.mox.StubOutWithMock(subnetpool.ListSubnetPool, "extend_list") @@ -115,6 +135,24 @@ class CLITestV20SubnetPoolJSON(test_cli20.CLITestV20Base): {'name': 'myname'} ) + def test_update_subnetpool_with_address_scope(self): + """Update subnetpool: myid --address-scope newscope.""" + resource = 'subnetpool' + cmd = subnetpool.UpdateSubnetPool(test_cli20.MyApp(sys.stdout), None) + self._test_update_resource(resource, cmd, 'myid', + ['myid', '--address-scope', 'newscope'], + {'address_scope_id': 'newscope'} + ) + + def test_update_subnetpool_with_no_address_scope(self): + """Update subnetpool: myid --no-address-scope.""" + resource = 'subnetpool' + cmd = subnetpool.UpdateSubnetPool(test_cli20.MyApp(sys.stdout), None) + self._test_update_resource(resource, cmd, 'myid', + ['myid', '--no-address-scope'], + {'address_scope_id': None} + ) + def test_show_subnetpool(self): """Show subnetpool: --fields id --fields name myid.""" resource = 'subnetpool'