Forum Discussion
Uploading ASM policy files?
I am trying to use the REST API to upload multiple ASM policies to a new install. I have followed the instructions found in the REST API guide (https://devcentral.f5.com/wiki/icontrolrest.icontrolrestuserguide_v1300_7.ashx) to upload the policy files and then import the policy to the ASM. The import seems to be working but I get an error about not completing because the file doesn't seem to be there. I am not seeing any errors on the upload command but it does not seem to be uploading the XML file to the upload folder on the F5. I am using Python and the requests library to post the file. Here is the command that I used to upload the XML file:
- uploadPolicy = 'https://192.168.242.129/mgmt/tm/asm/file-transfer/uploads/'
- response = requests.post(url=uploadPolicy + fname, verify=False, auth=(uname, pw))
- print(response)
I have a CSV file that has a list of all the file names and a for loop to go through them for this process. The response that I get from this is a 400 during the upload of the file. All of the XML files are in the same folder as this script so it should be able to see the files. Any suggestions as to why it is not uploading them?
- suttonsc
Employee
When uploading you need to add the file itself and the headers:
>>> response = requests.post(url=uploadPolicy+fileName,verify=False,auth=("admin","admin"),data=open('test.xml', 'rb'),headers={'Content-Type': 'application/octet-stream', 'Content-Range': '0-402287/402288'}) >>> >>> response.status_code 200 >>> >>> print(response) >>> >>> response.content b'{"remainingByteCount":0,"usedChunks":{"0":402288},"totalByteCount":402288,"localFilePath":"/ts/var/rest/admin~test.xml","temporaryFilePath":"/ts/var/rest/tmp/admin~test.xml","generation":0,"lastUpdateMicros":1543445350182166}'
Or using curl:
curl -sku admin:admin -X POST https://155.140.lab.es.f5net.com/mgmt/tm/asm/file-transfer/uploads/test.xml -H "Content-Type: application/octet-stream" -H "Content-Range: 0-402287/402288" --data-binary "@test.xml" | jq . { "remainingByteCount": 0, "usedChunks": { "0": 402288 }, "totalByteCount": 402288, "localFilePath": "/ts/var/rest/admin~test.xml", "temporaryFilePath": "/ts/var/rest/tmp/admin~test.xml", "generation": 0, "lastUpdateMicros": 1543445684953045 }
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com