From d3074268218aa3e1e00153cc73fd18b7022b0cef Mon Sep 17 00:00:00 2001 From: Kent Wu Date: Wed, 12 Oct 2016 14:28:57 -0700 Subject: [PATCH] [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 --- gbpclient/gbp/v2_0/groupbasedpolicy.py | 14 ++++++++-- gbpclient/tests/unit/test_cli20_l3policy.py | 29 +++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/gbpclient/gbp/v2_0/groupbasedpolicy.py b/gbpclient/gbp/v2_0/groupbasedpolicy.py index 72c4895..41a09ac 100644 --- a/gbpclient/gbp/v2_0/groupbasedpolicy.py +++ b/gbpclient/gbp/v2_0/groupbasedpolicy.py @@ -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 diff --git a/gbpclient/tests/unit/test_cli20_l3policy.py b/gbpclient/tests/unit/test_cli20_l3policy.py index f1df4c9..a2a47cb 100644 --- a/gbpclient/tests/unit/test_cli20_l3policy.py +++ b/gbpclient/tests/unit/test_cli20_l3policy.py @@ -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)