AdminUtil: using nsxlib func for orphan dhcp rm

Removing abuse and using get_by_attachement function
in nsxlib, in order to get the API url.

Change-Id: I68786ca57275d3d1e358b1b877947188823013c2
Signed-off-by: Michal Kelner Mishali <mkelnermishal@vmware.com>
This commit is contained in:
Michal Kelner Mishali 2018-03-08 10:36:29 +02:00
parent 3cac9174d8
commit 1427c83397

@ -140,11 +140,8 @@ def nsx_clean_orphaned_dhcp_servers(resource, event, trigger, **kwargs):
for server in orphaned_servers:
try:
# TODO(asarfaty): should add this as api to nsxlib instead of
# abusing it
resource = ('?attachment_type=DHCP_SERVICE&attachment_id=%s' %
server['id'])
response = nsxlib.logical_port.get(resource)
response = nsxlib.logical_port.get_by_attachment('DHCP_SERVICE',
server['id'])
if response and response['result_count'] > 0:
nsxlib.logical_port.delete(response['results'][0]['id'])
nsxlib.dhcp_server.delete(server['id'])