Zend_Cloud_Infrastructure

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. $key    = 'key';
  2. $secret = 'secret';
  3. $region = 'region';
  4.  
  5. $infrastructure = Zend_Cloud_Infrastructure_Factory::getAdapter(array(
  6.     Zend_Cloud_Infrastructure_Factory::INFRASTRUCTURE_ADAPTER_KEY => 'Zend_Cloud_Infrastructure_Adapter_Ec2',
  7.     Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_ACCESS_KEY => $key,
  8.     Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_SECRET_KEY => $secret,
  9.     Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_REGION     => $region,
  10. ));

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

  1. $param = array (
  2.     'imageId'      => 'your-image-id',
  3.     'instanceType' => 'your-instance-type',
  4. );
  5.  
  6. $instance = $infrastructure->createInstance('name of the instance', $param);
  7.  
  8. printf("Name of the instance: %s\n", $instance->getName());
  9. 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. $options= array (
  2.     Instance::MONITOR_START_TIME => '2008-02-26T19:00:00+00:00',
  3.     Instance::MONITOR_END_TIME   => '2008-02-26T20:00:00+00:00',
  4. );
  5.  
  6. $cpuUsage= $infrastructure->monitorInstance('id-instance', Zend_Cloud_Infrastructure_Instance::MONITOR_CPU, $options);
  7.  
  8. 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. $user = 'username';
  2. $key  = 'API key';
  3.  
  4. $infrastructure = Zend_Cloud_Infrastructure_Factory::getAdapter(array(
  5.     Zend_Cloud_Infrastructure_Factory::INFRASTRUCTURE_ADAPTER_KEY => 'Zend_Cloud_Infrastructure_Adapter_Rackspace',
  6.     Zend_Cloud_Infrastructure_Adapter_Rackspace::RACKSPACE_USER => $user,
  7.     Zend_Cloud_Infrastructure_Adapter_Rackspace::RACKSPACE_KEY  => $key,
  8. ));

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

  1. $param = array (
  2.     'imageId'  => 'image-id-of-the-instance',
  3.     'flavorId' => 'flavor-id-of-the-instance',
  4.     'metadata' => array (
  5.         'foo' => 'bar',
  6.     ),
  7.     'file' => array (
  8.         'remote-instance-path' => 'local-path',
  9.     ),
  10. );
  11.  
  12. $instance = $infrastructure->createInstance('name of the instance', $param);
  13.  
  14. printf("Name of the instance: %s\n", $instance->getName());
  15. 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. $options = array (
  2.     'username' => 'your-username',
  3.     'password' => 'your-password',
  4. );
  5.  
  6. $cpuUsage  = $infrastructure->monitorInstance('id-instance', Instance::MONITOR_CPU, $options);
  7. $ramUsage  = $infrastructure->monitorInstance('id-instance', Instance::MONITOR_RAM, $options);
  8. $diskUsage = $infrastructure->monitorInstance('id-instance', Instance::MONITOR_DISK, $options);
  9.  
  10. print_r($cpuUsage);
  11. print_r($ramUsage);
  12. print_r($diskUsage);

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


Zend_Cloud_Infrastructure