PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Rackspace Cloud Servers

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

<?php
$user 
'username';
$key  'API key';

$infrastructure Zend_Cloud_Infrastructure_Factory::getAdapter(array( 
    
Zend_Cloud_Infrastructure_Factory::INFRASTRUCTURE_ADAPTER_KEY => 'Zend_Cloud_Infrastructure_Adapter_Rackspace'
    
Zend_Cloud_Infrastructure_Adapter_Rackspace::RACKSPACE_USER => $user
    
Zend_Cloud_Infrastructure_Adapter_Rackspace::RACKSPACE_KEY  => $key,
));

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

<?php
$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.

<?php
$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.

Zend Framework