Best Python code snippet using fMBT_python
BulkUpdate-UserGroup.py
Source:BulkUpdate-UserGroup.py
1from suds.client import Client2from suds.xsd.doctor import Import3from suds.xsd.doctor import ImportDoctor4from getpass import getpass5from optparse import OptionParser6import os7import sys8import platform9# This is "monkeypatching" SSL due to a certificate error I get using suds-jurko10import ssl11if hasattr(ssl, '_create_unverified_context'):12 ssl._create_default_https_context = ssl._create_unverified_context13# End of SSL "monkeypatch"14# Variable assignments15f = 016ip, user, pwd = '', '', ''17cucmver = ''18wsdl = ''19loginfo = ''20## This script requires a file with only userID data. One user per line.21## user22## A log file is generated using the name of the csv file used but ending with .log23## The log file is helpful in determining if any of the entries failed.24def axltoolkit(axlver):25 # This block checks the path you are in and uses the axlsqltoolkit26 # under the path of the script location.27 fileDir = os.path.dirname(os.path.realpath('__file__'))28 rel_path = 'axlsqltoolkit/schema/' + str(axlver) + '/AXLAPI.wsdl'29 fullfilepath = os.path.join(fileDir, rel_path)30 # If it's Windows we need to fix the backslashes to forward slashes.31 normalizedfilepath = fullfilepath.replace('\\', '/')32 # Join the file path depending on the system33 if platform.system() == 'Windows':34 wsdl = 'file:///' + normalizedfilepath35 else:36 wsdl = 'file://' + normalizedfilepath37 return wsdl38def main():39 parser = OptionParser()40 parser.add_option('-f', dest='file', help='Please specify file name with extension.')41 parser.add_option('-i', dest='host', help='Please specify UCM address.')42 parser.add_option('-u', dest='user', help='Enter Username.')43 parser.add_option('-p', dest='pwd', help='Enter Password.')44 parser.add_option('-v', dest='ver', help='Enter Version.')45 (options, args) = parser.parse_args()46 global ip, user, pwd, client, axlver, wsdl47 if options.ver:48 axlver = options.ver49 else:50 axlver = raw_input("Please Enter the version of the CUCM cluster (10.0, 10.5, 11.0, 11.5) > ")51 if options.host:52 ip = options.host53 else:54 ip = raw_input("Please Enter the IP Address or Hostname of your CUCM > ")55 if options.user:56 user = options.user57 else:58 user = raw_input("Please Enter Your CUCM User ID > ")59 if options.pwd:60 pwd = options.pwd61 else:62 pwd = getpass("Please Enter Your Password > ")63 tns = 'http://schemas.cisco.com/ast/soap/'64 imp = Import('http://schemas.xmlsoap.org/soap/encoding/',65 'http://schemas.xmlsoap.org/soap/encoding/')66 imp.filter.add(tns) 67 location = 'https://' + ip + ':8443/axl/'68 wsdl = axltoolkit(axlver)69 try:70 client = Client(wsdl, location=location, faults=False,71 plugins=[ImportDoctor(imp)], username=user, password=pwd)72 except:73 print "Error with version or IP address of server. Please try again."74 sys.exit()75 try:76 verresp = client.service.getCCMVersion()77 except:78 print('Unknown Error. Please try again.')79 sys.exit()80 if verresp[0] == 401:81 print('Authentication failure. Wrong username or password.')82 sys.exit()83 cucmver = verresp[1]['return'].componentVersion.version84 cucmsplitver = cucmver.split('.')85 cucmactualver = cucmsplitver[0] + '.' + cucmsplitver[1]86 print('This cluster is version ' + cucmver)87 if axlver != cucmactualver:88 print('You chose the wrong version. The correct version is ') + cucmactualver89 print('Please choose the correct version next time.')90 sys.exit()91 92 loginfo = "Log File for: " + options.file93 logfilesplit = options.file.split('.')94 logfile = logfilesplit[0] + '.log'95 print logfile96 with open(options.file, 'r') as f:97 for file_line in f.readlines():98 if file_line == '\n':99 continue100 userid = file_line.rstrip()101 # Define the Groups to be added to the user. 102 associated_groups = {'userGroup' : [{'name' : 'Standard CCM End Users'}, 103 {'name' : 'Standard CTI Allow Control of Phones supporting Connected Xfer and conf'},104 {'name' : 'Standard CTI Allow Control of Phones supporting Rollover Mode'},105 {'name' : 'Standard CTI Enabled'}]}106 # Update the user107 update_user_resp = client.service.updateUser(userid=userid, 108 associatedGroups=associated_groups)109 if update_user_resp[0] == 200:110 print ("Success - Updated user %s." % (userid))111 loginfo = loginfo + "\nSuccess - Updated user " + userid112 else:113 print ("Problem updating user %s." % (userid))114 loginfo = loginfo + "\nProblem updating user " + userid115 with open(logfile, 'w') as f:116 f.write(loginfo)117if __name__ == '__main__':...
BulkChangeDeviceDescription.py
Source:BulkChangeDeviceDescription.py
1from suds.client import Client2from suds.xsd.doctor import Import3from suds.xsd.doctor import ImportDoctor4from getpass import getpass5from optparse import OptionParser6import os7import sys8import platform9# This is monkeypatching SSL due to a certificate error I get using suds-jurko10import ssl11if hasattr(ssl, '_create_unverified_context'):12 ssl._create_default_https_context = ssl._create_unverified_context13# End of SSL monkeypatch14# Variable assignments15f = 016dnp = ""17ip, user, pwd = '', '', ''18exitcode = 019cucmver = ''20wsdl = ''21loginfo = ''22## This script requires a file with phone and device description data separated by comma.23## phone,description24def axltoolkit(axlver):25 # This block checks the path you are in and uses the axlsqltoolkit26 # under the path of the script location.27 fileDir = os.path.dirname(os.path.realpath('__file__'))28 rel_path = 'axlsqltoolkit/schema/' + str(axlver) + '/AXLAPI.wsdl'29 fullfilepath = os.path.join(fileDir, rel_path)30 # If it's Windows we need to fix the backslashes to forward slashes.31 normalizedfilepath = fullfilepath.replace('\\', '/')32 # Join the file path depending on the system33 if platform.system() == 'Windows':34 wsdl = 'file:///' + normalizedfilepath35 else:36 wsdl = 'file://' + normalizedfilepath37 return wsdl38def main():39 parser = OptionParser()40 parser.add_option('-f', dest='file', help='Please specify file name with extension.')41 parser.add_option('-i', dest='host', help='Please specify UCM address.')42 parser.add_option('-u', dest='user', help='Enter Username.')43 parser.add_option('-p', dest='pwd', help='Enter Password.')44 parser.add_option('-v', dest='ver', help='Enter Version.')45 (options, args) = parser.parse_args()46 global ip, user, pwd, client, axlver, wsdl47 if options.ver:48 axlver = options.ver49 else:50 axlver = raw_input("Please Enter the version of the CUCM cluster (10.0, 10.5, 11.0, 11.5) > ")51 if options.host:52 ip = options.host53 else:54 ip = raw_input("Please Enter the IP Address or Hostname of your CUCM > ")55 if options.user:56 user = options.user57 else:58 user = raw_input("Please Enter Your CUCM User ID > ")59 if options.pwd:60 pwd = options.pwd61 else:62 pwd = getpass("Please Enter Your Password > ")63 tns = 'http://schemas.cisco.com/ast/soap/'64 imp = Import('http://schemas.xmlsoap.org/soap/encoding/',65 'http://schemas.xmlsoap.org/soap/encoding/')66 imp.filter.add(tns) 67 location = 'https://' + ip + ':8443/axl/'68 wsdl = axltoolkit(axlver)69 try:70 client = Client(wsdl, location=location, faults=False,71 plugins=[ImportDoctor(imp)], username=user, password=pwd)72 except:73 print "Error with version or IP address of server. Please try again."74 sys.exit()75 try:76 verresp = client.service.getCCMVersion()77 except:78 print('Unknown Error. Please try again.')79 sys.exit()80 if verresp[0] == 401:81 print('Authentication failure. Wrong username or password.')82 sys.exit()83 cucmver = verresp[1]['return'].componentVersion.version84 cucmsplitver = cucmver.split('.')85 cucmactualver = cucmsplitver[0] + '.' + cucmsplitver[1]86 print('This cluster is version ' + cucmver)87 if axlver != cucmactualver:88 print('You chose the wrong version. The correct version is ') + cucmactualver89 print('Please choose the correct version next time.')90 sys.exit()91 loginfo = "Log File for: " + options.file92 logfilesplit = options.file.split('.')93 logfile = logfilesplit[0] + '.log'94 print logfile95 with open(options.file, 'r') as f:96 for dn_dest in f.readlines():97 if dn_dest == '\n':98 continue99 if ',' in dn_dest:100 dn_dest = dn_dest.split(',')101 phone, newdevicedesc = dn_dest[0], dn_dest[1].rstrip()102 update_phone_resp = client.service.updatePhone(name=phone, description=newdevicedesc)103 if update_phone_resp[0] == 200:104 print ("Success - Changed Device Description on phone %s." % (phone))105 loginfo = loginfo + "\nSuccess - Updated phone " + phone + " Description"106 else:107 print ("Problem changing Device Description on phone %s." % (phone))108 loginfo = loginfo + "\nProblem updating phone " + phone109 with open(logfile, 'w') as f:110 f.write(loginfo)111if __name__ == '__main__':...
BulkChangeDeviceDescription3.py
Source:BulkChangeDeviceDescription3.py
1from suds.client import Client2from suds.xsd.doctor import Import3from suds.xsd.doctor import ImportDoctor4from getpass import getpass5from optparse import OptionParser6import os7import sys8import platform9# This is monkeypatching SSL due to a certificate error I get using suds-jurko10import ssl11if hasattr(ssl, '_create_unverified_context'):12 ssl._create_default_https_context = ssl._create_unverified_context13# End of SSL monkeypatch14# Variable assignments15f = 016dnp = ""17ip, user, pwd = '', '', ''18exitcode = 019cucmver = ''20wsdl = ''21loginfo = ''22## This script requires a file with phone and device description data separated by comma.23## phone,description24def axltoolkit(axlver):25 # This block checks the path you are in and uses the axlsqltoolkit26 # under the path of the script location.27 fileDir = os.path.dirname(os.path.realpath('__file__'))28 rel_path = 'axlsqltoolkit/schema/' + str(axlver) + '/AXLAPI.wsdl'29 fullfilepath = os.path.join(fileDir, rel_path)30 # If it's Windows we need to fix the backslashes to forward slashes.31 normalizedfilepath = fullfilepath.replace('\\', '/')32 # Join the file path depending on the system33 if platform.system() == 'Windows':34 wsdl = 'file:///' + normalizedfilepath35 else:36 wsdl = 'file://' + normalizedfilepath37 return wsdl38def main():39 parser = OptionParser()40 parser.add_option('-f', dest='file', help='Please specify file name with extension.')41 parser.add_option('-i', dest='host', help='Please specify UCM address.')42 parser.add_option('-u', dest='user', help='Enter Username.')43 parser.add_option('-p', dest='pwd', help='Enter Password.')44 parser.add_option('-v', dest='ver', help='Enter Version.')45 (options, args) = parser.parse_args()46 global ip, user, pwd, client, axlver, wsdl47 if options.ver:48 axlver = options.ver49 else:50 axlver = input("Please Enter the version of the CUCM cluster (10.0, 10.5, 11.0, 11.5) > ")51 if options.host:52 ip = options.host53 else:54 ip = input("Please Enter the IP Address or Hostname of your CUCM > ")55 if options.user:56 user = options.user57 else:58 user = input("Please Enter Your CUCM User ID > ")59 if options.pwd:60 pwd = options.pwd61 else:62 pwd = getpass("Please Enter Your Password > ")63 tns = 'http://schemas.cisco.com/ast/soap/'64 imp = Import('http://schemas.xmlsoap.org/soap/encoding/',65 'http://schemas.xmlsoap.org/soap/encoding/')66 imp.filter.add(tns) 67 location = 'https://' + ip + ':8443/axl/'68 wsdl = axltoolkit(axlver)69 try:70 client = Client(wsdl, location=location, faults=False,71 plugins=[ImportDoctor(imp)], username=user, password=pwd)72 except:73 print ("Error with version or IP address of server. Please try again.")74 sys.exit()75 try:76 verresp = client.service.getCCMVersion()77 except:78 print('Unknown Error. Please try again.')79 sys.exit()80 if verresp[0] == 401:81 print('Authentication failure. Wrong username or password.')82 sys.exit()83 cucmver = verresp[1]['return'].componentVersion.version84 cucmsplitver = cucmver.split('.')85 cucmactualver = cucmsplitver[0] + '.' + cucmsplitver[1]86 print('This cluster is version ' + cucmver)87 if axlver != cucmactualver:88 print('You chose the wrong version. The correct version is ') + cucmactualver89 print('Please choose the correct version next time.')90 sys.exit()91 loginfo = "Log File for: " + options.file92 logfilesplit = options.file.split('.')93 logfile = logfilesplit[0] + '.log'94 print (logfile)95 with open(options.file, 'r') as f:96 for dn_dest in f.readlines():97 if dn_dest == '\n':98 continue99 if ',' in dn_dest:100 dn_dest = dn_dest.split(',')101 phone, newdevicedesc = dn_dest[0], dn_dest[1].rstrip()102 update_phone_resp = client.service.updatePhone(name=phone, description=newdevicedesc)103 if update_phone_resp[0] == 200:104 print ("Success - Changed Device Description on phone %s." % (phone))105 loginfo = loginfo + "\nSuccess - Updated phone " + phone + " Description"106 else:107 print ("Problem changing Device Description on phone %s." % (phone))108 loginfo = loginfo + "\nProblem updating phone " + phone109 with open(logfile, 'w') as f:110 f.write(loginfo)111if __name__ == '__main__':...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!