Skip to content

Commit

Permalink
Added try catch and terminal output to webex builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan-Prescott committed Sep 20, 2024
1 parent 2ce1064 commit f006b30
Showing 1 changed file with 58 additions and 28 deletions.
86 changes: 58 additions & 28 deletions odins_spear/scripts/webex_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"]
Expand All @@ -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:
Expand All @@ -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 = {
Expand All @@ -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

0 comments on commit f006b30

Please sign in to comment.