bennetgallein / proxmoxve
一个简单的PHP 8+ Proxmox API客户端。
Requires
- php: >=8.0
- lib-curl: *
- guzzlehttp/guzzle: ~7.0
Requires (Dev)
- phpunit/phpunit: ~9.0
This package is auto-updated.
Last update: 2024-09-05 21:08:46 UTC
README
这个 PHP 8+ 库允许您通过API与您的Proxmox服务器交互。
安装
建议使用Composer进行安装,如果您还没有Composer,您在等什么呢?
在您的项目根目录中执行以下操作
$ composer require bennetgallein/proxmoxve ~v5.0
或者将其添加到您的composer.json
文件中
{ "require": { "bennetgallein/proxmoxve": "~v5.0" } }
然后执行安装
$ composer install --no-dev
用法
<?php // Require the autoloader require_once 'vendor/autoload.php'; // Use the library namespace use ProxmoxVE\Proxmox; // Create your credentials array $credentials = [ 'hostname' => 'proxmox.server.com', // Also can be an IP 'username' => 'root', 'password' => 'secret', ]; // realm and port defaults to 'pam' and '8006' but you can specify them like so $credentials = [ 'hostname' => 'proxmox.server.com', 'username' => 'root', 'password' => 'secret', 'realm' => 'pve', 'port' => '9009', ]; // you can also specify token-id and token-secret to use API tokens. They will be preffered over normal username/password $credentials = [ 'hostname' => 'proxmox.server.com', 'token-id' => 'root@pam!prod', 'token-secret' => 'a806bdd1-de9a-4860-9ce0-bc427d3f2067' ] // Then simply pass your credentials when creating the API client object. $proxmox = new Proxmox($credentials); $allNodes = $proxmox->get('/nodes'); print_r($allNodes);
示例输出
Array ( [data] => Array ( [0] => Array ( [disk] => 2539465464 [cpu] => 0.031314446882002 [maxdisk] => 30805066770 [maxmem] => 175168446464 [node] => mynode1 [maxcpu] => 24 [level] => [uptime] => 139376 [id] => node/mynode1 [type] => node [mem] => 20601992182 ) ) )
使用MailGateway API
此库还可以用于通过简单更改凭据数组中的system
条目与Proxmox MailGateway API通信。
<?php $credentials = [ 'hostname' => 'proxmox.server.com', // Also can be an IP 'username' => 'root', 'password' => 'secret', 'system' => 'pmg', // Defaults to 'pve' for the PVE API. Use 'pmg' for the PMG API. ];
Using the backup Server API
-------------------------
This library can be used to communicate with the [Proxmox Backup Server API](https://pbs.proxmox.com/docs/api-viewer/index.html) as well, by simply changing the `system` entry in the credentials array.
```php
<?php
$credentials = [
'hostname' => 'proxmox.server.com', // Also can be an IP
'username' => 'root',
'password' => 'secret',
'system' => 'pbs', // Defaults to 'pve' for the PVE API. Use 'pbs' for the PBS API.
];
文档
在您的Proxmox客户端对象上,您可以使用get()
、create()
、set()
和delete()
函数来操作在PVE2 API文档中指定的所有资源,参数作为关联数组的第二个参数传递。
我可以与哪些资源或路径交互以及如何交互?
在您的Proxmox服务器上,您可以使用pvesh CLI工具来管理所有pve资源,您可以像使用pvesh工具一样使用此库。例如,您可以使用pvesh
,然后,就像屏幕消息中说的那样,您可以输入help [path] [--verbose]
来查看如何使用路径以及应传递给它的参数。务必在Proxmox wiki上阅读有关pvesh CLI工具的说明。
Proxmox API是如何工作的?
请参考ProxmoxVE API文章,该文章位于Proxmox wiki。
我觉得你隐藏了一些酷技巧!我需要更多的文档!
请参阅项目的wiki以获取更详细的文档,我在那里发誓它都在……我想。
许可证
该项目是在MIT许可证下发布的。有关详细信息,请参阅捆绑的LICENSE文件。
想要贡献?
谢谢!请查看CONTRIBUTING,您可以轻松设置开发环境,以便您快速开始!