web/lib/Zend/Service/WindowsAzure/CommandLine/Service.php
changeset 808 6b6c2214f778
child 1230 68c69c656a2c
equal deleted inserted replaced
807:877f952ae2bd 808:6b6c2214f778
       
     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  * Service 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 service
       
    33  * @command-handler-description Windows Azure Service 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_Service
       
    47 	extends Zend_Service_Console_Command
       
    48 {	
       
    49 	/**
       
    50 	 * List hosted service accounts for a specified subscription.
       
    51 	 * 
       
    52 	 * @command-name List
       
    53 	 * @command-description List hosted service 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 hosted service accounts for subscription:
       
    58 	 * @command-example List -sid:"<your_subscription_id>" -cert:"mycert.pem"
       
    59 	 */
       
    60 	public function listCommand($subscriptionId, $certificate, $certificatePassphrase)
       
    61 	{
       
    62 		$client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
       
    63 		$result = $client->listHostedServices();
       
    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 hosted service account properties.
       
    75 	 * 
       
    76 	 * @command-name GetProperties
       
    77 	 * @command-description Get hosted service 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 $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.
       
    82 	 * @command-example Get hosted service account properties for service "phptest":
       
    83 	 * @command-example GetProperties -sid:"<your_subscription_id>" -cert:"mycert.pem"
       
    84 	 * @command-example --Name:"phptest"
       
    85 	 */
       
    86 	public function getPropertiesCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName)
       
    87 	{
       
    88 		$client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
       
    89 		$result = $client->getHostedServiceProperties($serviceName);
       
    90 		
       
    91 		$this->_displayObjectInformation($result, array('ServiceName', 'Label', 'AffinityGroup', 'Location'));
       
    92 	}
       
    93 	
       
    94 	/**
       
    95 	 * Get hosted service 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 $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.
       
   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 hosted service account.
       
   104 	 * @command-example Get hosted service account property "Url" for service "phptest":
       
   105 	 * @command-example GetProperty -sid:"<your_subscription_id>" -cert:"mycert.pem"
       
   106 	 * @command-example --Name:"phptest" --Property:Url
       
   107 	 */
       
   108 	public function getPropertyCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $property)
       
   109 	{
       
   110 		$client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
       
   111 		$result = $client->getHostedServiceProperties($serviceName);
       
   112 		
       
   113 		printf("%s\r\n", $result->$property);
       
   114 	}
       
   115 	
       
   116 	/**
       
   117 	 * Create hosted service account.
       
   118 	 * 
       
   119 	 * @command-name Create
       
   120 	 * @command-description Create hosted service account.
       
   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 $serviceName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Name Required. The hosted service account name.
       
   125 	 * @command-parameter-for $label Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Label Required. A label for the hosted service.
       
   126 	 * @command-parameter-for $description Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Description Optional. A description for the hosted service.
       
   127 	 * @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.
       
   128 	 * @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.
       
   129 	 * @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?
       
   130 	 * @command-example Create hosted service account in West Europe
       
   131 	 * @command-example Create -p:"phpazure" --Name:"phptestsdk2" --Label:"phptestsdk2" --Location:"West Europe"
       
   132 	 */
       
   133 	public function createCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $label, $description, $location, $affinityGroup, $waitForOperation = false)
       
   134 	{
       
   135 		$client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
       
   136 		$client->createHostedService($serviceName, $label, $description, $location, $affinityGroup);
       
   137 		if ($waitForOperation) {
       
   138 			$client->waitForOperation();
       
   139 		}
       
   140 		echo $client->getLastRequestId();
       
   141 	}
       
   142 	
       
   143 	/**
       
   144 	 * Update hosted service account.
       
   145 	 * 
       
   146 	 * @command-name Update
       
   147 	 * @command-description Update hosted service account.
       
   148 	 * @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.
       
   149 	 * @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.
       
   150 	 * @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.
       
   151 	 * @command-parameter-for $serviceName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Name Required. The hosted service account name.
       
   152 	 * @command-parameter-for $label Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Label Required. A label for the hosted service.
       
   153 	 * @command-parameter-for $description Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Description Optional. A description for the hosted service.
       
   154 	 * @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?
       
   155 	 * @command-example Update hosted service
       
   156 	 * @command-example Update -p:"phpazure" --Name:"phptestsdk2" --Label:"New label" --Description:"Some description"
       
   157 	 */
       
   158 	public function updateCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $label, $description, $waitForOperation = false)
       
   159 	{
       
   160 		$client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
       
   161 		$client->updateHostedService($serviceName, $label, $description);
       
   162 		if ($waitForOperation) {
       
   163 			$client->waitForOperation();
       
   164 		}
       
   165 		echo $client->getLastRequestId();
       
   166 	}
       
   167 	
       
   168 	/**
       
   169 	 * Delete hosted service account.
       
   170 	 * 
       
   171 	 * @command-name Delete
       
   172 	 * @command-description Delete hosted service account.
       
   173 	 * @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.
       
   174 	 * @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.
       
   175 	 * @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.
       
   176 	 * @command-parameter-for $serviceName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Name Required. The hosted service account name.
       
   177 	 * @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?
       
   178 	 * @command-example Delete hosted service
       
   179 	 * @command-example Delete -p:"phpazure" --Name:"phptestsdk2"
       
   180 	 */
       
   181 	public function deleteCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $waitForOperation = false)
       
   182 	{
       
   183 		$client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
       
   184 		$client->deleteHostedService($serviceName);
       
   185 		if ($waitForOperation) {
       
   186 			$client->waitForOperation();
       
   187 		}
       
   188 		echo $client->getLastRequestId();
       
   189 	}
       
   190 }
       
   191 
       
   192 Zend_Service_Console_Command::bootstrap($_SERVER['argv']);