2017 © Pedro PelĂĄez
 

library hetzner-cloud-api-client

A client to manage Hetzner's Cloud via API

image

webfoersterei/hetzner-cloud-api-client

A client to manage Hetzner's Cloud via API

  • Tuesday, February 6, 2018
  • by Hecke29
  • Repository
  • 4 Watchers
  • 4 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 138 % Grown

The README.md

hetzner-cloud-api-client

API Client for managing Hetzner's Cloud, (*1)

Build Status Packagist Packagist Pre Release GitHub license, (*2)

Usage

Install this package via composer composer require webfoersterei/hetzner-cloud-api-client "dev-master@dev", (*3)

Note: There is no stable release at the moment, (*4)

After that you can use the client like this:, (*5)

define('API_KEY', 'MYSECRETAPIKEY'); # See https://docs.hetzner.cloud/#header-authentication-1
$cloudApiClient = Webfoersterei\HetznerCloudApiClient\ClientFactory::create(API_KEY);

# You can now use the cloudApiClient. E.g:
$cloudApiClient->getServers();

Implemented Methods

The client provides implementations for the following methods (grouped by resources)., (*6)

Actions

See: https://docs.hetzner.cloud/#resources-actions * List all: getActions() * Get one: getAction(int $id), (*7)

Servers

See: https://docs.hetzner.cloud/#resources-servers * Get all: getServers() * Get one: getServer(int $id) * Create one: createServer(CreateRequest $createRequest) * Rename: changeServerName(int $id, string $name) * Delete one: deleteServer(int $id), (*8)

ServerTypes

See: https://docs.hetzner.cloud/#resources-server-types * Get all: getServerTypes() * Get one: getServerType(int $id), (*9)

Pricing

See: https://docs.hetzner.cloud/#resources-pricing-get * Get all: getPricing(), (*10)

Contribute

Feel free to contribute to this github repository by reporting bugs and ideas to improve this API-client., (*11)

Examples

List of serverTypes

Lists all serverTypes: name and specs, (*12)

# Require vendors/autoload.php here

define('API_KEY', 'MYSECRETAPIKEY');
$client = \Webfoersterei\HetznerCloudApiClient\ClientFactory::create(API_KEY);

$serverTypes = $client->getServerTypes();

foreach ($serverTypes->server_types as $serverType) {
    printf("%--12s CPU: %2d Cores, RAM: %3d GB, Storage: %4d GB (%s)\n", $serverType->name, $serverType->cores,
        $serverType->memory, $serverType->disk, $serverType->storage_type);
}

My first server

Create a new server and delete it after started, (*13)

# Require vendors/autoload.php here

define('API_KEY', 'MYSECRETAPIKEY');
$client = \Webfoersterei\HetznerCloudApiClient\ClientFactory::create(API_KEY);

$createServerRequest = new \Webfoersterei\HetznerCloudApiClient\Model\Server\CreateRequest();
$createServerRequest->name = 'my-first-server-created-with-php';
$createServerRequest->server_type = 'cx11';
$createServerRequest->start_after_create = true;
$createServerRequest->image = 1;

echo "Creating server.\n";

$createResponse = $client->createServer($createServerRequest);

$progress = $createResponse->action->progress;
$status = $createResponse->action->status;

while ($progress != 100 && $status != 'success') {
    $actionResponse = $client->getAction($createResponse->action->id);
    echo $actionResponse->action->progress."%\n";
    $progress = $actionResponse->action->progress;
    sleep(1);
}

echo sprintf("Server created. Root-PW: %s\n", $createResponse->root_password);
sleep(10);
echo "Deleting server.\n";

$client->deleteServer($createResponse->server->id);

echo "Done.\n";

The Versions

06/02 2018
06/02 2018
06/02 2018
30/01 2018