Zend_Cloud_Infrastructure.xml 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.cloud.infrastructure">
  4. <title>Zend_Cloud_Infrastructure</title>
  5. <sect2 id="zend.cloud.infrastructure.intro">
  6. <title>Overview</title>
  7. <para>
  8. The <classname>Zend_Cloud_Infrastructure</classname> is a class to manage different
  9. cloud computing infrastructures using a common <acronym>API</acronym>.
  10. </para>
  11. <para>
  12. In order to provide a common class API for different cloud vendors we implemented
  13. a small set of basic operations for the management of instances (servers) in a cloud infrastructure.
  14. These basic operations are:
  15. </para>
  16. <itemizedlist>
  17. <listitem>
  18. <para>
  19. <emphasis>create a new instance</emphasis>;
  20. </para>
  21. </listitem>
  22. <listitem>
  23. <para>
  24. <emphasis>delete a new instance</emphasis>;
  25. </para>
  26. </listitem>
  27. <listitem>
  28. <para>
  29. <emphasis>start/stop an instance</emphasis>;
  30. </para>
  31. </listitem>
  32. <listitem>
  33. <para>
  34. <emphasis>reboot an instance</emphasis>;
  35. </para>
  36. </listitem>
  37. <listitem>
  38. <para>
  39. <emphasis>list of the available instances</emphasis>;
  40. </para>
  41. </listitem>
  42. <listitem>
  43. <para>
  44. <emphasis>get the status of an instance</emphasis>;
  45. </para>
  46. </listitem>
  47. <listitem>
  48. <para>
  49. <emphasis>wait for a status change of an instance</emphasis>;
  50. </para>
  51. </listitem>
  52. <listitem>
  53. <para>
  54. <emphasis>get the public IP or DNS name of the instance</emphasis>;
  55. </para>
  56. </listitem>
  57. <listitem>
  58. <para>
  59. <emphasis>list all the available images for new instances</emphasis>;
  60. </para>
  61. </listitem>
  62. <listitem>
  63. <para>
  64. <emphasis>list all the available geographical zones for new instances</emphasis>;
  65. </para>
  66. </listitem>
  67. <listitem>
  68. <para>
  69. <emphasis>monitor an instance getting the systems information (CPU%, RAM%, DISK%, NETWORK% usage)</emphasis>;
  70. </para>
  71. </listitem>
  72. <listitem>
  73. <para>
  74. <emphasis>deploy of an instance (run arbitrary shell script on an instance)</emphasis>;
  75. </para>
  76. </listitem>
  77. </itemizedlist>
  78. <note>
  79. <title>Deployment of an instance</title>
  80. <para>
  81. For the deploy operations we used the <ulink url="http://www.php.net/manual/en/book.ssh2.php">
  82. SSH2 PHP extension (ext/ssh2)</ulink> to connect on an instance and execute shell script. The SSH2
  83. extensions can be used to connect only to Gnu/Linux instances (servers).
  84. </para>
  85. </note>
  86. <para>
  87. This class is managed by a factory to initialize specific cloud computing adapters.
  88. </para>
  89. </sect2>
  90. <sect2 id="zend.cloud.infrastructure.quick-start">
  91. <title>Quick Start</title>
  92. <para>
  93. To use this class you have to initialize the factory with a specific adapters. You can
  94. check the supported apadters in the specific Chapter <link linkend="zend.cloud.infrastructure.adapter">Zend_Cloud_Infrastructure_Adapter</link>.
  95. We are planning to support other cloud computing vendors very soon.
  96. </para>
  97. <para>
  98. For instance, to work with the AMAZON EC2 adapter you have to initialize the class with
  99. following parameters:
  100. </para>
  101. <programlisting language="php"><![CDATA[
  102. $key = 'key';
  103. $secret = 'secret';
  104. $region = 'region';
  105. $infrastructure = Zend_Cloud_Infrastructure_Factory::getAdapter(array(
  106. Zend_Cloud_Infrastructure_Factory::INFRASTRUCTURE_ADAPTER_KEY => 'Zend_Cloud_Infrastructure_Adapter_Ec2',
  107. Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_ACCESS_KEY => $key,
  108. Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_SECRET_KEY => $secret,
  109. Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_REGION => $region,
  110. ));
  111. ]]></programlisting>
  112. <para>
  113. <classname>Zend_Cloud_Infrastructure</classname> has only a couple of methods that are vendor specific.
  114. These methods are the creation of a new instance and the monitoring of an instance.
  115. For instance, below is reported an example that shows how to create a new instance using the Amazon EC2 adapter:
  116. </para>
  117. <programlisting language="php"><![CDATA[
  118. $param= array (
  119. 'imageId' => 'your-image-id',
  120. 'instanceType' => 'your-instance-type',
  121. );
  122. $instance= $infrastructure->createInstance('name of the instance', $param);
  123. printf ("Name of the instance: %s\n", $instance->getName());
  124. printf ("ID of the instance : %s\n", $instance->getId());
  125. ]]></programlisting>
  126. <para>
  127. The interface of the <methodname>createInstance</methodname> is always the same, only
  128. the content of <emphasis>$param</emphasis> is specific to the adapter. for more
  129. information about the adapter supported by Zend_Cloud_Infrastructure go to the specific
  130. <link linkend="zend.cloud.infrastructure.adapter">page of the manual</link>.
  131. </para>
  132. <para>
  133. The <classname>Zend_Cloud_Infrastructure</classname> uses the classes
  134. <classname>Zend_Cloud_Infrastructure_Instance</classname> and
  135. <classname>Zend_Cloud_Infrastructure_Image</classname> to manage the instances (servers)
  136. and the images of an instance.
  137. </para>
  138. </sect2>
  139. <sect2 id="zend.cloud.infrastructure.methods">
  140. <title>Available Methods</title>
  141. <variablelist>
  142. <varlistentry id="zend.cloud.infrastructure.methods.create-instance">
  143. <term>
  144. <methodsynopsis>
  145. <methodname>createInstance</methodname>
  146. <methodparam>
  147. <funcparams>string $name, array $options</funcparams>
  148. </methodparam>
  149. </methodsynopsis>
  150. </term>
  151. <listitem>
  152. <para>
  153. Create an instance.
  154. The return value is an instance of <classname>Zend_Cloud_Infrastructure_Instance</classname>.
  155. In case of error the return is <emphasis>false</emphasis>.
  156. </para>
  157. <para>
  158. <emphasis>$name</emphasis> is the name of the instance to create
  159. </para>
  160. <para>
  161. <emphasis>$options</emphasis> is the array contains the specific parameter for the cloud adapter.
  162. For more info read the Chapter of <link linkend="zend.cloud.infrastructure.adapter">Zend_Cloud_Infrastructure_Adapter</link>.
  163. </para>
  164. </listitem>
  165. </varlistentry>
  166. <varlistentry id="zend.cloud.infrastructure.methods.deploy-instance">
  167. <term>
  168. <methodsynopsis>
  169. <methodname>deployInstance</methodname>
  170. <methodparam>
  171. <funcparams>string $id, array $param, string|array $cmd</funcparams>
  172. </methodparam>
  173. </methodsynopsis>
  174. </term>
  175. <listitem>
  176. <para>
  177. Run arbitrary shell scripts on an instance.
  178. Return a string or an array contains all the standard output (errors included) of the scripts executed in the instance.
  179. <note><title>Requirement</title>
  180. <para>
  181. In order to use the deployInstance method you have to install the SSH2 extension (ext/ssh2) of PHP.
  182. The SSH2 extensions can be used to connect only to Gnu/Linux instances (servers).
  183. For more info about the SSH2 extension, <ulink url="http://www.php.net/manual/en/book.ssh2.php">click here</ulink>.
  184. </para>
  185. </note>
  186. </para>
  187. <para>
  188. <emphasis>$id</emphasis> is the ID of the instance
  189. </para>
  190. <para>
  191. <emphasis>$param</emphasis> is an array contains the username and the password to be used for the SSH connection.
  192. The username and the password must be specified using the following constants key of the <classname>Zend_Cloud_Infrastructure_Instance</classname>:
  193. SSH_USERNAME, SSH_PASSWORD.
  194. </para>
  195. <para>
  196. <emphasis>$cmd</emphasis> is a string (or an array) contains the commands line to be executed in the instance.
  197. </para>
  198. </listitem>
  199. </varlistentry>
  200. <varlistentry id="zend.cloud.infrastructure.methods.destroy-instance">
  201. <term>
  202. <methodsynopsis>
  203. <methodname>destroyInstance</methodname>
  204. <methodparam>
  205. <funcparams>string $id</funcparams>
  206. </methodparam>
  207. </methodsynopsis>
  208. </term>
  209. <listitem>
  210. <para>
  211. Destroy an instance.
  212. Return <emphasis>true</emphasis> in case of success, <emphasis>false</emphasis> in case of error.
  213. </para>
  214. <para>
  215. <emphasis>$id</emphasis> is the ID of the instance
  216. </para>
  217. </listitem>
  218. </varlistentry>
  219. <varlistentry id="zend.cloud.infrastructure.methods.get-adapter">
  220. <term>
  221. <methodsynopsis>
  222. <methodname>getAdapter</methodname>
  223. <methodparam>
  224. <funcparams/>
  225. </methodparam>
  226. </methodsynopsis>
  227. </term>
  228. <listitem>
  229. <para>
  230. Return the adapter object.
  231. </para>
  232. </listitem>
  233. </varlistentry>
  234. <varlistentry id="zend.cloud.infrastructure.methods.get-adapter-result">
  235. <term>
  236. <methodsynopsis>
  237. <methodname>getAdapterResult</methodname>
  238. <methodparam>
  239. <funcparams/>
  240. </methodparam>
  241. </methodsynopsis>
  242. </term>
  243. <listitem>
  244. <para>
  245. Return the original adapter result.
  246. </para>
  247. </listitem>
  248. </varlistentry>
  249. <varlistentry id="zend.cloud.infrastructure.methods.get-last-http-request">
  250. <term>
  251. <methodsynopsis>
  252. <methodname>getLastHttpRequest</methodname>
  253. <methodparam>
  254. <funcparams/>
  255. </methodparam>
  256. </methodsynopsis>
  257. </term>
  258. <listitem>
  259. <para>
  260. Return the last HTTP Request of the adapter.
  261. </para>
  262. </listitem>
  263. </varlistentry>
  264. <varlistentry id="zend.cloud.infrastructure.methods.get-last-http-response">
  265. <term>
  266. <methodsynopsis>
  267. <methodname>getLastHttpResponse</methodname>
  268. <methodparam>
  269. <funcparams/>
  270. </methodparam>
  271. </methodsynopsis>
  272. </term>
  273. <listitem>
  274. <para>
  275. Return the last HTTP Response of the adapter.
  276. </para>
  277. </listitem>
  278. </varlistentry>
  279. <varlistentry id="zend.cloud.infrastructure.methods.images-instance">
  280. <term>
  281. <methodsynopsis>
  282. <methodname>imagesInstance</methodname>
  283. <methodparam>
  284. <funcparams/>
  285. </methodparam>
  286. </methodsynopsis>
  287. </term>
  288. <listitem>
  289. <para>
  290. Return all the available images to use for an instance.
  291. The return value is an instance of <classname>Zend_Cloud_Infrastructure_ImageList</classname>
  292. </para>
  293. </listitem>
  294. </varlistentry>
  295. <varlistentry id="zend.cloud.infrastructure.methods.list-instances">
  296. <term>
  297. <methodsynopsis>
  298. <methodname>listInstances</methodname>
  299. <methodparam>
  300. <funcparams/>
  301. </methodparam>
  302. </methodsynopsis>
  303. </term>
  304. <listitem>
  305. <para>
  306. Return the list of of the available instances.
  307. The return is an instance of <classname>Zend_Cloud_Infrastructure_InstanceList</classname>.
  308. </para>
  309. </listitem>
  310. </varlistentry>
  311. <varlistentry id="zend.cloud.infrastructure.methods.monitor-instance">
  312. <term>
  313. <methodsynopsis>
  314. <methodname>monitorInstance</methodname>
  315. <methodparam>
  316. <funcparams>string $id,string $metric,array $options=null</funcparams>
  317. </methodparam>
  318. </methodsynopsis>
  319. </term>
  320. <listitem>
  321. <para>
  322. Monitor an instance. Return the system information about the metric of an instance.
  323. The return value is an array that contains samples of values, timestamp and the elaboration of the average value.
  324. </para>
  325. <para>
  326. <emphasis>$id</emphasis> is the ID of the instance;
  327. </para>
  328. <para>
  329. <emphasis>$metric</emphasis> is the metric to be monitored. The allowed metrics are reported as contants of the
  330. <classname>Zend_Cloud_Infrastructure_Instance</classname> class: MONITOR_CPU, MONITOR_RAM,
  331. MONITOR_NETWORK_IN, MONITOR_NETWORK_OUT, MONITOR_DISK, MONITOR_DISK_WRITE, MONITOR_DISK_READ.
  332. </para>
  333. <para>
  334. <emphasis>$options</emphasis> is the optional array contains the adapter specific options.
  335. </para>
  336. </listitem>
  337. </varlistentry>
  338. <varlistentry id="zend.cloud.infrastructure.methods.public-dns-instance">
  339. <term>
  340. <methodsynopsis>
  341. <methodname>publicDnsInstance</methodname>
  342. <methodparam>
  343. <funcparams>string $id</funcparams>
  344. </methodparam>
  345. </methodsynopsis>
  346. </term>
  347. <listitem>
  348. <para>
  349. Return the public DNS name or the IP address of the instance. The return value is a string.
  350. In case of error the return is <emphasis>false</emphasis>.
  351. </para>
  352. <para>
  353. <emphasis>$id</emphasis> is the ID of the instance
  354. </para>
  355. </listitem>
  356. </varlistentry>
  357. <varlistentry id="zend.cloud.infrastructure.methods.reboot-instance">
  358. <term>
  359. <methodsynopsis>
  360. <methodname>rebootInstance</methodname>
  361. <methodparam>
  362. <funcparams>string $id</funcparams>
  363. </methodparam>
  364. </methodsynopsis>
  365. </term>
  366. <listitem>
  367. <para>
  368. Reboot an instance.
  369. Return <emphasis>true</emphasis> in case of success, <emphasis>false</emphasis> in case of error.
  370. </para>
  371. <para>
  372. <emphasis>$id</emphasis> is the ID of the instance
  373. </para>
  374. </listitem>
  375. </varlistentry>
  376. <varlistentry id="zend.cloud.infrastructure.methods.start-instance">
  377. <term>
  378. <methodsynopsis>
  379. <methodname>startInstance</methodname>
  380. <methodparam>
  381. <funcparams>string $id</funcparams>
  382. </methodparam>
  383. </methodsynopsis>
  384. </term>
  385. <listitem>
  386. <para>
  387. Start an instance.
  388. Return <emphasis>true</emphasis> in case of success, <emphasis>false</emphasis> in case of error.
  389. </para>
  390. <para>
  391. <emphasis>$id</emphasis> is the ID of the instance
  392. </para>
  393. </listitem>
  394. </varlistentry>
  395. <varlistentry id="zend.cloud.infrastructure.methods.status-instance">
  396. <term>
  397. <methodsynopsis>
  398. <methodname>statusInstance</methodname>
  399. <methodparam>
  400. <funcparams>string $id</funcparams>
  401. </methodparam>
  402. </methodsynopsis>
  403. </term>
  404. <listitem>
  405. <para>
  406. Get the status of an instance. The return value is a string.
  407. The available status are reported in the following constants of the class <classname>Zend_Cloud_Infrastructure_Instance</classname>:
  408. STATUS_STOPPED, STATUS_RUNNING, STATUS_SHUTTING_DOWN, STATUS_REBOOTING,
  409. STATUS_TERMINATED, STATUS_PENDING, STATUS_REBUILD.
  410. In case of error the return is <emphasis>false</emphasis>.
  411. </para>
  412. <para>
  413. <emphasis>$id</emphasis> is the ID of the instance
  414. </para>
  415. </listitem>
  416. </varlistentry>
  417. <varlistentry id="zend.cloud.infrastructure.methods.stop-instance">
  418. <term>
  419. <methodsynopsis>
  420. <methodname>stopInstance</methodname>
  421. <methodparam>
  422. <funcparams>string $id</funcparams>
  423. </methodparam>
  424. </methodsynopsis>
  425. </term>
  426. <listitem>
  427. <para>
  428. Stop an instance.
  429. Return <emphasis>true</emphasis> in case of success, <emphasis>false</emphasis> in case of error.
  430. </para>
  431. <para>
  432. <emphasis>$id</emphasis> is the ID of the instance
  433. </para>
  434. </listitem>
  435. </varlistentry>
  436. <varlistentry id="zend.cloud.infrastructure.methods.wait-status-instance">
  437. <term>
  438. <methodsynopsis>
  439. <methodname>waitStatusInstance</methodname>
  440. <methodparam>
  441. <funcparams>string $id, string $status,integer $timeout=30</funcparams>
  442. </methodparam>
  443. </methodsynopsis>
  444. </term>
  445. <listitem>
  446. <para>
  447. Wait the status change of an instance for a maximum time of <emphasis>n</emphasis> seconds.
  448. Return <emphasis>true</emphasis> if the status changes as expected, <emphasis>false</emphasis> if not.
  449. </para>
  450. <para>
  451. <emphasis>$id</emphasis> is the ID of the instance;
  452. </para>
  453. <para>
  454. <emphasis>$status</emphasis> is the status to wait for;
  455. </para>
  456. <para>
  457. <emphasis>$timeout</emphasis> is the maximum time, in seconds, to wait for the status change. This parametr is optional and the default value is 30 seconds.
  458. </para>
  459. </listitem>
  460. </varlistentry>
  461. <varlistentry id="zend.cloud.infrastructure.methods.zones-instance">
  462. <term>
  463. <methodsynopsis>
  464. <methodname>zonesInstance</methodname>
  465. <methodparam>
  466. <funcparams/>
  467. </methodparam>
  468. </methodsynopsis>
  469. </term>
  470. <listitem>
  471. <para>
  472. Return all the available zones for an instance.
  473. The return value is an array.
  474. </para>
  475. </listitem>
  476. </varlistentry>
  477. </variablelist>
  478. </sect2>
  479. <sect2 id="zend.cloud.infrastructure.examples">
  480. <title>Examples</title>
  481. <example id="zend.cloud.infrastructure.examples.authenticate">
  482. <title>Get the datetime system information of an instance</title>
  483. <para>Get the result of the <emphasis>date</emphasis> command line.</para>
  484. <programlisting language="php"><![CDATA[
  485. $param = array (
  486. Instance::SSH_USERNAME => 'username',
  487. Instance::SSH_PASSWORD => 'password',
  488. );
  489. $cmd = 'date';
  490. $output = $infrastructure->deployInstance('instance-id', $param, $cmd);
  491. echo $output;
  492. ]]></programlisting>
  493. </example>
  494. <example id="zend.cloud.infrastructure.examples.get-datetime">
  495. <title>Get the datetime system information of an instance</title>
  496. <para>Get the result of the <emphasis>date</emphasis> command line.</para>
  497. <programlisting language="php"><![CDATA[
  498. $param = array (
  499. Instance::SSH_USERNAME => 'username',
  500. Instance::SSH_PASSWORD => 'password',
  501. );
  502. $cmd = 'date';
  503. $output = $infrastructure->deployInstance('instance-id', $param, $cmd);
  504. echo $output;
  505. ]]></programlisting>
  506. </example>
  507. <example id="zend.cloud.infrastructure.examples.reboot">
  508. <title>Reboot an instance and wait for the running status</title>
  509. <para>Reboot an instance and wait 60 seconds for the running status.</para>
  510. <programlisting language="php"><![CDATA[
  511. if (!$infrastructure->rebootInstance('instance-id')) {
  512. die ('Error in the execution of the reboot command');
  513. }
  514. echo 'Reboot command executed successfully';
  515. if ($rackspace->waitStatusInstance('instance-id', Zend_Cloud_Infrastructure_Instance::STATUS_RUNNING, 60)) {
  516. echo 'The instance is ready';
  517. } else {
  518. echo 'The instance is not ready yet';
  519. }
  520. ]]></programlisting>
  521. </example>
  522. </sect2>
  523. </sect1>