GetAsynchronousOperation.php 6.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_Console
  17. * @subpackage Exception
  18. * @version $Id$
  19. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. /**
  23. * @see Zend_Service_Console_Command
  24. */
  25. require_once 'Zend/Service/Console/Command.php';
  26. /**
  27. * @see Zend_Service_WindowsAzure_Management_Client
  28. */
  29. require_once 'Zend/Service/WindowsAzure/Management/Client.php';
  30. /**
  31. * Asynchronous Operation commands
  32. *
  33. * @category Zend
  34. * @package Zend_Service_WindowsAzure_CommandLine
  35. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. *
  38. * @command-handler getasynchronousoperation
  39. * @command-handler-description Windows Azure Asynchronous Operation commands
  40. * @command-handler-header Windows Azure SDK for PHP
  41. * @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
  42. * @command-handler-footer Note: Parameters that are common across all commands can be stored
  43. * @command-handler-footer in two dedicated environment variables.
  44. * @command-handler-footer - SubscriptionId: The Windows Azure Subscription Id to operate on.
  45. * @command-handler-footer - Certificate The Windows Azure .cer Management Certificate.
  46. * @command-handler-footer
  47. * @command-handler-footer All commands support the --ConfigurationFile or -F parameter.
  48. * @command-handler-footer The parameter file is a simple INI file carrying one parameter
  49. * @command-handler-footer value per line. It accepts the same parameters as one can
  50. * @command-handler-footer use from the command line command.
  51. */
  52. class Zend_Service_WindowsAzure_CommandLine_GetAsynchronousOperation
  53. extends Zend_Service_Console_Command
  54. {
  55. /**
  56. * Get information for a specific asynchronous request.
  57. *
  58. * @command-name GetInfo
  59. * @command-description Get information for a specific asynchronous request.
  60. * @command-parameter-for $subscriptionId Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
  61. * @command-parameter-for $certificate Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
  62. * @command-parameter-for $certificatePassphrase Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
  63. * @command-parameter-for $requestId Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --RequestId|-r Required. The value returned by a call that starts an asynchronous operation to monitor.
  64. * @command-example Get information for a specific asynchronous operation:
  65. * @command-example GetInfo -sid:"<your_subscription_id>" -cert:"mycert.pem" -r:"dab87a4b70e94a36805f5af2d20fc593"
  66. */
  67. public function getInfoCommand($subscriptionId, $certificate, $certificatePassphrase, $requestId)
  68. {
  69. $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
  70. $result = $client->getOperationStatus($requestId);
  71. $this->_displayObjectInformation($result, array('ID', 'Status', 'ErrorMessage'));
  72. }
  73. /**
  74. * Wait for a specific asynchronous request to complete.
  75. *
  76. * @command-name WaitFor
  77. * @command-description Wait for a specific asynchronous request to complete.
  78. * @command-parameter-for $subscriptionId Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
  79. * @command-parameter-for $certificate Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
  80. * @command-parameter-for $certificatePassphrase Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
  81. * @command-parameter-for $requestId Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --RequestId|-r Required. The value returned by a call that starts an asynchronous operation to monitor.
  82. * @command-parameter-for $interval Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Interval|-i Optional. The interval between two status checks (in milliseconds).
  83. * @command-example Wait for a specific asynchronous operation:
  84. * @command-example WaitFor -sid:"<your_subscription_id>" -cert:"mycert.pem" -r:"dab87a4b70e94a36805f5af2d20fc593"
  85. */
  86. public function waitForCommand($subscriptionId, $certificate, $certificatePassphrase, $requestId, $interval = 250)
  87. {
  88. $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
  89. $client->waitForOperation($requestId, $interval);
  90. }
  91. }
  92. Zend_Service_Console_Command::bootstrap($_SERVER['argv']);