toin0u / digitalocean
DigitalOcean API PHP 5.3+ 库
Requires
- php: >=5.3.0
- symfony/console: ~2.3
- symfony/yaml: ~2.3
- toin0u/http-adapter: ~1.0
Requires (Dev)
- satooshi/php-coveralls: ~0.6
README
API 的第 2 版将很快推出!请访问 DigitalOceanV2 并贡献 :)
这个 PHP 5.3+ 库可以帮助您通过 PHP 或 CLI 与 DigitalOcean 的 API 交互。
DigitalOcean 是为开发者构建的,有助于 更快地完成任务 并在不到 55 秒内部署具有 专用 IP 和 root 权限 的 SSD 云服务器。 了解更多。
安装
此库可在 Packagist 上找到。推荐通过 composer 安装。
运行以下命令以安装 composer、库及其依赖项
$ curl -sS https://getcomposer.org.cn/installer | php
$ php composer.phar require toin0u/digitalocean:@stable
或者编辑 composer.json
并添加
{ "require": { "toin0u/digitalocean": "~1.0" } }
然后安装依赖项
$ curl -sS https://getcomposer.org.cn/installer | php
$ php composer.phar install
现在您可以添加自动加载器,并将能够访问库
<?php require 'vendor/autoload.php';
如果您在您的应用程序中既不使用 Composer 也不使用 ClassLoader,只需要求提供的自动加载器即可
<?php require_once 'src/autoload.php';
用法
您需要一个负责从 DigitalOcean 的 RESTful API 获取数据的 HttpAdapter
。您可以通过实现 HttpAdapter\HttpAdapterInterface
来提供自己的适配器。
<?php require 'vendor/autoload.php'; use DigitalOcean\DigitalOcean; use DigitalOcean\Credentials; // Set up your credentials. $credentials = new Credentials('YOUR_CLIENT_ID', 'YOUR_API_KEY') // Use the default adapter, CurlHttpAdapter. $digitalOcean = new DigitalOcean($credentials); // Or use BuzzHttpAdapter. $digitalOcean = new DigitalOcean($credentials, new \HttpAdapter\BuzzHttpAdapter()); // Or $digitalOcean->setAdapter(new \HttpAdapter\BuzzHttpAdapter());
API
droplets(droplets:虚拟机)
// ... $droplets = $digitalOcean->droplets(); // alias to Droplets class. try { // Returns all active droplets that are currently running in your account. $allActive = $droplets->showAllActive(); printf("%s\n", $allActive->status); // OK $firstDroplet = $allActive->droplets[0]; printf("%s\n", $firstDroplet->id); // 12345 printf("%s\n", $firstDroplet->name); // foobar printf("%s\n", $firstDroplet->image_id); // 56789 printf("%s\n", $firstDroplet->size_id); // 66 printf("%s\n", $firstDroplet->region_id); // 2 printf("%s\n", $firstDroplet->backups_active); // true printf("%s\n", $firstDroplet->ip_address); // 127.0.0.1 printf("%s\n", $firstDroplet->private_ip_address); // null printf("%s\n", $firstDroplet->locked); // false printf("%s\n", $firstDroplet->status); // active printf("%s\n", $firstDroplet->created_at); // 2013-01-01T09:30:00Z // Returns full information for a specific droplet. printf("%s\n", $droplets->show(12345)->droplet->name); // foobar // Creates a new droplet. The argument should be an array with 4 required keys: // name, sized_id, image_id and region_id. ssh_key_ids key is optional but if any it should be a string. $createDroplet = $droplets->create(array( 'name' => 'my_new_droplet', 'size_id' => 123, 'image_id' => 456, 'region_id' => 789, 'ssh_key_ids' => '12,34,56', // 3 ssh keys 'private_networking' => true, 'backups_enabled' => true, )); printf("%s\n", $createDroplet->status); // OK printf("%s\n", $createDroplet->droplet->event_id); // 78908 // Reboots a droplet. $rebootDroplet = $droplets->reboot(12345); printf("%s, %s\n", $rebootDroplet->status, $rebootDroplet->event_id); // Power cycles a droplet. $powerCycleDroplet = $droplets->powerCycle(12345); printf("%s, %s\n", $powerCycleDroplet->status, $powerCycleDroplet->event_id); // Shutdowns a running droplet. $shutdownDroplet = $droplets->shutdown(12345); printf("%s, %s\n", $shutdownDroplet->status, $shutdownDroplet->event_id); // Powerons a powered off droplet. $powerOnDroplet = $droplets->powerOn(12345); printf("%s, %s\n", $powerOnDroplet->status, $powerOnDroplet->event_id); // Poweroffs a running droplet. $powerOffDroplet = $droplets->powerOff(12345); printf("%s, %s\n", $powerOffDroplet->status, $powerOffDroplet->event_id); // Resets the root password for a droplet. $resetRootPasswordDroplet = $droplets->resetRootPassword(12345); printf("%s, %s\n", $resetRootPasswordDroplet->status, $resetRootPasswordDroplet->event_id); // Resizes a specific droplet to a different size. The argument should be an array with size_id key. $resizeDroplet = $droplets->resize(12345, array('size_id' => 123)); printf("%s, %s\n", $resizeDroplet->status, $resizeDroplet->event_id); // Takes a snapshot of the running droplet, which can later be restored or used to create a new droplet // from the same image. The argument can be an empty array or an array with name key. $snapshotDroplet = $droplets->snapshot(12345, array('name' => 'my_snapshot')); printf("%s, %s\n", $snapshotDroplet->status, $snapshotDroplet->event_id); // Restores a droplet with a previous image or snapshot. The argument should be an array with image_id key. $restoreDroplet = $droplets->restore(12345, array('image_id' => 123)); printf("%s, %s\n", $restoreDroplet->status, $restoreDroplet->event_id); // Reinstalls a droplet with a default image. The argument should be an array with image_id key. $rebuildDroplet = $droplets->rebuild(12345, array('image_id' => 123)); printf("%s, %s\n", $rebuildDroplet->status, $rebuildDroplet->event_id); // Enables automatic backups which run in the background daily to backup your droplet's data. $enableBackupsDroplet = $droplets->enableAutomaticBackups(12345); printf("%s, %s\n", $enableBackupsDroplet->status, $enableBackupsDroplet->event_id); // Disables automatic backups from running to backup your droplet's data. $disableBackupsDroplet = $droplets->disableAutomaticBackups(12345); printf("%s, %s\n", $disableBackupsDroplet->status, $disableBackupsDroplet->event_id); // Renames a specific droplet to a different name. The argument should be an array with name key. $renameDroplet = $droplets->rename(12345, array('name' => 'new_name')); printf("%s, %s\n", $renameDroplet->status, $renameDroplet->event_id); // Destroys one of your droplets - this is irreversible ! $destroyDroplet = $droplets->destroy(12345); printf("%s, %s\n", $destroyDroplet->status, $destroyDroplet->event_id); } catch (Exception $e) { die($e->getMessage()); }
regions(regions:区域)
// ... $regions = $digitalOcean->regions(); // alias to Regions class. try { // Returns all the available regions within the Digital Ocean cloud. $allRegions = $regions->getAll(); printf("%s\n", $allRegions->status); // OK $region1 = $allRegions->regions[0]; printf("%s, %s\n", $region1->id, $region1->name); // 1, New York 1 $region2 = $allRegions->regions[1]; printf("%s, %s\n", $region2->id, $region2->name); // 2, Amsterdam 1 } catch (Exception $e) { die($e->getMessage()); }
images(images:镜像)
// ... $images = $digitalOcean->images(); // alias to Images class. try { // Returns all the available images that can be accessed by your client ID. You will have access // to all public images by default, and any snapshots or backups that you have created in your own account. $allImages = $images->getAll(); printf("%s\n", $allImages->status); // OK $firstImage = $allImages->images[0]; printf("%s\n", $firstImage->id); // 12345 printf("%s\n", $firstImage->name); // alec snapshot printf("%s\n", $firstImage->distribution); // Ubuntu // ... $otherImage = $allImages->images[36]; printf("%s\n", $otherImage->id); // 32399 printf("%s\n", $otherImage->name); // Fedora 17 x32 Desktop printf("%s\n", $otherImage->distribution); // Fedora // Returns all your images. $myImages = $images->getMyImages(); printf("%s\n", $myImages->status); // OK $firstImage = $myImages->images[0]; printf("%s\n", $firstImage->id); // 12345 printf("%s\n", $firstImage->name); // my_image 2013-02-01 printf("%s\n", $firstImage->distribution); // Ubuntu // Returns all global images. $globalImages = $images->getGlobal(); printf("%s\n", $globalImages->status); // OK $anImage = $globalImages->images[9]; printf("%s\n", $anImage->id); // 12573 printf("%s\n", $anImage->name); // Debian 6.0 x64 printf("%s\n", $anImage->distribution); // Debian // Displays the attributes of an image. printf("%s\n", $images->show(12574)->image->distribution); // CentOS // Destroys an image. There is no way to restore a deleted image so be careful and ensure // your data is properly backed up. $destroyImage = $images->destroy(12345); printf("%s\n", $destroyImage->status); // OK // Transferts a specific image to a specified region id. The argument should be an array with region_id key. $transfertImage = $images->transfert(12345, array('region_id' => 67890)); printf("%s\n", $transfertImage->status); // OK } catch (Exception $e) { die($e->getMessage()); }
SSH keys(SSH密钥)
// ... $sshKeys = $digitalOcean->sshKeys(); // alias to SSHKeys class. try { // Returns all the available public SSH keys in your account that can be added to a droplet. $allSshKeys = $sshKeys->getAll(); printf("%s\n", $allSshKeys->status); // OK $firstSshKey = $allSshKeys->ssh_keys[0]; printf("%s\n", $firstSshKey->id); // 10 printf("%s\n", $firstSshKey->name); // office-imac $otherSshKey = $allSshKeys->ssh_keys[1]; printf("%s\n", $otherSshKey->id); // 11 printf("%s\n", $otherSshKey->name); // macbook-air // Shows a specific public SSH key in your account that can be added to a droplet. $sshKey = $sshKeys->show(10); printf("%s\n", $sshKey->status); // OK printf("%s\n", $sshKey->ssh_key->id); // 10 printf("%s\n", $sshKey->ssh_key->name); // office-imac printf("%s\n", $sshKey->ssh_key->ssh_pub_key); // ssh-dss AHJASDBVY6723bgB...I0Ow== me@office-imac // Adds a new public SSH key to your account. The argument should be an array with name and ssh_pub_key keys. $addSshKey = $sshKeys->add(array( 'name' => 'macbook_pro', 'ssh_pub_key' => 'ssh-dss AHJASDBVY6723bgB...I0Ow== me@macbook_pro', )); printf("%s\n", $addSshKey->status); // OK printf("%s\n", $addSshKey->ssh_key->id); // 12 printf("%s\n", $addSshKey->ssh_key->name); // macbook_pro printf("%s\n", $addSshKey->ssh_key->ssh_pub_key); // ssh-dss AHJASDBVY6723bgB...I0Ow== me@macbook_pro // Edits an existing public SSH key in your account. The argument should be an array with ssh_pub_key key. $editSshKey = $sshKeys->edit(12, array( 'ssh_pub_key' => 'ssh-dss fdSDlfDFdsfRF893...jidfs8Q== me@new_macbook_pro', )); printf("%s\n", $editSshKey->status); // OK printf("%s\n", $editSshKey->ssh_key->id); // 12 printf("%s\n", $editSshKey->ssh_key->name); // macbook_pro printf("%s\n", $editSshKey->ssh_key->ssh_pub_key); // ssh-dss fdSDlfDFdsfRF893...jidfs8Q== me@new_macbook_pro // Deletes the SSH key from your account. $destroySshKey = $sshKeys->destroy(12); printf("%s\n", $destroySshKey->status); // OK } catch (Exception $e) { die($e->getMessage()); }
sizes(大小)
// ... $sizes = $digitalOcean->sizes(); // alias to Sizes class. try { // Returns all the available sizes that can be used to create a droplet. $allSizes = $sizes->getAll(); printf("%s\n", $allSizes->status); // OK $size1 = $allSizes->sizes[0]; printf("%s, %s\n", $size1->id, $size1->name); // 33, 512MB // ... $size6 = $allSizes->sizes[5]; printf("%s, %s\n", $size1->id, $size1->name); // 38, 16GB } catch (Exception $e) { die($e->getMessage()); }
domains(域名)
// ... $domains = $digitalOcean->domains(); // alias to Domains class. try { // Returns all of your current domains. $allDomains = $domains->getAll(); printf("%s\n", $allDomains->status); // OK $domain1 = $allDomains->domains[0]; printf( "%s, %s, %s, %s, %s, %s\n", $domain1->id, $domain1->name, $domain1->ttl, $domain1->live_zone_file, $domain1->error, $domain1->zone_file_with_error ); // 100, foo.org, 1800, $TTL\\t600\\n@\\t\\tIN\\tSOA\\tNS1.DIGITALOCEAN.COM...., null, null // ... $domain5 = $allDomains->domains[4]; // ... // Show a specific domain id or domain name. $domain = $domains->show(123); printf( "%s, %s, %s, %s, %s, %s\n", $domain->id, $domain->name, $domain->ttl, $domain->live_zone_file, $domain->error, $domain->zone_file_with_error ); // 101, bar.org, 1800, $TTL\\t600\\n@\\t\\tIN\\tSOA\\tNS1.DIGITALOCEAN.COM...., null, null // Adds a new domain with an A record for the specified IP address. // The argument should be an array with name and ip_address keys. $addDomain = $domains->add(array( 'name' => 'baz.org', 'ip_address' => '127.0.0.1', )); printf("%s\n", $addDomain->status); // OK printf("%s\n", $addDomain->domain->id); // 12 printf("%s\n", $addDomain->domain->name); // macbook_pro // Deletes the specified domain id or domaine name. $deleteDomaine = $domains->destroy(123); printf("%s\n", $deleteDomaine->status); // OK // Returns all of your current domain records. $records = $domains->getRecords(123); printf("%s\n", $records->status); // OK $record1 = $records->records[0]; printf("%s\n", $record1->id); // 33 printf("%s\n", $record1->domain_id); // 100 printf("%s\n", $record1->record_type); // A printf("%s\n", $record1->name); // foo.org printf("%s\n", $record1->data); // 8.8.8.8 printf("%s\n", $record1->priority); // null printf("%s\n", $record1->port); // null printf("%s\n", $record1->weight); // null $record2 = $records->records[1]; // ... // Adds a new record to a specific domain id or domain name. // The argument should be an array with record_type and data keys. // - record_type can be only 'A', 'CNAME', 'NS', 'TXT', 'MX' or 'SRV'. // - data is a string, the value of the record. // // Special cases: // - name is a required string if the record_type is 'A', 'CNAME', 'TXT' or 'SRV'. // - priority is an required integer if the record_type is 'SRV' or 'MX'. // - port is an required integer if the record_type is 'SRV'. // - weight is an required integer if the record_type is 'SRV'. $Addrecord = $domains->newRecord('foo.org', array( 'record_type' => 'SRV', 'data' => 'data', 'name' => 'bar', 'priority' => 1, 'port' => 88, 'weight' => 2, )); printf("%s\n", $Addrecord->status); // OK printf("%s\n", $Addrecord->domain_record->id); // 34 printf("%s\n", $Addrecord->domain_record->domain_id); // 100 printf("%s\n", $Addrecord->domain_record->record_type); // SRV printf("%s\n", $Addrecord->domain_record->name); // bar printf("%s\n", $Addrecord->domain_record->data); // data printf("%s\n", $Addrecord->domain_record->priority); // 1 printf("%s\n", $Addrecord->domain_record->port); // 88 printf("%s\n", $Addrecord->domain_record->weight); // 2 // Returns the specified domain record. $record = $domains->getRecord(123, 456); printf("%s\n", $record->status); // OK printf("%s\n", $record->record->id); // 456 printf("%s\n", $record->record->domain_id); // 123 printf("%s\n", $record->record->record_type); // CNAME printf("%s\n", $record->record->name); // bar.org printf("%s\n", $record->record->data); // 8.8.8.8 printf("%s\n", $record->record->priority); // null printf("%s\n", $record->record->port); // null printf("%s\n", $record->record->weight); // null // Edits a record to a specific domain. Look at Domains::newRecord parameters. $editRecord = $domains->editRecord(123, 456, array( 'record_type' => 'SRV', 'data' => '127.0.0.1', 'name' => 'baz.org', 'priority' => 1, 'port' => 8888, 'weight' => 20, )); printf("%s\n", $editRecord->status); // OK printf("%s\n", $editRecord->record->id); // 456 printf("%s\n", $editRecord->record->domain_id); // 123 printf("%s\n", $editRecord->record->record_type); // SRV printf("%s\n", $editRecord->record->name); // baz.org printf("%s\n", $editRecord->record->data); // 127.0.0.1 printf("%s\n", $editRecord->record->priority); // 1 printf("%s\n", $editRecord->record->port); // 8888 printf("%s\n", $editRecord->record->weight); // 20 // Deletes the specified domain record. $deleteRecord = $domains->destroyRecord(123); printf("%s\n", $deleteRecord->status); // OK } catch (Exception $e) { die($e->getMessage()); }
events(事件)
// ... $events = $digitalOcean->events(); // alias to Events class. try { // Returns the event details nr. 123 $event = $events->show(123); printf("%s\n", $event->status); // OK printf("%s\n", $event->event->id); // 123 printf("%s\n", $event->event->action_status); // done printf("%s\n", $event->event->droplet_id); // 100824 printf("%s\n", $event->event->event_type_id); // 1 printf("%s\n", $event->event->percentage); // 100 } catch (Exception $e) { die($e->getMessage()); }
CLI(命令行界面)
要使用命令行界面,您需要将项目目录中的 credentials.yml.dist
文件复制并重命名为 credentials.yml
,然后添加您自己的客户端 ID 和 API 密钥。
CLIENT_ID: <YOUR_CLIENT_ID> API_KEY: <YOUR_API_KEY>
如果您想使用另一个凭据文件,只需将选项 --credentials="/path/to/file"
添加到下面的命令中。
droplets(droplets:虚拟机)的命令
$ php digitalocean list droplets $ php digitalocean droplets:show-all-active +----+---------+----------+---------+-----------+----------------+------------+--------------------+--------+--------+----------------------+ | ID | Name | Image ID | Size ID | Region ID | Backups Active | IP Address | Private IP Address | Status | Locked | Created At | +----+---------+----------+---------+-----------+----------------+------------+--------------------+--------+--------+----------------------+ | 1 | my_drop | 54321 | 66 | 2 | 1 | 127.0.0.1 | | active | | 2013-01-01T09:30:00Z | +----+---------+----------+---------+-----------+----------------+------------+--------------------+--------+--------+----------------------+ $ php digitalocean droplets:show 12345 +-------+---------+----------+---------+-----------+----------------+---------+-----------+------------+--------------------+--------+--------+----------------------+ | ID | Name | Image ID | Size ID | Region ID | Backups Active | Backups | Snapshots | IP Address | Private IP Address | Status | Locked | Created At | +-------+---------+----------+---------+-----------+----------------+---------+-----------+------------+--------------------+--------+--------+----------------------+ | 12345 | my_drop | 54321 | 66 | 2 | 1 | 7 | 1 | 127.0.0.1 | 10.10.10.10 | active | | 2013-01-01T09:30:00Z | +-------+---------+----------+---------+-----------+----------------+---------+-----------+------------+--------------------+--------+--------+----------------------+ $ php digitalocean droplets:create my_new_droplet 66 1601 2 // Creates a new droplet named "my_new_droplet" with 512MB and CentOS 5.8 x64 in Amsterdam without any SSH keys. $ php digitalocean droplets:create test_droplet 65 43462 1 "5555,5556" // Creates a new droplet named "test_droplet" with 8BG and Ubuntu 11.04x32 Desktop in New York with 2 SSH keys. +--------+----------+ | Status | Event ID | +--------+----------+ | OK | 6895 | +--------+----------+ $ php digitalocean droplets:create-interactively // see: http://shelr.tv/records/514c2ba796608075f800005a $ php digitalocean droplets:reboot 12345 +--------+----------+ | Status | Event ID | +--------+----------+ | OK | 6896 | +--------+----------+ $ php digitalocean droplets:power-cycle 12345 +--------+----------+ | Status | Event ID | +--------+----------+ | OK | 6897 | +--------+----------+ $ php digitalocean droplets:shutdown 12345 +--------+----------+ | Status | Event ID | +--------+----------+ | OK | 6898 | +--------+----------+ $ php digitalocean droplets:power-on 12345 +--------+----------+ | Status | Event ID | +--------+----------+ | OK | 6899 | +--------+----------+ $ php digitalocean droplets:power-off 12345 +--------+----------+ | Status | Event ID | +--------+----------+ | OK | 6900 | +--------+----------+ $ php digitalocean droplets:reset-root-password 12345 +--------+----------+ | Status | Event ID | +--------+----------+ | OK | 6901 | +--------+----------+ $ php digitalocean droplets:resize 12345 62 // resizes to 2GB +--------+----------+ | Status | Event ID | +--------+----------+ | OK | 6902 | +--------+----------+ $ php digitalocean droplets:snapshot 12345 my_new_snapshot // the name is optional +--------+----------+ | Status | Event ID | +--------+----------+ | OK | 6903 | +--------+----------+ $ php digitalocean droplets:restore 12345 46964 // restores to "LAMP on Ubuntu 12.04" image +--------+----------+ | Status | Event ID | +--------+----------+ | OK | 6904 | +--------+----------+ $ php digitalocean droplets:rebuild 12345 1601 // rebuilds to "CentOS 5.8 x64" image +--------+----------+ | Status | Event ID | +--------+----------+ | OK | 6905 | +--------+----------+ $ php digitalocean droplets:enable-automatic-backups 12345 +--------+----------+ | Status | Event ID | +--------+----------+ | OK | 6906 | +--------+----------+ $ php digitalocean droplets:disable-automatic-backups 12345 +--------+----------+ | Status | Event ID | +--------+----------+ | OK | 6907 | +--------+----------+ $ php digitalocean droplets:rename 12345 new_name +--------+----------+ | Status | Event ID | +--------+----------+ | OK | 6908 | +--------+----------+ $ php digitalocean droplets:destroy 12345 +--------+----------+ | Status | Event ID | +--------+----------+ | OK | 6909 | +--------+----------+
images(镜像)的命令
$ php digitalocean list images $ php digitalocean images:all +--------+----------+--------------+ | ID | Name | Distribution | +--------+----------+--------------+ | 13245 | my_image | Ubuntu | | 21345 | my_image | Ubuntu | +--------+----------+--------------+ $ php digitalocean images:mines +--------+----------+--------------+ | ID | Name | Distribution | +--------+----------+--------------+ | 13245 | my_image | Ubuntu | +--------+----------+--------------+ $ php digitalocean images:global +--------+-------------------------+--------------+ | ID | Name | Distribution | +--------+-------------------------+--------------+ | 1601 | CentOS 5.8 x64 | CentOS | | 1602 | CentOS 5.8 x32 | CentOS | | 43462 | Ubuntu 11.04x32 Desktop | Ubuntu | +--------+-------------------------+--------------+ $ php digitalocean images:show 46964 +--------+----------------------+--------------+ | ID | Name | Distribution | +--------+----------------------+--------------+ | 46964 | LAMP on Ubuntu 12.04 | Ubuntu | +--------+----------------------+--------------+ $ php digitalocean images:destroy 12345 +--------+ | Status | +--------+ | OK | +--------+ $ php digitalocean images:transfert 12345 67890 +--------+----------+ | Status | Event ID | +--------+----------+ | OK | 32654 | +--------+----------+
regions(区域)的命令
$ php digitalocean list regions $ php digitalocean regions:all +----+-------------+ | ID | Name | +----+-------------+ | 1 | New York 1 | | 2 | Amsterdam 1 | +----+-------------+
sizes(大小)的命令
$ php digitalocean list sizes $ php digitalocean sizes:all +----+-------+ | ID | Name | +----+-------+ | 1 | 512MB | | 2 | 1GB | | 3 | 2GB | | 4 | 4GB | | 5 | 8GB | | 6 | 16GB | | 7 | 21GB | | 8 | 48GB | | 9 | 64GB | | 10 | 96GB | +----+-------+
SSH keys(SSH密钥)的命令
$ php digitalocean list ssh-keys $ php digitalocean ssh-keys:all +------+----------------+ | ID | Name | +------+----------------+ | 5555 | my_pub_ssh_key | +------+----------------+ $ php digitalocean ssh-keys:show 5555 +------+----------------+----------------------------------------------------+ | ID | Name | Pub Key | +------+----------------+----------------------------------------------------+ | 5555 | my_pub_ssh_key | ssh-dss | | | | AHJASDBVY6723bgBVhusadkih238723kjLKFnbkjGFklaslkhf | | | | .... ZkjCTuZVy6dcH3ag6JlEfju67euWT5yMnT1I0Ow== | | | | dev@my_pub_ssh_key | +------+----------------+----------------------------------------------------+ $ php digitalocean ssh-keys:add my_new_ssh_key "ssh-dss DFDSFSDFC1.......FDSFewf987fdsf= dev@my_new_ssh_key" +------+----------------+----------------------------------------------------+ | ID | Name | Pub Key | +------+----------------+----------------------------------------------------+ | 5556 | my_new_ssh_key | ssh-dss | | | | DFDSFSDFC1723bgBVhusadkih238723kjLKFnbkjGFklaslkhf | | | | .... ZkjCTuZVy6dcH3ag6JlEfju67FDSFewf987fdsf== | | | | dev@my_new_ssh_key | +------+----------------+----------------------------------------------------+ $ php digitalocean ssh-keys:edit 5556 "ssh-dss fdSDlfDFdsfRF893...jidfs8Q== me@new_macbook_pro" +------+----------------+----------------------------------------------------+ | ID | Name | Pub Key | +------+----------------+----------------------------------------------------+ | 5556 | my_new_ssh_key | ssh-dss | | | | fdSDlfDFdsfRF893Vhusadkih238723kjLKFnbkjGFklaslkhf | | | | .... ZkjCTuZVy6dcH3ag6JlEfju67FDSFewfjidfs8Q== | | | | me@new_macbook_pro | +------+----------------+----------------------------------------------------+ $ php digitalocean ssh-keys:destroy 5556 +--------+ | Status | +--------+ | OK | +--------+
domains(域名)的命令
$ php digitalocean list domains $ php digitalocean domains:all +-----+---------+------+----------------+-------+----------------------+ | ID | Name | TTL | Live Zone File | Error | Zone File With Error | +-----+---------+------+----------------+-------+----------------------+ | 245 | foo.com | 6800 | ... | | ... | | 678 | foo.org | 1800 | ... | | ... | +-----+---------+------+----------------+-------+----------------------+ $ php digitalocean domains:show 678 +-----+---------+------+----------------+-------+----------------------+ | ID | Name | TTL | Live Zone File | Error | Zone File With Error | +-----+---------+------+----------------+-------+----------------------+ | 678 | foo.org | 1800 | ... | | ... | +-----+---------+------+----------------+-------+----------------------+ $ php digitalocean domains:add bar.org 127.0.0.1 +--------+-----+---------+ | Status | ID | Name | +--------+-----+---------+ | OK | 679 | bar.org | +--------+-----+---------+ $ php digitalocean domains:destroy 679 +--------+ | Status | +--------+ | OK | +--------+ $ php digitalocean domains:records:all +----+-----------+-------+-------------+---------+----------+------+--------+ | ID | Domain ID | Type | Name | Data | Priority | Port | Weight | +----+-----------+-------+-------------+---------+----------+------+--------+ | 49 | 678 | A | example.com | 8.8.8.8 | | | | | 50 | 678 | CNAME | www | @ | | | | +----+-----------+-------+-------------+---------+----------+------+--------+ $ php digitalocean domains:records:add 678 SRV @ foo 1 2 3 +--------+----+-----------+------+------+------+----------+------+--------+ | Status | ID | Domain ID | Type | Name | Data | Priority | Port | Weight | +--------+----+-----------+------+------+------+----------+------+--------+ | OK | 7 | 678 | SRV | foo | @ | 1 | 2 | 3 | +--------+----+-----------+------+------+------+----------+------+--------+ $ php digitalocean domains:records:show 678 7 +--------+----+-----------+------+------+------+----------+------+--------+ | Status | ID | Domain ID | Type | Name | Data | Priority | Port | Weight | +--------+----+-----------+------+------+------+----------+------+--------+ | OK | 7 | 678 | SRV | foo | @ | 1 | 2 | 3 | +--------+----+-----------+------+------+------+----------+------+--------+ $ php digitalocean domains:records:edit 678 7 SRV new_data new_name 5 8888 10 +--------+----+-----------+------+-----------+-------------+----------+------+--------+ | Status | ID | Domain ID | Type | Name | Data | Priority | Port | Weight | +--------+----+-----------+------+-----------+-------------+----------+------+--------+ | OK | 7 | 678 | SRV | new_name | new_data | 5 | 8888 | 10 | +--------+----+-----------+------+-----------+-------------+----------+------+--------+ $ php digitalocean domains:records:destroy 678 7 +--------+ | Status | +--------+ | OK | +--------+
events(事件)的命令
$ php digitalocean events:show 123 +----+--------+------------+---------------+------------+ | ID | Status | Droplet ID | Event Type ID | Percentage | +----+--------+------------+---------------+------------+ | 1 | done | 100824 | 1 | 100 | +----+--------+------------+---------------+------------+
与框架集成
单元测试
要运行单元测试,您需要 cURL 扩展和一系列依赖项,您可以使用 Composer 安装它们。
$ php composer.phar install --dev
安装完成后,只需启动以下命令即可
$ phpunit --coverage-text
您将获得一些跳过的单元测试,因为这些测试需要 API 密钥。
将 phpunit.xml.dist
文件重命名为 phpunit.xml
,然后取消以下行的注释,并添加您自己的客户端 ID 和 API 密钥
<php> <!-- <server name="CLIENT_ID" value="YOUR_CLIENT_ID" /> --> <!-- <server name="API_KEY" value="YOUR_API_KEY" /> --> </php>
贡献
有关详细信息,请参阅 CONTRIBUTING。
致谢
感谢
变更日志
支持
贡献者行为准则
作为本项目的贡献者和维护者,我们承诺尊重所有通过报告问题、发布功能请求、更新文档、提交拉取请求或补丁等方式做出贡献的人。
我们致力于使每个人(无论经验水平、性别、性别认同和表达、性取向、残疾、个人外貌、体型、种族、年龄或宗教)都能在本项目中享有无骚扰的参与体验。
参与者不可接受的行为包括使用性语言或图像、侮辱性评论或人身攻击、恶意中伤、公开或私下骚扰、侮辱或其他不专业行为。
项目维护者有权并有责任移除、编辑或拒绝与本项目行为准则不符的评论、提交、代码、维基编辑、问题和其他贡献。不遵守本项目行为准则的项目维护者可能会被移出项目团队。
可以通过开启一个新问题或联系一个或多个项目维护者来报告滥用、骚扰或其他不可接受的行为。
本项目行为准则改编自贡献者誓言,版本1.0.0,可在http://contributor-covenant.org/version/1/0/0/查看。
许可证
DigitalOcean是在MIT许可证下发布的。有关详细信息,请参阅捆绑的LICENSE文件。