import urllib3
from zeep import Client
from requests import Session
from requests.auth import HTTPBasicAuth
from zeep.transports import Transport
def setup_client(wsdl_url, cucm_address, username, password
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
session = Session()
session.verify = False
session.auth = HTTPBasicAuth(username, password)
transport = Transport(session=session)
client = Client(wsdl_url, transport=transport)
def create_partitions(service, partitions
for partition in partitions:
try:
service.addRoutePartition({
'name': partition,
'description': partition,
'isDefault': 'false'
})
print(f"Partition {partition} created successfully.")
except Exception as e:
print(f"Error creating partition {partition}: {e}")
def create_css(service, partitions
for partition in partitions:
try:
service.addCss({
'name': partition + '_CSS',
'description': partition + ' Calling Search Space',
'clause': partition,
'members': {
'member': {
'routePartitionName': partition,
'index': '1'
}
}
})
print(f"CSS {partition}_CSS created and associated with partition {partition}.")
except Exception as e:
print(f"Error creating CSS {partition}_CSS: {e}")
def create_srst_resources(service, srsts
for srst in srsts:
try:
service.addSrst({
'name': srst['name'],
'description': srst['name'] + ' SRST Resource',
'ipAddress': srst['ipAddress'],
'port': '2000',
'SipPort': '5060'
})
print(f"SRST Resource {srst['name']} created successfully.")
except Exception as e:
print(f"Error creating SRST Resource {srst['name']}: {e}")
def create_device_pools(service, device_pools
for dp in device_pools:
try:
service.addDevicePool({
'name': dp,
'description': dp + ' Device Pool',
'dateTimeSettingName': 'CMLocal',
'regionName': 'Default',
'callManagerGroupName': 'Default',
'srstName': 'SRST_Resource_89'
})
print(f"Device Pool {dp} created successfully.")
except Exception as e:
print(f"Error creating device pool {dp}: {e}")
def create_sip_trunk_cube(service
try:
service.addSipTrunk({
'name': 'cube',
'description': 'SIP Trunk to CUBE',
'product': 'SIP Trunk',
'class': 'Trunk',
'devicePoolName': 'school1', # Reference the existing 'school1' device pool
'protocol': 'SIP',
'protocolSide': 'Network',
'callingSearchSpaceName': 'pstninbound_CSS',
'sipProfileName': 'Standard SIP Profile',
'securityProfileName': 'Non Secure SIP Trunk Profile',
'destinations': {
'destination': {
'addressIpv4': 'xxx.xxx.x.xx',
'port': '5060',
'sortOrder': '1'
}
},
'locationName': 'Hub_None',
'presenceGroupName': 'Standard Presence group',
'callingAndCalledPartyInfoFormat': 'DeliverOriginatingCalledPartyNumber'
})
print("SIP Trunk 'cube' created successfully.")
except Exception as e:
print(f"Error creating SIP Trunk 'cube': {e}")
if __name__ == '__main__':
WSDL_URL = 'AXLAPI.wsdl'
CUCM_ADDRESS = 'xxx.xxx.x.xx'
USERNAME = 'XXX'
PASSWORD = 'XXXX'
service = setup_client(WSDL_URL, CUCM_ADDRESS, USERNAME, PASSWORD)
partitions = ['internal', 'longdistance', 'international', 'pstninbound']
create_partitions(service, partitions)
create_css(service, partitions)
srsts = [
{'name': 'SRST_Resource_89', 'ipAddress': 'XXX.168.1.89'},
{'name': 'SRST_Resource_99', 'ipAddress': 'XXX.168.1.99'}
]
create_srst_resources(service, srsts)
device_pools = ['school1', 'school2'] # Add 'school1' and other device pool names
create_device_pools(service, device_pools)
# ... [Other function calls...]
# Create SIP Trunk 'cube' at the end
create_sip_trunk_cube(service)