1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
<?xml version="1.0" encoding="utf-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.cloud.infrastructure.adapter">
<title>Zend_Cloud_Infrastructure_Adapter</title>
<sect2 id="zend.cloud.infrastructure.adapter.intro">
<title>Adapters</title>
<para>
The <classname>Zend_Cloud_Infrastructure</classname> supports the following adapters:
</para>
<itemizedlist>
<listitem>
<para>
<ulink url="http://aws.amazon.com/ec2/">Amazon EC2</ulink>;
</para>
</listitem>
<listitem>
<para>
<ulink url="http://www.rackspace.com/cloud/cloud_hosting_products/servers/">Rackspace Cloud Servers</ulink>.
</para>
</listitem>
</itemizedlist>
</sect2>
<sect2 id="zend.cloud.infrastructure.adapter.ec2">
<title>AMAZON EC2</title>
<para>
To initialize the AMAZON EC2 adapter you have to use the following code:
</para>
<programlisting language="php"><![CDATA[
$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,
));
]]></programlisting>
<para>
To create a new instance for AMAZON EC2 adapter you have to use the following parameters:
</para>
<programlisting language="php"><![CDATA[
$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());
]]></programlisting>
<para>
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.
</para>
<programlisting language="php"><![CDATA[
$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);
]]></programlisting>
<para>
The <emphasis>instanceType</emphasis> parameter is optional. This parameter specify the
type of the instance to create (for instance, 't1.micro').
</para>
</sect2>
<sect2 id="zend.cloud.infrastructure.adapter.rackspace">
<title>Rackspace Cloud Servers</title>
<para>
To initialize the Rackspace Cloud Servers adapter you have to use the following code:
</para>
<programlisting language="php"><![CDATA[
$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,
));
]]></programlisting>
<para>
To create a new instance for Rackspace Cloud Servers adapter you have to use the
following parameters:
</para>
<programlisting language="php"><![CDATA[
$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());
]]></programlisting>
<para>
The <emphasis>metadata</emphasis> array and the <emphasis>file</emphasis> array are
optional parameters.
</para>
<para>
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.
</para>
<programlisting language="php"><![CDATA[
$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);
]]></programlisting>
<para>
The <emphasis>$options</emphasis> contains the username and the password to be used for
the SSH connection.
</para>
</sect2>
</sect1>
|