Request to review my code please and see if I am following the best practices.
This is sending a POST operation via a Python script using the requests library to a networking cloud orchestration endpoint
import requests
import sys
requests.packages.urllib3.disable_warnings()
token = input("Please enter your token: ")
dev_ip = "1.1.1.1"
service_id_c = input("Please enter the service ID: ")
out_vlan_c = int(input("Please enter the uplink outer vlan ID: "))
in_vlan_c = int(input("Please enter the uplink inner vlan ID: "))
content_provider_c = input("Please enter the Content Provider name: ")
interface_name_c = input("Please enter the Downlink Interface name: ")
remote_id_c = input("Please enter the Remote ID: ")
agent_id_c = input("Please enter the Agent Circuit ID: ")
profile_name_c = input("Please enter the Profile name: ")
payload = f"{{\r\n \"input\": {{\r\n \"service-context\": {{\r\n \"service-id\": \"{service_id_c}\",\r\n \"uplink-endpoint\": {{\r\n \"interface-endpoint\": {{\r\n \"outer-tag-vlan-id\": {out_vlan_c},\r\n \"inner-tag-vlan-id\": {in_vlan_c},\r\n \"content-provider-name\": \"{content_provider_c}\"\r\n }}\r\n }},\r\n \"downlink-endpoint\": {{\r\n \"interface-endpoint\": {{\r\n \"outer-tag-vlan-id\": \"untagged\",\r\n \"inner-tag-vlan-id\": \"none\",\r\n \"interface-name\": \"{interface_name_c}\"\r\n }}\r\n }},\r\n \"remote-id\": \"{remote_id_c}\",\r\n \"agent-circuit-id\": \"{agent_id_c}\",\r\n \"profile-name\": \"{profile_name_c}\"\r\n }}\r\n }}\r\n}}"
headers = {
'Authorization': "Bearer " + token,
}
def main():
try:
with requests.post(
url=f"https://{dev_ip}/api/restconf/operations/cloud-platform-orchestration:create",
headers=headers,
data=payload,
verify=False,
timeout=10,
) as response:
represt_c = response.json()
except Exception as e:
print(f'An error occurred, please investigate further: {e!r}')
else:
print(response.status_code, response.reason, response.url)
print(represt_c)
if __name__ == '__main__':
sys.exit(main())
Credit to @Reinderien who helped me formulate best practices for GET requests which I have adopted into my POST script (with a few minor tweaks) above.
Successful response shown below
Please enter your token: ******************************
Please enter the service ID: ABCD-ABC2525
Please enter the uplink outer vlan ID: 3060
Please enter the uplink inner vlan ID: 1060
Please enter the Content Provider name: COMPANY-SERVICE-B50
Please enter the Downlink Interface name: ABC123456_ETH_20
Please enter the Remote ID: test897
Please enter the Agent Circuit ID: test897
Please enter the Profile name: Data Service
200 OK https://192.168.1.1/api/restconf/operations/abc-cloud-platform-orchestration:create
{'output': {'completion-status': 'in-progress',
'service-id': 'ADTN-ADTN2525',
'status': 'creating',
'timestamp': '2022-05-16T2:41:11.371020',
'trans-id': 'ed2667f3-629384-22734-t334-07d345551b93'}}
verify=False
? \$\endgroup\$_c
suffix stand for? \$\endgroup\$