Git Product home page Git Product logo

cv4pve-api-php's People

Contributors

franklupo avatar lukasbruha avatar nexus633 avatar noxomix avatar oren-c avatar sdiv877 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cv4pve-api-php's Issues

Error on User create

Hey,
i get an HTTPCode 500 but no Error on User Create.

$proxmox->getAccess()->getUsers()->createUser($username, password: "test1234");

Proxmox-Version is 7.0-11

Cant figure out how to create LXC

Hey,
I am trying to make a Container with this Libary.
This is the Code I have

if (isset($_POST['createContainer'])){
    $client = new Corsinvest\ProxmoxVE\Api\PVEClient('10.250.50.150');
    if ($client->login("root", "ultrasecurepasswordlol")) {
        $client->setResponseType('json');
        $client->setResultIsObject(false);
        echo '<div class="alert alert-success" role="alert">Container is creating...</div>';
        $id = $client->getCluster()->getNextid()->nextid()->getResponse();
        var_dump($client->getNodes()->get('pve-claas')->getLxc()->createVm(ostemplate: 'debian-11-standard_11.7.1_amd64.tar.zst',  vmid: $id['data'], rootfs: "local-lvm")->getError());
    } else {
        echo '<div class="alert alert-danger" role="alert">An Error Occurred.</div>';
    }
}

EDIT: I had to set storage to local-lvm lol <3

why doesnt it create it tho? the vardump prints out: string(0) ""
Thanks in advance

How to get rrd?

Hello why is this not working?

$retArr = $client->getNodes()->get("ns3365239")->getQemu()->get(100)->getRrd()->getResponse()->data;
echo "\n" . $retArr['data']['vmid'];

And how do you stop a vps and how do you create a vps.

lxc IP?

$client->getNodes()->get("nodex")->getLxc()->Vmlist()

but this one does not have and IP address. Any way to get it?

thanks

Remove VZ and create/remove CT

Hi!

I have a question, what is the structure of VM removal?
And the second question is the structure of the creation and removal of CT

Greetings,
Tobiasz

RRD not loading Image

Hello i use this code.

$retArr = $client->getNodes()->get("ns3365239")->getQemu()->get(101)->getRrd()->rrd('maxcpu', 'day')->getResponse(); print_r($retArr);

but i get thit output

Array ( [data] => )

Get VNC Ticket

What happened?

Hello,

how do you get a ticket?

$vncTicket = $client->get('/access/ticket');

is giving me status code 200, but the data block is empty.

Best regards

Expected behavior

Giving me a ticket instead of empty response in data block

Relevant log output

No response

PHP Version

8.4

Proxmox VE Version

5.4

Version (bug)

latest

Version (working)

No response

On what operating system are you experiencing the issue?

Mac OSX

Pull Request

  • I would like to do a Pull Request

about promox novnc

Hi
we login in promox novnc use api have trouble.
do you share php login novnc demo?
if we use root account login have safe trouble.

Expose HTTP Headers for requests made with PveClientBase

Hey there, thanks for the library, it's been great to use so far.

Overview

This is more of a feature request than bug, but it appears that the Proxmox API returns errors in HTTP headers, rather than the JSON response body in some cases.

This happens in multiple endpoints, but one example can be seen in /api2/json/nodes/{node}/qemu/{vmid}/clone (docs here). Here's what the headers looks like:

HTTP/1.1 500 VM is locked (backup)
Cache-Control: max-age=0
Connection: close
Date: Thu, 25 Jul 2024 23:24:26 GMT
Pragma: no-cache
Server: pve-api-daemon/3.0
Content-Length: 13
Content-Type: application/json;charset=UTF-8
Expires: Thu, 25 Jul 2024 23:24:26 GMT

Since this error is in the header rather than body, it's not present in the following methods for the Result class:

  • getReasonPhrase()
  • getResponse()
  • getErrors()

It would be useful if the raw headers were accessible by the user in these scenarios.

Steps to Replicate

  1. Create a VM template in PVE
  2. SSH onto the node this template is on, and open the template config file at /etc/pve/qemu-server/<VMID>.conf
  3. Add the line lock: backup to the bottom of the file, to manually lock the template
  4. Try to clone the VM using the Proxmox API, you should get an error message in the response headers rather than the body

Solution

There are multiple ways to solve this, but one way could potentially be to add a new field to the Result class, which contains the contents of the raw headers. The headers can then be inspected by the user when they encounter an error, if they need to.

I believe the code would need to be added somewhere here: https://github.com/Corsinvest/cv4pve-api-php/blob/master/src/PveClientBase.php#L460


Happy to create a PR for this feature. Thanks for reading.

[Feature] Change function to accept array

