PageRenderTime 67ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

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