Guest User

Untitled

a guest
May 21st, 2025
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.82 KB | None | 0 0
  1. import cgrateshttpapi
  2. import pprint
  3. import sys
  4. import time
  5. from datetime import datetime
  6.  
  7. CGRateS_Obj = cgrateshttpapi.CGRateS('172.31.6.253', 2080)
  8.  
  9. print("===== STEP 1: Setting up Charging Profile =====")
  10. charger_result = CGRateS_Obj.SendData({
  11. "method": "APIerSv1.SetChargerProfile",
  12. "params": [
  13. {
  14. "Tenant": "integration-test.connect-ez.com",
  15. "ID": "DEFAULT",
  16. 'FilterIDs': [],
  17. "AttributeIDs": ["<*resources>", "<*thresholds>"],
  18. 'Weight': 0,
  19. }
  20. ]})
  21. print("Charger Result:")
  22. pprint.pprint(charger_result)
  23.  
  24. print("\n===== STEP 2: Setting up Destination =====")
  25. dst_result = CGRateS_Obj.SendData({
  26. 'method': 'ApierV2.SetTPDestination',
  27. 'params': [{
  28. "TPid": "integration-test.connect-ez.com",
  29. "ID": "DST_USA_CAN_Toll_Free",
  30. "Prefixes": ["1800", "1888", "1877", "1866", "1855", "1844", "1833"]
  31. }]
  32. })
  33. print("Destination Result:")
  34. pprint.pprint(dst_result)
  35.  
  36. print("\n===== STEP 3: Setting up Rate =====")
  37. rate_result = CGRateS_Obj.SendData({
  38. "method": "ApierV1.SetTPRate",
  39. "params": [{
  40. "ID": "RT_USA_CAN_Toll_Free_Minutes",
  41. "TPid": "integration-test.connect-ez.com",
  42. "RateSlots": [{
  43. "ConnectFee": 0,
  44. "Rate": 1,
  45. "RateUnit": "60s",
  46. "RateIncrement": "60s",
  47. "GroupIntervalStart": "0s"
  48. }]
  49. }]
  50. })
  51. print("Rate Result:")
  52. pprint.pprint(rate_result)
  53.  
  54. print("\n===== STEP 4: Setting up Destination Rate =====")
  55. dr_result = CGRateS_Obj.SendData({
  56. "method": "ApierV1.SetTPDestinationRate",
  57. "params": [{
  58. "ID": "DR_USA_CAN_Toll_Free_Minutes",
  59. "TPid": "integration-test.connect-ez.com",
  60. "DestinationRates": [{
  61. "DestinationId": "DST_USA_CAN_Toll_Free",
  62. "RateId": "RT_USA_CAN_Toll_Free_Minutes",
  63. "RoundingMethod": "*up",
  64. "RoundingDecimals": 4,
  65. "MaxCost": 0,
  66. "MaxCostStrategy": ""
  67. }]
  68. }]
  69. })
  70. print("Destination Rate Result:")
  71. pprint.pprint(dr_result)
  72.  
  73. print("\n===== STEP 5: Setting up Rating Plan =====")
  74. rp_result = CGRateS_Obj.SendData({
  75. "method": "APIerSv1.SetTPRatingPlan",
  76. "params": [{
  77. "TPid": "integration-test.connect-ez.com",
  78. "ID": "RP_USA_CAN_Toll_Free_Minutes",
  79. "RatingPlanBindings": [{
  80. "DestinationRatesId": "DR_USA_CAN_Toll_Free_Minutes",
  81. "TimingId": "*any",
  82. "Weight": 10
  83. }]
  84. }]
  85. })
  86. print("Rating Plan Result:")
  87. pprint.pprint(rp_result)
  88.  
  89.  
  90. # ===== STEP 6: Now load from StorDB AFTER creating all necessary components =====
  91. print("\n===== STEP 11: Loading from StorDB =====")
  92. load_result = CGRateS_Obj.SendData({
  93. "method": "APIerSv1.LoadTariffPlanFromStorDb",
  94. "params": [{
  95. "TPid": "integration-test.connect-ez.com",
  96. "DryRun": False,
  97. "Validate": True
  98. }]
  99. })
  100. print("Load Result:")
  101. pprint.pprint(load_result)
  102.  
  103. # Wait for caches to fully refresh
  104. print("\nWaiting for caches to refresh...")
  105. time.sleep(5)
  106.  
  107. print("\n===== STEP 7: Setting up Rating Profile =====")
  108. profile_result = CGRateS_Obj.SendData({
  109. "method": "APIerSv1.SetRatingProfile",
  110. "params": [{
  111. "Tenant": "integration-test.connect-ez.com",
  112. "Category": "call",
  113. "Subject": "*any",
  114. "Overwrite": True,
  115. "RatingPlanActivations": [{
  116. "ActivationTime": "2014-01-14T00:00:00Z",
  117. "RatingPlanId": "RP_USA_CAN_Toll_Free_Minutes",
  118. "FallbackSubjects": ""
  119. }]
  120. }]
  121. })
  122. print("Rating Profile Result:")
  123. pprint.pprint(profile_result)
  124.  
  125. # Adding the new Filter Profile for concurrent calls
  126. print("\n===== STEP 8: Adding Filter Profile =====")
  127. filter_result = CGRateS_Obj.SendData({
  128. "method": "APIerSv1.SetFilter",
  129. "params": [{
  130. "Tenant": "integration-test.connect-ez.com",
  131. "ID": "FLTR_CONCURRENT_CALLS",
  132. "Type": "*string",
  133. "Element": "~*req.Account",
  134. "Values": ["1000000063"]
  135. }]
  136. })
  137. print("Filter Result:")
  138. pprint.pprint(filter_result)
  139.  
  140. # Adding the new Resource Profile for concurrent calls
  141. print("\n===== STEP 9: Adding Resource Profile =====")
  142. resource_result = CGRateS_Obj.SendData({
  143. "method": "APIerSv1.SetResourceProfile",
  144. "params": [{
  145. "Tenant": "integration-test.connect-ez.com",
  146. "ID": "RES_CONCURRENT_CALLS",
  147. "FilterIDs": ["FLTR_CONCURRENT_CALLS"],
  148. # "ActivationInterval": "",
  149. "TTL": "*unlimited",
  150. "Limit": 1, # Maximum 1 concurrent call
  151. "AllocationMessage": "Concurrent calls limit reached",
  152. "Blocker": False,
  153. "Stored": False,
  154. "Weight": 10
  155. }]
  156. })
  157. print("Resource Profile Result:")
  158. pprint.pprint(resource_result)
  159.  
  160. # Reloading Cache for Resources
  161. print("\n===== STEP 10: Reloading Cache for Resources =====")
  162. CGRateS_Obj.SendData({
  163. "method": "CacheSv1.ReloadCache",
  164. "params": [{
  165. "Tenant": "integration-test.connect-ez.com",
  166. "Args": {
  167. "*resources": True, # Force reload resources
  168. "*filters": True # And their associated filters
  169. }
  170. }]
  171. })
  172. print("Cache reloaded for resources/filters")
  173. time.sleep(1) # Short pause for cache propagation
  174.  
  175. # ===== STEP 11: Create Account =====
  176. account_result = CGRateS_Obj.SendData({
  177. "method": "APIerSv2.SetAccount",
  178. "params": [{
  179. "Tenant": "integration-test.connect-ez.com",
  180. "Account": "1000000063",
  181. # "FilterIDs": ["FLTR_CONCURRENT_CALLS"],
  182. "ActionPlansOverwrite": True,
  183. "ReloadScheduler":True
  184. }]
  185. })
  186. print("Account Setup Result:")
  187. pprint.pprint(account_result)
  188.  
  189. # -- Add the voice balance to the account
  190. print("\n===== STEP 12: Adding Voice Balance =====")
  191. voice_balance_result = CGRateS_Obj.SendData({
  192. "method": "ApierV1.SetBalance",
  193. "params": [
  194. {
  195. "Tenant": "integration-test.connect-ez.com",
  196. "Account": "1000000063",
  197. "BalanceType": "*voice",
  198. "Categories": "*any",
  199. "Balance": {
  200. "ID": "Daily_Toll_Free_Topup",
  201. "Units": 1200000000000, # 20 minutes = 1200 seconds (as numeric value)
  202. "Weight": 50,
  203. "Disabled": False
  204. }
  205. }
  206. ]
  207. })
  208. print("Voice Balance Result:")
  209. pprint.pprint(voice_balance_result)
  210.  
  211. # Wait for caches to fully refresh
  212. print("\nWaiting for caches to refresh...")
  213. time.sleep(5)
  214.  
  215. # Verify the account setup
  216. print("\n===== STEP 13: Verifying Account Setup =====")
  217. final_account_result = CGRateS_Obj.SendData({
  218. "method": "APIerSv1.GetAccount",
  219. "params": [{
  220. "Tenant": "integration-test.connect-ez.com",
  221. "Account": "1000000063"
  222. }]
  223. })
  224. print("Account Verification:")
  225. pprint.pprint(final_account_result)
Advertisement
Add Comment
Please, Sign In to add comment