Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cgrateshttpapi
- import pprint
- import sys
- import time
- from datetime import datetime
- CGRateS_Obj = cgrateshttpapi.CGRateS('172.31.6.253', 2080)
- print("===== STEP 1: Setting up Charging Profile =====")
- charger_result = CGRateS_Obj.SendData({
- "method": "APIerSv1.SetChargerProfile",
- "params": [
- {
- "Tenant": "integration-test.connect-ez.com",
- "ID": "DEFAULT",
- 'FilterIDs': [],
- "AttributeIDs": ["<*resources>", "<*thresholds>"],
- 'Weight': 0,
- }
- ]})
- print("Charger Result:")
- pprint.pprint(charger_result)
- print("\n===== STEP 2: Setting up Destination =====")
- dst_result = CGRateS_Obj.SendData({
- 'method': 'ApierV2.SetTPDestination',
- 'params': [{
- "TPid": "integration-test.connect-ez.com",
- "ID": "DST_USA_CAN_Toll_Free",
- "Prefixes": ["1800", "1888", "1877", "1866", "1855", "1844", "1833"]
- }]
- })
- print("Destination Result:")
- pprint.pprint(dst_result)
- print("\n===== STEP 3: Setting up Rate =====")
- rate_result = CGRateS_Obj.SendData({
- "method": "ApierV1.SetTPRate",
- "params": [{
- "ID": "RT_USA_CAN_Toll_Free_Minutes",
- "TPid": "integration-test.connect-ez.com",
- "RateSlots": [{
- "ConnectFee": 0,
- "Rate": 1,
- "RateUnit": "60s",
- "RateIncrement": "60s",
- "GroupIntervalStart": "0s"
- }]
- }]
- })
- print("Rate Result:")
- pprint.pprint(rate_result)
- print("\n===== STEP 4: Setting up Destination Rate =====")
- dr_result = CGRateS_Obj.SendData({
- "method": "ApierV1.SetTPDestinationRate",
- "params": [{
- "ID": "DR_USA_CAN_Toll_Free_Minutes",
- "TPid": "integration-test.connect-ez.com",
- "DestinationRates": [{
- "DestinationId": "DST_USA_CAN_Toll_Free",
- "RateId": "RT_USA_CAN_Toll_Free_Minutes",
- "RoundingMethod": "*up",
- "RoundingDecimals": 4,
- "MaxCost": 0,
- "MaxCostStrategy": ""
- }]
- }]
- })
- print("Destination Rate Result:")
- pprint.pprint(dr_result)
- print("\n===== STEP 5: Setting up Rating Plan =====")
- rp_result = CGRateS_Obj.SendData({
- "method": "APIerSv1.SetTPRatingPlan",
- "params": [{
- "TPid": "integration-test.connect-ez.com",
- "ID": "RP_USA_CAN_Toll_Free_Minutes",
- "RatingPlanBindings": [{
- "DestinationRatesId": "DR_USA_CAN_Toll_Free_Minutes",
- "TimingId": "*any",
- "Weight": 10
- }]
- }]
- })
- print("Rating Plan Result:")
- pprint.pprint(rp_result)
- # ===== STEP 6: Now load from StorDB AFTER creating all necessary components =====
- print("\n===== STEP 11: Loading from StorDB =====")
- load_result = CGRateS_Obj.SendData({
- "method": "APIerSv1.LoadTariffPlanFromStorDb",
- "params": [{
- "TPid": "integration-test.connect-ez.com",
- "DryRun": False,
- "Validate": True
- }]
- })
- print("Load Result:")
- pprint.pprint(load_result)
- # Wait for caches to fully refresh
- print("\nWaiting for caches to refresh...")
- time.sleep(5)
- print("\n===== STEP 7: Setting up Rating Profile =====")
- profile_result = CGRateS_Obj.SendData({
- "method": "APIerSv1.SetRatingProfile",
- "params": [{
- "Tenant": "integration-test.connect-ez.com",
- "Category": "call",
- "Subject": "*any",
- "Overwrite": True,
- "RatingPlanActivations": [{
- "ActivationTime": "2014-01-14T00:00:00Z",
- "RatingPlanId": "RP_USA_CAN_Toll_Free_Minutes",
- "FallbackSubjects": ""
- }]
- }]
- })
- print("Rating Profile Result:")
- pprint.pprint(profile_result)
- # Adding the new Filter Profile for concurrent calls
- print("\n===== STEP 8: Adding Filter Profile =====")
- filter_result = CGRateS_Obj.SendData({
- "method": "APIerSv1.SetFilter",
- "params": [{
- "Tenant": "integration-test.connect-ez.com",
- "ID": "FLTR_CONCURRENT_CALLS",
- "Type": "*string",
- "Element": "~*req.Account",
- "Values": ["1000000063"]
- }]
- })
- print("Filter Result:")
- pprint.pprint(filter_result)
- # Adding the new Resource Profile for concurrent calls
- print("\n===== STEP 9: Adding Resource Profile =====")
- resource_result = CGRateS_Obj.SendData({
- "method": "APIerSv1.SetResourceProfile",
- "params": [{
- "Tenant": "integration-test.connect-ez.com",
- "ID": "RES_CONCURRENT_CALLS",
- "FilterIDs": ["FLTR_CONCURRENT_CALLS"],
- # "ActivationInterval": "",
- "TTL": "*unlimited",
- "Limit": 1, # Maximum 1 concurrent call
- "AllocationMessage": "Concurrent calls limit reached",
- "Blocker": False,
- "Stored": False,
- "Weight": 10
- }]
- })
- print("Resource Profile Result:")
- pprint.pprint(resource_result)
- # Reloading Cache for Resources
- print("\n===== STEP 10: Reloading Cache for Resources =====")
- CGRateS_Obj.SendData({
- "method": "CacheSv1.ReloadCache",
- "params": [{
- "Tenant": "integration-test.connect-ez.com",
- "Args": {
- "*resources": True, # Force reload resources
- "*filters": True # And their associated filters
- }
- }]
- })
- print("Cache reloaded for resources/filters")
- time.sleep(1) # Short pause for cache propagation
- # ===== STEP 11: Create Account =====
- account_result = CGRateS_Obj.SendData({
- "method": "APIerSv2.SetAccount",
- "params": [{
- "Tenant": "integration-test.connect-ez.com",
- "Account": "1000000063",
- # "FilterIDs": ["FLTR_CONCURRENT_CALLS"],
- "ActionPlansOverwrite": True,
- "ReloadScheduler":True
- }]
- })
- print("Account Setup Result:")
- pprint.pprint(account_result)
- # -- Add the voice balance to the account
- print("\n===== STEP 12: Adding Voice Balance =====")
- voice_balance_result = CGRateS_Obj.SendData({
- "method": "ApierV1.SetBalance",
- "params": [
- {
- "Tenant": "integration-test.connect-ez.com",
- "Account": "1000000063",
- "BalanceType": "*voice",
- "Categories": "*any",
- "Balance": {
- "ID": "Daily_Toll_Free_Topup",
- "Units": 1200000000000, # 20 minutes = 1200 seconds (as numeric value)
- "Weight": 50,
- "Disabled": False
- }
- }
- ]
- })
- print("Voice Balance Result:")
- pprint.pprint(voice_balance_result)
- # Wait for caches to fully refresh
- print("\nWaiting for caches to refresh...")
- time.sleep(5)
- # Verify the account setup
- print("\n===== STEP 13: Verifying Account Setup =====")
- final_account_result = CGRateS_Obj.SendData({
- "method": "APIerSv1.GetAccount",
- "params": [{
- "Tenant": "integration-test.connect-ez.com",
- "Account": "1000000063"
- }]
- })
- print("Account Verification:")
- pprint.pprint(final_account_result)
Advertisement
Add Comment
Please, Sign In to add comment