dutchie027/vultr 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dutchie027/vultr

Composer 安装命令:

composer require dutchie027/vultr

包简介

Vultr PHP API

README 文档

README

Latest Stable Version Total Downloads License CodeFactorPHPStan Check

PHP Library Intended to Interact with Vultr's v2 API

Installation

composer require dutchie027/vultr

Usage

// 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

This file drives the main configuration of the software. By default, it looks for the file in the root directory of your project using the name vultr.ini. If you want, you can give it another name and specifiy the full .ini path in the class instantiation.

The minimum Key/Value Pair in the [api] key with the TOKEN being your API token from the My Vultr Portal.

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

The full settings that can be supplied in the .ini are:

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

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

General Information

Class Listing

The library has the following classes:

Class Information

API

The main connection requires at minimum, an API key. You can get this by visiting My Vultr Portal -> Account -> API. In the portal, make sure you set the IP(s) you'll be calling the API from also, as by default it will lock it to the single IP you request the API from.

Once you have the API token, you can simply connect with it or you can add options

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

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

Account

Once you have a client, you can ask for the basic information about your account. NOTE: All payloads are returned in JSON, so you can choose how you want to deal with them:

// 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));

Block Storage

Creating Block Storage

// 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

If you call this without any $config it will still create block storage. It will use the defaults as described below.

Parameter Type Description Default Value
region string The region where you want the storage created. NOTE If you choose a location that does NOT have block storate, it will revert to the default. ewr
size integer The size (in GB) of how much storage you want created. NOTE This value must be between 10 and 10000 10
label string A text label to be associated with the storage null
Return Value

You will be returned with a JSON payload that includes the newly created Block ID as well as the cost (in dollars) and size (in GB):

{
  "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"
  }
}

Updating Block 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);
Block Storage Config

Block storage can only be updated once every 60 seconds. To update the storage you need a minimum of the blockid and either a size or new label.

Deleting Block Storage

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

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

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

The block ID is in the form of a GUID (something like 8692c434-08fa-4efb-a0fb-966a338aee07). If you provide a GUID that isn't in your storage container, it will fail.

Listing Specific Storage

// 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);

The block ID is in the form of a GUID (something like 8692c434-08fa-4efb-a0fb-966a338aee07). If you provide a GUID that isn't in your storage container, it will fail.

Attaching Block Storage

// 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);

All three values are required in the $config. The block_id is the ID of the block storage you want to attach. The instance is the instance ID of the machine you want the storage attached to. It must also be in the same location as the storage. The value live is either true or false. If it is set to true it will attach the storage but NOT restart the instance. If you set live to false it will RESTART the instance and then attach the block storage.

Detatching Block Storage

// 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);

Both values are required in the $config. The block_id is the ID of the block storage you want to detatch. The value live is either true or false. If it is set to true it will attach the storage but NOT restart the instance. If you set live to false it will RESTART the instance and then detatch the block storage.

Regions

For the most part, this is a support class, but if you want to use it you can. Here's a few things you can do with it:

// 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();

To-Do

  • Bring in more of the function(s) from Vultr
  • Document the class(es) with proper doc blocks better
  • Move the documentation in to separate markdowns

Contributing

If you're having problems, spot a bug, or have a feature suggestion, file an issue. If you want, feel free to fork the package and make a pull request. This is a work in progresss as I get more info and further test the API.

dutchie027/vultr 适用场景与选型建议

dutchie027/vultr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 257 次下载、GitHub Stars 达 9, 最近一次更新时间为 2020 年 12 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「composer」 「automation」 「paas」 「server administration」 「System Administration」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 dutchie027/vultr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dutchie027/vultr 我们能提供哪些服务?
定制开发 / 二次开发

基于 dutchie027/vultr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 257
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-18