PageRenderTime 50ms CodeModel.GetById 13ms app.highlight 25ms RepoModel.GetById 1ms app.codeStats 1ms

/src/lib/Zend/Service/WindowsAzure/Management/Client.php

https://bitbucket.org/mkrasuski/magento-ce
PHP | 2426 lines | 1315 code | 264 blank | 847 comment | 492 complexity | 7ea9a8aeec1b66c29127ce846788caeb MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   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_WindowsAzure
  17 * @subpackage Management
  18 * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19 * @license    http://framework.zend.com/license/new-bsd     New BSD License
  20 * @version    $Id$
  21 */
  22
  23/**
  24 * @see Zend_Service_WindowsAzure_Management_OperationStatusInstance
  25 */
  26#require_once 'Zend/Service/WindowsAzure/Management/OperationStatusInstance.php';
  27
  28/**
  29 * @see Zend_Service_WindowsAzure_Management_SubscriptionOperationInstance
  30 */
  31#require_once 'Zend/Service/WindowsAzure/Management/SubscriptionOperationInstance.php';
  32
  33/**
  34 * @see Zend_Service_WindowsAzure_Management_DeploymentInstance
  35 */
  36#require_once 'Zend/Service/WindowsAzure/Management/DeploymentInstance.php';
  37
  38/**
  39 * @see Zend_Service_WindowsAzure_Storage_Blob
  40 */
  41#require_once 'Zend/Service/WindowsAzure/Storage/Blob.php';
  42
  43/**
  44 * @see Zend_Service_WindowsAzure_Storage_Table
  45 */
  46#require_once 'Zend/Service/WindowsAzure/Storage/Table.php';
  47
  48/**
  49 * @see Zend_Service_WindowsAzure_Management_HostedServiceInstance
  50 */
  51#require_once 'Zend/Service/WindowsAzure/Management/HostedServiceInstance.php';
  52
  53/**
  54 * @see Zend_Service_WindowsAzure_Management_CertificateInstance
  55 */
  56#require_once 'Zend/Service/WindowsAzure/Management/CertificateInstance.php';
  57
  58/**
  59 * @see Zend_Service_WindowsAzure_Management_AffinityGroupInstance
  60 */
  61#require_once 'Zend/Service/WindowsAzure/Management/AffinityGroupInstance.php';
  62
  63/**
  64 * @see Zend_Service_WindowsAzure_Management_LocationInstance
  65 */
  66#require_once 'Zend/Service/WindowsAzure/Management/LocationInstance.php';
  67
  68/**
  69 * @see Zend_Service_WindowsAzure_Management_OperatingSystemInstance
  70 */
  71#require_once 'Zend/Service/WindowsAzure/Management/OperatingSystemInstance.php';
  72
  73/**
  74 * @see Zend_Service_WindowsAzure_Management_OperatingSystemFamilyInstance
  75 */
  76#require_once 'Zend/Service/WindowsAzure/Management/OperatingSystemFamilyInstance.php';
  77
  78/** @see Zend_Xml_Security */
  79#require_once 'Zend/Xml/Security.php';
  80
  81/**
  82 * @category   Zend
  83 * @package    Zend_Service_WindowsAzure
  84 * @subpackage Management
  85 * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  86 * @license    http://framework.zend.com/license/new-bsd     New BSD License
  87 */
  88class Zend_Service_WindowsAzure_Management_Client
  89{
  90	/**
  91	 * Management service URL
  92	 */
  93	const URL_MANAGEMENT        = "https://management.core.windows.net";
  94	
  95	/**
  96	 * Operations
  97	 */
  98	const OP_OPERATIONS                = "operations";
  99	const OP_STORAGE_ACCOUNTS          = "services/storageservices";
 100	const OP_HOSTED_SERVICES           = "services/hostedservices";
 101	const OP_AFFINITYGROUPS            = "affinitygroups";
 102	const OP_LOCATIONS                 = "locations";
 103	const OP_OPERATINGSYSTEMS          = "operatingsystems";
 104	const OP_OPERATINGSYSTEMFAMILIES   = "operatingsystemfamilies";
 105
 106	/**
 107	 * Current API version
 108	 * 
 109	 * @var string
 110	 */
 111	protected $_apiVersion = '2011-02-25';
 112	
 113	/**
 114	 * Subscription ID
 115	 *
 116	 * @var string
 117	 */
 118	protected $_subscriptionId = '';
 119	
 120	/**
 121	 * Management certificate path (.PEM)
 122	 *
 123	 * @var string
 124	 */
 125	protected $_certificatePath = '';
 126	
 127	/**
 128	 * Management certificate passphrase
 129	 *
 130	 * @var string
 131	 */
 132	protected $_certificatePassphrase = '';
 133	
 134	/**
 135	 * Zend_Http_Client channel used for communication with REST services
 136	 * 
 137	 * @var Zend_Http_Client
 138	 */
 139	protected $_httpClientChannel = null;	
 140
 141	/**
 142	 * Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract instance
 143	 * 
 144	 * @var Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract
 145	 */
 146	protected $_retryPolicy = null;
 147	
 148	/**
 149	 * Returns the last request ID
 150	 * 
 151	 * @var string
 152	 */
 153	protected $_lastRequestId = null;
 154	
 155	/**
 156	 * Creates a new Zend_Service_WindowsAzure_Management instance
 157	 * 
 158	 * @param string $subscriptionId Subscription ID
 159	 * @param string $certificatePath Management certificate path (.PEM)
 160	 * @param string $certificatePassphrase Management certificate passphrase
 161     * @param Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy Retry policy to use when making requests
 162	 */
 163	public function __construct(
 164		$subscriptionId,
 165		$certificatePath,
 166		$certificatePassphrase,
 167		Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy = null
 168	) {
 169		$this->_subscriptionId = $subscriptionId;
 170		$this->_certificatePath = $certificatePath;
 171		$this->_certificatePassphrase = $certificatePassphrase;
 172		
 173		$this->_retryPolicy = $retryPolicy;
 174		if (is_null($this->_retryPolicy)) {
 175		    $this->_retryPolicy = Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract::noRetry();
 176		}
 177		
 178		// Setup default Zend_Http_Client channel
 179		$options = array(
 180		    'adapter'       => 'Zend_Http_Client_Adapter_Socket',
 181		    'ssltransport'  => 'ssl',
 182			'sslcert'       => $this->_certificatePath,
 183			'sslpassphrase' => $this->_certificatePassphrase,
 184			'sslusecontext' => true,
 185		);
 186		if (function_exists('curl_init')) {
 187			// Set cURL options if cURL is used afterwards
 188			$options['curloptions'] = array(
 189					CURLOPT_FOLLOWLOCATION => true,
 190					CURLOPT_TIMEOUT => 120,
 191			);
 192		}
 193		$this->_httpClientChannel = new Zend_Http_Client(null, $options);
 194	}
 195	
 196	/**
 197	 * Set the HTTP client channel to use
 198	 * 
 199	 * @param Zend_Http_Client_Adapter_Interface|string $adapterInstance Adapter instance or adapter class name.
 200	 */
 201	public function setHttpClientChannel($adapterInstance = 'Zend_Http_Client_Adapter_Socket')
 202	{
 203		$this->_httpClientChannel->setAdapter($adapterInstance);
 204	}
 205	
 206    /**
 207     * Retrieve HTTP client channel
 208     * 
 209     * @return Zend_Http_Client_Adapter_Interface
 210     */
 211    public function getHttpClientChannel()
 212    {
 213        return $this->_httpClientChannel;
 214    }
 215	
 216	/**
 217	 * Returns the Windows Azure subscription ID
 218	 * 
 219	 * @return string
 220	 */
 221	public function getSubscriptionId()
 222	{
 223		return $this->_subscriptionId;
 224	}
 225	
 226	/**
 227	 * Returns the last request ID.
 228	 * 
 229	 * @return string
 230	 */
 231	public function getLastRequestId()
 232	{
 233		return $this->_lastRequestId;
 234	}
 235	
 236	/**
 237	 * Get base URL for creating requests
 238	 *
 239	 * @return string
 240	 */
 241	public function getBaseUrl()
 242	{
 243		return self::URL_MANAGEMENT . '/' . $this->_subscriptionId;
 244	}
 245	
 246	/**
 247	 * Perform request using Zend_Http_Client channel
 248	 *
 249	 * @param string $path Path
 250	 * @param string $queryString Query string
 251	 * @param string $httpVerb HTTP verb the request will use
 252	 * @param array $headers x-ms headers to add
 253	 * @param mixed $rawData Optional RAW HTTP data to be sent over the wire
 254	 * @return Zend_Http_Response
 255	 */
 256	protected function _performRequest(
 257		$path = '/',
 258		$queryString = '',
 259		$httpVerb = Zend_Http_Client::GET,
 260		$headers = array(),
 261		$rawData = null
 262	) {
 263	    // Clean path
 264		if (strpos($path, '/') !== 0) {
 265			$path = '/' . $path;
 266		}
 267			
 268		// Clean headers
 269		if (is_null($headers)) {
 270		    $headers = array();
 271		}
 272		
 273		// Ensure cUrl will also work correctly:
 274		//  - disable Content-Type if required
 275		//  - disable Expect: 100 Continue
 276		if (!isset($headers["Content-Type"])) {
 277			$headers["Content-Type"] = '';
 278		}
 279		//$headers["Expect"] = '';
 280
 281		// Add version header
 282		$headers['x-ms-version'] = $this->_apiVersion;
 283		    
 284		// URL encoding
 285		$path           = self::urlencode($path);
 286		$queryString    = self::urlencode($queryString);
 287
 288		// Generate URL and sign request
 289		$requestUrl     = $this->getBaseUrl() . $path . $queryString;
 290		$requestHeaders = $headers;
 291
 292		// Prepare request 
 293		$this->_httpClientChannel->resetParameters(true);
 294		$this->_httpClientChannel->setUri($requestUrl);
 295		$this->_httpClientChannel->setHeaders($requestHeaders);
 296		$this->_httpClientChannel->setRawData($rawData);
 297
 298		// Execute request
 299		$response = $this->_retryPolicy->execute(
 300		    array($this->_httpClientChannel, 'request'),
 301		    array($httpVerb)
 302		);
 303		
 304		// Store request id
 305		$this->_lastRequestId = $response->getHeader('x-ms-request-id');
 306		
 307		return $response;
 308	}
 309	
 310	/** 
 311	 * Parse result from Zend_Http_Response
 312	 *
 313	 * @param Zend_Http_Response $response Response from HTTP call
 314	 * @return object
 315	 * @throws Zend_Service_WindowsAzure_Exception
 316	 */
 317	protected function _parseResponse(Zend_Http_Response $response = null)
 318	{
 319		if (is_null($response)) {
 320			#require_once 'Zend/Service/WindowsAzure/Exception.php';
 321			throw new Zend_Service_WindowsAzure_Exception('Response should not be null.');
 322		}
 323		
 324        $xml = Zend_Xml_Security::scan($response->getBody());
 325        
 326        if ($xml !== false) {
 327            // Fetch all namespaces 
 328            $namespaces = array_merge($xml->getNamespaces(true), $xml->getDocNamespaces(true)); 
 329            
 330            // Register all namespace prefixes
 331            foreach ($namespaces as $prefix => $ns) { 
 332                if ($prefix != '') {
 333                    $xml->registerXPathNamespace($prefix, $ns);
 334                } 
 335            } 
 336        }
 337        
 338        return $xml;
 339	}
 340	
 341	/**
 342	 * URL encode function
 343	 * 
 344	 * @param  string $value Value to encode
 345	 * @return string        Encoded value
 346	 */
 347	public static function urlencode($value)
 348	{
 349	    return str_replace(' ', '%20', $value);
 350	}
 351	
 352    /**
 353     * Builds a query string from an array of elements
 354     * 
 355     * @param array     Array of elements
 356     * @return string   Assembled query string
 357     */
 358    public static function createQueryStringFromArray($queryString)
 359    {
 360    	return count($queryString) > 0 ? '?' . implode('&', $queryString) : '';
 361    }
 362    
 363	/**
 364	 * Get error message from Zend_Http_Response
 365	 *
 366	 * @param Zend_Http_Response $response Repsonse
 367	 * @param string $alternativeError Alternative error message
 368	 * @return string
 369	 */
 370	protected function _getErrorMessage(Zend_Http_Response $response, $alternativeError = 'Unknown error.')
 371	{
 372		$response = $this->_parseResponse($response);
 373		if ($response && $response->Message) {
 374			return (string)$response->Message;
 375		} else {
 376			return $alternativeError;
 377		}
 378	}
 379    
 380    /**
 381     * The Get Operation Status operation returns the status of the specified operation.
 382     * After calling an asynchronous operation, you can call Get Operation Status to
 383     * determine whether the operation has succeed, failed, or is still in progress.
 384     *
 385     * @param string $requestId The request ID. If omitted, the last request ID will be used.
 386     * @return Zend_Service_WindowsAzure_Management_OperationStatusInstance
 387     * @throws Zend_Service_WindowsAzure_Management_Exception
 388     */
 389    public function getOperationStatus($requestId = '')
 390    {
 391    	if ($requestId == '') {
 392    		$requestId = $this->getLastRequestId();
 393    	}
 394    	
 395    	$response = $this->_performRequest(self::OP_OPERATIONS . '/' . $requestId);
 396
 397    	if ($response->isSuccessful()) {
 398			$result = $this->_parseResponse($response);
 399
 400			if (!is_null($result)) {
 401				return new Zend_Service_WindowsAzure_Management_OperationStatusInstance(
 402					(string)$result->ID,
 403					(string)$result->Status,
 404					($result->Error ? (string)$result->Error->Code : ''),
 405					($result->Error ? (string)$result->Error->Message : '')
 406				);
 407			}
 408			return null;
 409		} else {
 410			#require_once 'Zend/Service/Management/Exception.php';
 411			throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 412		}
 413    }
 414    
 415
 416    
 417    /**
 418     * The List Subscription Operations operation returns a list of create, update,
 419     * and delete operations that were performed on a subscription during the specified timeframe.
 420     * Documentation on the parameters can be found at http://msdn.microsoft.com/en-us/library/gg715318.aspx.
 421     *
 422     * @param string $startTime The start of the timeframe to begin listing subscription operations in UTC format. This parameter and the $endTime parameter indicate the timeframe to retrieve subscription operations. This parameter cannot indicate a start date of more than 90 days in the past.
 423     * @param string $endTime The end of the timeframe to begin listing subscription operations in UTC format. This parameter and the $startTime parameter indicate the timeframe to retrieve subscription operations. 
 424     * @param string $objectIdFilter Returns subscription operations only for the specified object type and object ID. 
 425     * @param string $operationResultFilter Returns subscription operations only for the specified result status, either Succeeded, Failed, or InProgress.
 426     * @param string $continuationToken Internal usage.
 427     * @return array Array of Zend_Service_WindowsAzure_Management_SubscriptionOperationInstance
 428     * @throws Zend_Service_WindowsAzure_Management_Exception
 429     */
 430    public function listSubscriptionOperations($startTime, $endTime, $objectIdFilter = null, $operationResultFilter = null, $continuationToken = null)
 431    {
 432    	if ($startTime == '' || is_null($startTime)) {
 433			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 434    		throw new Zend_Service_WindowsAzure_Management_Exception('Start time should be specified.');
 435    	}
 436    	if ($endTime == '' || is_null($endTime)) {
 437			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 438    		throw new Zend_Service_WindowsAzure_Management_Exception('End time should be specified.');
 439    	}
 440    	if ($operationResultFilter != '' && !is_null($operationResultFilter)) {
 441	        $operationResultFilter = strtolower($operationResultFilter);
 442	    	if ($operationResultFilter != 'succeeded' && $operationResultFilter != 'failed' && $operationResultFilter != 'inprogress') {
 443				#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 444	    		throw new Zend_Service_WindowsAzure_Management_Exception('OperationResultFilter should be succeeded|failed|inprogress.');
 445	    	}
 446    	}
 447    	
 448    	$parameters = array();
 449    	$parameters[] = 'StartTime=' . $startTime;
 450    	$parameters[] = 'EndTime=' . $endTime;
 451    	if ($objectIdFilter != '' && !is_null($objectIdFilter)) {
 452    		$parameters[] = 'ObjectIdFilter=' . $objectIdFilter;
 453    	}
 454    	if ($operationResultFilter != '' && !is_null($operationResultFilter)) {
 455    		$parameters[] = 'OperationResultFilter=' . ucfirst($operationResultFilter);
 456    	}
 457    	if ($continuationToken != '' && !is_null($continuationToken)) {
 458    		$parameters[] = 'ContinuationToken=' . $continuationToken;
 459    	}
 460    	
 461    	$response = $this->_performRequest(self::OP_OPERATIONS, '?' . implode('&', $parameters));
 462
 463    	if ($response->isSuccessful()) {
 464			$result = $this->_parseResponse($response);
 465			$namespaces = $result->getDocNamespaces(); 
 466    		$result->registerXPathNamespace('__empty_ns', $namespaces['']);
 467 
 468			$xmlOperations = $result->xpath('//__empty_ns:SubscriptionOperation');
 469			
 470		    // Create return value
 471		    $returnValue = array();		    
 472		    foreach ($xmlOperations as $xmlOperation) {
 473		    	// Create operation instance
 474		    	$operation = new Zend_Service_WindowsAzure_Management_SubscriptionOperationInstance(
 475		    		$xmlOperation->OperationId,
 476		    		$xmlOperation->OperationObjectId,
 477		    		$xmlOperation->OperationName,
 478		    		array(),
 479		    		(array)$xmlOperation->OperationCaller,
 480		    		(array)$xmlOperation->OperationStatus
 481		    	);
 482		    	
 483		    	// Parse parameters
 484		    	$xmlOperation->registerXPathNamespace('__empty_ns', $namespaces['']); 
 485		    	$xmlParameters = $xmlOperation->xpath('.//__empty_ns:OperationParameter');
 486		    	foreach ($xmlParameters as $xmlParameter) {
 487		    		$xmlParameterDetails = $xmlParameter->children('http://schemas.datacontract.org/2004/07/Microsoft.Samples.WindowsAzure.ServiceManagement');
 488		    		$operation->addOperationParameter((string)$xmlParameterDetails->Name, (string)$xmlParameterDetails->Value);
 489		    	}
 490		    	
 491    		    // Add to result
 492    		    $returnValue[] = $operation;
 493		    }
 494		    
 495			// More data?
 496		    if (!is_null($result->ContinuationToken) && $result->ContinuationToken != '') {
 497		    	$returnValue = array_merge($returnValue, $this->listSubscriptionOperations($startTime, $endTime, $objectIdFilter, $operationResultFilter, (string)$result->ContinuationToken));
 498		    }
 499		    
 500		    // Return
 501		    return $returnValue;
 502		} else {
 503			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 504			throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 505		}
 506    }
 507    
 508    /**
 509     * Wait for an operation to complete
 510     * 
 511     * @param string $requestId The request ID. If omitted, the last request ID will be used.
 512     * @param int $sleepInterval Sleep interval in milliseconds.
 513     * @return Zend_Service_WindowsAzure_Management_OperationStatusInstance
 514     * @throws Zend_Service_WindowsAzure_Management_Exception
 515     */
 516    public function waitForOperation($requestId = '', $sleepInterval = 250)
 517    {
 518    	if ($requestId == '') {
 519    		$requestId = $this->getLastRequestId();
 520    	}
 521    	if ($requestId == '' || is_null($requestId)) {
 522    		return null;
 523    	}
 524
 525		$status = $this->getOperationStatus($requestId);
 526		while ($status->Status == 'InProgress') {
 527		  $status = $this->getOperationStatus($requestId);
 528		  usleep($sleepInterval);
 529		}
 530		
 531		return $status;
 532    }
 533    
 534	/**
 535	 * Creates a new Zend_Service_WindowsAzure_Storage_Blob instance for the current account
 536	 *
 537	 * @param string $serviceName the service name to create a storage client for.
 538	 * @param Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy Retry policy to use when making requests
 539	 * @return Zend_Service_WindowsAzure_Storage_Blob
 540	 */
 541	public function createBlobClientForService($serviceName, Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy = null)
 542	{
 543		if ($serviceName == '' || is_null($serviceName)) {
 544    		throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
 545    	}
 546    	
 547    	$storageKeys = $this->getStorageAccountKeys($serviceName);
 548    	
 549		
 550		
 551		return new Zend_Service_WindowsAzure_Storage_Blob(
 552			Zend_Service_WindowsAzure_Storage::URL_CLOUD_BLOB,
 553			$serviceName,
 554			$storageKeys[0],
 555			false,
 556			$retryPolicy
 557		);
 558	}
 559	
 560	/**
 561	 * Creates a new Zend_Service_WindowsAzure_Storage_Table instance for the current account
 562	 *
 563	 * @param string $serviceName the service name to create a storage client for.
 564	 * @param Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy Retry policy to use when making requests
 565	 * @return Zend_Service_WindowsAzure_Storage_Table
 566	 */
 567	public function createTableClientForService($serviceName, Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy = null)
 568	{
 569		if ($serviceName == '' || is_null($serviceName)) {
 570			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 571    		throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
 572    	}
 573    	
 574    	$storageKeys = $this->getStorageAccountKeys($serviceName);
 575		
 576		return new Zend_Service_WindowsAzure_Storage_Table(
 577			Zend_Service_WindowsAzure_Storage::URL_CLOUD_TABLE,
 578			$serviceName,
 579			$storageKeys[0],
 580			false,
 581			$retryPolicy
 582		);
 583	}
 584	
 585	/**
 586	 * Creates a new Zend_Service_WindowsAzure_Storage_Queue instance for the current account
 587	 *
 588	 * @param string $serviceName the service name to create a storage client for.
 589	 * @param Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy Retry policy to use when making requests
 590	 * @return Zend_Service_WindowsAzure_Storage_Queue
 591	 */
 592	public function createQueueClientForService($serviceName, Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy = null)
 593	{
 594		if ($serviceName == '' || is_null($serviceName)) {
 595			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 596    		throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
 597    	}
 598    	
 599    	$storageKeys = $this->getStorageAccountKeys($serviceName);
 600    	
 601		#require_once 'Zend/Service/WindowsAzure/Storage/Queue.php';
 602		
 603		return new Zend_Service_WindowsAzure_Storage_Queue(
 604			Zend_Service_WindowsAzure_Storage::URL_CLOUD_QUEUE,
 605			$serviceName,
 606			$storageKeys[0],
 607			false,
 608			$retryPolicy
 609		);
 610	}
 611    
 612    /**
 613     * The List Storage Accounts operation lists the storage accounts available under
 614     * the current subscription.
 615     *
 616     * @return array An array of Zend_Service_WindowsAzure_Management_StorageServiceInstance
 617     */
 618    public function listStorageAccounts()
 619    {
 620    	$response = $this->_performRequest(self::OP_STORAGE_ACCOUNTS);
 621
 622    	if ($response->isSuccessful()) {
 623			$result = $this->_parseResponse($response);
 624			
 625    		if (!$result->StorageService) {
 626				return array();
 627			}
 628		    if (count($result->StorageService) > 1) {
 629    		    $xmlServices = $result->StorageService;
 630    		} else {
 631    		    $xmlServices = array($result->StorageService);
 632    		}
 633    		
 634			$services = array();
 635			if (!is_null($xmlServices)) {				
 636				for ($i = 0; $i < count($xmlServices); $i++) {
 637					$services[] = new Zend_Service_WindowsAzure_Management_StorageServiceInstance(
 638					    (string)$xmlServices[$i]->Url,
 639					    (string)$xmlServices[$i]->ServiceName
 640					);
 641				}
 642			}
 643			return $services;
 644		} else {
 645			throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 646		}
 647    }
 648    
 649    /**
 650     * The Get Storage Account Properties operation returns the system properties for the
 651     * specified storage account. These properties include: the address, description, and 
 652     * label of the storage account; and the name of the affinity group to which the service
 653     * belongs, or its geo-location if it is not part of an affinity group.
 654     *
 655     * @param string $serviceName The name of your service.
 656     * @return Zend_Service_WindowsAzure_Management_StorageServiceInstance
 657     * @throws Zend_Service_WindowsAzure_Management_Exception
 658     */
 659    public function getStorageAccountProperties($serviceName)
 660    {
 661    	if ($serviceName == '' || is_null($serviceName)) {
 662    		throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
 663    	}
 664    	
 665    	$response = $this->_performRequest(self::OP_STORAGE_ACCOUNTS . '/' . $serviceName);
 666
 667    	if ($response->isSuccessful()) {
 668			$xmlService = $this->_parseResponse($response);
 669
 670			if (!is_null($xmlService)) {
 671				#require_once 'Zend/Service/WindowsAzure/Management/StorageServiceInstance.php';
 672				
 673				return new Zend_Service_WindowsAzure_Management_StorageServiceInstance(
 674					(string)$xmlService->Url,
 675					(string)$xmlService->ServiceName,
 676					(string)$xmlService->StorageServiceProperties->Description,
 677					(string)$xmlService->StorageServiceProperties->AffinityGroup,
 678					(string)$xmlService->StorageServiceProperties->Location,
 679					(string)$xmlService->StorageServiceProperties->Label
 680				);
 681			}
 682			return null;
 683		} else {
 684			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 685			throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 686		}
 687    }
 688    
 689    /**
 690     * The Get Storage Keys operation returns the primary
 691     * and secondary access keys for the specified storage account.
 692     *
 693     * @param string $serviceName The name of your service.
 694     * @return array An array of strings
 695     * @throws Zend_Service_WindowsAzure_Management_Exception
 696     */
 697    public function getStorageAccountKeys($serviceName)
 698    {
 699    	if ($serviceName == '' || is_null($serviceName)) {
 700			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 701    		throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
 702    	}
 703    	
 704    	$response = $this->_performRequest(self::OP_STORAGE_ACCOUNTS . '/' . $serviceName . '/keys');
 705
 706    	if ($response->isSuccessful()) {
 707			$xmlService = $this->_parseResponse($response);
 708
 709			if (!is_null($xmlService)) {
 710				return array(
 711					(string)$xmlService->StorageServiceKeys->Primary,
 712					(string)$xmlService->StorageServiceKeys->Secondary
 713				);
 714			}
 715			return array();
 716		} else {
 717			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 718			throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 719		}
 720    }
 721    
 722    /**
 723     * The Regenerate Keys operation regenerates the primary
 724     * or secondary access key for the specified storage account.
 725     *
 726     * @param string $serviceName The name of your service.
 727     * @param string $key		  The key to regenerate (primary or secondary)
 728     * @return array An array of strings
 729     * @throws Zend_Service_WindowsAzure_Management_Exception
 730     */
 731    public function regenerateStorageAccountKey($serviceName, $key = 'primary')
 732    {
 733    	if ($serviceName == '' || is_null($serviceName)) {
 734			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 735    		throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
 736    	}
 737    	$key = strtolower($key);
 738    	if ($key != 'primary' && $key != 'secondary') {
 739			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 740    		throw new Zend_Service_WindowsAzure_Management_Exception('Key identifier should be primary|secondary.');
 741    	}
 742    	
 743    	$response = $this->_performRequest(
 744    		self::OP_STORAGE_ACCOUNTS . '/' . $serviceName . '/keys', '?action=regenerate',
 745    		Zend_Http_Client::POST,
 746    		array('Content-Type' => 'application/xml'),
 747    		'<?xml version="1.0" encoding="utf-8"?>
 748             <RegenerateKeys xmlns="http://schemas.microsoft.com/windowsazure">
 749               <KeyType>' . ucfirst($key) . '</KeyType>
 750             </RegenerateKeys>');
 751
 752    	if ($response->isSuccessful()) {
 753			$xmlService = $this->_parseResponse($response);
 754
 755			if (!is_null($xmlService)) {
 756				return array(
 757					(string)$xmlService->StorageServiceKeys->Primary,
 758					(string)$xmlService->StorageServiceKeys->Secondary
 759				);
 760			}
 761			return array();
 762		} else {
 763			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 764			throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 765		}
 766    }
 767    
 768    /**
 769     * The List Hosted Services operation lists the hosted services available
 770     * under the current subscription.
 771     *
 772     * @return array An array of Zend_Service_WindowsAzure_Management_HostedServiceInstance
 773     * @throws Zend_Service_WindowsAzure_Management_Exception
 774     */
 775    public function listHostedServices()
 776    {
 777    	$response = $this->_performRequest(self::OP_HOSTED_SERVICES);
 778
 779    	if ($response->isSuccessful()) {
 780			$result = $this->_parseResponse($response);
 781			
 782    		if (!$result->HostedService) {
 783				return array();
 784			}
 785		    if (count($result->HostedService) > 1) {
 786    		    $xmlServices = $result->HostedService;
 787    		} else {
 788    		    $xmlServices = array($result->HostedService);
 789    		}
 790    		
 791			$services = array();
 792			if (!is_null($xmlServices)) {	
 793				
 794				for ($i = 0; $i < count($xmlServices); $i++) {
 795					$services[] = new Zend_Service_WindowsAzure_Management_HostedServiceInstance(
 796					    (string)$xmlServices[$i]->Url,
 797					    (string)$xmlServices[$i]->ServiceName
 798					);
 799				}
 800			}
 801			return $services;
 802		} else {
 803			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 804			throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 805		}
 806    }
 807    
 808    /**
 809     * The Create Hosted Service operation creates a new hosted service in Windows Azure.
 810     * 
 811     * @param string $serviceName A name for the hosted service that is unique to the subscription.
 812     * @param string $label A label for the hosted service. The label may be up to 100 characters in length.
 813     * @param string $description A description for the hosted service. The description may be up to 1024 characters in length.
 814     * @param string $location Required if AffinityGroup is not specified. The location where the hosted service will be created. 
 815     * @param string $affinityGroup Required if Location is not specified. The name of an existing affinity group associated with this subscription.
 816     */
 817    public function createHostedService($serviceName, $label, $description = '', $location = null, $affinityGroup = null)
 818    {
 819    	if ($serviceName == '' || is_null($serviceName)) {
 820			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 821    		throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
 822    	}
 823    	if ($label == '' || is_null($label)) {
 824			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 825    		throw new Zend_Service_WindowsAzure_Management_Exception('Label should be specified.');
 826    	}
 827        if (strlen($label) > 100) {
 828			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 829    		throw new Zend_Service_WindowsAzure_Management_Exception('Label is too long. The maximum length is 100 characters.');
 830    	}
 831        if (strlen($description) > 1024) {
 832			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 833    		throw new Zend_Service_WindowsAzure_Management_Exception('Description is too long. The maximum length is 1024 characters.');
 834    	}
 835    	if ( (is_null($location) && is_null($affinityGroup)) || (!is_null($location) && !is_null($affinityGroup)) ) {
 836			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 837    		throw new Zend_Service_WindowsAzure_Management_Exception('Please specify a location -or- an affinity group for the service.');
 838    	}
 839    	
 840    	$locationOrAffinityGroup = is_null($location)
 841    		? '<AffinityGroup>' . $affinityGroup . '</AffinityGroup>'
 842    		: '<Location>' . $location . '</Location>';
 843    	
 844        $response = $this->_performRequest(self::OP_HOSTED_SERVICES, '',
 845    		Zend_Http_Client::POST,
 846    		array('Content-Type' => 'application/xml; charset=utf-8'),
 847    		'<CreateHostedService xmlns="http://schemas.microsoft.com/windowsazure"><ServiceName>' . $serviceName . '</ServiceName><Label>' . base64_encode($label) . '</Label><Description>' . $description . '</Description>' . $locationOrAffinityGroup . '</CreateHostedService>');
 848 	
 849    	if (!$response->isSuccessful()) {
 850			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 851			throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 852		}
 853    }
 854    
 855    /**
 856     * The Update Hosted Service operation updates the label and/or the description for a hosted service in Windows Azure.
 857     * 
 858     * @param string $serviceName A name for the hosted service that is unique to the subscription.
 859     * @param string $label A label for the hosted service. The label may be up to 100 characters in length.
 860     * @param string $description A description for the hosted service. The description may be up to 1024 characters in length.
 861     */
 862    public function updateHostedService($serviceName, $label, $description = '')
 863    {
 864    	if ($serviceName == '' || is_null($serviceName)) {
 865			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 866    		throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
 867    	}
 868    	if ($label == '' || is_null($label)) {
 869			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 870    		throw new Zend_Service_WindowsAzure_Management_Exception('Label should be specified.');
 871    	}
 872        if (strlen($label) > 100) {
 873			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 874    		throw new Zend_Service_WindowsAzure_Management_Exception('Label is too long. The maximum length is 100 characters.');
 875    	}
 876    	
 877        $response = $this->_performRequest(self::OP_HOSTED_SERVICES . '/' . $serviceName, '',
 878    		Zend_Http_Client::PUT,
 879    		array('Content-Type' => 'application/xml; charset=utf-8'),
 880    		'<UpdateHostedService xmlns="http://schemas.microsoft.com/windowsazure"><Label>' . base64_encode($label) . '</Label><Description>' . $description . '</Description></UpdateHostedService>');
 881 	
 882    	if (!$response->isSuccessful()) {
 883			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 884			throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 885		}
 886    }
 887    
 888    /**
 889     * The Delete Hosted Service operation deletes the specified hosted service in Windows Azure.
 890     * 
 891     * @param string $serviceName A name for the hosted service that is unique to the subscription.
 892     */
 893    public function deleteHostedService($serviceName)
 894    {
 895    	if ($serviceName == '' || is_null($serviceName)) {
 896			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 897    		throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
 898    	}
 899    	
 900        $response = $this->_performRequest(self::OP_HOSTED_SERVICES . '/' . $serviceName, '', Zend_Http_Client::DELETE);
 901 	
 902    	if (!$response->isSuccessful()) {
 903			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 904			throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 905		}
 906    }
 907    
 908    /**
 909     * The Get Hosted Service Properties operation retrieves system properties
 910     * for the specified hosted service. These properties include the service
 911     * name and service type; the name of the affinity group to which the service
 912     * belongs, or its location if it is not part of an affinity group; and
 913     * optionally, information on the service's deployments.
 914     *
 915     * @param string $serviceName The name of your service.
 916     * @return Zend_Service_WindowsAzure_Management_HostedServiceInstance
 917     * @throws Zend_Service_WindowsAzure_Management_Exception
 918     */
 919    public function getHostedServiceProperties($serviceName)
 920    {
 921    	if ($serviceName == '' || is_null($serviceName)) {
 922			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 923    		throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
 924    	}
 925    	
 926    	$response = $this->_performRequest(self::OP_HOSTED_SERVICES . '/' . $serviceName, '?embed-detail=true');
 927
 928    	if ($response->isSuccessful()) {
 929			$xmlService = $this->_parseResponse($response);
 930
 931			if (!is_null($xmlService)) {
 932				
 933				$returnValue = new Zend_Service_WindowsAzure_Management_HostedServiceInstance(
 934					(string)$xmlService->Url,
 935					(string)$xmlService->ServiceName,
 936					(string)$xmlService->HostedServiceProperties->Description,
 937					(string)$xmlService->HostedServiceProperties->AffinityGroup,
 938					(string)$xmlService->HostedServiceProperties->Location,
 939					(string)$xmlService->HostedServiceProperties->Label
 940				);
 941				
 942				// Deployments
 943		    	if (count($xmlService->Deployments->Deployment) > 1) {
 944    		    	$xmlServices = $xmlService->Deployments->Deployment;
 945    			} else {
 946    		    	$xmlServices = array($xmlService->Deployments->Deployment);
 947    			}
 948    			
 949    			$deployments = array();
 950    			foreach ($xmlServices as $xmlDeployment) {
 951					$deployments[] = $this->_convertXmlElementToDeploymentInstance($xmlDeployment);
 952    			}
 953				$returnValue->Deployments = $deployments;
 954				
 955				return $returnValue;
 956			}
 957			return null;
 958		} else {
 959			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 960			throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 961		}
 962    }
 963
 964    /**
 965     * The Create Deployment operation uploads a new service package
 966     * and creates a new deployment on staging or production.
 967     * 
 968     * @param string $serviceName		The service name
 969     * @param string $deploymentSlot	The deployment slot (production or staging)
 970	 * @param string $name              The name for the deployment. The deployment ID as listed on the Windows Azure management portal must be unique among other deployments for the hosted service.
 971	 * @param string $label             A URL that refers to the location of the service package in the Blob service. The service package must be located in a storage account beneath the same subscription.
 972	 * @param string $packageUrl        The service configuration file for the deployment.
 973	 * @param string $configuration     A label for this deployment, up to 100 characters in length.
 974	 * @param boolean $startDeployment  Indicates whether to start the deployment immediately after it is created.
 975	 * @param boolean $treatWarningsAsErrors Indicates whether to treat package validation warnings as errors.
 976     * @throws Zend_Service_WindowsAzure_Management_Exception
 977     */
 978    public function createDeployment($serviceName, $deploymentSlot, $name, $label, $packageUrl, $configuration, $startDeployment = false, $treatWarningsAsErrors = false)
 979    {
 980        if ($serviceName == '' || is_null($serviceName)) {
 981			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 982    		throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
 983    	}
 984    	$deploymentSlot = strtolower($deploymentSlot);
 985    	if ($deploymentSlot != 'production' && $deploymentSlot != 'staging') {
 986			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 987    		throw new Zend_Service_WindowsAzure_Management_Exception('Deployment slot should be production|staging.');
 988    	}
 989    	if ($name == '' || is_null($name)) {
 990			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 991    		throw new Zend_Service_WindowsAzure_Management_Exception('Name should be specified.');
 992    	}
 993    	if ($label == '' || is_null($label)) {
 994			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 995    		throw new Zend_Service_WindowsAzure_Management_Exception('Label should be specified.');
 996    	}
 997        if (strlen($label) > 100) {
 998			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
 999    		throw new Zend_Service_WindowsAzure_Management_Exception('Label is too long. The maximum length is 100 characters.');
1000    	}
1001    	if ($packageUrl == '' || is_null($packageUrl)) {
1002			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1003    		throw new Zend_Service_WindowsAzure_Management_Exception('Package URL should be specified.');
1004    	}
1005    	if ($configuration == '' || is_null($configuration)) {
1006			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1007    		throw new Zend_Service_WindowsAzure_Management_Exception('Configuration should be specified.');
1008    	}
1009    	
1010    	if (@file_exists($configuration)) {
1011    		$configuration = utf8_decode(file_get_contents($configuration));
1012    	}
1013    	
1014    	// Clean up the configuration
1015    	$conformingConfiguration = $this->_cleanConfiguration($configuration);
1016    	
1017    	$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deploymentslots/' . $deploymentSlot;
1018        $response = $this->_performRequest($operationUrl, '',
1019    		Zend_Http_Client::POST,
1020    		array('Content-Type' => 'application/xml; charset=utf-8'),
1021    		'<CreateDeployment xmlns="http://schemas.microsoft.com/windowsazure"><Name>' . $name . '</Name><PackageUrl>' . $packageUrl . '</PackageUrl><Label>' . base64_encode($label) . '</Label><Configuration>' . base64_encode($conformingConfiguration) . '</Configuration><StartDeployment>' . ($startDeployment ? 'true' : 'false') . '</StartDeployment><TreatWarningsAsError>' . ($treatWarningsAsErrors ? 'true' : 'false') . '</TreatWarningsAsError></CreateDeployment>');
1022 	
1023    	if (!$response->isSuccessful()) {
1024			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1025			throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
1026		}    	
1027    }
1028    
1029    /**
1030     * The Get Deployment operation returns configuration information, status,
1031     * and system properties for the specified deployment.
1032     * 
1033     * @param string $serviceName		The service name
1034     * @param string $deploymentSlot	The deployment slot (production or staging)
1035     * @return Zend_Service_WindowsAzure_Management_DeploymentInstance
1036     * @throws Zend_Service_WindowsAzure_Management_Exception
1037     */
1038    public function getDeploymentBySlot($serviceName, $deploymentSlot)
1039    {
1040        if ($serviceName == '' || is_null($serviceName)) {
1041			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1042    		throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
1043    	}
1044    	$deploymentSlot = strtolower($deploymentSlot);
1045    	if ($deploymentSlot != 'production' && $deploymentSlot != 'staging') {
1046			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1047    		throw new Zend_Service_WindowsAzure_Management_Exception('Deployment slot should be production|staging.');
1048    	}
1049    	
1050    	$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deploymentslots/' . $deploymentSlot;
1051    	return $this->_getDeployment($operationUrl);
1052    }
1053    
1054    /**
1055     * The Get Deployment operation returns configuration information, status,
1056     * and system properties for the specified deployment.
1057     * 
1058     * @param string $serviceName		The service name
1059     * @param string $deploymentId	The deployment ID as listed on the Windows Azure management portal
1060     * @return Zend_Service_WindowsAzure_Management_DeploymentInstance
1061     * @throws Zend_Service_WindowsAzure_Management_Exception
1062     */
1063    public function getDeploymentByDeploymentId($serviceName, $deploymentId)
1064    {
1065        if ($serviceName == '' || is_null($serviceName)) {
1066			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1067    		throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
1068    	}
1069        if ($deploymentId == '' || is_null($deploymentId)) {
1070			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1071    		throw new Zend_Service_WindowsAzure_Management_Exception('Deployment ID should be specified.');
1072    	}
1073    	
1074    	$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deployments/' . $deploymentId;
1075    	return $this->_getDeployment($operationUrl);
1076    }
1077    
1078    /**
1079     * The Get Deployment operation returns configuration information, status,
1080     * and system properties for the specified deployment.
1081     * 
1082     * @param string $operationUrl		The operation url
1083     * @return Zend_Service_WindowsAzure_Management_DeploymentInstance
1084     * @throws Zend_Service_WindowsAzure_Management_Exception
1085     */
1086    protected function _getDeployment($operationUrl)
1087    {
1088        $response = $this->_performRequest($operationUrl);
1089
1090    	if ($response->isSuccessful()) {
1091			$xmlService = $this->_parseResponse($response);
1092			
1093			return $this->_convertXmlElementToDeploymentInstance($xmlService);
1094		} else {
1095			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1096			throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
1097		}
1098    }
1099    
1100    /**
1101     * The Swap Deployment operation initiates a virtual IP swap between
1102     * the staging and production deployment environments for a service.
1103     * If the service is currently running in the staging environment,
1104     * it will be swapped to the production environment. If it is running
1105     * in the production environment, it will be swapped to staging.
1106     * 
1107     * @param string $serviceName The service name.
1108     * @param string $productionDeploymentName The name of the production deployment.
1109     * @param string $sourceDeploymentName The name of the source deployment.
1110     * @throws Zend_Service_WindowsAzure_Management_Exception
1111     */
1112    public function swapDeployment($serviceName, $productionDeploymentName, $sourceDeploymentName)
1113    {
1114    	if ($serviceName == '' || is_null($serviceName)) {
1115			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1116    		throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
1117    	}
1118    	if ($productionDeploymentName == '' || is_null($productionDeploymentName)) {
1119			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1120    		throw new Zend_Service_WindowsAzure_Management_Exception('Production Deployment ID should be specified.');
1121    	}
1122    	if ($sourceDeploymentName == '' || is_null($sourceDeploymentName)) {
1123			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1124    		throw new Zend_Service_WindowsAzure_Management_Exception('Source Deployment ID should be specified.');
1125    	}
1126    	
1127    	$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName;
1128        $response = $this->_performRequest($operationUrl, '',
1129    		Zend_Http_Client::POST,
1130    		array('Content-Type' => 'application/xml; charset=utf-8'),
1131    		'<Swap xmlns="http://schemas.microsoft.com/windowsazure"><Production>' . $productionDeploymentName . '</Production><SourceDeployment>' . $sourceDeploymentName . '</SourceDeployment></Swap>');
1132    		
1133    	if (!$response->isSuccessful()) {
1134			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1135			throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
1136		}    	
1137    }
1138    
1139    /**
1140     * The Delete Deployment operation deletes the specified deployment.
1141     * 
1142     * @param string $serviceName		The service name
1143     * @param string $deploymentSlot	The deployment slot (production or staging)
1144     * @throws Zend_Service_WindowsAzure_Management_Exception
1145     */
1146    public function deleteDeploymentBySlot($serviceName, $deploymentSlot)
1147    {
1148        if ($serviceName == '' || is_null($serviceName)) {
1149			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1150    		throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
1151    	}
1152    	$deploymentSlot = strtolower($deploymentSlot);
1153    	if ($deploymentSlot != 'production' && $deploymentSlot != 'staging') {
1154			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1155    		throw new Zend_Service_WindowsAzure_Management_Exception('Deployment slot should be production|staging.');
1156    	}
1157    	
1158    	$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deploymentslots/' . $deploymentSlot;
1159    	return $this->_deleteDeployment($operationUrl);
1160    }
1161    
1162    /**
1163     * The Delete Deployment operation deletes the specified deployment.
1164     * 
1165     * @param string $serviceName		The service name
1166     * @param string $deploymentId	The deployment ID as listed on the Windows Azure management portal
1167     * @throws Zend_Service_WindowsAzure_Management_Exception
1168     */
1169    public function deleteDeploymentByDeploymentId($serviceName, $deploymentId)
1170    {
1171        if ($serviceName == '' || is_null($serviceName)) {
1172			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1173    		throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
1174    	}
1175    	if ($deploymentId == '' || is_null($deploymentId)) {
1176			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1177    		throw new Zend_Service_WindowsAzure_Management_Exception('Deployment ID should be specified.');
1178    	}
1179    	
1180    	$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deployments/' . $deploymentId;
1181    	return $this->_deleteDeployment($operationUrl);
1182    }
1183    
1184    /**
1185     * The Delete Deployment operation deletes the specified deployment.
1186     * 
1187     * @param string $operationUrl		The operation url
1188     * @throws Zend_Service_WindowsAzure_Management_Exception
1189     */
1190    protected function _deleteDeployment($operationUrl)
1191    {
1192        $response = $this->_performRequest($operationUrl, '', Zend_Http_Client::DELETE);
1193			 
1194    	if (!$response->isSuccessful()) {
1195			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1196			throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
1197		}
1198    }
1199    
1200    /**
1201     * The Update Deployment Status operation initiates a change in deployment status.
1202     * 
1203     * @param string $serviceName		The service name
1204     * @param string $deploymentSlot	The deployment slot (production or staging)
1205     * @param string $status            The deployment status (running|suspended)
1206     * @throws Zend_Service_WindowsAzure_Management_Exception
1207     */
1208    public function updateDeploymentStatusBySlot($serviceName, $deploymentSlot, $status = 'running')
1209    {
1210        if ($serviceName == '' || is_null($serviceName)) {
1211			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1212    		throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
1213    	}
1214    	$deploymentSlot = strtolower($deploymentSlot);
1215    	if ($deploymentSlot != 'production' && $deploymentSlot != 'staging') {
1216			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1217    		throw new Zend_Service_WindowsAzure_Management_Exception('Deployment slot should be production|staging.');
1218    	}
1219    	$status = strtolower($status);
1220    	if ($status != 'running' && $status != 'suspended') {
1221			#require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
1222    		throw new Zend_Service_WindowsAzure_Management_Exception('Status should be running|suspended.');
1223    	}
1224    	
1225    	$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/dep…

Large files files are truncated, but you can click here to view the full file