Exemple #1
0
def oxe_create_user(host, token, extension, last_name, first_name,
                    station_type, max_retries):
    """Summary

    Args:
        host (TYPE): Description
        token (TYPE): Description
        extension (TYPE): Description
        last_name (TYPE): Description
        first_name (TYPE): Description
        station_type (TYPE): Description
        max_retries (TYPE): Description
    """
    requests.packages.urllib3.disable_warnings(
        requests.packages.urllib3.exceptions.InsecureRequestWarning)
    payload = {
        "Annu_Name": last_name,
        "Annu_First_Name": first_name,
        "Station_Type": station_type
    }
    for i in range(max_retries):
        response = requests.post('https://' + host +
                                 '/api/mgt/1.0/Node/1/Subscriber/' +
                                 str(extension),
                                 headers=oxe_set_headers(token, 'POST'),
                                 json=payload,
                                 verify=False)
        # code status 201: CREATED
        if response.status_code in (201, 401):
            break
        # code status 503: retry with same requests + wait 500ms (oxe max 2r/s)
        elif response.status_code == 503:
            time.sleep(.500)
Exemple #2
0
def oxe_set_flex(host, token, flex_ip_address, flex_port):
    """Summary

    Args:
        host (TYPE): Description
        token (TYPE): Description
        flex_ip_address (TYPE): Description
        flex_port (TYPE): Description

    Returns:
        TYPE: Description
    """
    requests.packages.urllib3.disable_warnings(
        requests.packages.urllib3.exceptions.InsecureRequestWarning)
    payload = {
        "Flex_Licensing_Enable": "Yes",
        "Flex_Server_Address": flex_ip_address,
        "Flex_Server_Port": flex_port,
        "Flex_ProductId_Discovery": "Yes"
    }
    try:
        response = requests.put(
            'https://' + host +
            '/api/mgt/1.0/Node/1/System_Parameters/1/Flex_Server/1',
            headers=oxe_set_headers(token, 'PUT'),
            json=payload,
            verify=False)
    except requests.exceptions.RequestException as e:
        pprint.pprint(e)
    # todo: manage errors
    return response.status_code
Exemple #3
0
def oxe_set_rainbow(host, token, rainbow_domain, pbx_id, temp_password,
                    phone_book):
    """Summary

    Args:
        host (TYPE): Description
        token (TYPE): Description
        rainbow_domain (TYPE): Description
        pbx_id (TYPE): Description
        temp_password (TYPE): Description
        phone_book (TYPE): Description

    Returns:
        TYPE: Description
    """
    requests.packages.urllib3.disable_warnings(
        requests.packages.urllib3.exceptions.InsecureRequestWarning)
    payload = {
        "Rainbow_Agent_Enable": "Yes",
        "Rainbow_Domain": rainbow_domain,
        "Rainbow_Pbx_Id": pbx_id,
        "Rainbow_Temp_Password": temp_password,
        "Rainbow_Use_PhoneBook": phone_book.capitalize()
    }
    try:
        response = requests.put('https://' + host +
                                '/api/mgt/1.0/Node/1/RAINBOW/1',
                                headers=oxe_set_headers(token, 'PUT'),
                                json=payload,
                                verify=False)
    except requests.exceptions.RequestException as e:
        pprint.pprint(e)
    return response.status_code
Exemple #4
0
def oxe_sip_gateway(host, token, trunk_id):
    payload = {
        'SIP_Subnetwork': '15',
        'SIP_Trunk_Group': trunk_id
    }
    requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)
    try:
        modification = requests.put('https://' + host + '/api/mgt/1.0/Node/1/SIP/1/SIP_Gateway/1',
                                    json=payload,
                                    headers=oxe_set_headers(token, 'PUT'),
                                    verify=False)
    except requests.exceptions.RequestException as e:
        pprint.pprint(e)
    return modification.status_code
