- What data model (fields) is needed to upload config file to APIC-em. is the following correct:
- in version 1.2 want to use API to upload config file for PNP,
- found can use ""POST /file/config"
- but the API doc does not show anything about the data model, that is how to format the data/header.
Yes, POST /file/config. What language are you programming in? Many have libraries or helpers to do file uploads. From a raw standpoint, the headers and request look like:
POST /apic/api/v1/file/config HTTP/1.1
Host: apic-em.company.com
Connection: keep-alive
Content-Length: 87291
Pragma: no-cache
Cache-Control: no-cache
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary3B3MLAy0FwOwzuz7
scope: ALL
Accept: application/json, text/javascript, */*; q=0.01
------WebKitFormBoundary3B3MLAy0FwOwzuz7
Content-Disposition: form-data; name="fileUpload"; filename="rtr1.cfg"
Content-Type: application/octet-stream
------WebKitFormBoundary3B3MLAy0FwOwzuz7--
using python, can you clarify more, not a experience programmer.
so in the REST API the data body is:
( onnection: keep-alive,
Content-Length: 87291,
Pragma: no-cache,
Cache-Control: no-cache)
header = ( Content-Type: multipart/form-data;
boundary=----WebKitFormBoundary3B3MLAy0FwOwzuz7'
scope: ALL,
Accept: application/json, text/javascript, */*; q=0.01)
Assuming you're using the requests module, this should work for you:
url = "https://apic-em.company.com/api/v1/file/config" file = { 'rtr1.cfg':open('rtr1.cfg', 'rb') } res = requests.post(url, files=file)
Or Get a token and the following should work:
ticket = get_X_auth_token()
headers = {"content-type" : "application/json","X-Auth-Token": ticket}
# need to change source and destination IP to the one you like to trace
name = "/TFTP-Root/2911cfg.bin" # your file
content = open(name, "r")
post_url = "https://"+apicem_ip+"/api/v1/file/config"
files = {'fileUpload': (name, content)}
headers = {"X-Auth-Token": ticket}
r = requests.post(post_url, headers=headers,files=files,verify=False)
response_json = r.json()
print ("POST Status: ",r.status_code)
print (json.dumps(response_json,indent=4))
Comments
0 comments
Please sign in to leave a comment.