Storage.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_Console
  17. * @subpackage Exception
  18. * @version $Id$
  19. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. /**
  23. * Storage commands
  24. *
  25. * @category Zend
  26. * @package Zend_Service_WindowsAzure_CommandLine
  27. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. *
  30. * @command-handler storage
  31. * @command-handler-description Windows Azure Storage commands
  32. * @command-handler-header Windows Azure SDK for PHP
  33. * @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
  34. * @command-handler-footer Note: Parameters that are common across all commands can be stored
  35. * @command-handler-footer in two dedicated environment variables.
  36. * @command-handler-footer - SubscriptionId: The Windows Azure Subscription Id to operate on.
  37. * @command-handler-footer - Certificate The Windows Azure .cer Management Certificate.
  38. * @command-handler-footer
  39. * @command-handler-footer All commands support the --ConfigurationFile or -F parameter.
  40. * @command-handler-footer The parameter file is a simple INI file carrying one parameter
  41. * @command-handler-footer value per line. It accepts the same parameters as one can
  42. * @command-handler-footer use from the command line command.
  43. */
  44. class Zend_Service_WindowsAzure_CommandLine_Storage
  45. extends Zend_Service_Console_Command
  46. {
  47. /**
  48. * List storage accounts for a specified subscription.
  49. *
  50. * @command-name ListAccounts
  51. * @command-description List storage accounts for a specified subscription.
  52. * @command-parameter-for $subscriptionId Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
  53. * @command-parameter-for $certificate Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
  54. * @command-parameter-for $certificatePassphrase Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
  55. * @command-example List storage accounts for subscription:
  56. * @command-example ListAccounts -sid:"<your_subscription_id>" -cert:"mycert.pem"
  57. */
  58. public function listAccountsCommand($subscriptionId, $certificate, $certificatePassphrase)
  59. {
  60. $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
  61. $result = $client->listStorageAccounts();
  62. if (count($result) == 0) {
  63. echo 'No data to display.';
  64. }
  65. foreach ($result as $object) {
  66. $this->_displayObjectInformation($object, array('ServiceName', 'Url'));
  67. }
  68. }
  69. /**
  70. * Get storage account properties.
  71. *
  72. * @command-name GetProperties
  73. * @command-description Get storage account properties.
  74. * @command-parameter-for $subscriptionId Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
  75. * @command-parameter-for $certificate Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
  76. * @command-parameter-for $certificatePassphrase Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
  77. * @command-parameter-for $accountName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --AccountName Required. The storage account name to operate on.
  78. * @command-example Get storage account properties for account "phptest":
  79. * @command-example GetProperties -sid:"<your_subscription_id>" -cert:"mycert.pem"
  80. * @command-example --AccountName:"phptest"
  81. */
  82. public function getPropertiesCommand($subscriptionId, $certificate, $certificatePassphrase, $accountName)
  83. {
  84. $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
  85. $result = $client->getStorageAccountProperties($accountName);
  86. $this->_displayObjectInformation($result, array('ServiceName', 'Label', 'AffinityGroup', 'Location'));
  87. }
  88. /**
  89. * Get storage account property.
  90. *
  91. * @command-name GetProperty
  92. * @command-description Get storage account property.
  93. * @command-parameter-for $subscriptionId Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
  94. * @command-parameter-for $certificate Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
  95. * @command-parameter-for $certificatePassphrase Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
  96. * @command-parameter-for $accountName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --AccountName Required. The storage account name to operate on.
  97. * @command-parameter-for $property Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Property|-prop Required. The property to retrieve for the storage account.
  98. * @command-example Get storage account property "Url" for account "phptest":
  99. * @command-example GetProperty -sid:"<your_subscription_id>" -cert:"mycert.pem"
  100. * @command-example --AccountName:"phptest" --Property:Url
  101. */
  102. public function getPropertyCommand($subscriptionId, $certificate, $certificatePassphrase, $accountName, $property)
  103. {
  104. $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
  105. $result = $client->getStorageAccountProperties($accountName);
  106. printf("%s\r\n", $result->$property);
  107. }
  108. /**
  109. * Get storage account keys.
  110. *
  111. * @command-name GetKeys
  112. * @command-description Get storage account keys.
  113. * @command-parameter-for $subscriptionId Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
  114. * @command-parameter-for $certificate Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
  115. * @command-parameter-for $certificatePassphrase Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
  116. * @command-parameter-for $accountName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --AccountName Required. The storage account name to operate on.
  117. * @command-example Get storage account keys for account "phptest":
  118. * @command-example GetKeys -sid:"<your_subscription_id>" -cert:"mycert.pem"
  119. * @command-example --AccountName:"phptest"
  120. */
  121. public function getKeysCommand($subscriptionId, $certificate, $certificatePassphrase, $accountName)
  122. {
  123. $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
  124. $result = $client->getStorageAccountKeys($accountName);
  125. $this->_displayObjectInformation((object)array('Key' => 'primary', 'Value' => $result[0]), array('Key', 'Value'));
  126. $this->_displayObjectInformation((object)array('Key' => 'secondary', 'Value' => $result[1]), array('Key', 'Value'));
  127. }
  128. /**
  129. * Get storage account key.
  130. *
  131. * @command-name GetKey
  132. * @command-description Get storage account key.
  133. * @command-parameter-for $subscriptionId Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
  134. * @command-parameter-for $certificate Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
  135. * @command-parameter-for $certificatePassphrase Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
  136. * @command-parameter-for $accountName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --AccountName Required. The storage account name to operate on.
  137. * @command-parameter-for $key Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Key|-k Optional. Specifies the key to regenerate (primary|secondary). If omitted, primary key is used as the default.
  138. * @command-example Get primary storage account key for account "phptest":
  139. * @command-example GetKey -sid:"<your_subscription_id>" -cert:"mycert.pem"
  140. * @command-example --AccountName:"phptest" -Key:primary
  141. */
  142. public function getKeyCommand($subscriptionId, $certificate, $certificatePassphrase, $accountName, $key = 'primary')
  143. {
  144. $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
  145. $result = $client->getStorageAccountKeys($accountName);
  146. if (strtolower($key) == 'secondary') {
  147. printf("%s\r\n", $result[1]);
  148. }
  149. printf("%s\r\n", $result[0]);
  150. }
  151. /**
  152. * Regenerate storage account keys.
  153. *
  154. * @command-name RegenerateKeys
  155. * @command-description Regenerate storage account keys.
  156. * @command-parameter-for $subscriptionId Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
  157. * @command-parameter-for $certificate Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
  158. * @command-parameter-for $certificatePassphrase Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
  159. * @command-parameter-for $accountName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --AccountName Required. The storage account name to operate on.
  160. * @command-parameter-for $key Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Key|-k Optional. Specifies the key to regenerate (primary|secondary). If omitted, primary key is used as the default.
  161. * @command-parameter-for $waitForOperation Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
  162. * @command-example Regenerate secondary key for account "phptest":
  163. * @command-example RegenerateKeys -sid:"<your_subscription_id>" -cert:"mycert.pem"
  164. * @command-example --AccountName:"phptest" -Key:secondary
  165. */
  166. public function regenerateKeysCommand($subscriptionId, $certificate, $certificatePassphrase, $accountName, $key = 'primary', $waitForOperation = false)
  167. {
  168. $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
  169. $client->regenerateStorageAccountKey($accountName, $key);
  170. if ($waitForOperation) {
  171. $client->waitForOperation();
  172. }
  173. echo $client->getLastRequestId();
  174. }
  175. }
  176. Zend_Service_Console_Command::bootstrap($_SERVER['argv']);