11import time
22
3- # functions for cucm export
3+
44def export_users (ucm_axl ):
55 """
66 retrieve users from ucm
@@ -32,15 +32,14 @@ def export_users(ucm_axl):
3232
3333 for user in user_list :
3434 # print(user)
35- user_details = {
36- "userid" : user .userid ,
37- "firstName" : user .firstName ,
38- "lastName" : user .lastName ,
39- "telephoneNumber" : user .telephoneNumber ,
40- "primaryExtension" : user .primaryExtension .pattern ,
41- "directoryUri" : user .directoryUri ,
42- "mailid" : user .mailid ,
43- }
35+ user_details = {}
36+ user_details ['userid' ] = user .userid
37+ user_details ['firstName' ] = user .firstName
38+ user_details ['lastName' ] = user .lastName
39+ user_details ['telephoneNumber' ] = user .telephoneNumber
40+ user_details ['primaryExtension' ] = user .primaryExtension .pattern
41+ user_details ['directoryUri' ] = user .directoryUri
42+ user_details ['mailid' ] = user .mailid
4443
4544 all_users .append (user_details )
4645 print (
@@ -148,7 +147,8 @@ def export_phones(ucm_axl):
148147 }
149148 all_phones .append (phone_details )
150149
151- print (f"exporting: { phone .name } : { phone .model } - { phone .description } " )
150+ print (
151+ f"exporting: { phone .name } : { phone .model } - { phone .description } " )
152152
153153 print ("-" * 35 )
154154 print (f"number of phones: { len (all_phones )} " )
@@ -182,6 +182,15 @@ def export_siptrunks(ucm_axl):
182182 trunk ["callingSearchSpace" ] = siptrunk .callingSearchSpaceName ._value_1
183183 trunk ["mtpRequired" ] = siptrunk .mtpRequired
184184 trunk ["sigDigits" ] = siptrunk .sigDigits ._value_1
185+ # TODO: get_siptrunk details for destinations
186+ trunk_details = ucm_axl .get_sip_trunk (name = siptrunk .name )
187+ destinations = trunk_details ['return' ]['sipTrunk' ]['destinations' ]['destination' ]
188+ # print(destinations)
189+ for count , destination in enumerate (destinations ):
190+ trunk [f'addressIpv4_{ count } ' ] = destination .addressIpv4
191+ trunk [f'port_{ count } ' ] = destination .port
192+ trunk [f'sortOrder_{ count } ' ] = destination .sortOrder
193+
185194 all_sip_trunks .append (trunk )
186195 # print(siptrunk)
187196 print (f"exporting: { siptrunk .name } : { siptrunk .description } " )
@@ -209,8 +218,9 @@ def export_phone_registrations(ucm_axl, ucm_ris):
209218 reg = {}
210219 for phone in phones :
211220 all_phones .append (phone .name )
212- limit = lambda all_phones , n = 1000 : [
213- all_phones [i : i + n ] for i in range (0 , len (all_phones ), n )
221+
222+ def limit (all_phones , n = 1000 ): return [
223+ all_phones [i : i + n ] for i in range (0 , len (all_phones ), n )
214224 ]
215225 groups = limit (all_phones )
216226 for group in groups :
@@ -220,8 +230,7 @@ def export_phone_registrations(ucm_axl, ucm_ris):
220230 else :
221231 reg ["user" ] = registered ["LoginUserId" ]
222232 reg ["regtime" ] = time .strftime (
223- "%Y-%m-%d %H:%M:%S" , time .localtime (registered ["TimeStamp" ])
224- )
233+ "%Y-%m-%d %H:%M:%S" , time .localtime (registered ["TimeStamp" ]))
225234 for item in registered ["IPAddress" ]:
226235 reg ["ip" ] = item [1 ][0 ]["IP" ]
227236 for item in registered ["LinesStatus" ]:
@@ -246,20 +255,13 @@ def export_translations(ucm_axl):
246255 xlate ["routePartition" ] = translation .routePartitionName ._value_1
247256 xlate ["description" ] = translation .description
248257 xlate ["callingSearchSpace" ] = translation .callingSearchSpaceName ._value_1
249- xlate [
250- "calledPartyTransformationMask"
251- ] = translation .calledPartyTransformationMask
252- xlate [
253- "callingPartyTransformationMask"
254- ] = translation .callingPartyTransformationMask
255- xlate [
256- "digitDiscardInstructionName"
257- ] = translation .digitDiscardInstructionName ._value_1
258+ xlate ["calledPartyTransformationMask" ] = translation .calledPartyTransformationMask
259+ xlate ["callingPartyTransformationMask" ] = translation .callingPartyTransformationMask
260+ xlate ["digitDiscardInstructionName" ] = translation .digitDiscardInstructionName ._value_1
258261 xlate ["prefixDigitsOut" ] = translation .prefixDigitsOut
259262 all_translations .append (xlate )
260263 print (
261- f"exporting: { xlate ['pattern' ]} : { xlate ['routePartition' ]} - { xlate ['description' ]} --> { xlate ['calledPartyTransformationMask' ]} "
262- )
264+ f"exporting: { xlate ['pattern' ]} : { xlate ['routePartition' ]} - { xlate ['description' ]} --> { xlate ['calledPartyTransformationMask' ]} " )
263265 print ("-" * 35 )
264266 print (f"number of translations: { len (all_translations )} " )
265267 return all_translations
0 commit comments