PageRenderTime 58ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/Microsoft/WindowsAzure/Management/Client.php

https://bitbucket.org/ktos/tinyshare
PHP | 2400 lines | 1436 code | 255 blank | 709 comment | 545 complexity | b3ae1f793af2686e89a3825e627021e2 MD5 | raw file
Possible License(s): BSD-3-Clause

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

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

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