|
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-2012 Zend Technologies USA Inc. (http://www.zend.com) |
|
20 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
21 */ |
|
22 |
|
23 |
|
24 /** |
|
25 * Storage commands |
|
26 * |
|
27 * @category Zend |
|
28 * @package Zend_Service_WindowsAzure_CommandLine |
|
29 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
|
30 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
31 * |
|
32 * @command-handler storage |
|
33 * @command-handler-description Windows Azure Storage commands |
|
34 * @command-handler-header Windows Azure SDK for PHP |
|
35 * @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com) |
|
36 * @command-handler-footer Note: Parameters that are common across all commands can be stored |
|
37 * @command-handler-footer in two dedicated environment variables. |
|
38 * @command-handler-footer - SubscriptionId: The Windows Azure Subscription Id to operate on. |
|
39 * @command-handler-footer - Certificate The Windows Azure .cer Management Certificate. |
|
40 * @command-handler-footer |
|
41 * @command-handler-footer All commands support the --ConfigurationFile or -F parameter. |
|
42 * @command-handler-footer The parameter file is a simple INI file carrying one parameter |
|
43 * @command-handler-footer value per line. It accepts the same parameters as one can |
|
44 * @command-handler-footer use from the command line command. |
|
45 */ |
|
46 class Zend_Service_WindowsAzure_CommandLine_Storage |
|
47 extends Zend_Service_Console_Command |
|
48 { |
|
49 /** |
|
50 * List storage accounts for a specified subscription. |
|
51 * |
|
52 * @command-name ListAccounts |
|
53 * @command-description List storage accounts for a specified subscription. |
|
54 * @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. |
|
55 * @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. |
|
56 * @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. |
|
57 * @command-example List storage accounts for subscription: |
|
58 * @command-example ListAccounts -sid:"<your_subscription_id>" -cert:"mycert.pem" |
|
59 */ |
|
60 public function listAccountsCommand($subscriptionId, $certificate, $certificatePassphrase) |
|
61 { |
|
62 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); |
|
63 $result = $client->listStorageAccounts(); |
|
64 |
|
65 if (count($result) == 0) { |
|
66 echo 'No data to display.'; |
|
67 } |
|
68 foreach ($result as $object) { |
|
69 $this->_displayObjectInformation($object, array('ServiceName', 'Url')); |
|
70 } |
|
71 } |
|
72 |
|
73 /** |
|
74 * Get storage account properties. |
|
75 * |
|
76 * @command-name GetProperties |
|
77 * @command-description Get storage account properties. |
|
78 * @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. |
|
79 * @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. |
|
80 * @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. |
|
81 * @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. |
|
82 * @command-example Get storage account properties for account "phptest": |
|
83 * @command-example GetProperties -sid:"<your_subscription_id>" -cert:"mycert.pem" |
|
84 * @command-example --AccountName:"phptest" |
|
85 */ |
|
86 public function getPropertiesCommand($subscriptionId, $certificate, $certificatePassphrase, $accountName) |
|
87 { |
|
88 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); |
|
89 $result = $client->getStorageAccountProperties($accountName); |
|
90 |
|
91 $this->_displayObjectInformation($result, array('ServiceName', 'Label', 'AffinityGroup', 'Location')); |
|
92 } |
|
93 |
|
94 /** |
|
95 * Get storage account property. |
|
96 * |
|
97 * @command-name GetProperty |
|
98 * @command-description Get storage account property. |
|
99 * @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. |
|
100 * @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. |
|
101 * @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. |
|
102 * @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. |
|
103 * @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. |
|
104 * @command-example Get storage account property "Url" for account "phptest": |
|
105 * @command-example GetProperty -sid:"<your_subscription_id>" -cert:"mycert.pem" |
|
106 * @command-example --AccountName:"phptest" --Property:Url |
|
107 */ |
|
108 public function getPropertyCommand($subscriptionId, $certificate, $certificatePassphrase, $accountName, $property) |
|
109 { |
|
110 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); |
|
111 $result = $client->getStorageAccountProperties($accountName); |
|
112 |
|
113 printf("%s\r\n", $result->$property); |
|
114 } |
|
115 |
|
116 /** |
|
117 * Get storage account keys. |
|
118 * |
|
119 * @command-name GetKeys |
|
120 * @command-description Get storage account keys. |
|
121 * @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. |
|
122 * @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. |
|
123 * @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. |
|
124 * @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. |
|
125 * @command-example Get storage account keys for account "phptest": |
|
126 * @command-example GetKeys -sid:"<your_subscription_id>" -cert:"mycert.pem" |
|
127 * @command-example --AccountName:"phptest" |
|
128 */ |
|
129 public function getKeysCommand($subscriptionId, $certificate, $certificatePassphrase, $accountName) |
|
130 { |
|
131 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); |
|
132 $result = $client->getStorageAccountKeys($accountName); |
|
133 |
|
134 $this->_displayObjectInformation((object)array('Key' => 'primary', 'Value' => $result[0]), array('Key', 'Value')); |
|
135 $this->_displayObjectInformation((object)array('Key' => 'secondary', 'Value' => $result[1]), array('Key', 'Value')); |
|
136 } |
|
137 |
|
138 /** |
|
139 * Get storage account key. |
|
140 * |
|
141 * @command-name GetKey |
|
142 * @command-description Get storage account key. |
|
143 * @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. |
|
144 * @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. |
|
145 * @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. |
|
146 * @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. |
|
147 * @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. |
|
148 * @command-example Get primary storage account key for account "phptest": |
|
149 * @command-example GetKey -sid:"<your_subscription_id>" -cert:"mycert.pem" |
|
150 * @command-example --AccountName:"phptest" -Key:primary |
|
151 */ |
|
152 public function getKeyCommand($subscriptionId, $certificate, $certificatePassphrase, $accountName, $key = 'primary') |
|
153 { |
|
154 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); |
|
155 $result = $client->getStorageAccountKeys($accountName); |
|
156 |
|
157 if (strtolower($key) == 'secondary') { |
|
158 printf("%s\r\n", $result[1]); |
|
159 } |
|
160 printf("%s\r\n", $result[0]); |
|
161 } |
|
162 |
|
163 /** |
|
164 * Regenerate storage account keys. |
|
165 * |
|
166 * @command-name RegenerateKeys |
|
167 * @command-description Regenerate storage account keys. |
|
168 * @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. |
|
169 * @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. |
|
170 * @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. |
|
171 * @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. |
|
172 * @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. |
|
173 * @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? |
|
174 * @command-example Regenerate secondary key for account "phptest": |
|
175 * @command-example RegenerateKeys -sid:"<your_subscription_id>" -cert:"mycert.pem" |
|
176 * @command-example --AccountName:"phptest" -Key:secondary |
|
177 */ |
|
178 public function regenerateKeysCommand($subscriptionId, $certificate, $certificatePassphrase, $accountName, $key = 'primary', $waitForOperation = false) |
|
179 { |
|
180 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); |
|
181 $client->regenerateStorageAccountKey($accountName, $key); |
|
182 if ($waitForOperation) { |
|
183 $client->waitForOperation(); |
|
184 } |
|
185 echo $client->getLastRequestId(); |
|
186 } |
|
187 } |
|
188 |
|
189 Zend_Service_Console_Command::bootstrap($_SERVER['argv']); |