Zend_Cloud_Infrastructure_Adapter.xml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.cloud.infrastructure.adapter">
  4. <title>Zend_Cloud_Infrastructure_Adapter</title>
  5. <sect2 id="zend.cloud.infrastructure.adapter.intro">
  6. <title>Adapters</title>
  7. <para>
  8. The <classname>Zend_Cloud_Infrastructure</classname> supports the following adapters:
  9. </para>
  10. <itemizedlist>
  11. <listitem>
  12. <para>
  13. <ulink url="http://aws.amazon.com/ec2/">Amazon EC2</ulink>;
  14. </para>
  15. </listitem>
  16. <listitem>
  17. <para>
  18. <ulink url="http://www.rackspace.com/cloud/cloud_hosting_products/servers/">Rackspace Cloud Servers</ulink>.
  19. </para>
  20. </listitem>
  21. </itemizedlist>
  22. </sect2>
  23. <sect2 id="zend.cloud.infrastructure.adapter.ec2">
  24. <title>AMAZON EC2</title>
  25. <para>
  26. To initialize the AMAZON EC2 adapter you have to use the following code:
  27. </para>
  28. <programlisting language="php"><![CDATA[
  29. $key = 'key';
  30. $secret = 'secret';
  31. $region = 'region';
  32. $infrastructure = Zend_Cloud_Infrastructure_Factory::getAdapter(array(
  33. Zend_Cloud_Infrastructure_Factory::INFRASTRUCTURE_ADAPTER_KEY => 'Zend_Cloud_Infrastructure_Adapter_Ec2',
  34. Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_ACCESS_KEY => $key,
  35. Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_SECRET_KEY => $secret,
  36. Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_REGION => $region,
  37. ));
  38. ]]></programlisting>
  39. <para>
  40. To create a new instance for AMAZON EC2 adapter you have to use the following parameters:
  41. </para>
  42. <programlisting language="php"><![CDATA[
  43. $param = array (
  44. 'imageId' => 'your-image-id',
  45. 'instanceType' => 'your-instance-type',
  46. );
  47. $instance = $infrastructure->createInstance('name of the instance', $param);
  48. printf("Name of the instance: %s\n", $instance->getName());
  49. printf("ID of the instance : %s\n", $instance->getId());
  50. ]]></programlisting>
  51. <para>
  52. The monitor an instance of AMAZON EC2 you can use the starting time and ending time optional parameters.
  53. The times must be specified using the ISO 8601 format.
  54. </para>
  55. <programlisting language="php"><![CDATA[
  56. $options= array (
  57. Instance::MONITOR_START_TIME => '2008-02-26T19:00:00+00:00',
  58. Instance::MONITOR_END_TIME => '2008-02-26T20:00:00+00:00',
  59. );
  60. $cpuUsage= $infrastructure->monitorInstance('id-instance', Zend_Cloud_Infrastructure_Instance::MONITOR_CPU, $options);
  61. print_r($cpuUsage);
  62. ]]></programlisting>
  63. <para>
  64. The <emphasis>instanceType</emphasis> parameter is optional. This parameter specify the
  65. type of the instance to create (for instance, 't1.micro').
  66. </para>
  67. </sect2>
  68. <sect2 id="zend.cloud.infrastructure.adapter.rackspace">
  69. <title>Rackspace Cloud Servers</title>
  70. <para>
  71. To initialize the Rackspace Cloud Servers adapter you have to use the following code:
  72. </para>
  73. <programlisting language="php"><![CDATA[
  74. $user = 'username';
  75. $key = 'API key';
  76. $infrastructure = Zend_Cloud_Infrastructure_Factory::getAdapter(array(
  77. Zend_Cloud_Infrastructure_Factory::INFRASTRUCTURE_ADAPTER_KEY => 'Zend_Cloud_Infrastructure_Adapter_Rackspace',
  78. Zend_Cloud_Infrastructure_Adapter_Rackspace::RACKSPACE_USER => $user,
  79. Zend_Cloud_Infrastructure_Adapter_Rackspace::RACKSPACE_KEY => $key,
  80. ));
  81. ]]></programlisting>
  82. <para>
  83. To create a new instance for Rackspace Cloud Servers adapter you have to use the
  84. following parameters:
  85. </para>
  86. <programlisting language="php"><![CDATA[
  87. $param = array (
  88. 'imageId' => 'image-id-of-the-instance',
  89. 'flavorId' => 'flavor-id-of-the-instance',
  90. 'metadata' => array (
  91. 'foo' => 'bar',
  92. ),
  93. 'file' => array (
  94. 'remote-instance-path' => 'local-path',
  95. ),
  96. );
  97. $instance = $infrastructure->createInstance('name of the instance', $param);
  98. printf("Name of the instance: %s\n", $instance->getName());
  99. printf("ID of the instance : %s\n", $instance->getId());
  100. ]]></programlisting>
  101. <para>
  102. The <emphasis>metadata</emphasis> array and the <emphasis>file</emphasis> array are
  103. optional parameters.
  104. </para>
  105. <para>
  106. To monitor an instance of Rackspace Cloud Servers we can use only the SSH2 extension.
  107. The Rackspace API does not offer a dedicated service to monitor the instance. The
  108. monitoring features using the SSH2 connection are limited to the CPU usage, the RAM
  109. usage and the DISK usage.
  110. </para>
  111. <programlisting language="php"><![CDATA[
  112. $options = array (
  113. 'username' => 'your-username',
  114. 'password' => 'your-password',
  115. );
  116. $cpuUsage = $infrastructure->monitorInstance('id-instance', Instance::MONITOR_CPU, $options);
  117. $ramUsage = $infrastructure->monitorInstance('id-instance', Instance::MONITOR_RAM, $options);
  118. $diskUsage = $infrastructure->monitorInstance('id-instance', Instance::MONITOR_DISK, $options);
  119. print_r($cpuUsage);
  120. print_r($ramUsage);
  121. print_r($diskUsage);
  122. ]]></programlisting>
  123. <para>
  124. The <emphasis>$options</emphasis> contains the username and the password to be used for
  125. the SSH connection.
  126. </para>
  127. </sect2>
  128. </sect1>