cedricziel/php-hetzner-cloud-api
Composer 安装命令:
composer require cedricziel/php-hetzner-cloud-api
包简介
Hetzner Cloud API Client for PHP
README 文档
README
A API client library for the Hetzner Cloud APIs.
API keys can be obtained through the project settings.
Installation
composer require cedricziel/php-hetzner-cloud-api
Configuration and Basic Usage
$token = '...'; // create an api client $client = new \CedricZiel\HetznerCloudAPI\Client(); // set the credentials on your client $client->authenticate($token); // retrieve a list of servers $client->servers->all();
Available clients
Actions
Actions show the results and progress of asynchronous requests to the API.
Source (HCloud API Documentation)
// retrieve all actions $actions = $client->actions->all(); // get one action $action = $client->actions->show($actionId);
Images
Images are blueprints for your VM disks.
Source (HCloud API Documentation)
// retrieve all images $images = $client->images->all(); // get one image $image = $client->images->show($imageId);
Pricing
Returns prices for all resources available on the platform. VAT and currency of the project owner are used for calculations.
Both net and gross prices are included in the response.
Source (HCloud API Documentation)
// retrieve all prices $prices = $client->pricing->all();
Servers
Servers are virtual machines that can be provisioned.
Source (HCloud API Documentation)
// retrieve all servers $server = $client->servers->all(); // get one server $server = $client->servers->show($serverId); // create a server $server = $client->servers->create($parameters); // rename a server $server = $client->servers->rename($serverId, $newName); // remove a server $client->servers->remove($serverId);
ServerActions
Apply actions to your servers and retrieve progress/status messages.
Source (HCloud API Documentation)
// retrieve all server actions $actions = $client->server_actions->all(); // get one server action $action = $client->server_actions->show($actionId); // powerOn $action = $client->server_actions->powerOn($serverId); // reboot $action = $client->server_actions->reboot($serverId); // reset $action = $client->server_actions->reset($serverId); // powerOn $action = $client->server_actions->powerOn($serverId); // shutdown $action = $client->server_actions->shutdown($serverId); // powerOff $action = $client->server_actions->powerOff($serverId); // resetPassword $action = $client->server_actions->resetPassword($serverId); // enableRescueMode $action = $client->server_actions->enableRescueMode($serverId); // disableRescueMode $action = $client->server_actions->disableRescueMode($serverId); // createImage $action = $client->server_actions->createImage($serverId, $parameters); // rebuild $action = $client->server_actions->rebuild($serverId, $parameters); // changeType $action = $client->server_actions->changeType($serverId, $parameters); // enableBackup $action = $client->server_actions->enableBackup($serverId, $parameters); // disableBackup $action = $client->server_actions->disableBackup($serverId); // attachIso $action = $client->server_actions->attachIso($serverId, $parameters); // detachIso $action = $client->server_actions->detachIso($serverId); // changeDnsPtr $action = $client->server_actions->changeDnsPtr($serverId, $parameters); // changeProtection $action = $client->server_actions->detachIso($serverId, $parameters); // requestConsole $action = $client->server_actions->requestConsole($serverId);
SSH Keys
SSH keys are public keys you provide to the cloud system.
Source (HCloud API Documentation)
// retrieve all SSH Keys $keys = $client->ssh_keys->all(); // get one SSH Key $key = $client->ssh_keys->show($keyId); // create a SSH Key $key = $client->ssh_keys->create($parameters); // rename a SSH Key $key = $client->ssh_keys->rename($keyId, $name); // remove a SSH Key $key = $client->ssh_keys->remove($keyId);
Usage with Symfony
This library uses the httpplug client library. The project provides a Symfony bundle. When installed, you can directly integrate the client library to make the API queries visible and debuggable:
# in config/services.yaml parameters: hetzner_token: '...' # Hetzner API Base Client CedricZiel\HetznerCloudAPI\Client: factory: ['CedricZiel\HetznerCloudAPI\Client', 'createWithHttpClient'] arguments: - '@httplug.client.app' calls: - ['authenticate', ['%hetzner_token%', !php/const CedricZiel\HetznerCloudAPI\Client::AUTH_HTTP_TOKEN]] # You can add a client service for the different resource types if you like: CedricZiel\HetznerCloudAPI\Api\DataCenters: factory: ['@CedricZiel\HetznerCloudAPI\Client', 'api'] arguments: - 'data_centers' CedricZiel\HetznerCloudAPI\Api\ServerTypes: factory: ['@CedricZiel\HetznerCloudAPI\Client', 'api'] arguments: - 'server_types'
Credits
The project is heavily inspired by the Gitlab PHP API Client by @m4tthumphrey.
License
MIT
cedricziel/php-hetzner-cloud-api 适用场景与选型建议
cedricziel/php-hetzner-cloud-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 689 次下载、GitHub Stars 达 5, 最近一次更新时间为 2018 年 04 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 cedricziel/php-hetzner-cloud-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cedricziel/php-hetzner-cloud-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 689
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-04-15