Caution: The documentation you are viewing is
for an older version of Zend Framework.
You can find the documentation of the current version at:
https://docs.zendframework.com/
Zend_Cloud_Infrastructure - SimpleCloud API: Zend_Cloud
The Zend_Cloud_Infrastructure is a class to manage different cloud computing infrastructures using a common API.
In order to provide a common class API for different cloud vendors we implemented a small set of basic operations for the management of instances (servers) in a cloud infrastructure. These basic operations are:
create a new instance;
delete a new instance;
start/stop an instance;
reboot an instance;
list of the available instances;
get the status of an instance;
wait for a status change of an instance;
get the public IP or DNS name of the instance;
list all the available images for new instances;
list all the available geographical zones for new instances;
monitor an instance getting the systems information (CPU%, RAM%, DISK%, NETWORK% usage);
deploy of an instance (run arbitrary shell script on an instance);
Note: Deployment of an instance
For the deploy operations we used the » SSH2 PHP extension (ext/ssh2) to connect on an instance and execute shell script. The SSH2 extensions can be used to connect only to Gnu/Linux instances (servers).
This class is managed by a factory to initialize specific cloud computing adapters.
To use this class you have to initialize the factory with a specific adapters. You can check the supported apadters in the specific Chapter Zend_Cloud_Infrastructure_Adapter. We are planning to support other cloud computing vendors very soon.
For instance, to work with the AMAZON EC2 adapter you have to initialize the class with following parameters:
Zend_Cloud_Infrastructure has only a couple of methods that are vendor specific. These methods are the creation of a new instance and the monitoring of an instance. For instance, below is reported an example that shows how to create a new instance using the Amazon EC2 adapter:
The interface of the createInstance is always the same, only the content of $param is specific to the adapter. for more information about the adapter supported by Zend_Cloud_Infrastructure go to the specific page of the manual.
The Zend_Cloud_Infrastructure uses the classes Zend_Cloud_Infrastructure_Instance and Zend_Cloud_Infrastructure_Image to manage the instances (servers) and the images of an instance.
Create an instance. The return value is an instance of Zend_Cloud_Infrastructure_Instance. In case of error the return is false.
$name is the name of the instance to create
$options is the array contains the specific parameter for the cloud adapter. For more info read the Chapter of Zend_Cloud_Infrastructure_Adapter.
Run arbitrary shell scripts on an instance. Return a string or an array contains all the standard output (errors included) of the scripts executed in the instance.
Note: Requirement
In order to use the deployInstance method you have to install the SSH2 extension (ext/ssh2) of PHP. The SSH2 extensions can be used to connect only to Gnu/Linux instances (servers). For more info about the SSH2 extension, » click here.
$id is the ID of the instance
$param is an array contains the username and the password to be used for the SSH connection. The username and the password must be specified using the following constants key of the Zend_Cloud_Infrastructure_Instance: SSH_USERNAME, SSH_PASSWORD.
$cmd is a string (or an array) contains the commands line to be executed in the instance.
Destroy an instance. Return true in case of success, false in case of error.
$id is the ID of the instance
Return the adapter object.
Return the original adapter result.
Return the last HTTP Request of the adapter.
Return the last HTTP Response of the adapter.
Return all the available images to use for an instance. The return value is an instance of Zend_Cloud_Infrastructure_ImageList
Return the list of of the available instances. The return is an instance of Zend_Cloud_Infrastructure_InstanceList.
Monitor an instance. Return the system information about the metric of an instance. The return value is an array that contains samples of values, timestamp and the elaboration of the average value.
$id is the ID of the instance;
$metric is the metric to be monitored. The allowed metrics are reported as contants of the Zend_Cloud_Infrastructure_Instance class: MONITOR_CPU, MONITOR_RAM, MONITOR_NETWORK_IN, MONITOR_NETWORK_OUT, MONITOR_DISK, MONITOR_DISK_WRITE, MONITOR_DISK_READ.
$options is the optional array contains the adapter specific options.
Return the public DNS name or the IP address of the instance. The return value is a string. In case of error the return is false.
$id is the ID of the instance
Reboot an instance. Return true in case of success, false in case of error.
$id is the ID of the instance
Start an instance. Return true in case of success, false in case of error.
$id is the ID of the instance
Get the status of an instance. The return value is a string. The available status are reported in the following constants of the class Zend_Cloud_Infrastructure_Instance: STATUS_STOPPED, STATUS_RUNNING, STATUS_SHUTTING_DOWN, STATUS_REBOOTING, STATUS_TERMINATED, STATUS_PENDING, STATUS_REBUILD. In case of error the return is false.
$id is the ID of the instance
Stop an instance. Return true in case of success, false in case of error.
$id is the ID of the instance
Wait the status change of an instance for a maximum time of n seconds. Return true if the status changes as expected, false if not.
$id is the ID of the instance;
$status is the status to wait for;
$timeout is the maximum time, in seconds, to wait for the status change. This parametr is optional and the default value is 30 seconds.
Return all the available zones for an instance. The return value is an array.
Example #1 Get the datetime system information of an instance
Get the result of the date command line.
Example #2 Get the datetime system information of an instance
Get the result of the date command line.
Example #3 Reboot an instance and wait for the running status
Reboot an instance and wait 60 seconds for the running status.