corsinvest / cv4pve-api-php Goto Github PK
View Code? Open in Web Editor NEWProxmox VE Client API for PHP
Home Page: https://www.corsinvest.it/cv4pve
License: GNU General Public License v3.0
Proxmox VE Client API for PHP
Home Page: https://www.corsinvest.it/cv4pve
License: GNU General Public License v3.0
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
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
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.
$client->getNodes()->get("nodex")->getLxc()->Vmlist()
but this one does not have and IP address. Any way to get it?
thanks
Hello,
How do you create a Qemu VM?
Tom Lammers
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
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] => )
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
Giving me a ticket instead of empty response in data block
No response
8.4
5.4
latest
No response
Mac OSX
hi boss.
how to write php code running api qm guest exec ..?
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.
Hey there, thanks for the library, it's been great to use so far.
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.
/etc/pve/qemu-server/<VMID>.conf
lock: backup
to the bottom of the file, to manually lock the templateThere 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.
Remove dependency from GuzzleHttp and use directly Curl
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)
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
Hello,
this api isn't working for me under proxmox 6. When will there be an update?
Thanks for your great work!
hi,
Installation guide is for version 1.0 but usage part is for later version
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.
No error
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
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?
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 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.
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');
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.
Message: Class 'Corsinvest\ProxmoxVE\Api\PveClient' not found
What to do?
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
Change Password
No response
8.1
8.1.3
1
No response
Linux
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:
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.
Hello, is there any example how to establish a connection via API-Token instead Username/Password?
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.