[apic-mapping] Allowed VM Name extension for L3 Policy CLI

The patch: https://review.openstack.org/#/c/385218/ introduced a new extension
cisco_apic_gbp_allowed_vm_name for the apic policy drivers. An extension
attribute: allowed_vm_names, that extends the L3 Policy definition, is
being introduced in that extension. The allowed_vm_names attribute is a
list of regex strings. This patch introduces a CLI option: --allowed-vm-names
for the l3_policy create and update operations. This CLI option accepts a
comma separated regex string as the option value.

Change-Id: I3d038398a2033d47eeb37ce5f48061d42eae86e4
This commit is contained in:
Kent Wu 2016-10-12 14:28:57 -07:00
parent 1d4cbfb193
commit d307426821
2 changed files with 41 additions and 2 deletions

View File

@ -510,6 +510,10 @@ class CreateL3Policy(neutronV20.CreateCommand):
parser.add_argument(
'name', metavar='NAME',
help=_('Name of L3 policy to create (required argument)'))
parser.add_argument(
'--allowed-vm-names', type=utils.str2list,
help=_('Comma separated list of allowed VM name regexes, each '
'regex can be up to 255 characters.'))
n_utils.add_boolean_argument(
parser, '--shared', dest='shared',
help=_('Enable or disable resource sharing, default is False'))
@ -535,7 +539,8 @@ class CreateL3Policy(neutronV20.CreateCommand):
neutronV20.update_dict(parsed_args, body[self.resource],
['name', 'tenant_id', 'description',
'ip_version', 'ip_pool', 'routers',
'subnet_prefix_length', 'shared'])
'subnet_prefix_length', 'shared',
'allowed_vm_names'])
return body
@ -576,6 +581,10 @@ class UpdateL3Policy(neutronV20.UpdateCommand):
parser.add_argument(
'--name',
help=_('New name of the L3 Policy'))
parser.add_argument(
'--allowed-vm-names', type=utils.str2list,
help=_('Comma separated list of allowed VM name regexes, each '
'regex can be up to 255 characters.'))
n_utils.add_boolean_argument(
parser, '--shared', dest='shared',
help=_('Enable or disable resource sharing'))
@ -603,7 +612,8 @@ class UpdateL3Policy(neutronV20.UpdateCommand):
neutronV20.update_dict(parsed_args, body[self.resource],
['name', 'tenant_id', 'description',
'ip_version', 'ip_pool', 'routers',
'subnet_prefix_length', 'shared'])
'subnet_prefix_length', 'shared',
'allowed_vm_names'])
return body

View File

@ -96,6 +96,23 @@ class CLITestV20L3PolicyJSON(test_cli20.CLITestV20Base):
external_segments=
expected_external_segments)
def test_create_l3_policy_with_allowed_vm_names(self):
resource = 'l3_policy'
cmd = gbp.CreateL3Policy(test_cli20.MyApp(sys.stdout), None)
name = 'name'
tenant_id = 'mytenant'
my_id = 'someid'
allowed_vm_names = "^safe_vm*,good_vm*"
args = ['--tenant-id', tenant_id,
'--allowed-vm-names', allowed_vm_names,
name]
position_names = ['name', ]
position_values = [name, ]
self._test_create_resource(resource, cmd, name, my_id, args,
position_names, position_values,
tenant_id=tenant_id,
allowed_vm_names=['^safe_vm*', 'good_vm*'])
def test_list_l3_policies(self):
resource = 'l3_policies'
cmd = gbp.ListL3Policy(test_cli20.MyApp(sys.stdout), None)
@ -178,6 +195,18 @@ class CLITestV20L3PolicyJSON(test_cli20.CLITestV20Base):
}
self._test_update_resource(resource, cmd, my_id, args, params)
def test_update_l3_policy_with_allowed_vm_names(self):
resource = 'l3_policy'
cmd = gbp.UpdateL3Policy(test_cli20.MyApp(sys.stdout), None)
my_id = 'someid'
allowed_vm_names = "bad_vm*,^worse_vm*"
args = ['--allowed-vm-names', allowed_vm_names,
my_id]
params = {
'allowed_vm_names': ['bad_vm*', '^worse_vm*'],
}
self._test_update_resource(resource, cmd, my_id, args, params)
def test_delete_l3_policy_name(self):
resource = 'l3_policy'
cmd = gbp.DeleteL3Policy(test_cli20.MyApp(sys.stdout), None)