Parse provider network attributes in net_create

Currently when provider network attributes are placed before the network
name in neutron net-create command, the network name is incorrectly parsed
to one of the provider attribute values. This patch addresses the issue by
parsing the provider network attributes, which inturn allows us to place
these attributes at any location in the argument list.

Closes-Bug: #1384984
Change-Id: I930ced12d1f6747df91a47af8f34585ed36b84f3
This commit is contained in:
sridhargaddam 2014-11-16 13:56:57 +00:00
parent adf358d2b0
commit cb5d462f6e
2 changed files with 37 additions and 2 deletions
neutronclient
neutron/v2_0
tests/unit

@ -124,6 +124,21 @@ class CreateNetwork(neutronV20.CreateCommand):
action='store_true',
help=_('Set network as external, it is only available for admin'),
default=argparse.SUPPRESS)
parser.add_argument(
'--provider:network_type',
metavar='<network_type>',
help=_('The physical mechanism by which the virtual network'
' is implemented.'))
parser.add_argument(
'--provider:physical_network',
metavar='<physical_network_name>',
help=_('Name of the physical network over which the virtual'
' network is implemented.'))
parser.add_argument(
'--provider:segmentation_id',
metavar='<segmentation_id>',
help=_('VLAN ID for VLAN networks or tunnel-id for GRE/VXLAN'
' networks.'))
parser.add_argument(
'name', metavar='NAME',
help=_('Name of network to create.'))
@ -133,8 +148,10 @@ class CreateNetwork(neutronV20.CreateCommand):
'name': parsed_args.name,
'admin_state_up': parsed_args.admin_state}, }
neutronV20.update_dict(parsed_args, body['network'],
['shared', 'tenant_id', 'router:external'])
['shared', 'tenant_id', 'router:external',
'provider:network_type',
'provider:physical_network',
'provider:segmentation_id'])
return body

@ -72,6 +72,24 @@ class CLITestV20NetworkJSON(test_cli20.CLITestV20Base):
position_names, position_values,
tenant_id='tenantid')
def test_create_network_provider_args(self):
"""Create net: with --provider arguments."""
resource = 'network'
cmd = network.CreateNetwork(test_cli20.MyApp(sys.stdout), None)
name = 'myname'
myid = 'myid'
# Test --provider attributes before network name
args = ['--provider:network_type', 'vlan',
'--provider:physical_network', 'physnet1',
'--provider:segmentation_id', '400', name]
position_names = ['provider:network_type',
'provider:physical_network',
'provider:segmentation_id', 'name']
position_values = ['vlan', 'physnet1', '400', name]
self._test_create_resource(resource, cmd, name, myid, args,
position_names, position_values)
def test_create_network_tags(self):
"""Create net: myname --tags a b."""
resource = 'network'