Exemple #5
0
def oxe_shelf_ethernet_parameters(host, token, shelf_id, mac_address):
    payload = {'Board_Ethernet_Address': mac_address}
    requests.packages.urllib3.disable_warnings(
        requests.packages.urllib3.exceptions.InsecureRequestWarning)
    try:
        modification = requests.put(
            'https://' + host + '/api/mgt/1.0/Node/1/Rack/' + str(shelf_id) +
            '/Board/0/Ethernet_Parameters/' + str(shelf_id) + '-0',
            json=payload,
            headers=oxe_set_headers(token, 'PUT'),
            verify=False)
    except requests.exceptions.RequestException as e:
        pprint.pprint(e)
    return modification.status_code
Exemple #6
0
def oxe_sip_proxy(host, token):
    payload = {
        'SIP_min_auth_method': 'SIP_None',
        'SIP_Move_To_TCP': 'false',
        'ReTransNo_Invite': '4'
    }
    requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)
    try:
        modification = requests.put('https://' + host + '/api/mgt/1.0/Node/1/SIP/1/SIP_Proxy/1',
                                    json=payload,
                                    headers=oxe_set_headers(token, 'PUT'),
                                    verify=False)
    except requests.exceptions.RequestException as e:
        pprint.pprint(e)
    return modification.status_code
Exemple #7
0
def oxe_create_shelf(host, token, shelf_id, rack_size):
    payload = {'MediaServer': 'Yes', 'Rack_Size': rack_size}
    if id == 0 or id == 18 or id == 19:
        print('Error can\'t proceed to create shelf with reserved id : {}'.
              format(id))
        exit(-1)
    requests.packages.urllib3.disable_warnings(
        requests.packages.urllib3.exceptions.InsecureRequestWarning)
    try:
        creation = requests.post('https://' + host +
                                 '/api/mgt/1.0/Node/1/Rack/' + str(shelf_id),
                                 json=payload,
                                 headers=oxe_set_headers(token, 'POST'),
                                 verify=False)
    except requests.exceptions.RequestException as e:
        pprint.pprint(e)
    return creation.status_code
Exemple #8
0
def oxe_sip_create_default_trunk_groups(host, token, trunk_id):
    payload = {
        'Homo_Net_For_Direct_RTP': 'Yes',
        'Number_Of_Digits_To_Send': '4',
        'Public_Network_Category_Id': '31',
        'Remote_Network': '15',
        'Signalization_Variation': 'ABC_F_VARIANT',
        'T2_Specificity': 'SIP',
        'Trunk_Group_Name': 'SIP'
    }
    requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)
    try:
        creation = requests.post('https://' + host + '/api/mgt/1.0/Node/1/Trunk_Group_Overview/' + str(trunk_id),
                                 json=payload,
                                 headers=oxe_set_headers(token, 'POST'),
                                 verify=False)
    except requests.exceptions.RequestException as e:
        pprint.pprint(e)
    return creation.status_code
Exemple #9
0
def oxe_get_json_model(host, token):
    """Summary

    Args:
        host (TYPE): Description
        token (TYPE): Description

    Returns:
        TYPE: Description
    """
    requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)
    response = requests.get('https://' + host + '/api/mgt/1.0/model',
                            headers=oxe_set_headers(token),
                            verify=False,
                            stream=True)
    result = ''
    for chunk in response.iter_content(chunk_size=1024):
        if chunk:
            result += chunk.decode('utf-8')
    return result
Exemple #10
0
def oxe_delete_user(host, token, extension, max_retries):
    """Summary

    Args:
        host (TYPE): Description
        token (TYPE): Description
        extension (TYPE): Description
        max_retries (TYPE): Description
    """
    requests.packages.urllib3.disable_warnings(
        requests.packages.urllib3.exceptions.InsecureRequestWarning)
    for i in range(max_retries):
        response = requests.delete('https://' + host +
                                   '/api/mgt/1.0/Node/1/Subscriber/' +
                                   str(extension),
                                   headers=oxe_set_headers(token, 'DELETE'),
                                   verify=False)
        # code status 200: OK
        if response.status_code in (200, 404):
            break
        # code status 503: retry with same requests + wait 500ms (oxe max 2r/s)
        elif response.status_code == 503:
            time.sleep(.500)