2017 © Pedro Peláez
 

library linode

Wrapper for Linode API using Guzzle

image

hampel/linode

Wrapper for Linode API using Guzzle

  • Friday, February 26, 2016
  • by hampel
  • Repository
  • 0 Watchers
  • 0 Stars
  • 407 Installations
  • 2 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 14 Versions
  • 0 % Grown

The README.md

Linode API Wrapper

A Linode API wrapper using Guzzle and implemented using simple Command objects, (*1)

By Simon Hampel., (*2)

Thanks to Everett Griffiths for implementing additional API calls., (*3)

Installation

The recommended way of installing Hampel Linode is through Composer:, (*4)

:::json
{
    "require": {
        "hampel/linode": "~3.1"
    }
}

Note that if you intend to use this package with Laravel, we recommend installing the hampel/linode-laravel package instead, which provides a simple Laravel service provider and Facade for working with this API wrapper., (*5)

Usage

Note: v3.0 of this wrapper is not backwards compatible with v1.0 or v2.0 versions - applications using this wrapper will need to be re-written to utilise this new interface., (*6)

:::php
<?php

use Hampel\Linode\Linode;
use Hampel\Linode\Commands\TestCommand;
use Hampel\Linode\Commands\UserCommand;
use Hampel\Linode\Commands\DomainCommand;

// long-hand initialisation method
$client = new GuzzleHttp\Client();
$linode = new Linode($client, 'your api key here');

// alternative static factory
$linode = Linode::make('your api key here');

// create a command object for the Linode service to execute
// in this case, a simple echo test, API echos back parameters passed
$command = new TestCommand('echo', ['foo' => 'bar']);

// pass the command to Linode service
$response = $linode->execute($command);

var_dump($response);

// get api key
$command = new UserCommand('getapikey', ['username' => 'foo', 'password' => 'bar']);
$response = $linode->execute($command);

var_dump($response);

// create a new domain entry
$options = array("soa_email" => "soa_email@domain-name.com", "ttl_sec" => 3600);
$command = new DomainCommand('create', $options);
$response = $linode->execute($command);

var_dump($response);

// retrieve details about a domain
$response = $linode->execute(new DomainCommand('list', ['domainid' => 12345])); // specify domain id as parameter

var_dump($response);
?>

Example: Creating a New Linode

Sometimes it's not clear how the individual API commands fit together to bring up a new server. The process usually goes something like this:, (*7)

  • Create the Linode (this acts as a container)
  • Create the primary disk (e.g. from a stack script)
  • Create the swap disk
  • Create the configuration profile
  • Boot the Linode

Below is the outline in code. For production use, consider wrapping the command execution in try/catch blocks., (*8)

:::php
<?php

use Hampel\Linode\Linode;
use Hampel\Linode\Commands\LinodeCommand;
use Hampel\Linode\Commands\LinodeDiskCommand;
use Hampel\Linode\Commands\LinodeConfigCommand;

$linode = Linode::make('your api key here');

// Create the Linode
$response = $linode->execute(new LinodeCommand('create', [
    'datacenterid' => 2, // from avail.datacenters()
    'planid' => 2, // from avail.LinodePlans()
    'paymentterm' => 1
]));

$linodeid = $response['LinodeID'];

// Create the Primary Disk
$response = $linode->execute(new LinodeDiskCommand('createfromstackscript', [
    'linodeid' => $linodeid, // the one we just created
    'stackscriptid' => 123,
    'stackscriptudfresponses' => '{}',
    'distributionid' => 89,
    'label' => 'PrimaryDisk',
    'size' => 24576
    'rootpass' => 'xxxxxxxx'
]));
$primarydiskid = $response['DiskID'];

// Create the Swap Disk
$response = $linode->execute(new LinodeDiskCommand('create', [
    'linodeid' => $linodeid,
    'label' => 'SwapDisk',
    'type' => 'swap',
    'size' => 256
]));
$swapdiskid = $response['DiskID'];

// Create the Configuration Profile
$response = $linode->execute(new LinodeConfigCommand('create', [
    'linodeid' => $linodeid,
    'kernelid' => 138, // from avail.kernels()
    'label' => 'StandardProfile',
    'disklist' => "$primarydiskid,$swapdiskid,,,,,,,",
    'rootdevicenum' => 1
]));
$configid = $response['ConfigID'];

// Boot the Linode
$response = $linode->execute(new LinodeCommand('boot', [
    'linodeid' => $linodeid,
    'configid' => $configid
]));