Change function parameter accept array only parameter changed.

example

From

updateVm($acpi = null, $agent = null, $args = null, $autostart = null, $balloon = null, $bios = null, $boot = null, $bootdisk = null, $cdrom = null, $cores = null, $cpu = null, $cpulimit = null, $cpuunits = null, $delete = null, $description = null, $digest = null, $force = null, $freeze = null, $hostpciN = null, $hotplug = null, $hugepages = null, $ideN = null, $keyboard = null, $kvm = null, $localtime = null, $lock = null, $machine = null, $memory = null, $migrate_downtime = null, $migrate_speed = null, $name = null, $netN = null, $numa = null, $numaN = null, $onboot = null, $ostype = null, $parallelN = null, $protection = null, $reboot = null, $revert = null, $sataN = null, $scsiN = null, $scsihw = null, $serialN = null, $shares = null, $skiplock = null, $smbios1 = null, $smp = null, $sockets = null, $startdate = null, $startup = null, $tablet = null, $tdf = null, $template = null, $unusedN = null, $usbN = null, $vcpus = null, $vga = null, $virtioN = null, $vmstatestorage = null, $watchdog = null)

To

$params = [
'acpi' => ...,
'scsihw' => ...,,
];

updateVm($params)

Call to undefined method Corsinvest\ProxmoxVE\Api\PVEClusterNextid::getResponse()

Hello. I am feeling a little dumb with how to get responses from methods like Nextid or for example "shutdown"

