CUCM AXL API – Bulk Logout of Extension Mobility Profile Using Python

In our last blog, we covered how to set up the environment for running AXL API commands for CUCM and implemented a Python program for removing directory numbers. Now, we’ll create another Python program that enables bulk logout of extension mobility profiles from phone devices. You’ll simply need to provide a list of MAC addresses in an Excel sheet.

Going for Bulk logout of extension mobility

In the SOAP UI application, navigate to the left panel and expand AXLAPIBinding. Next, locate and expand doDeviceLogout to open the request window.

CUCM AXL API-Bulk Logout of Extension Mobility Profiles Using Python

Extract the MAC address to uniquely identify the device.  Remove the UUID portion and replace the question mark with your actual MAC address.

CUCM AXL API-Bulk Logout of Extension Mobility Profiles Using Python

With the XML request prepared, you can test it using Postman before converting it to Python code.

CUCM AXL API-Bulk Logout of Extension Mobility Profiles Using Python

After running the command, you’ll see a successful response indicated by a 200 OK status code and a message, similar to the one shown in the screenshot above.

Python Code

import requests
import base64
import openpyxl

# Define the AXL API URL
url = "https://hq-cucm-pub.ciscouc.com/axl/"

# Define username and password
username = "axlapiuser"
password = "axlapiuser"

# Define request headers, including Basic Authentication
headers = {
    'Content-Type': 'text/xml',
    'Authorization': f'Basic {base64.b64encode(f"{username}:{password}".encode()).decode()}'
}

def device_logout(device_name):
    # Define the SOAP request payload
    payload = f"""
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/12.5">
       <soapenv:Header/>
       <soapenv:Body>
          <ns:doDeviceLogout sequence="">
             <deviceName>{device_name}</deviceName>
          </ns:doDeviceLogout>
       </soapenv:Body>
    </soapenv:Envelope>
    """

    try:
        # Send a POST request to the AXL API
        response = requests.post(url, headers=headers, data=payload, verify=False)

        # Check if the request was successful (status code 200)
        if response.status_code == 200:
            print(f"Request for device '{device_name}' was successful. Response:")
            print(response.text)
        else:
            print(f"Request for device '{device_name}' failed with status code: {response.status_code}")
            print(response.text)
    except requests.exceptions.RequestException as e:
        print(f"An error occurred while sending the request: {e}")

if __name__ == "__main__":
    # Load the Excel file
    workbook = openpyxl.load_workbook('data.xlsx')
    sheet = workbook.active

    # Iterate through rows in the Excel file to get device names
    for row in sheet.iter_rows(values_only=True):
        device_name = row[0]  
        
        # Skip empty rows
        if device_name is None:
            continue
        
        device_logout(device_name)

    workbook.close()  # Close the Excel file after usage

Github Link: https://github.com/anashira/CUCM-AXL-Extension-Mobility-Logout

Update the username, password, and URL fields with your own credentials.

Below is the screenshot of my sample excel sheet where I supplied the MAC address of the phones

CUCM AXL API SOAP UI and Python

I hope you found this article useful. Your feedback and comments are highly appreciated. Feel free to leave a comment below or reach out to me on LinkedIn.

Conclusion: Simplify CUCM Extension Mobility Management with Python

Managing Extension Mobility profiles across multiple Cisco CUCM devices can become time-consuming, especially in large enterprise environments. However, automation provides a practical way to simplify this process and reduce repetitive administrative work.

By combining the Cisco CUCM AXL API with Python, administrators can perform bulk Extension Mobility logout operations without manually accessing each phone. Furthermore, using an Excel sheet containing device MAC addresses makes it easier to process multiple devices through a single script.

In this guide, we explored how to prepare the SOAP request, test the doDeviceLogout operation using Postman, and execute the Python script. Additionally, we demonstrated how to use the openpyxl library to read device information from an Excel file.

As a result, network administrators can streamline routine CUCM management tasks and reduce manual effort. Moreover, this approach provides a useful foundation for developing additional Cisco collaboration automation workflows.

The key takeaway: Automating CUCM Extension Mobility logout with Python can save valuable administrative time. However, administrators should first validate the script in a test environment and confirm the target devices before running bulk operations.

Ultimately, effective network automation is about making everyday administrative tasks simpler, more consistent, and easier to manage.

Ready to Automate Your Cisco CUCM Administration?

Still managing Cisco Extension Mobility sessions manually?

Discover how Python and the Cisco AXL API can simplify bulk device logout operations and reduce repetitive administration.

Explore the complete Python script on GitHub:

https://github.com/anashira/CUCM-AXL-Extension-Mobility-Logout

Want to explore more CUCM automation techniques?

Read our related guide on removing directory numbers using Python:

For more practical tutorials on Cisco collaboration, networking, and automation, visit:

https://www.networkbachelor.com

Have you automated Cisco CUCM tasks using Python? Share your experience or challenges in the comments. Your insights could help other network engineers.

Follow Network Bachelor for more hands-on networking and automation tutorials.

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *