Problems with uploading new storage via Proxmox API

quocbao

Member
Sep 26, 2017
6
0
6
Hi everyone,

I'm testing Proxmox API to automate VM creation process by cloning existing template on Proxmox VE 5.0-23/af4267bf. The problem is when a new VM is cloned, I want to mount a new CD/DVD device to the VM but I can't upload new ISO file to the server by Proxmox API. The API return HTTP code 501 which means this function is not implemented, and no error message is returned.

This is the document I follow (path: storage -> content -> upload)
pve.proxmox.com/pve-docs/api-viewer/index.html

About source code, I use pyproxmox library for Python. Please take a look at below photos for more information.

So how can I upload a ISO file to the server storage engine ? Strangely, web interface still use this API to upload new ISO file without problems. Does the document that I read is wrong ?

Any helps would be appreciated. Feel free to ask me more information for debugging purpose.
 

Attachments

  • Selection_048.png
    Selection_048.png
    21.7 KB · Views: 44
  • Selection_047.png
    Selection_047.png
    111.9 KB · Views: 44
  • Selection_049.png
    Selection_049.png
    355.4 KB · Views: 44
  • Selection_050.png
    Selection_050.png
    82.2 KB · Views: 45
Last edited:
can you also output 'self.response.reason' in addition to the status code? (so that you can see what the reason for the 501 is)
 
I think there is a problem with SSL

Code:
curl -k --verbose --upload-file ./CODE/cloudinit/cloudinit.iso https://192.168.0.40:8006/api2/json/nodes/pve/storage/local/upload
*   Trying 192.168.0.40...
* TCP_NODELAY set
* Connected to 192.168.0.40 (192.168.0.40) port 8006 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: CN=<censored>
*  start date: Oct 11 06:53:18 2017 GMT
*  expire date: Jan  9 06:53:18 2018 GMT
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*  SSL certificate verify ok.
> PUT /api2/json/nodes/pve/storage/local/upload HTTP/1.1
> Host: 192.168.0.40:8006
> User-Agent: curl/7.52.1
> Accept: */*
> Content-Length: 374784
> Expect: 100-continue
>
* Done waiting for 100-continue
* SSL_write() returned SYSCALL, errno = 32
* Curl_http_done: called premature == 1
* Closing connection 0
curl: (55) SSL_write() returned SYSCALL, errno = 32

Another try

Code:
curl -k --verbose --form "fileupload=@./CODE/cloudinit/cloudinit.iso;filename=cloudinit.iso" https://192.168.0.40:8006/api2/json/nodes/pve/storage/local/upload
*   Trying 192.168.0.40...
* TCP_NODELAY set
* Connected to 192.168.0.40 (192.168.0.40) port 8006 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: CN=<censored>
*  start date: Oct 11 06:53:18 2017 GMT
*  expire date: Jan  9 06:53:18 2018 GMT
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*  SSL certificate verify ok.
> POST /api2/json/nodes/pve/storage/local/upload HTTP/1.1
> Host: 192.168.0.40:8006
> User-Agent: curl/7.52.1
> Accept: */*
> Content-Length: 374995
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------052b4557d76911ce
>
* Done waiting for 100-continue
* SSL_write() returned SYSCALL, errno = 32
* Curl_http_done: called premature == 1
* Closing connection 0
curl: (55) SSL_write() returned SYSCALL, errno = 32

I want to repeat that the uploading function still work fine on web interface.
 

Attachments

  • Selection_010.png
    Selection_010.png
    25.3 KB · Views: 20
  • Selection_012.png
    Selection_012.png
    96.7 KB · Views: 18
Last edited:
so i tried to reproduce your issue and it works here, you just have to do it right

first you have to include a valid ticket in the cookie,
also you have to use the correct parameter for the filename and you have to specify the content type parameter
like this:

Code:
curl 'https://<IP/HOSTNAME>:8006/api2/json/nodes/<NODENAME>/storage/local/upload' -H 'Content-Type: multipart/form-data' -H 'Cookie: PVEAuthCookie=<VALID COOKIE>' --form "content=iso" --form "filename=@<PATH TO FILE>" -k --verbose
 
so i tried to reproduce your issue and it works here, you just have to do it right

first you have to include a valid ticket in the cookie,
also you have to use the correct parameter for the filename and you have to specify the content type parameter
like this:

Code:
curl 'https://<IP/HOSTNAME>:8006/api2/json/nodes/<NODENAME>/storage/local/upload' -H 'Content-Type: multipart/form-data' -H 'Cookie: PVEAuthCookie=<VALID COOKIE>' --form "content=iso" --form "filename=@<PATH TO FILE>" -k --verbose

I didn't include the cookie because I believe that the server should return an error message, not suddenly breaking current connection by not receiving any data from ssl_write().

I used the command you provide and happily, it works :) I decided to investigate more about this problems.

First, I deleted a single character in the cookie. In server side, "/var/log/pveproxy/access.log" point out that an HTTP 401 was returned, in client side, it was a crash as you see above. I believe there are some faults in the server because when I remove '--form="content=iso"', the server returned a clear error message as shown in below screenshots.

Anyway, thanks for your help :D
 

Attachments

  • Selection_018.png
    Selection_018.png
    238.9 KB · Views: 29
  • Selection_019.png
    Selection_019.png
    48.1 KB · Views: 29

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!