Package Home

Zend Framework 2 Documentation (Manual)

PHK Home

File: /modules/zendcloud.infrastructure.adapter.html

Size:20850
Storage flags:no_autoload,compress/gzip (19%)

Zend\Cloud\Infrastructure\Adapter — Zend Framework 2 2.4.2 documentation

Zend\Cloud\Infrastructure\Adapter

Adapters

The Zend\Cloud\Infrastructure supports the following adapters:

AMAZON EC2

To initialize the AMAZON EC2 adapter you have to use the following code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
use Zend\Cloud\Infrastructure\Adapter\Ec2 as Ec2Adapter;
use Zend\Cloud\Infrastructure\Factory as FactoryInfrastructure;

$key    = 'key';
$secret = 'secret';
$region = 'region';

$infrastructure = FactoryInfrastructure::getAdapter(array(
    FactoryInfrastructure::INFRASTRUCTURE_ADAPTER_KEY => 'Zend\Cloud\Infrastructure\Adapter\Ec2',
    Ec2Adapter::AWS_ACCESS_KEY => $key,
    Ec2Adapter::AWS_SECRET_KEY => $secret,
    Ec2Adapter::AWS_REGION     => $region,
));

To create a new instance for AMAZON EC2 adapter you have to use the following parameters:

1
2
3
4
5
6
7
8
9
$param = array (
    'imageId'      => 'your-image-id',
    'instanceType' => 'your-instance-type',
);

$instance = $infrastructure->createInstance('name of the instance', $param);

printf("Name of the instance: %s\n", $instance->getName());
printf("ID of the instance  : %s\n", $instance->getId());

The monitor an instance of AMAZON EC2 you can use the starting time and ending time optional parameters. The times must be specified using the ISO 8601 format.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
use Zend\Cloud\Infrastructure\Instance;

$options= array (
    Instance::MONITOR_START_TIME => '2008-02-26T19:00:00+00:00',
    Instance::MONITOR_END_TIME   => '2008-02-26T20:00:00+00:00',
);

$cpuUsage= $infrastructure->monitorInstance('id-instance', Instance::MONITOR_CPU, $options);

print_r($cpuUsage);

The instanceType parameter is optional. This parameter specify the type of the instance to create (for instance, ‘t1.micro’).

Rackspace Cloud Servers

To initialize the Rackspace Cloud Servers adapter you have to use the following code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
use Zend\Cloud\Infrastructure\Adapter\Rackspace as RackspaceAdapter;
use Zend\Cloud\Infrastructure\Factory as FactoryInfrastructure;

$user = 'username';
$key  = 'API key';

$infrastructure = FactoryInfrastructure::getAdapter(array(
    FactoryInfrastructure::INFRASTRUCTURE_ADAPTER_KEY => 'Zend\Cloud\Infrastructure\Adapter\Rackspace',
    RackspaceAdapter::RACKSPACE_USER => $user,
    RackspaceAdapter::RACKSPACE_KEY  => $key,
));

To create a new instance for Rackspace Cloud Servers adapter you have to use the following parameters:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
$param = array (
    'imageId'  => 'image-id-of-the-instance',
    'flavorId' => 'flavor-id-of-the-instance',
    'metadata' => array (
        'foo' => 'bar',
    ),
    'file' => array (
        'remote-instance-path' => 'local-path',
    ),
);

$instance = $infrastructure->createInstance('name of the instance', $param);

printf("Name of the instance: %s\n", $instance->getName());
printf("ID of the instance  : %s\n", $instance->getId());

The metadata array and the file array are optional parameters.

To monitor an instance of Rackspace Cloud Servers we can use only the SSH2 extension. The Rackspace API does not offer a dedicated service to monitor the instance. The monitoring features using the SSH2 connection are limited to the CPU usage, the RAM usage and the DISK usage.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
$options = array (
    'username' => 'your-username',
    'password' => 'your-password',
);

$cpuUsage  = $infrastructure->monitorInstance('id-instance', Instance::MONITOR_CPU, $options);
$ramUsage  = $infrastructure->monitorInstance('id-instance', Instance::MONITOR_RAM, $options);
$diskUsage = $infrastructure->monitorInstance('id-instance', Instance::MONITOR_DISK, $options);

print_r($cpuUsage);
print_r($ramUsage);
print_r($diskUsage);

The $options contains the username and the password to be used for the SSH connection.

Table Of Contents

This Page

Note: You need to stay logged into your GitHub account to contribute to the documentation.

Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Login with your GitHub account.
  2. Go to Zend\Cloud\Infrastructure\Adapter on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.

For more information about the PHK package format: http://phk.tekwire.net