Create new IPv6 attributes for Subnets by client

This is the client implementation of bp ipv6-two-attributes.
Add two optional arguments:
 --ipv6-ra-mode
 --ipv6-address-mode

Partially implements bp ipv6-two-attributes

Change-Id: Ia922a9b6bb4e1dbd372174d48f29f5411c7b5674
This commit is contained in:
Xuhan Peng
2014-02-24 08:46:21 -05:00
committed by Xu Han Peng
parent e0591432fc
commit 4927f74a8e
2 changed files with 112 additions and 0 deletions

View File

@@ -84,6 +84,14 @@ def add_updatable_arguments(parser):
'--enable-dhcp',
action='store_true',
help=_('Enable DHCP for this subnet.'))
parser.add_argument(
'--ipv6-ra-mode',
choices=['dhcpv6-stateful', 'dhcpv6-stateless', 'slaac'],
help=_('IPv6 RA (Router Advertisement) mode.'))
parser.add_argument(
'--ipv6-address-mode',
choices=['dhcpv6-stateful', 'dhcpv6-stateless', 'slaac'],
help=_('IPv6 address mode.'))
def updatable_args2body(parsed_args, body):
@@ -111,6 +119,17 @@ def updatable_args2body(parsed_args, body):
body['subnet']['host_routes'] = parsed_args.host_routes
if parsed_args.dns_nameservers:
body['subnet']['dns_nameservers'] = parsed_args.dns_nameservers
if parsed_args.ipv6_ra_mode:
if parsed_args.ip_version == 4:
raise exceptions.CommandError(_("--ipv6-ra-mode is invalid "
"when --ip-version is 4"))
body['subnet']['ipv6_ra_mode'] = parsed_args.ipv6_ra_mode
if parsed_args.ipv6_address_mode:
if parsed_args.ip_version == 4:
raise exceptions.CommandError(_("--ipv6-address-mode is "
"invalid when --ip-version "
"is 4"))
body['subnet']['ipv6_address_mode'] = parsed_args.ipv6_address_mode
class ListSubnet(neutronV20.ListCommand):

View File

@@ -336,6 +336,99 @@ class CLITestV20SubnetJSON(test_cli20.CLITestV20Base):
self.mox.VerifyAll()
self.mox.UnsetStubs()
def test_create_subnet_with_ipv6_ra_mode(self):
resource = 'subnet'
cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
name = 'myname'
myid = 'myid'
netid = 'netid'
cidr = 'prefixvalue'
args = ['--tenant_id', 'tenantid',
'--ip-version', '6',
'--ipv6-ra-mode', 'dhcpv6-stateful',
netid, cidr]
position_names = ['ip_version', 'ipv6_ra_mode',
'network_id', 'cidr']
position_values = [6, 'dhcpv6-stateful', netid, cidr]
self._test_create_resource(resource, cmd, name, myid, args,
position_names, position_values,
tenant_id='tenantid')
def test_create_subnet_with_ipv6_address_mode(self):
resource = 'subnet'
cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
name = 'myname'
myid = 'myid'
netid = 'netid'
cidr = 'prefixvalue'
args = ['--tenant_id', 'tenantid',
'--ip-version', '6',
'--ipv6-address-mode', 'dhcpv6-stateful',
netid, cidr]
position_names = ['ip_version', 'ipv6_address_mode',
'network_id', 'cidr']
position_values = [6, 'dhcpv6-stateful', netid, cidr]
self._test_create_resource(resource, cmd, name, myid, args,
position_names, position_values,
tenant_id='tenantid')
def test_create_subnet_with_ipv6_modes(self):
resource = 'subnet'
cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
name = 'myname'
myid = 'myid'
netid = 'netid'
cidr = 'prefixvalue'
args = ['--tenant_id', 'tenantid',
'--ip-version', '6',
'--ipv6-address-mode', 'slaac',
'--ipv6-ra-mode', 'slaac',
netid, cidr]
position_names = ['ip_version', 'ipv6_address_mode',
'ipv6_ra_mode', 'network_id', 'cidr']
position_values = [6, 'slaac', 'slaac', netid, cidr]
self._test_create_resource(resource, cmd, name, myid, args,
position_names, position_values,
tenant_id='tenantid')
def test_create_subnet_with_ipv6_ra_mode_ipv4(self):
resource = 'subnet'
cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
name = 'myname'
myid = 'myid'
netid = 'netid'
cidr = 'prefixvalue'
args = ['--tenant_id', 'tenantid',
'--ip-version', '4',
'--ipv6-ra-mode', 'slaac',
netid, cidr]
position_names = ['ip_version', 'ipv6_ra_mode',
'network_id', 'cidr']
position_values = [4, None, netid, cidr]
self.assertRaises(exceptions.CommandError, self._test_create_resource,
resource, cmd, name, myid, args, position_names,
position_values, tenant_id='tenantid')
def test_create_subnet_with_ipv6_address_mode_ipv4(self):
resource = 'subnet'
cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
name = 'myname'
myid = 'myid'
netid = 'netid'
cidr = 'prefixvalue'
args = ['--tenant_id', 'tenantid',
'--ip-version', '4',
'--ipv6-address-mode', 'slaac',
netid, cidr]
position_names = ['ip_version', 'ipv6_address_mode',
'network_id', 'cidr']
position_values = [4, None, netid, cidr]
self.assertRaises(exceptions.CommandError, self._test_create_resource,
resource, cmd, name, myid, args, position_names,
position_values, tenant_id='tenantid')
def test_list_subnets_detail(self):
"""List subnets: -D."""
resources = "subnets"