(To shutdown a machine i ended up using the Base Cliente like so:

$client->setResponseType('json');
$result = $client->create('/nodes/qindev/qemu/105/status/shutdown')->getResponse()->data;
return $result;

Could i please get an example of this? Thanks :D

Proxmox 6 support

Hello,

this api isn't working for me under proxmox 6. When will there be an update?

Thanks for your great work!

SSL EOF Error in Curl?

What happened?

Hello,

Some Bug, when I use the Laravel Php artisan development server the client works just fine, but when Im using the Queue Worker - which should make the same, it always failes with this error:

OpenSSL SSL_read: error:0A000126:SSL routines::unexpected eof while reading, errno 0

According to some sources and issues this is a well known issue in Php 8, but Im wondering how I can fix it.
It seems to usually appear in file_get_contents(https) but somehow also with cURL. But your client isnt using any of those, I tried to change those lines:

curl_setopt($prox_ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($prox_ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($prox_ch, CURLOPT_SSLVERSION, 7);

But even If im choosing the manual ssl version and skip openSSL 3 (i guess) the error still occurs. Hm.

Expected behavior

No error

Relevant log output

The whole Debug:

object(Corsinvest\ProxmoxVE\Api\Result)#963 (8) {
  ["reasonPhrase":"Corsinvest\ProxmoxVE\Api\Result":private]=>
  string(84) "OpenSSL SSL_read: error:0A000126:SSL routines::unexpected eof while reading, errno 0"
  ["statusCode":"Corsinvest\ProxmoxVE\Api\Result":private]=>
  int(401)
  ["response":"Corsinvest\ProxmoxVE\Api\Result":private]=>
  NULL
  ["resultIsObject":"Corsinvest\ProxmoxVE\Api\Result":private]=>
  bool(true)
  ["requestResource":"Corsinvest\ProxmoxVE\Api\Result":private]=>
  string(35) "/nodes/noxomix/lxc/401/status/start"
  ["requestParameters":"Corsinvest\ProxmoxVE\Api\Result":private]=>
  array(0) {
  }
  ["methodType":"Corsinvest\ProxmoxVE\Api\Result":private]=>
  string(6) "CREATE"
  ["responseType":"Corsinvest\ProxmoxVE\Api\Result":private]=>
  string(4) "json"
}


### PHP Version

8.1, 8.2, 8.3 - no others tested

### Proxmox VE Version

8

### Version (bug)

latest

### Version (working)

_No response_

### On what operating system are you experiencing the issue?

Linux

### Pull Request

- [ ] I would like to do a Pull Request

VNC

Hey!

this has only indirectly something to do with this, but maybe you know something about it.
We are currently trying our hand at VNC, but unfortunately it is not working properly.

The VNC page takes a long time to load.

This is the code:

$domain = "EXAMPLE_DOMAIN_TO_HOST.de"

$responseProxy = $proxmox->getNodes()->get($host_name)->getQemu()->get($external_id)->getVncproxy()->vncproxy(true, true)->getResponse();
    
$port = $responseProxy['data']['port'];
$ticket = $responseProxy['data']['ticket'];
$user = $responseProxy['data']['user']; 
$password = $responseProxy['data']['password'];
    
$response = $proxmox->getNodes()->get($host_name)->getQemu()->get($external_id)->getVncwebsocket()->vncwebsocket($port, $ticket)->getResponse();


$url = "https://vnc.EXAMPLE.com?host=$domain."&port=".$port."&novnc=1&vmname=".$external_name."&vmid=".$external_id."&node=".$host_name."&user=".$user."&password=".$password;

Do you know anything about that?

Bug Change VM Password

I'm using x cv4pve-api-php to communicate with the api

I'm trying to reset the password of a vm using the proxmox API.

$data = $pve->getNodes()->get($node)->getQemu()->get($vmid)->getAgent()->getSetUserPassword()->setUserPassword('Administrator', 'QAZ2wsx2')->getResponse();

return $data;

When I do this command I get the following API response:

{"data": null}

I went to vm but the password is not changed. So I tried the following commands to check if communication to the VM was working and yes it was.

$data1 = $pve->getNodes()->get($node)->getQemu()->get($vmid)->getAgent()->getGetUsers()->getUsers()->getResponse();

$data2 = $pve->getNodes()->get($node)->getQemu()->get($vmid)->getAgent()->getNetworkGetInterfaces()->networkGetInterfaces()->getResponse();

return $data1;

return $data2;
{"data":{"result":[{"user":"Administrator","login-time":1703928164.75337,"domain":"WIN-42DB1GRE758"}]}}

{"data":{"result":[{"name":"Ethernet","statistics":{"rx-bytes":37858,"tx-dropped":0,"tx-errs":0,"rx-packets":16,"rx-errs":0,"rx-dropped":0,"tx-bytes":7751,"tx-packets":13},"hardware-address":"bc:24:11:7b:69:b1","ip-addresses":[{"prefix":64,"ip-address-type":"ipv6","ip-address":"fe80::8629:4e3c:bc25:63e3%14"},{"prefix":24,"ip-address-type":"ipv4","ip-address":"163.172.112.35"},{"ip-address":"169.254.165.33","ip-address-type":"ipv4","prefix":16}]},{"name":"Loopback Pseudo-Interface 1","ip-addresses":[{"ip-address-type":"ipv6","prefix":128,"ip-address":"::1"},{"ip-address":"127.0.0.1","ip-address-type":"ipv4","prefix":8}],"statistics":{"rx-bytes":0,"tx-errs":0,"tx-dropped":0,"rx-packets":0,"rx-errs":0,"rx-dropped":0,"tx-bytes":0,"tx-packets":0}}]}}

Then I changed the password through the proxmox shell with the following command and the password is changed:

qm guest passwd 104 root -password QAZ2wsx

I tried to change the username to root and with that user the error message appears.

$data = $pve->getNodes()->get($node)->getQemu()->get($vmid)->getAgent()->getSetUserPassword()->setUserPassword('root', 'QAZ2wsx2')->getResponse();

return $data;

{"errors":{"password":"value must be at least 5 characters long"},"data":null}

I can't understand why this happened since the root user does not exist in the vm's OS.

If anyone can help I would be grateful. Thanks

How to Set Timeout?

How can we set a Timeout for example when the Host is not reachable? Currently its blocking my Webserver somehow If i try to Connect to a Proxmox Node which is offline.

How to get next bigger vmID?

Hey,
I want to automatically deploy new containers. How do I auto Increment the vmID?

my code:
$client->getNodes()->get('pve-claas')->getLxc()->createVm('debian-11-standard_11.7.1_amd64.tar.zst', '...AUTOINCREMENT-HERE');

Error on Resize

Hey,

I have some problems with resizing a hard disk.

e.g.
$disk = 10;
$host_name = "server01"; (ServerName)
$service_id = "100"; (VM ID)

$request = $proxmox->getNodes()->get($host_name)->getQemu()->get($service_id)->getResize()->resizeVm("scsi0", "+".$disk ."G");
Resizing does not work with the shown command, the error message just says "null". everything else works, with the same data.

I also get this error (sometimes).

"TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given in \/vendor\/corsinvest\/cv4pve-api-php\/src\/Result.php:156",
"Stack trace:",
"#0 \/vendor\/corsinvest\/cv4pve-api-php\/src\/Result.php(156): array_key_exists()",
"#1 \/vendor\/corsinvest\/cv4pve-api-php\/src\/Result.php(166): Corsinvest\\ProxmoxVE\\Api\\Result->responseInError()",
"#2 proxmoxController.php(161): Corsinvest\\ProxmoxVE\\Api\\Result->getError()",
"#3 ..."

161 = if(!$request->isSuccessStatusCode()) return ...

Please help.

Not working

Message: Class 'Corsinvest\ProxmoxVE\Api\PveClient' not found
What to do?

Bug Change Password VM

What happened?

I'm using x cv4pve-api-php to communicate with the api

I'm trying to reset the password of a vm using the proxmox API.

[CODE=php]$data = $pve->getNodes()->get($node)->getQemu()->get($vmid)->getAgent()->getSetUserPassword()->setUserPassword('Administrator', 'QAZ2wsx2')->getResponse();

return $data;[/CODE]

When I do this command I get the API response like:

[CODE=json]{"data": null}[/CODE]

I went to vm but the password is not changed. So I tried the following commands to check if communication to the VM was working and yes it was.

[CODE=php]$data1 = $pve->getNodes()->get($node)->getQemu()->get($vmid)->getAgent()->getGetUsers()->getUsers()->getResponse();

$data2 = $pve->getNodes()->get($node)->getQemu()->get($vmid)->getAgent()->getNetworkGetInterfaces()->networkGetInterfaces()->getResponse();

return $data1;

return $data2;

[/CODE]

[CODE=json]{"data":{"result":[{"user":"Administrator","login-time":1703928164.75337,"domain":"WIN-42DB1GRE758"}]}}

{"data":{"result":[{"name":"Ethernet","statistics":{"rx-bytes":37858,"tx-dropped":0,"tx-errs":0,"rx-packets":16,"rx-errs":0,"rx-dropped":0,"tx-bytes":7751,"tx-packets":13},"hardware-address":"bc:24:11:7b:69:b1","ip-addresses":[{"prefix":64,"ip-address-type":"ipv6","ip-address":"fe80::8629:4e3c:bc25:63e3%14"},{"prefix":24,"ip-address-type":"ipv4","ip-address":"163.172.112.35"},{"ip-address":"169.254.165.33","ip-address-type":"ipv4","prefix":16}]},{"name":"Loopback Pseudo-Interface 1","ip-addresses":[{"ip-address-type":"ipv6","prefix":128,"ip-address":"::1"},{"ip-address":"127.0.0.1","ip-address-type":"ipv4","prefix":8}],"statistics":{"rx-bytes":0,"tx-errs":0,"tx-dropped":0,"rx-packets":0,"rx-errs":0,"rx-dropped":0,"tx-bytes":0,"tx-packets":0}}]}}

[/CODE]

Then I changed the password through the proxmox shell with the following command and the password is changed:

[CODE=bash]qm guest passwd 104 root -password QAZ2wsx[/CODE]

I tried to change the username to root and with that user the error message appears.

[CODE=php]$data = $pve->getNodes()->get($node)->getQemu()->get($vmid)->getAgent()->getSetUserPassword()->setUserPassword('root', 'QAZ2wsx2')->getResponse();

return $data;[/CODE]

[CODE=json]{"errors":{"password":"value must be at least 5 characters long"},"data":null}[/CODE]

I can't understand why this happened since the root user does not exist in the vm's OS.

If anyone can help I would be grateful. Thanks

Expected behavior

Change Password

Relevant log output

No response

PHP Version

8.1

Proxmox VE Version

8.1.3

Version (bug)

1

Version (working)

No response

On what operating system are you experiencing the issue?

Linux

Pull Request

  • I would like to do a Pull Request

JSON vs. x-www-form-urlencoded for PUT/POST

Hi,

thx for you lib. But I was wondering if json_encode($parameters) for PUT/POST methods is correct behavior since API doc, see https://pve.proxmox.com/wiki/Proxmox_VE_API#API_URL, specifies following:

Parameters can be passed using standard HTTP techniques:

  • via the URL
  • using x-www-form-urlencoded content-type for PUT and POST request.

As far as I can see, there is no JSON support for PUT/POST parameters. Currently, I am getting 501 Not Implemented when I want to call eg. POST /api2/json/nodes/NODE-01/qemu/103/status/stop via this library. But once I replace $data = json_encode($parameters) to eg. $data = http_build_query($parameters) in executeAction() and remove array_push for headers' Content-Type and Content-Length on lines that follows, server accepts it with 200 OK.

I am sure this library is using by several devs, so maybe it is about my Proxmox configuration. But since there is no official support of JSON mentioned in Proxmox documentation, I would kindly ask you for any response to this issue.

Thx.

API Token Example?

Hello, is there any example how to establish a connection via API-Token instead Username/Password?

  • When I do setApiToken() i cant connect.
    (- When I use token instead of the users password in the login() method it also not working)

What I forgot?

$client = new PveClient($cluster_data->hostname, $cluster_data->port);
$client->setApiToken($cluster_data->token);
$client->getVersion();

Would be nice if there is any example provided how to connect via Token.

Best Regards
Theo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.