From c4a2cf6b1436b09537631a6ce82ce156daa3dc3a Mon Sep 17 00:00:00 2001 From: Shih-Hao Li Date: Mon, 1 Aug 2016 11:03:12 -0700 Subject: [PATCH] NSX|V3: Delete backend DHCP servers during devstack cleanup Add a new function to delete backend logical DHCP servers created via openstack plugin when running devstack cleanup script. Change-Id: Ib98c036af2d3e065eb73e9855501262aba30641a --- devstack/tools/nsxv3_cleanup.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/devstack/tools/nsxv3_cleanup.py b/devstack/tools/nsxv3_cleanup.py index fc52fb20df..8e3f302668 100755 --- a/devstack/tools/nsxv3_cleanup.py +++ b/devstack/tools/nsxv3_cleanup.py @@ -410,6 +410,37 @@ class NSXClient(object): for lr in tier0_routers: self.cleanup_logical_router_ports(lr) + def get_logical_dhcp_servers(self): + """ + Retrieve all logical DHCP servers on NSX backend + """ + response = self.get(endpoint="/dhcp/servers") + return response.json()['results'] + + def get_os_logical_dhcp_servers(self): + """ + Retrieve all logical DHCP servers created from OpenStack + """ + dhcp_servers = self.get_logical_dhcp_servers() + return self.get_os_resources(dhcp_servers) + + def cleanup_os_logical_dhcp_servers(self): + """ + Cleanup all logical DHCP servers created from OpenStack plugin + """ + dhcp_servers = self.get_os_logical_dhcp_servers() + print("Number of OS Logical DHCP Servers to be deleted: %s" % + len(dhcp_servers)) + for server in dhcp_servers: + endpoint = "/dhcp/servers/%s" % server['id'] + response = self.delete(endpoint=endpoint) + if response.status_code == requests.codes.ok: + print("Successfully deleted logical DHCP server: %s" % + server['display_name']) + else: + print("Failed to delete logical DHCP server: %s" % + server['display_name']) + def cleanup_all(self): """ Cleanup steps: @@ -427,6 +458,7 @@ class NSXClient(object): self.cleanup_os_tier0_logical_ports() self.cleanup_os_logical_ports() self.cleanup_os_logical_switches() + self.cleanup_os_logical_dhcp_servers() self.cleanup_os_switching_profiles()