dutchie027/vultr

v3.0.1 2022-11-07 23:02 UTC

This package is auto-updated.

Last update: 2024-09-10 18:10:21 UTC


README

Latest Stable Version Total Downloads License CodeFactorPHPStan Check

PHP 库,用于与 Vultr 的 v2 API 交互

安装

composer require dutchie027/vultr

使用

// require the composer library
require_once ('vendor/autoload.php');

// make the connction to the API for use
// this will use "vultr.ini" with the KVPs created
// at composer load. As a minimum you need the API
$api = new dutchie027\Vultr\API();

...

vultr.ini

该文件驱动软件的主要配置。默认情况下,它在项目根目录中查找名为 vultr.ini 的文件。如果您愿意,您可以给它另一个名称,并在类实例化时指定完整的 .ini 路径。

[api] 键中键/值对的最低要求,其中 TOKEN 是您从我的 Vultr 门户获取的 API 令牌。

# minimum vultr.ini
[api]
TOKEN='8675309TOMMY30918IN'

可以提供给 .ini 的完整设置

# full vultr.ini
[api]
TOKEN='12345

[log]
LOG_PREFIX='vultr'
LOG_LEVEL=200
LOG_DIR='/var/log/'

一般信息

类列表

该库具有以下类

类信息

API

主要连接至少需要一个 API 密钥。您可以通过访问 我的 Vultr 门户 -> 账户 -> API 来获取此密钥。在门户中,请确保您也设置了您将从中调用 API 的 IP 地址,因为默认情况下它将锁定到您请求 API 的单个 IP 地址。

一旦您有了 API 令牌,您就可以简单地使用它来连接,或者您可以添加选项

// Ensure we have the composer libraries
require_once ('vendor/autoload.php');

// Instantiate with defaults
$api = new dutchie027\Vultr\API();

Account

一旦您有了客户端,您就可以获取有关您账户的基本信息。注意:所有有效负载都以 JSON 格式返回,因此您可以选择如何处理它们

// Ensure we have the composer libraries
require_once ('vendor/autoload.php');

// Instantiate with defaults
$api = new dutchie027\Vultr\API();

// Lets get the account info and what else this API key can do
print_r(json_decode($api->account()->getAccountInfo(), true));

块存储

创建块存储

// Ensure we have the composer libraries
require_once ('vendor/autoload.php');

// Instantiate with defaults
$api = new dutchie027\Vultr\API();

$config = [
    'region' => 'ewr',
    'size' => '10',
    'label' => 'my first storage',
];

$json_return = $api->blockStorage()->createBlockStorage($config);
配置

如果您不带任何 $config 调用此函数,它仍然会创建块存储。它将使用以下描述的默认值。

返回值

您将获得一个包含新创建的块 ID 以及成本(以美元计)和大小(以 GB 计)的 JSON 有效负载。

{
  "block": {
    "id": "8692c434-08fa-4efb-a0fb-966a338aee07",
    "date_created": "2020-12-18T03:11:57+00:00",
    "cost": 1,
    "status": "pending",
    "size_gb": 10,
    "region": "ewr",
    "attached_to_instance": "",
    "label": "my first storage"
  }
}

更新块存储

// Ensure we have the composer libraries
require_once ('vendor/autoload.php');

// Instantiate with defaults
$api = new dutchie027\Vultr\API();

$config = [
    'blockid' => '8692c434-08fa-4efb-a0fb-966a338aee07',
    'size' => '40',
    'label' => 'not my first rodeo',
];

$api->blockStorage()->updateBlockStorage($config);
块存储配置

块存储只能每 60 秒更新一次。要更新存储,您需要至少提供 blockid 以及 size 或新的 label

删除块存储

// Ensure we have the composer libraries
require_once ('vendor/autoload.php');

// Instantiate with defaults
$api = new dutchie027\Vultr\API();

$api->blockStorage()->deleteBlockStorage($blockid);

块 ID 的格式为 GUID(例如 8692c434-08fa-4efb-a0fb-966a338aee07)。如果您提供的 GUID 不在您的存储容器中,它将失败。

列出特定存储

// Ensure we have the composer libraries
require_once ('vendor/autoload.php');

// Instantiate with defaults
$api = new dutchie027\Vultr\API();

$json_return = $api->blockStorage()->getBlockStorage($blockid);

块 ID 的格式为 GUID(例如 8692c434-08fa-4efb-a0fb-966a338aee07)。如果您提供的 GUID 不在您的存储容器中,它将失败。

附加块存储

// Ensure we have the composer libraries
require_once ('vendor/autoload.php');

// Instantiate with defaults
$api = new dutchie027\Vultr\API();

$config = [
 'block_id' => '98772323-044a-4efb-a0fb-1234338abb07',
 'instance' => '12345434-08fa-4efb-a0fb-966a338aee07',
    'live' => false,
];

$api->blockStorage()->attachBlockStorage($config);

$config 中需要三个值。其中 block_id 是您想要附加的块存储的 ID。其中 instance 是您想要附加存储的机器的实例 ID。它还必须在存储的同一位置。值 livetruefalse。如果将其设置为 true,它将附加存储但不会重新启动实例。如果您将 live 设置为 false,它将重新启动实例然后附加块存储。

断开块存储连接

// Ensure we have the composer libraries
require_once ('vendor/autoload.php');

// Instantiate with defaults
$api = new dutchie027\Vultr\API();

$config = [
 'block_id' => '98772323-044a-4efb-a0fb-1234338abb07',
    'live' => false,
];

$api->blockStorage()->detatchBlockStorage($config);

$config 中需要两个值。其中 block_id 是您想要断开连接的块存储的 ID。值 livetruefalse。如果将其设置为 true,它将附加存储但不会重新启动实例。如果您将 live 设置为 false,它将重新启动实例然后断开块存储连接。

Regions

大部分情况下,这是一个支持类,但如果你想使用它,也可以。以下是一些你可以用它的方式

// Ensure we have the composer libraries
require_once ('vendor/autoload.php');

// Instantiate with defaults
$api = new dutchie027\Vultr\API();

// Print various information about the Regions. All pretty self-explanatory
$api->regions()->listIds();
$api->regions()->listCities();
$api->regions()->listCountries();
$api->regions()->listContinents();
$api->regions()->listNames();

待办事项

  • 引入更多来自 Vultr 的功能(s)
  • 用更合适的文档块更好地记录类(们)
  • 将文档移动到单独的 markdown 文件中

贡献

如果你遇到问题,发现错误,或者有功能建议,请提交一个 issues。如果你想,可以随意fork这个包并提交一个 pull request。随着我获取更多信息并进一步测试API,这是一个持续进行中的项目。