From f006b301b20a5f49c801c8d9af2960f2d1be1fb9 Mon Sep 17 00:00:00 2001 From: Jordan Prescott Date: Fri, 20 Sep 2024 09:45:07 +0100 Subject: [PATCH] Added try catch and terminal output to webex builder --- odins_spear/scripts/webex_builder.py | 86 +++++++++++++++++++--------- 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/odins_spear/scripts/webex_builder.py b/odins_spear/scripts/webex_builder.py index 7eb3572..9f715fe 100644 --- a/odins_spear/scripts/webex_builder.py +++ b/odins_spear/scripts/webex_builder.py @@ -3,6 +3,7 @@ def main(api, service_provider_id, group_id, user_id, device_type, email, primary_device, webex_feature_pack_name): + print("Start.\n") # Update the email & alt user id email_alt_userid = { "emailAddress": email, @@ -14,24 +15,36 @@ def main(api, service_provider_id, group_id, user_id, device_type, ] } - api.put.user( - service_provider_id, - group_id, - user_id, - updates=email_alt_userid - ) + try: + api.put.user( + service_provider_id, + group_id, + user_id, + updates=email_alt_userid + ) + print("Updated email and alt user ID.") + except Exception as e: + print(f"\tERROR: Failed to update users email and alt user ID. Detail: {e}") # Assign feature pack - if webex_feature_pack_name: - api.put.user_services( - user_id=user_id, - service_packs=[webex_feature_pack_name] - ) + try: + if webex_feature_pack_name: + api.put.user_services( + user_id=user_id, + service_packs=[webex_feature_pack_name] + ) + print(f"Added feature: {webex_feature_pack_name}") + except Exception: + print(f"\tERROR: Failed to add feature - {webex_feature_pack_name}. Detail: {e}") # enable IMP in service settings enable_IMP = {'Integrated IMP': {'isActive': True}} - api.put.user_service_settings(user_id=user_id, settings=enable_IMP) - + try: + api.put.user_service_settings(user_id=user_id, settings=enable_IMP) + print("Enabled integrated IMP.") + except Exception as e: + print(f"\tERROR: Failed to enable Integrated IMP. Detail: {e}") + # build device device_name = f"{user_id.split('@')[0]}_WBX" device_password = api.get.password_generate(service_provider_id, group_id)["password"] @@ -45,13 +58,17 @@ def main(api, service_provider_id, group_id, user_id, device_type, "userName": device_name } - api.post.group_device( - service_provider_id=service_provider_id, - group_id=group_id, - device_name=device_name, - device_type=device_type, - payload=device_payload - ) + try: + api.post.group_device( + service_provider_id=service_provider_id, + group_id=group_id, + device_name=device_name, + device_type=device_type, + payload=device_payload + ) + print("Built device.") + except Exception as e: + print(f"\tERROR: Failed to build device. Detail: {e}") # Add device to user based on primary flag - JP if primary_device: @@ -68,17 +85,29 @@ def main(api, service_provider_id, group_id, user_id, device_type, "linePort": user_id, } } - api.put.user(service_provider_id, group_id, user_id, primary_device_configuration) + try: + api.put.user(service_provider_id, group_id, user_id, primary_device_configuration) + print("Added device to user as primary.") + except Exception as e: + print(f"\tERROR: Failed to add device as primary. Detail: {e}") else: - api.post.user_shared_call_appearance_endpoint( - user_id, - user_id.replace("@", "_WBX@"), - device_name - ) + try: + api.post.user_shared_call_appearance_endpoint( + user_id, + user_id.replace("@", "_WBX@"), + device_name + ) + print("Added device as shared call appearance.") + except Exception as e: + print(f"\tERROR: Failed to add devie as shared call appearance. Detail {e}") # Get webex password - password = api.get.password_generate(service_provider_id, group_id)["password"] - api.put.user_web_authentication_password(user_id, password) + try: + password = api.get.password_generate(service_provider_id, group_id)["password"] + api.put.user_web_authentication_password(user_id, password) + print("Set webex password.") + except Exception as e: + print(f"\tERROR: Failed to set webex password. Detail {e}") # Return formatted data webex_user_details = { @@ -88,4 +117,5 @@ def main(api, service_provider_id, group_id, user_id, device_type, "device_type": device_type } + print("\nEnd.") return webex_user_details \ No newline at end of file