antcool / easy-cloud-pods
PHP SDK for Cloud Pods
1.1.2
2023-04-26 04:21 UTC
Requires
- php: ^8.0.2
- ext-curl: *
- ext-openssl: *
- guzzlehttp/guzzle: ^7.5
- illuminate/collections: ^9.0|^10.0
- monolog/monolog: ^2.0|^3.0
- nyholm/psr7: ^1.5
- nyholm/psr7-server: ^1.0
- psr/simple-cache: ^1.0|^2.0|^3.0
- symfony/cache: ^6.2
This package is auto-updated.
Last update: 2025-02-26 08:24:11 UTC
README
PHP SDK for Cloud Pods.
Overtrue! Respect!
文档链接
安装
$ composer require antcool/easy-cloud-pods -vvv
使用
需开启统一API入口, 查看文档
配置项
$config = [ 'default' => 'production', 'projects' => [ 'production' => [ 'api_gateway' => 'https://<ip_or_domain_of_apigatway>/api/s/', 'project_id' => '****', 'project_name' => null, 'auth_type' => 'password', // ak/sk 'user_name' => '****', 'user_password' => '****', 'key_id' => '****', 'secret' => '****', 'domain' => null, 'domain_name' => null, ], ], /** * 默认使用各 endpoint type 字段作为统一 API 入口请求时的服务类型路径 * 由于每个版本的路径会有不同, 当默认路径错误时, 可通过此配置覆盖 * compute_v2: compute_v2 * image: image/v1 * identity: identity/v3 */ 'endpoint_path' => [ 'image' => 'image/v1', 'identity' => 'identity/v3', ], 'debug' => true, 'runtime_path' => storage_path('cloud-pods'), 'http' => [ 'timeout' => 30, 'verify' => false, ], ];
创建实例
use AntCool\CloudPods\Application; $app = new Application(new Config(\config('cloudpods')); // use other project config $config = $app->getConfig()->useProject('project_name'); /** @var \AntCool\CloudPods\Kernel\Client $client */ $client = $app->getClient();
API 调用示范
\AntCool\CloudPods\Middleware\AccessTokenMiddleware 已经实现对 AuthToken 和 Endpoints 的自动处理
// 查看 Endpoints $client->getEndpoints(); // 获取支持的镜像 $client->withService('image')->getJson('images', ['limit' => 1000, 'details' => true]) // 实际请求 URL: https://<gateway>/api/s/image/v1/images?limit=1000&details=1 // 获取主机规格 $client->withService('compute_v2')->getJson('serverskus', ['limit' => 1000, 'details' => true]); // 创建秘钥对 $client->withService('compute_v2')->postJson('keypairs', [ 'count' => 1, 'keypair' => [ 'description' => 'description', 'name' => 'name', ], ]); // 创建虚拟机 $client->withService('compute_v2')->postJson('servers', $params); // 删除虚拟机 $client->withService('compute_v2')->deleteJson('servers/' . $id, [ 'OverridePendingDelete' => true, 'Purge' => true, 'DeleteSnapshots' => true, 'DeleteEip' => true, 'DeleteDisks' => true, ]); // 获取 monitor 监控服务 unified monitor 的查询接口签名 $app->getUtils()->unifiedMonitorSign($params);
Contributing
You can contribute in one of three ways:
- ...
- ...
License
MIT