Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

131 locate free extensions #139

Merged
merged 9 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions odins_spear/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,14 @@ class OSInvalidPasswordType(OSError):
"""

def __str__(self) -> str:
return f"Invalid or unsupported password, please review supported passwords."

return f"Invalid or unsupported password, please review supported passwords."

class OSExtensionNotFound(OSError):
""" Raised when a searched extension is not found
"""

def __str__(self) -> str:
return f"Cannot locate extension. Please alter search criteria"

class OSServiceNotAssigned(OSError):
""" Raised a service needed is not assigned to a Broadworks entity.
Expand All @@ -123,7 +129,6 @@ class OSServiceNotAssigned(OSError):
def __str__(self) -> str:
return f"Service not assigend to target Broadworks entity. Please check services assigned."


class OSFileNotFound(OSError):
""" Raised when a file can not be found.
"""
Expand Down
11 changes: 11 additions & 0 deletions odins_spear/scripter.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ def remove_numbers(self, service_provider_id: str, group_id: str, start_of_range
return scripts.remove_numbers.main(self.api, service_provider_id, group_id, start_of_range_number,
end_of_range_number)

def locate_free_extension(self, service_provider_id: str, group_id: str, extension_range: list):
"""Locates the lowest value free extension given the provided range of extension numbers.

Jordan-Prescott marked this conversation as resolved.
Show resolved Hide resolved
Note: The extension range is passed as a list like such [100, 1000]

Args:
service_provider_id (str): Service Provider/ Enterprise ID where Group is located which hosts needed free extensions
group_id (str): Group ID where target extensions are located.
extension_range (list): List value representing the search range for free extensions
"""
return scripts.locate_free_extension.main(self.api, service_provider_id, group_id, extension_range)

def service_provider_trunking_capacity(self, service_provider_id: str):
"""Returns a JSON breakdown of the Trunking Call Capacity of a Service Provider/ Enterprise (SP/ENT).
Expand Down
1 change: 1 addition & 0 deletions odins_spear/scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
from .user_activity import main
from .user_association import main
from .webex_builder import main
from .locate_free_extension import main
56 changes: 56 additions & 0 deletions odins_spear/scripts/locate_free_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from exceptions import OSExtensionNotFound

Jordan-Prescott marked this conversation as resolved.
Show resolved Hide resolved
def retrieve_extensions(
api,
service_provider_id: str,
group_id: str
) -> list:

extensions = []

dataset = (
api.get.users( service_provider_id, group_id ) +
api.get.group_hunt_groups( service_provider_id,group_id ) +
api.get.group_call_centers( service_provider_id, group_id ) +
api.get.auto_attendants( service_provider_id, group_id )
)

for data in dataset:
if not data['extension']:
continue

extensions.append(int(data['extension']))

return extensions if extensions else None

def main(
api,
service_provider_id: str,
group_id: str,
extension_range: list
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still the old param not the new start of and end of range.

):
'''Retrieves The Lowest Free Extension Available In The Designated Group Passed.
'''

if extension_range[0] > extension_range[1]:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can avoid this range adjusting by separating into two params and raise an error if the end is larger. Instead of extension_range remove this and introduce 'start_of_range' and 'end_of_range'. Then in the code you can create a new error and do the below:

if start_of_range > end_of_range:
raise OSInvalidInput <- example (check if we have an existing error you could throw)

initial_range = extension_range[1]

extension_range[1] = extension_range[0]
extension_range[0] = initial_range

# Retrieve List Of Occupied Extensions Within The Group
extensions = retrieve_extensions(
api,
service_provider_id,
group_id,
)

for extension in range(extension_range[0], extension_range[1] + 1):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can update this inline with the new params

if extension not in extensions:
return {'extension': extension}

raise OSExtensionNotFound