Zend_Cloud_Infrastructure | SimpleCloud API: Zend_Cloud Programmer's Reference Guide | Zend_CodeGenerator
# Zend_Cloud_Infrastructure_Adapter # Adapters The Zend_Cloud_Infrastructure supports the following adapters: » Amazon EC2; » Rackspace Cloud Servers. # AMAZON EC2 To initialize the AMAZON EC2 adapter you have to use the following code: $key = 'key'; $secret = 'secret'; $region = 'region'; $infrastructure = Zend_Cloud_Infrastructure_Factory::getAdapter(array( Zend_Cloud_Infrastructure_Factory::INFRASTRUCTURE_ADAPTER_KEY => 'Zend_Cloud_Infrastructure_Adapter_Ec2', Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_ACCESS_KEY => $key, Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_SECRET_KEY => $secret, Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_REGION => $region, )); To create a new instance for AMAZON EC2 adapter you have to use the following parameters: $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. $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', Zend_Cloud_Infrastructure_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: $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: $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. $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_Cloud_Infrastructure | SimpleCloud API: Zend_Cloud Programmer's Reference Guide | Zend_CodeGenerator