From ee6b6eafb7799f7066d437f826deb39bd3172c87 Mon Sep 17 00:00:00 2001 From: Armando Migliaccio Date: Tue, 23 Aug 2016 17:13:28 -0700 Subject: [PATCH] Provide client bindings for DELETE method of auto-allocated-topology extension DocImpact: Add documentation for auto-allocate-topology-delete CLI Partial-bug: #1614872 Depends-on: I2fba51bdf8c781fcc0449e1e9947de976c96eec4 Change-Id: I07ef85e4a0c43613351820bd56e429d0155c9fa5 --- .../neutron/v2_0/auto_allocated_topology.py | 32 +++++++++++++++++++ neutronclient/shell.py | 2 ++ .../unit/test_auto_allocated_topology.py | 21 ++++++++++++ neutronclient/v2_0/client.py | 8 +++++ ...ated-topology-delete-aaccd60bd0f2e7b2.yaml | 4 +++ 5 files changed, 67 insertions(+) create mode 100644 releasenotes/notes/add-auto-allocated-topology-delete-aaccd60bd0f2e7b2.yaml diff --git a/neutronclient/neutron/v2_0/auto_allocated_topology.py b/neutronclient/neutron/v2_0/auto_allocated_topology.py index 3f0f58baf..12ca4dbd1 100644 --- a/neutronclient/neutron/v2_0/auto_allocated_topology.py +++ b/neutronclient/neutron/v2_0/auto_allocated_topology.py @@ -14,6 +14,8 @@ # under the License. # +from __future__ import print_function + import argparse from cliff import show from oslo_serialization import jsonutils @@ -79,3 +81,33 @@ class ShowAutoAllocatedTopology(v2_0.NeutronCommand, show.ShowOne): return zip(*sorted(data[self.resource].items())) else: return None + + +class DeleteAutoAllocatedTopology(v2_0.NeutronCommand): + """Delete the auto-allocated topology of a given tenant.""" + + resource = 'auto_allocated_topology' + + def get_parser(self, prog_name): + parser = super(DeleteAutoAllocatedTopology, self).get_parser(prog_name) + parser.add_argument( + '--tenant-id', metavar='tenant-id', + help=_('The owner tenant ID.')) + # Allow people to do + # neutron auto-allocated-topology-delete + # (Only useful to users who can look at other tenants' topologies.) + # We use a different name for this arg because the default will + # override whatever is in the named arg otherwise. + parser.add_argument( + 'pos_tenant_id', + help=argparse.SUPPRESS, nargs='?') + return parser + + def take_action(self, parsed_args): + client = self.get_client() + tenant_id = parsed_args.tenant_id or parsed_args.pos_tenant_id + client.delete_auto_allocated_topology(tenant_id) + # It tenant is None, let's be clear on what it means. + tenant_id = tenant_id or 'None (i.e. yours)' + print(_('Deleted topology for tenant %s.') % tenant_id, + file=self.app.stdout) diff --git a/neutronclient/shell.py b/neutronclient/shell.py index 831996c1d..dad8d48ed 100644 --- a/neutronclient/shell.py +++ b/neutronclient/shell.py @@ -413,6 +413,8 @@ COMMAND_V2 = { 'availability-zone-list': availability_zone.ListAvailabilityZone, 'auto-allocated-topology-show': ( auto_allocated_topology.ShowAutoAllocatedTopology), + 'auto-allocated-topology-delete': ( + auto_allocated_topology.DeleteAutoAllocatedTopology), 'bgp-dragent-speaker-add': ( bgp_drsched.AddBGPSpeakerToDRAgent ), diff --git a/neutronclient/tests/unit/test_auto_allocated_topology.py b/neutronclient/tests/unit/test_auto_allocated_topology.py index af2742b0e..e2f7e5b13 100644 --- a/neutronclient/tests/unit/test_auto_allocated_topology.py +++ b/neutronclient/tests/unit/test_auto_allocated_topology.py @@ -53,3 +53,24 @@ class TestAutoAllocatedTopologyJSON(test_cli20.CLITestV20Base): args = ['--dry-run', 'some-tenant'] self._test_show_resource(resource, cmd, "some-tenant", args, fields=('dry-run',)) + + def test_delete_auto_allocated_topology_arg(self): + resource = 'auto_allocated_topology' + cmd = aat.DeleteAutoAllocatedTopology(test_cli20.MyApp(sys.stdout), + None) + args = ['--tenant-id', self.test_id] + self._test_delete_resource(resource, cmd, self.test_id, args) + + def test_delete_auto_allocated_topology_posarg(self): + resource = 'auto_allocated_topology' + cmd = aat.DeleteAutoAllocatedTopology(test_cli20.MyApp(sys.stdout), + None) + args = ['some-tenant'] + self._test_delete_resource(resource, cmd, "some-tenant", args) + + def test_delete_auto_allocated_topology_no_arg(self): + resource = 'auto_allocated_topology' + cmd = aat.DeleteAutoAllocatedTopology(test_cli20.MyApp(sys.stdout), + None) + args = [] + self._test_delete_resource(resource, cmd, "None", args) diff --git a/neutronclient/v2_0/client.py b/neutronclient/v2_0/client.py index 9c48fe009..3b6a5900e 100644 --- a/neutronclient/v2_0/client.py +++ b/neutronclient/v2_0/client.py @@ -1807,6 +1807,14 @@ class Client(ClientBase): self.auto_allocated_topology_path % project_id, params=_params) + @debtcollector.renames.renamed_kwarg( + 'tenant_id', 'project_id', replace=True) + def delete_auto_allocated_topology(self, project_id, **_params): + """Delete a project's auto-allocated topology.""" + return self.delete( + self.auto_allocated_topology_path % project_id, + params=_params) + @debtcollector.renames.renamed_kwarg( 'tenant_id', 'project_id', replace=True) def validate_auto_allocated_topology_requirements(self, project_id): diff --git a/releasenotes/notes/add-auto-allocated-topology-delete-aaccd60bd0f2e7b2.yaml b/releasenotes/notes/add-auto-allocated-topology-delete-aaccd60bd0f2e7b2.yaml new file mode 100644 index 000000000..84c395236 --- /dev/null +++ b/releasenotes/notes/add-auto-allocated-topology-delete-aaccd60bd0f2e7b2.yaml @@ -0,0 +1,4 @@ +--- +features: + - The ``auto-allocated-topology-delete`` command allows users to + delete the auto allocated topology.