...
Info |
---|
This python script includes all API calls to get the first modem online. At the bottom of the script there is an example of how to mass-import contracts from a CSV file. Feel free to adjust the code as needed. We are using verify=False in the post statements since we assume you haven't set up a proper TLS certifcates certificate yet. You may do so using Getting a X.509 certificate via Let's Encrypt. |
...
Code Block | ||||
---|---|---|---|---|
| ||||
import json import requests session = requests.Session() # the username is the email address of the user session.auth = ('root@localhost.com', 'toor') cfg_cm = """ UsServiceFlow { UsServiceFlowRef 101; QosParamSetType 7; MaxRateSustained {qos.us_rate_max_help.0}; MaxTrafficBurst {{qos.us_rate_max_help.0},*,0.1875}; } DsServiceFlow { DsServiceFlowRef 1; QosParamSetType 7; MaxRateSustained {qos.ds_rate_max_help.0}; } ModemCapabilities { ConcatenationSupport 1; IGMPSupport 1; } GlobalPrivacyEnable 1; BaselinePrivacy { AuthTimeout 10; ReAuthTimeout 10; AuthGraceTime 600; OperTimeout 10; ReKeyTimeout 10; TEKGraceTime 1800; AuthRejectTimeout 60; SAMapWaitTimeout 1; SAMapMaxRetries 4; } /* DOCS-CABLE-DEVICE-MIB rfc4639 */ /* SNMP Access to CM */ SnmpMibObject sysLocation.0 String "{test}"; /* strings always inside apostrophes! */ SnmpMibObject docsDevNmAccessIp.10 IPAddress 172.20.0.1; SnmpMibObject docsDevNmAccessIp.20 IPAddress 172.20.0.1; SnmpMibObject docsDevNmAccessIpMask.10 IPAddress 255.255.255.255; SnmpMibObject docsDevNmAccessIpMask.20 IPAddress 255.255.255.255; SnmpMibObject docsDevNmAccessCommunity.10 String "{provbase.ro_community.0}"; SnmpMibObject docsDevNmAccessCommunity.20 String "{provbase.rw_community.0}"; SnmpMibObject docsDevNmAccessControl.10 Integer 2; /* read */ SnmpMibObject docsDevNmAccessControl.20 Integer 3; /* readWrite */ SnmpMibObject docsDevNmAccessInterfaces.10 String "@"; SnmpMibObject docsDevNmAccessInterfaces.20 String "@"; SnmpMibObject docsDevNmAccessStatus.10 Integer 4; /* createAndGo */ SnmpMibObject docsDevNmAccessStatus.20 Integer 4; /* createAndGo */ /* Firewall */ /* Layer2: filter possibly harmful Ethernet traffic */ SnmpMibObject docsDevFilterLLCUnmatchedAction.0 Integer 1; /* discard if not matching */ SnmpMibObject docsDevFilterLLCStatus.1 Integer 4; /* createAndGo */ SnmpMibObject docsDevFilterLLCStatus.2 Integer 4; /* createAndGo */ SnmpMibObject docsDevFilterLLCIfIndex.1 Integer 0; /* all Interfaces */ SnmpMibObject docsDevFilterLLCIfIndex.2 Integer 0; /* all Interfaces */ SnmpMibObject docsDevFilterLLCProtocolType.1 Integer 1; /* ethertype (default) */ SnmpMibObject docsDevFilterLLCProtocolType.2 Integer 1; /* ethertype (default) */ /* Layer 3 */ SnmpMibObject docsDevFilterLLCProtocol.1 Integer 2048; /* ? depends on docsDevFilterLLCProtocolType */ SnmpMibObject docsDevFilterLLCProtocol.2 Integer 2054; /* IPv4 !? */ SnmpMibObject docsDevFilterIpDefault.0 Integer 2; /* accept for further processing when not matching an prior specified IP filter*/ SnmpMibObject docsDevFilterIpStatus.3 Integer 4; /* createAndGo a filter row */ SnmpMibObject docsDevFilterIpControl.3 Integer 1; /* discard */ SnmpMibObject docsDevFilterIpIfIndex.3 Integer 1; /* all customer facing interfaces */ SnmpMibObject docsDevFilterIpDirection.3 Integer 1; /* inbound traffic */ SnmpMibObject docsDevFilterIpBroadcast.3 Integer 2; /* false - applies to all traffic */ SnmpMibObject docsDevFilterIpSaddr.3 IPAddress 0.0.0.0; /* all ip addresses - masked against docsDevFilterIpSmask */ SnmpMibObject docsDevFilterIpSmask.3 IPAddress 0.0.0.0; /* all ip addresses */ SnmpMibObject docsDevFilterIpDaddr.3 IPAddress 0.0.0.0; /* all ip addresses */ SnmpMibObject docsDevFilterIpDmask.3 IPAddress 0.0.0.0; /* all ip addresses */ SnmpMibObject docsDevFilterIpProtocol.3 Integer 17; /* udp */ SnmpMibObject docsDevFilterIpSourcePortLow.3 Integer 67; /* udp */ SnmpMibObject docsDevFilterIpSourcePortHigh.3 Integer 67; /* udp */ SnmpMibObject docsDevFilterIpDestPortLow.3 Integer 0; SnmpMibObject docsDevFilterIpDestPortHigh.3 Integer 65535; """.replace("\n", "\r\n") # firstname;lastname;street;house_number;zip;city;phone;birthday contract_csv = """John;Doe;Main Street;1;01234;Anytown;012345678910;1970-01-01 Jane;Doe;Main Street;2;01234;Anytown;012345678911;1971-01-01 Bob;Doe;Main Street;3;01234;Anytown;012345678912;1972-01-01 """ r = session.post('https://localhost:8080/admin/api/v0/CostCenter', json={'name' : 'NMS Prime', 'billing_month' : 0}, verify=False) costcenter_id = json.loads(r.text)['id'] print(r.text) r = session.post('https://localhost:8080/admin/api/v0/Qos', json={'name' : '100:10', 'ds_rate_max' : '100', 'us_rate_max' : '10'}, verify=False) qos_id = json.loads(r.text)['id'] print(r.text) r = session.post('https://localhost:8080/admin/api/v0/Product', json={'name' : '100:10', 'type' : 'Internet', 'qos_id' : qos_id, 'billing_cycle' : 'Monthly', 'price' : '20', 'proportional' : True}, verify=False) product_id = json.loads(r.text)['id'] print(r.text) r = session.post('https://localhost:8080/admin/api/v0/Configfile', json={'name' : 'Base' ,'device' : 'cm', 'public' : 'yes', 'text' : cfg_cm}, verify=False) cfg_cm_id = json.loads(r.text)['id'] print(r.text) r = session.post('https://localhost:8080/admin/api/v0/Configfile', json={'name' : 'Base MTA' ,'device' : 'mta', 'public' : 'yes', 'text' : 'SnmpMibObject enterprises.4115.10.1.24.0 Integer 4096; /* mtaSafeReset - only restart when lines are idle */'}, verify=False) cfg_mta_id = json.loads(r.text)['id'] print(r.text) r = session.post('https://localhost:8080/admin/api/v0/Contract', json={'number' : '1', 'firstname' : 'John', 'lastname' : 'Doe', 'street' : 'Dörfelstraße', 'house_number' : '7', 'zip' : '09496', 'city' : 'Marienberg', 'phone' : '037359387570', 'birthday' : '2017-12-19', 'contract_start' : '2017-12-19', 'costcenter_id' : costcenter_id, 'create_invoice' : True}, verify=False) contract_id = json.loads(r.text)['id'] print(r.text) r = session.post('https://localhost:8080/admin/api/v0/ItemModem', json={'contractconfigfile_id' : contractcfg_cm_id , 'productmac' : '00:11:22:33:44:55', 'contract_id' : productcontract_id, 'countinternet_access' : 1True, 'validqos_from_fixedid' : True}, verify=False) itemqos_id = json.loads(r.text)['id'] print(r.text) r = session.post('https://localhost:8080/admin/api/v0/Modem', json={'configfile_id' : cfg_cm_id , 'mac' : '00:11:22:33:44:55', 'contract_id' : contract_id, 'internet_access' : True, 'qos_id' : qos_id, 'firstname' : 'NMS', 'lastname' : 'Prime', 'street' : 'Dörfelstraße', 'house_number' : '7', 'zip' : '09496', 'city' : 'Marienberg', 'birthday' : '2017-12-19', 'firstname' : 'NMS', 'lastname' : 'Prime', 'street' : 'Dörfelstraße', 'house_number' : '7', 'zip' : '09496', 'city' : 'Marienberg', 'birthday' : '2017-12-19'}, verify=False) modem_id = json.loads(r.text)['id'] print(r.text) r = session.post('https://localhost:8080/admin/api/v0/Item', json={'contract_id' : contract_id , 'product_id' : product_id, 'count' : 1, 'valid_from_fixed' : True}, verify=False) modemitem_id = json.loads(r.text)['id'] print(r.text) r = session.post('https://localhost:8080/admin/api/v0/Mta', json={'configfile_id' : cfg_mta_id , 'mac' : '00:11:22:33:44:56', 'modem_id' : modem_id, 'type' : 'sip'}, verify=False) mta_id = json.loads(r.text)['id'] print(r.text) r = session.post('https://localhost:8080/admin/api/v0/Phonenumber', json={'mta_id' : mta_id , 'port' : 1, 'country_code' : '0049', 'prefix_number' : '03735', 'number' : '9387570', 'username' : 'user', 'password' : 'secret', 'sipdomain' : 'sip.nmsprime.com', 'active' : True}, verify=False) phonenumber_id = json.loads(r.text)['id'] print(r.text) r = session.post('https://localhost:8080/admin/api/v0/NetGw', json={'type' : 'cmts', 'company' : 'Cisco', 'series' : 'ubr10k', 'hostname' : 'dev-cable-gw10', 'ip' : '172.20.3.253'}, verify=False) netgw_id = json.loads(r.text)['id'] print(r.text) r = session.post('https://localhost:8080/admin/api/v0/IpPool', json={'netgw_id' : 1, 'type' : 'CM', 'net' : '10.0.0.0', 'netmask' : '255.255.224.0', 'ip_pool_start' : '10.0.0.1', 'ip_pool_end' : '10.0.31.253', 'router_ip' : '10.0.31.254', 'broadcast_ip' : '10.0.31.255'}, verify=False) print(r.text) r = session.post('https://localhost:8080/admin/api/v0/IpPool', json={'netgw_id' : 1, 'type' : 'MTA', 'net' : '172.17.0.0', 'netmask' : '255.255.255.0', 'ip_pool_start' : '172.17.0.1', 'ip_pool_end' : '172.17.0.253', 'router_ip' : '172.17.0.254', 'broadcast_ip' : '172.17.0.255', 'dns1_ip' : '172.20.0.1'}, verify=False) print(r.text) r = session.post('https://localhost:8080/admin/api/v0/IpPool', json={'netgw_id' : 1, 'type' : 'CPEPriv', 'net' : '100.64.0.0', 'netmask' : '255.255.252.0', 'ip_pool_start' : '100.64.0.1', 'ip_pool_end' : '100.64.3.253', 'router_ip' : '100.64.3.254', 'broadcast_ip' : '100.64.3.255', 'dns1_ip' : '8.8.8.8', 'dns2_ip' : '8.8.4.4', 'dns3_ip' : '172.20.0.1'}, verify=False) print(r.text) r = session.post('https://localhost:8080/admin/api/v0/IpPool', json={'netgw_id' : 1, 'type' : 'CPEPub', 'net' : '192.0.0.0', 'netmask' : '255.255.252.0', 'ip_pool_start' : '192.0.0.1', 'ip_pool_end' : '192.0.3.253', 'router_ip' : '192.0.3.254', 'broadcast_ip' : '192.0.3.255', 'dns1_ip' : '8.8.8.8', 'dns2_ip' : '8.8.4.4', 'dns3_ip' : '172.20.0.1'}, verify=False) print(r.text) i = 2 for contract in contract_csv.strip('\n').strip('\n').split('\n'): fields = contract.strip(';').split(';') r = session.post('https://localhost:8080/admin/api/v0/Contract', json={'number' : str(i), 'firstname' : fields[0], 'lastname' : fields[1], 'street' : fields[2], 'house_number' : fields[3], 'zip' : fields[4], 'city' : fields[5], 'phone' : fields[6], 'birthday' : fields[7], 'costcenter_id' : costcenter_id, 'create_invoice' : True}, verify=False) i += 1 print(r.text) |
...