#NEWLINE# def getDevices( ticket , count , type , file_name ) : #NEWLINE# #INDENT# get_devices_url = ( ( controller_url + '/api/v1/network-device/1/' ) + str ( count ) ) #NEWLINE# logging . info ( ( 'Calling APIC-EM API url:' + get_devices_url ) ) #NEWLINE# header = { #NEWLINE# #INDENT# 'content-type' : 'application/json' , #NEWLINE# 'X-Auth-Token' : ticket , #NEWLINE# #UNINDENT# } #NEWLINE# get_devices_response = requests . get ( get_devices_url , headers = header , verify = False ) #NEWLINE# get_devices_json = get_devices_response . json ( ) #NEWLINE# logging . debug ( ( 'API response: ' + json . dumps ( get_devices_json , indent = 4 , separators = ( ',' , ': ' ) ) ) ) #NEWLINE# file = open ( file_name , 'w' ) #NEWLINE# logging . info ( ( 'File opened:' + file_name ) ) #NEWLINE# logging . info ( ( 'Begin writing list:' + file_name ) ) #NEWLINE# file . write ( ( ( 'The list of devices of type: ' + type ) + '\n' ) ) #NEWLINE# parent = get_devices_json [ 'response' ] #NEWLINE# for item in lowerCaseType : #NEWLINE# #INDENT# lowerCaseType = item [ 'type' ] . lower ( ) #NEWLINE# if ( lowerCaseType . find ( type ) != ( - 1 ) ) : #NEWLINE# #INDENT# file . write ( ( ( ( ( 'id = ' + item [ 'id' ] ) + ' type = ' ) + item [ 'type' ] ) + '\n' ) ) #NEWLINE# #UNINDENT# #UNINDENT# print ( 'Finished writing list ...' ) #NEWLINE# logging . info ( ( 'End writing list:' + file_name ) )