From 43d49d060122cf86859fe1395f6a9cb43b479bf7 Mon Sep 17 00:00:00 2001 From: Amit Bose Date: Thu, 17 Nov 2016 18:15:03 -0800 Subject: [PATCH] [Apic-mapping] Reuse BD option for L2 Policy CLI Partial-bug: 1642784 Change-Id: I51247322143eecc9d6ef035bccbd79e0ba529e07 Signed-off-by: Amit Bose --- gbpclient/gbp/v2_0/groupbasedpolicy.py | 11 ++++++++++- gbpclient/tests/unit/test_cli20_l2policy.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gbpclient/gbp/v2_0/groupbasedpolicy.py b/gbpclient/gbp/v2_0/groupbasedpolicy.py index a1703bf..85db642 100644 --- a/gbpclient/gbp/v2_0/groupbasedpolicy.py +++ b/gbpclient/gbp/v2_0/groupbasedpolicy.py @@ -393,6 +393,11 @@ class CreateL2Policy(neutronV20.CreateCommand): n_utils.add_boolean_argument( parser, '--shared', dest='shared', help=_('Enable or disable resource sharing, default is False')) + parser.add_argument( + '--reuse-bd', + default=None, + help=_('Name or UUID of L2 Policy whose BridgeDomain should ' + 'be reused (APIC only)')) def args2body(self, parsed_args): body = {self.resource: {}, } @@ -408,7 +413,11 @@ class CreateL2Policy(neutronV20.CreateCommand): if parsed_args.network: body[self.resource]['network_id'] = ( parsed_args.network) - + if parsed_args.reuse_bd: + body[self.resource]['reuse_bd'] = \ + neutronV20.find_resourceid_by_name_or_id( + self.get_client(), 'l2_policy', + parsed_args.reuse_bd) return body diff --git a/gbpclient/tests/unit/test_cli20_l2policy.py b/gbpclient/tests/unit/test_cli20_l2policy.py index e089822..7d77904 100644 --- a/gbpclient/tests/unit/test_cli20_l2policy.py +++ b/gbpclient/tests/unit/test_cli20_l2policy.py @@ -63,6 +63,23 @@ class CLITestV20L2PolicyJSON(test_cli20.CLITestV20Base): tenant_id=tenant_id, shared=shared, inject_default_route=inject_default_route) + def test_create_l2_policy_with_reuse_bd(self): + """l2-policy-create with reuse_bd option.""" + resource = 'l2_policy' + cmd = gbp.CreateL2Policy(test_cli20.MyApp(sys.stdout), None) + my_id = 'my-id' + tenant_id = 'my-tenant' + name = 'my-name' + target_l2p = 'another-l2p' + args = [name, + '--tenant-id', tenant_id, + '--reuse-bd', target_l2p] + position_names = ['name', 'reuse_bd'] + position_values = [name, target_l2p] + self._test_create_resource(resource, cmd, name, my_id, args, + position_names, position_values, + tenant_id=tenant_id) + def test_list_l2_policies(self): resource = 'l2_policies' cmd = gbp.ListL2Policy(test_cli20.MyApp(sys.stdout), None)