File indexing completed on 2025-01-12 05:22:24
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Service_Console 0017 * @subpackage Exception 0018 * @version $Id$ 0019 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0020 * @license http://framework.zend.com/license/new-bsd New BSD License 0021 */ 0022 0023 /** 0024 * @see Zend_Service_Console_Command 0025 */ 0026 // require_once 'Zend/Service/Console/Command.php'; 0027 0028 /** 0029 * @see Zend_Service_WindowsAzure_Management_Client 0030 */ 0031 // require_once 'Zend/Service/WindowsAzure/Management/Client.php'; 0032 0033 /** 0034 * Service commands 0035 * 0036 * @category Zend 0037 * @package Zend_Service_WindowsAzure_CommandLine 0038 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0039 * @license http://framework.zend.com/license/new-bsd New BSD License 0040 * 0041 * @command-handler service 0042 * @command-handler-description Windows Azure Service commands 0043 * @command-handler-header Windows Azure SDK for PHP 0044 * @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com) 0045 * @command-handler-footer Note: Parameters that are common across all commands can be stored 0046 * @command-handler-footer in two dedicated environment variables. 0047 * @command-handler-footer - SubscriptionId: The Windows Azure Subscription Id to operate on. 0048 * @command-handler-footer - Certificate The Windows Azure .cer Management Certificate. 0049 * @command-handler-footer 0050 * @command-handler-footer All commands support the --ConfigurationFile or -F parameter. 0051 * @command-handler-footer The parameter file is a simple INI file carrying one parameter 0052 * @command-handler-footer value per line. It accepts the same parameters as one can 0053 * @command-handler-footer use from the command line command. 0054 */ 0055 class Zend_Service_WindowsAzure_CommandLine_Service 0056 extends Zend_Service_Console_Command 0057 { 0058 /** 0059 * List hosted service accounts for a specified subscription. 0060 * 0061 * @command-name List 0062 * @command-description List hosted service accounts for a specified subscription. 0063 * @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. 0064 * @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. 0065 * @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. 0066 * @command-example List hosted service accounts for subscription: 0067 * @command-example List -sid:"<your_subscription_id>" -cert:"mycert.pem" 0068 */ 0069 public function listCommand($subscriptionId, $certificate, $certificatePassphrase) 0070 { 0071 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); 0072 $result = $client->listHostedServices(); 0073 0074 if (count($result) == 0) { 0075 echo 'No data to display.'; 0076 } 0077 foreach ($result as $object) { 0078 $this->_displayObjectInformation($object, array('ServiceName', 'Url')); 0079 } 0080 } 0081 0082 /** 0083 * Get hosted service account properties. 0084 * 0085 * @command-name GetProperties 0086 * @command-description Get hosted service account properties. 0087 * @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. 0088 * @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. 0089 * @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. 0090 * @command-parameter-for $serviceName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --Name Required. The hosted service account name to operate on. 0091 * @command-example Get hosted service account properties for service "phptest": 0092 * @command-example GetProperties -sid:"<your_subscription_id>" -cert:"mycert.pem" 0093 * @command-example --Name:"phptest" 0094 */ 0095 public function getPropertiesCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName) 0096 { 0097 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); 0098 $result = $client->getHostedServiceProperties($serviceName); 0099 0100 $this->_displayObjectInformation($result, array('ServiceName', 'Label', 'AffinityGroup', 'Location')); 0101 } 0102 0103 /** 0104 * Get hosted service account property. 0105 * 0106 * @command-name GetProperty 0107 * @command-description Get storage account property. 0108 * @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. 0109 * @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. 0110 * @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. 0111 * @command-parameter-for $serviceName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --Name Required. The hosted service account name to operate on. 0112 * @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 hosted service account. 0113 * @command-example Get hosted service account property "Url" for service "phptest": 0114 * @command-example GetProperty -sid:"<your_subscription_id>" -cert:"mycert.pem" 0115 * @command-example --Name:"phptest" --Property:Url 0116 */ 0117 public function getPropertyCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $property) 0118 { 0119 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); 0120 $result = $client->getHostedServiceProperties($serviceName); 0121 0122 printf("%s\r\n", $result->$property); 0123 } 0124 0125 /** 0126 * Create hosted service account. 0127 * 0128 * @command-name Create 0129 * @command-description Create hosted service account. 0130 * @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. 0131 * @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. 0132 * @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. 0133 * @command-parameter-for $serviceName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Name Required. The hosted service account name. 0134 * @command-parameter-for $label Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Label Required. A label for the hosted service. 0135 * @command-parameter-for $description Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Description Optional. A description for the hosted service. 0136 * @command-parameter-for $location Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Location Required if AffinityGroup is not specified. The location where the hosted service will be created. 0137 * @command-parameter-for $affinityGroup Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --AffinityGroup Required if Location is not specified. The name of an existing affinity group associated with this subscription. 0138 * @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? 0139 * @command-example Create hosted service account in West Europe 0140 * @command-example Create -p:"phpazure" --Name:"phptestsdk2" --Label:"phptestsdk2" --Location:"West Europe" 0141 */ 0142 public function createCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $label, $description, $location, $affinityGroup, $waitForOperation = false) 0143 { 0144 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); 0145 $client->createHostedService($serviceName, $label, $description, $location, $affinityGroup); 0146 if ($waitForOperation) { 0147 $client->waitForOperation(); 0148 } 0149 echo $client->getLastRequestId(); 0150 } 0151 0152 /** 0153 * Update hosted service account. 0154 * 0155 * @command-name Update 0156 * @command-description Update hosted service account. 0157 * @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. 0158 * @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. 0159 * @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. 0160 * @command-parameter-for $serviceName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Name Required. The hosted service account name. 0161 * @command-parameter-for $label Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Label Required. A label for the hosted service. 0162 * @command-parameter-for $description Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Description Optional. A description for the hosted service. 0163 * @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? 0164 * @command-example Update hosted service 0165 * @command-example Update -p:"phpazure" --Name:"phptestsdk2" --Label:"New label" --Description:"Some description" 0166 */ 0167 public function updateCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $label, $description, $waitForOperation = false) 0168 { 0169 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); 0170 $client->updateHostedService($serviceName, $label, $description); 0171 if ($waitForOperation) { 0172 $client->waitForOperation(); 0173 } 0174 echo $client->getLastRequestId(); 0175 } 0176 0177 /** 0178 * Delete hosted service account. 0179 * 0180 * @command-name Delete 0181 * @command-description Delete hosted service account. 0182 * @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. 0183 * @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. 0184 * @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. 0185 * @command-parameter-for $serviceName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Name Required. The hosted service account name. 0186 * @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? 0187 * @command-example Delete hosted service 0188 * @command-example Delete -p:"phpazure" --Name:"phptestsdk2" 0189 */ 0190 public function deleteCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $waitForOperation = false) 0191 { 0192 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); 0193 $client->deleteHostedService($serviceName); 0194 if ($waitForOperation) { 0195 $client->waitForOperation(); 0196 } 0197 echo $client->getLastRequestId(); 0198 } 0199 } 0200 0201 Zend_Service_Console_Command::bootstrap($_SERVER['argv']);