From 9794ce94de2aeb97fe6f3c019f024d16a7b77188 Mon Sep 17 00:00:00 2001 From: Ben Greear Date: Thu, 21 Jan 2021 10:22:58 -0800 Subject: [PATCH] cloudsdk: Support deleting equipment profiles. Signed-off-by: Ben Greear --- unit_tests/Nightly_Sanity.py | 6 +++--- unit_tests/cloudsdk.py | 12 +++++++++++- unit_tests/query_sdk.py | 29 ++++++++++++++++++----------- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/unit_tests/Nightly_Sanity.py b/unit_tests/Nightly_Sanity.py index 376464ee7..00388dff7 100755 --- a/unit_tests/Nightly_Sanity.py +++ b/unit_tests/Nightly_Sanity.py @@ -637,7 +637,7 @@ for key in equipment_ids: # First, remove any existing profiles # Paginated reads means we get an array of json objects back, one object per 'page' - # NOTE: Cloud gives error when I try to remove these. Not sure removal works? + # NOTE: You cannot remove profiles in use #profs = cloud.get_customer_profiles(cloudSDK_url, bearer, customer_id) #for p in profs: # for e in p['items']: @@ -650,11 +650,11 @@ for key in equipment_ids: # for pn in prof_names: # if pn == prof_name: # print("Deleting existing profile name: ", pn) - # cloud.delete_customer_profile(cloudSDK_url, bearer, customer_id, prof_id) + # cloud.delete_profile(cloudSDK_url, bearer, prof_id) # for pn in prof_names_eap: # if pn == prof_name: # print("Deleting existing profile name: ", pn) - # cloud.delete_customer_profile(cloudSDK_url, bearer, customer_id, prof_id) + # cloud.delete_profile(cloudSDK_url, bearer, prof_id) ### Create RADIUS profile - used for all EAP SSIDs radius_template = "Radius-Profile" # Default radius profile found in cloud-sdk diff --git a/unit_tests/cloudsdk.py b/unit_tests/cloudsdk.py index a64cfba54..5675f4614 100755 --- a/unit_tests/cloudsdk.py +++ b/unit_tests/cloudsdk.py @@ -178,7 +178,7 @@ class CloudSDK: return e return None - def delete_customer_profile(self, cloudSDK_url, bearer, customer_id, profile_id): + def delete_customer_profile(self, cloudSDK_url, bearer, profile_id): url = cloudSDK_url + '/portal/profile/?profileId=' + profile_id print("Deleting customer profile with url: " + url) payload = {} @@ -188,6 +188,16 @@ class CloudSDK: response = requests.request("DELETE", url, headers=headers, data=payload) return(response) + def delete_equipment(self, cloudSDK_url, bearer, eq_id): + url = cloudSDK_url + '/portal/equipment/?equipmentId=' + eq_id + print("Deleting equipment with url: " + url) + payload = {} + headers = { + 'Authorization': 'Bearer ' + bearer + } + response = requests.request("DELETE", url, headers=headers, data=payload) + return(response) + def get_customer_locations(self, cloudSDK_url, bearer, customer_id): url_base = cloudSDK_url + "/portal/location/forCustomer" + "?customerId=" + customer_id return self.get_paged_url(bearer, url_base) diff --git a/unit_tests/query_sdk.py b/unit_tests/query_sdk.py index 922e91ada..0e3dab1f7 100755 --- a/unit_tests/query_sdk.py +++ b/unit_tests/query_sdk.py @@ -46,14 +46,14 @@ if qtype == 'all' or qtype == 'profile': if cmd == "delete": delid = base.command_line_args.object_id; if delid.isdigit(): - rv = base.cloud.delete_customer_profile(base.cloudSDK_url, base.bearer, base.customer_id, base.command_line_args.object_id) + rv = base.cloud.delete_profile(base.cloudSDK_url, base.bearer, base.command_line_args.object_id) print("Delete profile for customer %s, id: %s results:"%(base.customer_id, base.command_line_args.object_id)) print(rv.json()) else: # Query object by name to find its ID targets = get_profile(base.cloudSDK_url, base.bearer, base.customer_id, base.command_line_args.object_id) for me in targets: - rv = base.cloud.delete_customer_profile(base.cloudSDK_url, base.bearer, base.customer_id, str(me['id'])) + rv = base.cloud.delete_profile(base.cloudSDK_url, base.bearer, str(me['id'])) print("Delete profile for customer %s, id: %s results:"%(base.customer_id, base.command_line_args.object_id)) print(rv.json()) @@ -107,15 +107,22 @@ if qtype == 'all' or qtype == 'location': if qtype == 'all' or qtype == 'equipment': # Get equipment info try: - rv = base.cloud.get_customer_equipment(base.cloudSDK_url, base.bearer, base.customer_id) - print("Equipment for customer %s:"%(base.customer_id)) - #jobj = json.load(ssids) - for e in rv: - if brief: - for eq in e['items']: - print("Equipment id: %s inventoryId: %s profileId: %s type: %s"%(eq['id'], eq['inventoryId'], eq['profileId'], eq['equipmentType'])) - else: - print(json.dumps(e, indent=4, sort_keys=True)) + if cmd == "get": + rv = base.cloud.get_customer_equipment(base.cloudSDK_url, base.bearer, base.customer_id) + print("Equipment for customer %s:"%(base.customer_id)) + #jobj = json.load(ssids) + for e in rv: + if brief: + for eq in e['items']: + print("Equipment id: %s inventoryId: %s profileId: %s type: %s"%(eq['id'], eq['inventoryId'], eq['profileId'], eq['equipmentType'])) + else: + print(json.dumps(e, indent=4, sort_keys=True)) + if cmd == "delete": + delid = base.command_line_args.object_id; + rv = base.cloud.delete_equipment(base.cloudSDK_url, base.bearer, base.command_line_args.object_id) + print("Delete Equipment, id: %s results:"%(base.command_line_args.object_id)) + print(rv.json()) + except Exception as ex: print(ex)