?>

Notes

The following calls have been implemented:, (*9)

  • account.*
  • api.*
  • avail.*
  • domain.*
  • domain.resource.*
  • linode.*
  • linode.config.*
  • linode.disk.*
  • linode.ip.*
  • linode.job.*
  • nodebalancer.*
  • nodebalancer.config.*
  • nodebalancer.node.*
  • stackscript.*
  • test.*
  • user.*

TODO:

Write network tests for all commands (this may incur credit card charges for some tests!), (*10)

Unit Testing

Rename phpunit.xml.dist to phpunit.xml to set up unit testing, configure your API Key in the php section:, (*11)

:::xml
<php>
    <const name="API_KEY" value="Linode API Key goes here" />
</php>

To run mock tests only and ignore network tests, run: phpunit --exclude-group network, (*12)

There are some additional tests which will incur credit card charges on your Linode account and as such, are disabled by default. You can run these specific tests by running the command: phpunit --group chargeable, (*13)

WARNING:, (*14)

Running the chargeable group tests will incur charges on your credit card! Even though servers created by the unit tests are deleted in the cleanup process, the amount refunded will not match the amount billed! If a unit test fails, the server(s) will remain in your Linode account and you will be charged for them: in this case you must delete them manually., (*15)

The Versions

26/02 2016

dev-master

9999999-dev https://bitbucket.org/hampel/linode

Wrapper for Linode API using Guzzle

  Sources   Download

MIT

The Requires

 

The Development Requires

api domains guzzle dns linode

26/02 2016

3.2.0

3.2.0.0 https://bitbucket.org/hampel/linode

Wrapper for Linode API using Guzzle

  Sources   Download

MIT

The Requires

 

The Development Requires

api domains guzzle dns linode

23/05 2015

3.1.1

3.1.1.0 https://bitbucket.org/hampel/linode

Wrapper for Linode API using Guzzle

  Sources   Download

MIT

The Requires

 

The Development Requires

api domains guzzle dns linode

04/02 2015

dev-develop

dev-develop https://bitbucket.org/hampel/linode

Wrapper for Linode API using Guzzle

  Sources   Download

MIT

The Requires

 

The Development Requires

api domains guzzle dns linode

04/02 2015

3.1.0

3.1.0.0 https://bitbucket.org/hampel/linode

Wrapper for Linode API using Guzzle

  Sources   Download

MIT

The Requires

 

The Development Requires

api domains guzzle dns linode

29/07 2014

3.0.0

3.0.0.0 https://bitbucket.org/hampel/linode

Wrapper for Linode API using Guzzle

  Sources   Download

MIT

The Requires

 

The Development Requires

api domains guzzle dns linode

01/06 2014

2.0.3

2.0.3.0 https://bitbucket.org/hampel/linode

Wrapper for Linode API using Guzzle

  Sources   Download

MIT

The Requires

 

api domains guzzle dns linode

01/06 2014

2.0.2

2.0.2.0 https://bitbucket.org/hampel/linode

Wrapper for Linode API using Guzzle

  Sources   Download

MIT

The Requires

 

api domains guzzle dns linode

27/05 2014

2.0.1

2.0.1.0 https://bitbucket.org/hampel/linode

Wrapper for Linode API using Guzzle

  Sources   Download

MIT

The Requires

 

The Development Requires

api domains guzzle dns linode

27/11 2013

2.0.0

2.0.0.0 https://bitbucket.org/hampel/linode

Wrapper for Linode API using Guzzle

  Sources   Download

MIT

The Requires

 

The Development Requires

api domains guzzle dns linode

28/08 2013

1.0.0

1.0.0.0 https://bitbucket.org/hampel/linode

Wrapper for Linode API using Guzzle

  Sources   Download

MIT

The Requires

 

The Development Requires

api domains guzzle dns linode

14/07 2013

0.3.0

0.3.0.0 https://bitbucket.org/hampel/linode

Wrapper for Linode API using Guzzle

  Sources   Download

MIT

The Requires

 

The Development Requires

php guzzle linode

03/07 2013

0.2.1

0.2.1.0 https://bitbucket.org/hampel/linode

Wrapper for Linode API using Guzzle

  Sources   Download

MIT

The Requires

 

The Development Requires

php guzzle linode

03/07 2013

0.2.0

0.2.0.0 https://bitbucket.org/hampel/linode

Wrapper for Linode API using Guzzle

  Sources   Download

MIT

The Requires

 

The Development Requires

php guzzle linode