diff --git a/library/Zend/Service/Console/Command.php b/library/Zend/Service/Console/Command.php new file mode 100644 index 0000000000..9d65b76af5 --- /dev/null +++ b/library/Zend/Service/Console/Command.php @@ -0,0 +1,413 @@ +_handler; + } + + /** + * Sets the handler. + * + * @param array $handler + * @return Zend_Service_Console_Command + */ + public function setHandler($handler) + { + $this->_handler = $handler; + return $this; + } + + /** + * Replaces PHP's error handler + * + * @param mixed $errno + * @param mixed $errstr + * @param mixed $errfile + * @param mixed $errline + */ + public static function phpstderr($errno, $errstr, $errfile, $errline) + { + self::stderr($errno . ': Error in ' . $errfile . ':' . $errline . ' - ' . $errstr); + } + + /** + * Replaces PHP's exception handler + * + * @param Exception $exception + */ + public static function phpstdex($exception) + { + self::stderr('Error: ' . $exception->getMessage()); + } + + /** + * Writes output to STDERR, followed by a newline (optional) + * + * @param string $errorMessage + * @param string $newLine + */ + public static function stderr($errorMessage, $newLine = true) + { + if (error_reporting() === 0) { + return; + } + file_put_contents('php://stderr', $errorMessage . ($newLine ? "\r\n" : '')); + } + + /** + * Bootstrap the shell command. + * + * @param array $argv PHP argument values. + */ + public static function bootstrap($argv) + { + // Abort bootstrapping depending on the MICROSOFT_CONSOLE_COMMAND_HOST constant. + if (defined('MICROSOFT_CONSOLE_COMMAND_HOST') && strtolower(MICROSOFT_CONSOLE_COMMAND_HOST) != 'console') { + return; + } + + // Replace error handler + set_error_handler(array('Zend_Service_Console_Command', 'phpstderr')); + set_exception_handler(array('Zend_Service_Console_Command', 'phpstdex')); + + // Build the application model + $model = self::_buildModel(); + + // Find a class that corresponds to the $argv[0] script name + $requiredHandlerName = str_replace('.bat', '', str_replace('.sh', '', str_replace('.php', '', strtolower(basename($argv[0]))))); + $handler = null; + foreach ($model as $possibleHandler) { + if ($possibleHandler->handler == strtolower($requiredHandlerName)) { + $handler = $possibleHandler; + break; + } + } + if (is_null($handler)) { + self::stderr("No class found that implements handler '" . $requiredHandlerName . "'. Create a class that is named '" . $requiredHandlerName . "' and extends Zend_Service_Console_Command or is decorated with a docblock comment '@command-handler " . $requiredHandlerName . "'. Make sure it is loaded either through an autoloader or explicitly using require_once()."); + die(); + } + + // Find a method that matches the command name + $command = null; + foreach ($handler->commands as $possibleCommand) { + if (in_array(strtolower(isset($argv[1]) ? $argv[1] : ''), $possibleCommand->aliases)) { + $command = $possibleCommand; + break; + } + } + if (is_null($command)) { + $commandName = (isset($argv[1]) ? $argv[1] : ''); + self::stderr("No method found that implements command " . $commandName . ". Create a method in class '" . $handler->class . "' that is named '" . strtolower($commandName) . "Command' or is decorated with a docblock comment '@command-name " . $commandName . "'."); + die(); + } + + // Parse parameter values + $parameterValues = array(); + $missingParameterValues = array(); + $parameterInputs = array_splice($argv, 2); + foreach ($command->parameters as $parameter) { + // Default value: null + $value = null; + + // Consult value providers for value. First one wins. + foreach ($parameter->valueproviders as $valueProviderName) { + if (!class_exists($valueProviderName)) { + $valueProviderName = 'Zend_Service_Console_Command_ParameterSource_' . $valueProviderName; + } + $valueProvider = new $valueProviderName(); + + $value = $valueProvider->getValueForParameter($parameter, $parameterInputs); + if (!is_null($value)) { + break; + } + } + if (is_null($value) && $parameter->required) { + $missingParameterValues[] = $parameter->aliases[0]; + } else if (is_null($value)) { + $value = $parameter->defaultvalue; + } + + // Set value + $parameterValues[] = $value; + $argvValues[$parameter->aliases[0]] = $value; + } + + // Mising parameters? + if (count($missingParameterValues) > 0) { + self::stderr("Some parameters are missing:\r\n" . implode("\r\n", $missingParameterValues)); + die(); + } + + // Supply argv in a nice way + $parameterValues['argv'] = $parameterInputs; + + // Run the command + $className = $handler->class; + $classInstance = new $className(); + $classInstance->setHandler($handler); + call_user_func_array(array($classInstance, $command->method), $parameterValues); + + // Restore error handler + restore_exception_handler(); + restore_error_handler(); + } + + /** + * Builds the handler model. + * + * @return array + */ + protected static function _buildModel() + { + $model = array(); + + $classes = get_declared_classes(); + foreach ($classes as $class) { + $type = new ReflectionClass($class); + + $handlers = self::_findValueForDocComment('@command-handler', $type->getDocComment()); + if (count($handlers) == 0 && $type->isSubclassOf('Zend_Service_Console_Command')) { + // Fallback: if the class extends Zend_Service_Console_Command, register it as + // a command handler. + $handlers[] = $class; + } + $handlerDescriptions = self::_findValueForDocComment('@command-handler-description', $type->getDocComment()); + $handlerHeaders = self::_findValueForDocComment('@command-handler-header', $type->getDocComment()); + $handlerFooters = self::_findValueForDocComment('@command-handler-footer', $type->getDocComment()); + + for ($hi = 0; $hi < count($handlers); $hi++) { + $handler = $handlers[$hi]; + $handlerDescription = isset($handlerDescriptions[$hi]) ? $handlerDescriptions[$hi] : isset($handlerDescriptions[0]) ? $handlerDescriptions[0] : ''; + $handlerDescription = str_replace('\r\n', "\r\n", $handlerDescription); + $handlerDescription = str_replace('\n', "\n", $handlerDescription); + + $handlerModel = (object)array( + 'handler' => strtolower($handler), + 'description' => $handlerDescription, + 'headers' => $handlerHeaders, + 'footers' => $handlerFooters, + 'class' => $class, + 'commands' => array() + ); + + $methods = $type->getMethods(); + foreach ($methods as $method) { + $commands = self::_findValueForDocComment('@command-name', $method->getDocComment()); + if (substr($method->getName(), -7) == 'Command' && !in_array(substr($method->getName(), 0, -7), $commands)) { + // Fallback: if the method is named Command, + // register it as a command. + $commands[] = substr($method->getName(), 0, -7); + } + for ($x = 0; $x < count($commands); $x++) { + $commands[$x] = strtolower($commands[$x]); + } + $commands = array_unique($commands); + $commandDescriptions = self::_findValueForDocComment('@command-description', $method->getDocComment()); + $commandExamples = self::_findValueForDocComment('@command-example', $method->getDocComment()); + + if (count($commands) > 0) { + $command = $commands[0]; + $commandDescription = isset($commandDescriptions[0]) ? $commandDescriptions[0] : ''; + + $commandModel = (object)array( + 'command' => $command, + 'aliases' => $commands, + 'description' => $commandDescription, + 'examples' => $commandExamples, + 'class' => $class, + 'method' => $method->getName(), + 'parameters' => array() + ); + + $parameters = $method->getParameters(); + $parametersFor = self::_findValueForDocComment('@command-parameter-for', $method->getDocComment()); + for ($pi = 0; $pi < count($parameters); $pi++) { + // Initialize + $parameter = $parameters[$pi]; + $parameterFor = null; + $parameterForDefaultValue = null; + + // Is it a "catch-all" parameter? + if ($parameter->getName() == 'argv') { + continue; + } + + // Find the $parametersFor with the same name defined + foreach ($parametersFor as $possibleParameterFor) { + $possibleParameterFor = explode(' ', $possibleParameterFor, 4); + if ($possibleParameterFor[0] == '$' . $parameter->getName()) { + $parameterFor = $possibleParameterFor; + break; + } + } + if (is_null($parameterFor)) { + die('@command-parameter-for missing for parameter $' . $parameter->getName()); + } + + if (is_null($parameterForDefaultValue) && $parameter->isOptional()) { + $parameterForDefaultValue = $parameter->getDefaultValue(); + } + + $parameterModel = (object)array( + 'name' => '$' . $parameter->getName(), + 'defaultvalue' => $parameterForDefaultValue, + 'valueproviders' => explode('|', $parameterFor[1]), + 'aliases' => explode('|', $parameterFor[2]), + 'description' => (isset($parameterFor[3]) ? $parameterFor[3] : ''), + 'required' => (isset($parameterFor[3]) ? strpos(strtolower($parameterFor[3]), 'required') !== false && strpos(strtolower($parameterFor[3]), 'required if') === false : false), + ); + + // Add to model + $commandModel->parameters[] = $parameterModel; + } + + // Add to model + $handlerModel->commands[] = $commandModel; + } + } + + // Add to model + $model[] = $handlerModel; + } + } + + return $model; + } + + /** + * Finds the value for a specific docComment. + * + * @param string $docCommentName Comment name + * @param unknown_type $docComment Comment object + * @return array + */ + protected static function _findValueForDocComment($docCommentName, $docComment) + { + $returnValue = array(); + + $commentLines = explode("\n", $docComment); + foreach ($commentLines as $commentLine) { + if (strpos($commentLine, $docCommentName . ' ') !== false) { + $returnValue[] = trim(substr($commentLine, strpos($commentLine, $docCommentName) + strlen($docCommentName) + 1)); + } + } + + return $returnValue; + } + + /** + * Display information on an object + * + * @param object $object Object + * @param array $propertiesToDump Property names to display + */ + protected function _displayObjectInformation($object, $propertiesToDump = array()) + { + foreach ($propertiesToDump as $property) { + printf('%-16s: %s' . "\r\n", $property, $object->$property); + } + printf("\r\n"); + } + + /** + * Displays the help information. + * + * @command-name + * @command-name -h + * @command-name -help + * @command-description Displays the current help information. + */ + public function helpCommand() { + $handler = $this->getHandler(); + $newline = "\r\n"; + + if (count($handler->headers) > 0) { + foreach ($handler->headers as $header) { + printf('%s%s', $header, $newline); + } + printf($newline); + } + printf('%s%s', $handler->description, $newline); + printf($newline); + printf('Available commands:%s', $newline); + foreach ($handler->commands as $command) { + $description = str_split($command->description, 50); + printf(' %-25s %s%s', implode(', ', $command->aliases), $description[0], $newline); + for ($di = 1; $di < count($description); $di++) { + printf(' %-25s %s%s', '', $description[$di], $newline); + } + printf($newline); + + if (count($command->parameters) > 0) { + foreach ($command->parameters as $parameter) { + $description = str_split($parameter->description, 50); + printf(' %-23s %s%s', implode(', ', $parameter->aliases), $description[0], $newline); + for ($di = 1; $di < count($description); $di++) { + printf(' %-23s %s%s', '', $description[$di], $newline); + } + printf($newline); + } + } + printf($newline); + + if (count($command->examples) > 0) { + printf(' Example usage:%s', $newline); + foreach ($command->examples as $example) { + printf(' %s%s', $example, $newline); + } + printf($newline); + } + } + + if (count($handler->footers) > 0) { + printf($newline); + foreach ($handler->footers as $footer) { + printf('%s%s', $footer, $newline); + } + printf($newline); + } + } +} diff --git a/library/Zend/Service/Console/Command/ParameterSource/Argv.php b/library/Zend/Service/Console/Command/ParameterSource/Argv.php new file mode 100644 index 0000000000..da4da706aa --- /dev/null +++ b/library/Zend/Service/Console/Command/ParameterSource/Argv.php @@ -0,0 +1,71 @@ +aliases)) { + $parameterValue = isset($parameterInput[1]) ? $parameterInput[1] : true; + break; + } + } + if (strtolower($parameterValue) == 'true') { + $parameterValue = true; + } else if (strtolower($parameterValue) == 'false') { + $parameterValue = false; + } + + // Done! + return $parameterValue; + } +} diff --git a/library/Zend/Service/Console/Command/ParameterSource/ConfigFile.php b/library/Zend/Service/Console/Command/ParameterSource/ConfigFile.php new file mode 100644 index 0000000000..1efd4d23fc --- /dev/null +++ b/library/Zend/Service/Console/Command/ParameterSource/ConfigFile.php @@ -0,0 +1,104 @@ +aliases as $alias) { + if (array_key_exists($alias, $iniValues)) { + $parameterValue = $iniValues[$alias]; break; + } else if (array_key_exists(strtolower($alias), $iniValues)) { + $parameterValue = $iniValues[strtolower($alias)]; break; + } else if (array_key_exists(str_replace('-', '', $alias), $iniValues)) { + $parameterValue = $iniValues[str_replace('-', '', $alias)]; break; + } else if (array_key_exists(strtolower(str_replace('-', '', $alias)), $iniValues)) { + $parameterValue = $iniValues[strtolower(str_replace('-', '', $alias))]; break; + } + } + + if (strtolower($parameterValue) == 'true') { + $parameterValue = true; + } else if (strtolower($parameterValue) == 'false') { + $parameterValue = false; + } + + // Done! + return $parameterValue; + } +} diff --git a/library/Zend/Service/Console/Command/ParameterSource/Env.php b/library/Zend/Service/Console/Command/ParameterSource/Env.php new file mode 100644 index 0000000000..48d4fb60cb --- /dev/null +++ b/library/Zend/Service/Console/Command/ParameterSource/Env.php @@ -0,0 +1,75 @@ +aliases as $alias) { + while (strpos($alias, '-') !== false) { + $alias = substr($alias, 1); + } + $value = getenv($alias); + + if (!is_null($value) && $value !== false) { + $parameterValue = $value; + break; + } + } + + if (strtolower($parameterValue) == 'true') { + $parameterValue = true; + } else if (strtolower($parameterValue) == 'false') { + $parameterValue = false; + } + + // Done! + return $parameterValue; + } +} diff --git a/library/Zend/Service/Console/Command/ParameterSource/ParameterSourceInterface.php b/library/Zend/Service/Console/Command/ParameterSource/ParameterSourceInterface.php new file mode 100644 index 0000000000..82d6c48f6d --- /dev/null +++ b/library/Zend/Service/Console/Command/ParameterSource/ParameterSourceInterface.php @@ -0,0 +1,43 @@ +aliases[0] . ": "); + /*if ($parameter->description != '' && !is_null($parameter->description)) { + fwrite(STDOUT, $parameter->description . ".\r\n"); + }*/ + + while (is_null($parameterValue) || $parameterValue == '') { + $parameterValue = trim(fgets(STDIN)); + } + + // Done! + return $parameterValue; + } +} diff --git a/library/Zend/Service/Console/Command/ParameterSource/StdIn.php b/library/Zend/Service/Console/Command/ParameterSource/StdIn.php new file mode 100644 index 0000000000..e1d023ef26 --- /dev/null +++ b/library/Zend/Service/Console/Command/ParameterSource/StdIn.php @@ -0,0 +1,81 @@ +_displayObjectInformation($object, array('Thumbprint', 'CertificateUrl', 'ThumbprintAlgorithm')); } } - + /** * Add a certificate for a specified hosted service in a specified subscription. - * + * * @command-name Add * @command-description Add a certificate for a specified hosted service in a specified subscription. * @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. @@ -95,10 +105,10 @@ public function addCertificateCommand($subscriptionId, $certificate, $certificat } echo $client->getLastRequestId(); } - + /** * Gets a certificate from a specified hosted service in a specified subscription. - * + * * @command-name Get * @command-description Gets a certificate from a specified hosted service in a specified subscription. * @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. @@ -117,10 +127,10 @@ public function getCertificateCommand($subscriptionId, $certificate, $certificat $this->_displayObjectInformation($result, array('Thumbprint', 'CertificateUrl', 'ThumbprintAlgorithm')); } - + /** * Gets a certificate property from a specified hosted service in a specified subscription. - * + * * @command-name GetProperty * @command-description Gets a certificate property from a specified hosted service in a specified subscription. * @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. @@ -140,10 +150,10 @@ public function getCertificatePropertyCommand($subscriptionId, $certificate, $ce printf("%s\r\n", $result->$property); } - + /** * Deletes a certificate from a specified hosted service in a specified subscription. - * + * * @command-name Delete * @command-description Deletes a certificate from a specified hosted service in a specified subscription. * @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. diff --git a/library/Zend/Service/WindowsAzure/CommandLine/Deployment.php b/library/Zend/Service/WindowsAzure/CommandLine/Deployment.php index 69312dea63..356cef72ca 100644 --- a/library/Zend/Service/WindowsAzure/CommandLine/Deployment.php +++ b/library/Zend/Service/WindowsAzure/CommandLine/Deployment.php @@ -25,23 +25,28 @@ */ require_once 'Zend/Service/Console/Command.php'; +/** + * @see Zend_Service_WindowsAzure_Management_Client + */ +require_once 'Zend/Service/WindowsAzure/Management/Client.php'; + /** * Deployment commands - * + * * @category Zend * @package Zend_Service_WindowsAzure_CommandLine * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * + * * @command-handler deployment * @command-handler-description Windows Azure Deployment commands * @command-handler-header Windows Azure SDK for PHP * @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com) - * @command-handler-footer Note: Parameters that are common across all commands can be stored + * @command-handler-footer Note: Parameters that are common across all commands can be stored * @command-handler-footer in two dedicated environment variables. * @command-handler-footer - SubscriptionId: The Windows Azure Subscription Id to operate on. * @command-handler-footer - Certificate The Windows Azure .cer Management Certificate. - * @command-handler-footer + * @command-handler-footer * @command-handler-footer All commands support the --ConfigurationFile or -F parameter. * @command-handler-footer The parameter file is a simple INI file carrying one parameter * @command-handler-footer value per line. It accepts the same parameters as one can @@ -49,10 +54,10 @@ */ class Zend_Service_WindowsAzure_CommandLine_Deployment extends Zend_Service_Console_Command -{ +{ /** * Creates a deployment from a remote package file and service configuration. - * + * * @command-name CreateFromStorage * @command-description Creates a deployment from a remote package file and service configuration. * @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. @@ -92,10 +97,10 @@ public function createFromStorageCommand($subscriptionId, $certificate, $certifi } echo $client->getLastRequestId(); } - + /** * Creates a deployment from a local package file and service configuration. - * + * * @command-name CreateFromLocal * @command-description Creates a deployment from a local package file and service configuration. * @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. @@ -134,21 +139,21 @@ public function createFromLocalCommand($subscriptionId, $certificate, $certifica $blobClient->createContainerIfNotExists('phpazuredeployments'); $blobClient->putBlob('phpazuredeployments', basename($packageLocation), $packageLocation); $package = $blobClient->getBlobInstance('phpazuredeployments', basename($packageLocation)); - + $client->createDeployment($serviceName, $deploymentSlot, $deploymentName, $label, $package->Url, $serviceConfigurationLocation, $startImmediately, $warningsAsErrors); $client->waitForOperation(); $blobClient->deleteBlob('phpazuredeployments', basename($packageLocation)); - + if ($waitForOperation) { $client->waitForOperation(); } echo $client->getLastRequestId(); } - + /** * Get deployment properties. - * + * * @command-name GetProperties * @command-description Get deployment properties. * @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. @@ -163,12 +168,12 @@ public function createFromLocalCommand($subscriptionId, $certificate, $certifica public function getPropertiesCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName) { $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); - + $result = null; - + if (!is_null($deploymentSlot) && $deploymentSlot != '') { $deploymentSlot = strtolower($deploymentSlot); - + $result = $client->getDeploymentBySlot($serviceName, $deploymentSlot); } else { $result = $client->getDeploymentByDeploymentId($serviceName, $deploymentName); @@ -176,10 +181,10 @@ public function getPropertiesCommand($subscriptionId, $certificate, $certificate $this->_displayObjectInformation($result, array('Name', 'DeploymentSlot', 'Label', 'Url', 'Status')); } - + /** * Get hosted service account property. - * + * * @command-name GetProperty * @command-description Get deployment property. * @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. @@ -196,12 +201,12 @@ public function getPropertiesCommand($subscriptionId, $certificate, $certificate public function getPropertyCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName, $property) { $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); - + $result = null; - + if (!is_null($deploymentSlot) && $deploymentSlot != '') { $deploymentSlot = strtolower($deploymentSlot); - + $result = $client->getDeploymentBySlot($serviceName, $deploymentSlot); } else { $result = $client->getDeploymentByDeploymentId($serviceName, $deploymentName); @@ -209,10 +214,10 @@ public function getPropertyCommand($subscriptionId, $certificate, $certificatePa printf("%s\r\n", $result->$property); } - + /** * Swap deployment slots (perform VIP swap). - * + * * @command-name Swap * @command-description Swap deployment slots (perform VIP swap). * @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. @@ -226,13 +231,13 @@ public function getPropertyCommand($subscriptionId, $certificate, $certificatePa public function swapCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $waitForOperation = false) { $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); - + $productionDeploymentName = null; try { $productionDeploymentName = $client->getDeploymentBySlot($serviceName, 'production')->Name; } catch (Exception $ex) {} - + $stagingDeploymentName = null; try { $stagingDeploymentName = $client->getDeploymentBySlot($serviceName, 'staging')->Name; } catch (Exception $ex) {} - + if (is_null($productionDeploymentName)) { $productionDeploymentName = $stagingDeploymentName; } @@ -242,16 +247,16 @@ public function swapCommand($subscriptionId, $certificate, $certificatePassphras } $client->swapDeployment($serviceName, $productionDeploymentName, $stagingDeploymentName); - + if ($waitForOperation) { $client->waitForOperation(); } echo $client->getLastRequestId(); } - + /** * Deletes a deployment. - * + * * @command-name Delete * @command-description Deletes a deployment. * @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. @@ -270,21 +275,21 @@ public function deleteCommand($subscriptionId, $certificate, $certificatePassphr if (!is_null($deploymentSlot) && $deploymentSlot != '') { $deploymentSlot = strtolower($deploymentSlot); - + $client->deleteDeploymentBySlot($serviceName, $deploymentSlot); } else { $client->deleteDeploymentByDeploymentId($serviceName, $deploymentName); } - + if ($waitForOperation) { $client->waitForOperation(); } echo $client->getLastRequestId(); } - + /** * Updates a deployment's configuration. - * + * * @command-name UpdateConfig * @command-description Updates a deployment's configuration. * @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. @@ -306,21 +311,21 @@ public function updateConfigurationCommand($subscriptionId, $certificate, $certi if (!is_null($deploymentSlot) && $deploymentSlot != '') { $deploymentSlot = strtolower($deploymentSlot); - + $client->configureDeploymentBySlot($serviceName, $deploymentSlot, $serviceConfigurationLocation); } else { $client->configureDeploymentByDeploymentId($serviceName, $deploymentName, $serviceConfigurationLocation); } - + if ($waitForOperation) { $client->waitForOperation(); } echo $client->getLastRequestId(); } - + /** * Updates a deployment's status. - * + * * @command-name UpdateStatus * @command-description Updates a deployment's status. * @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. @@ -342,21 +347,21 @@ public function updateStatusCommand($subscriptionId, $certificate, $certificateP if (!is_null($deploymentSlot) && $deploymentSlot != '') { $deploymentSlot = strtolower($deploymentSlot); - + $client->updateDeploymentStatusBySlot($serviceName, $deploymentSlot, $newStatus); } else { $client->updateDeploymentStatusByDeploymentId($serviceName, $deploymentName, $newStatus); } - + if ($waitForOperation) { $client->waitForOperation(); } echo $client->getLastRequestId(); } - + /** * Updates the number of instances. - * + * * @command-name EditInstanceNumber * @command-description Updates the number of instances. * @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. @@ -379,21 +384,21 @@ public function editInstanceNumberCommand($subscriptionId, $certificate, $certif if (!is_null($deploymentSlot) && $deploymentSlot != '') { $deploymentSlot = strtolower($deploymentSlot); - + $client->setInstanceCountBySlot($serviceName, $deploymentSlot, $roleName, $newInstanceNumber); } else { $client->setInstanceCountByDeploymentId($serviceName, $deploymentName, $roleName, $newInstanceNumber); } - + if ($waitForOperation) { $client->waitForOperation(); } echo $client->getLastRequestId(); } - + /** * Reboots a role instance. - * + * * @command-name RebootInstance * @command-description Reboots a role instance. * @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. @@ -415,21 +420,21 @@ public function rebootInstanceCommand($subscriptionId, $certificate, $certificat if (!is_null($deploymentSlot) && $deploymentSlot != '') { $deploymentSlot = strtolower($deploymentSlot); - + $client->rebootRoleInstanceBySlot($serviceName, $deploymentSlot, $instanceName); } else { $client->rebootRoleInstanceByDeploymentId($serviceName, $deploymentName, $instanceName); } - + if ($waitForOperation) { $client->waitForOperation(); } echo $client->getLastRequestId(); } - + /** * Reimages a role instance. - * + * * @command-name ReimageInstance * @command-description Reimages a role instance. * @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. @@ -451,21 +456,21 @@ public function reimageInstanceCommand($subscriptionId, $certificate, $certifica if (!is_null($deploymentSlot) && $deploymentSlot != '') { $deploymentSlot = strtolower($deploymentSlot); - + $client->reimageRoleInstanceBySlot($serviceName, $deploymentSlot, $instanceName); } else { $client->reimageRoleInstanceByDeploymentId($serviceName, $deploymentName, $instanceName); } - + if ($waitForOperation) { $client->waitForOperation(); } echo $client->getLastRequestId(); } - + /** * Upgrades a deployment from a remote package file and service configuration. - * + * * @command-name UpgradeFromStorage * @command-description Upgrades a deployment from a remote package file and service configuration. * @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. @@ -482,26 +487,26 @@ public function reimageInstanceCommand($subscriptionId, $certificate, $certifica * @command-parameter-for $waitForOperation Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete? */ public function upgradeFromStorageCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName, $label, $packageUrl, $serviceConfigurationLocation, $mode = 'auto', $roleName = null, $waitForOperation = false) - { + { $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); if (!is_null($deploymentSlot) && $deploymentSlot != '') { $deploymentSlot = strtolower($deploymentSlot); - + $client->upgradeDeploymentBySlot($serviceName, $deploymentSlot, $label, $packageUrl, $serviceConfigurationLocation, $mode, $roleName); } else { $client->upgradeDeploymentByDeploymentId($serviceName, $deploymentName, $label, $packageUrl, $serviceConfigurationLocation, $mode, $roleName); } - + if ($waitForOperation) { $client->waitForOperation(); } echo $client->getLastRequestId(); } - + /** * Upgrades a deployment from a local package file and service configuration. - * + * * @command-name UpgradeFromLocal * @command-description Upgrades a deployment from a local package file and service configuration. * @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. @@ -521,32 +526,32 @@ public function upgradeFromStorageCommand($subscriptionId, $certificate, $certif public function upgradeFromLocalCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName, $label, $packageLocation, $serviceConfigurationLocation, $storageAccount, $mode = 'auto', $roleName = null, $waitForOperation = false) { $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); - + $blobClient = $client->createBlobClientForService($storageAccount); $blobClient->createContainerIfNotExists('phpazuredeployments'); $blobClient->putBlob('phpazuredeployments', basename($packageLocation), $packageLocation); $package = $blobClient->getBlobInstance('phpazuredeployments', basename($packageLocation)); - + if (!is_null($deploymentSlot) && $deploymentSlot != '') { $deploymentSlot = strtolower($deploymentSlot); - + $client->upgradeDeploymentBySlot($serviceName, $deploymentSlot, $label, $package->Url, $serviceConfigurationLocation, $mode, $roleName); } else { $client->upgradeDeploymentByDeploymentId($serviceName, $deploymentName, $label, $package->Url, $serviceConfigurationLocation, $mode, $roleName); } - + $client->waitForOperation(); $blobClient->deleteBlob('phpazuredeployments', basename($packageLocation)); - + if ($waitForOperation) { $client->waitForOperation(); } echo $client->getLastRequestId(); } - + /** * Walks upgrade domains. - * + * * @command-name WalkUpgradeDomains * @command-description Walks upgrade domains. * @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. @@ -561,15 +566,15 @@ public function upgradeFromLocalCommand($subscriptionId, $certificate, $certific public function walkUpgradeDomainsCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName, $upgradeDomain, $waitForOperation = false) { $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); - + if (!is_null($deploymentSlot) && $deploymentSlot != '') { $deploymentSlot = strtolower($deploymentSlot); - + $client->walkUpgradeDomainBySlot($serviceName, $deploymentSlot, $upgradeDomain); } else { $client->walkUpgradeDomainByDeploymentId($serviceName, $deploymentName, $upgradeDomain); } - + if ($waitForOperation) { $client->waitForOperation(); } diff --git a/library/Zend/Service/WindowsAzure/CommandLine/GetAsynchronousOperation.php b/library/Zend/Service/WindowsAzure/CommandLine/GetAsynchronousOperation.php index ac6b624775..551ca69df2 100644 --- a/library/Zend/Service/WindowsAzure/CommandLine/GetAsynchronousOperation.php +++ b/library/Zend/Service/WindowsAzure/CommandLine/GetAsynchronousOperation.php @@ -20,23 +20,33 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ +/** +* @see Zend_Service_Console_Command +*/ +require_once 'Zend/Service/Console/Command.php'; + +/** +* @see Zend_Service_WindowsAzure_Management_Client +*/ +require_once 'Zend/Service/WindowsAzure/Management/Client.php'; + /** * Asynchronous Operation commands - * + * * @category Zend * @package Zend_Service_WindowsAzure_CommandLine * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * + * * @command-handler getasynchronousoperation * @command-handler-description Windows Azure Asynchronous Operation commands * @command-handler-header Windows Azure SDK for PHP * @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com) - * @command-handler-footer Note: Parameters that are common across all commands can be stored + * @command-handler-footer Note: Parameters that are common across all commands can be stored * @command-handler-footer in two dedicated environment variables. * @command-handler-footer - SubscriptionId: The Windows Azure Subscription Id to operate on. * @command-handler-footer - Certificate The Windows Azure .cer Management Certificate. - * @command-handler-footer + * @command-handler-footer * @command-handler-footer All commands support the --ConfigurationFile or -F parameter. * @command-handler-footer The parameter file is a simple INI file carrying one parameter * @command-handler-footer value per line. It accepts the same parameters as one can @@ -44,10 +54,10 @@ */ class Zend_Service_WindowsAzure_CommandLine_GetAsynchronousOperation extends Zend_Service_Console_Command -{ +{ /** * Get information for a specific asynchronous request. - * + * * @command-name GetInfo * @command-description Get information for a specific asynchronous request. * @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. @@ -64,10 +74,10 @@ public function getInfoCommand($subscriptionId, $certificate, $certificatePassph $this->_displayObjectInformation($result, array('ID', 'Status', 'ErrorMessage')); } - + /** * Wait for a specific asynchronous request to complete. - * + * * @command-name WaitFor * @command-description Wait for a specific asynchronous request to complete. * @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. diff --git a/library/Zend/Service/WindowsAzure/CommandLine/Package.php b/library/Zend/Service/WindowsAzure/CommandLine/Package.php index 8d533030bf..2739d0b8e3 100644 --- a/library/Zend/Service/WindowsAzure/CommandLine/Package.php +++ b/library/Zend/Service/WindowsAzure/CommandLine/Package.php @@ -23,19 +23,24 @@ /** @see Zend_Xml_Security */ require_once 'Zend/Xml/Security.php'; +/** +* @see Zend_Service_Console_Command +*/ +require_once 'Zend/Service/Console/Command.php'; + /** * Package commands - * + * * @category Zend * @package Zend_Service_WindowsAzure_CommandLine * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * + * * @command-handler package * @command-handler-description Windows Azure Package commands * @command-handler-header Windows Azure SDK for PHP * @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com) - * @command-handler-footer + * @command-handler-footer * @command-handler-footer All commands support the --ConfigurationFile or -F parameter. * @command-handler-footer The parameter file is a simple INI file carrying one parameter * @command-handler-footer value per line. It accepts the same parameters as one can @@ -43,15 +48,15 @@ */ class Zend_Service_WindowsAzure_CommandLine_Package extends Zend_Service_Console_Command -{ +{ /** * Scaffolds a Windows Azure project structure which can be customized before packaging. - * + * * @command-name Scaffold * @command-description Scaffolds a Windows Azure project structure which can be customized before packaging. - * + * * @command-parameter-for $path Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Path|-p Required. The path to create the Windows Azure project structure. - * @command-parameter-for $scaffolder Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --Scaffolder|-s Optional. The path to the scaffolder to use. Defaults to Scaffolders/DefaultScaffolder.phar + * @command-parameter-for $scaffolder Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --Scaffolder|-s Optional. The path to the scaffolder to use. Defaults to Scaffolders/DefaultScaffolder.phar */ public function scaffoldCommand($path, $scaffolder, $argv) { @@ -60,13 +65,13 @@ public function scaffoldCommand($path, $scaffolder, $argv) $scaffolder = dirname(__FILE__) . '/Scaffolders/DefaultScaffolder.phar'; } $scaffolder = realpath($scaffolder); - + // Verify scaffolder if (!is_file($scaffolder)) { require_once 'Zend/Service/Console/Exception.php'; throw new Zend_Service_Console_Exception('Could not locate the given scaffolder: ' . $scaffolder); } - + // Include scaffolder $archive = new Phar($scaffolder); include $scaffolder; @@ -74,7 +79,7 @@ public function scaffoldCommand($path, $scaffolder, $argv) require_once 'Zend/Service/Console/Exception.php'; throw new Zend_Service_Console_Exception('Could not locate a class named Scaffolder in the given scaffolder: ' . $scaffolder . '. Make sure the scaffolder package contains a file named index.php and contains a class named Scaffolder.'); } - + // Cleanup $argv $options = array(); foreach ($argv as $arg) { @@ -84,22 +89,22 @@ public function scaffoldCommand($path, $scaffolder, $argv) } $options[$key] = $value; } - + // Run scaffolder $scaffolderInstance = new Scaffolder(); $scaffolderInstance->invoke($archive, $path, $options); } - + /** * Packages a Windows Azure project structure. - * + * * @command-name Create * @command-description Packages a Windows Azure project structure. - * + * * @command-parameter-for $path Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Path|-p Required. The path to package. * @command-parameter-for $runDevFabric Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --RunDevFabric|-dev Required. Switch. Run and deploy to the Windows Azure development fabric. - * @command-parameter-for $outputPath Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --OutputPath|-out Optional. The output path for the resulting package. + * @command-parameter-for $outputPath Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --OutputPath|-out Optional. The output path for the resulting package. */ public function createPackageCommand($path, $runDevFabric, $outputPath) { @@ -120,7 +125,7 @@ public function createPackageCommand($path, $runDevFabric, $outputPath) } $cspack = '"' . $windowsAzureSdkFolderCandidates[0] . '\cspack.exe' . '"'; $csrun = '"' . $windowsAzureSdkFolderCandidates[0] . '\csrun.exe' . '"'; - + // Open the ServiceDefinition.csdef file and check for role paths $serviceDefinitionFile = $path . '/ServiceDefinition.csdef'; if (!file_exists($serviceDefinitionFile)) { @@ -143,7 +148,7 @@ public function createPackageCommand($path, $runDevFabric, $outputPath) $xmlRoles = array_merge($xmlRoles, array($serviceDefinition->WorkerRole)); } } - + // Build '/role:' command parameter $roleArgs = array(); foreach ($xmlRoles as $xmlRole) { @@ -151,7 +156,7 @@ public function createPackageCommand($path, $runDevFabric, $outputPath) $roleArgs[] = '/role:' . $xmlRole["name"] . ';' . realpath($path . '/' . $xmlRole["name"]); } } - + // Build command $command = $cspack; $args = array( @@ -163,14 +168,14 @@ public function createPackageCommand($path, $runDevFabric, $outputPath) $args[] = '/copyOnly'; } passthru($command . ' ' . implode(' ', $args)); - + // Can we copy a configuration file? $serviceConfigurationFile = $path . '/ServiceConfiguration.cscfg'; $serviceConfigurationFileOut = $outputPath . '/ServiceConfiguration.cscfg'; if (file_exists($serviceConfigurationFile) && !file_exists($serviceConfigurationFileOut)) { copy($serviceConfigurationFile, $serviceConfigurationFileOut); } - + // Do we have to start the development fabric? if ($runDevFabric) { passthru($csrun . ' /devstore:start /devfabric:start'); @@ -178,13 +183,13 @@ public function createPackageCommand($path, $runDevFabric, $outputPath) passthru($csrun . ' /run:"' . $packageOut . ';' . $serviceConfigurationFileOut . '" /launchBrowser'); } } - + /** * Creates a scaffolder from a given path. - * + * * @command-name CreateScaffolder * @command-description Creates a scaffolder from a given path. - * + * * @command-parameter-for $rootPath Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Path|-p Required. The path to package into a scaffolder. * @command-parameter-for $scaffolderFile Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --OutFile|-out Required. The filename of the scaffolder. */ diff --git a/library/Zend/Service/WindowsAzure/CommandLine/Service.php b/library/Zend/Service/WindowsAzure/CommandLine/Service.php index 04212b18d9..a2cec96a11 100644 --- a/library/Zend/Service/WindowsAzure/CommandLine/Service.php +++ b/library/Zend/Service/WindowsAzure/CommandLine/Service.php @@ -20,24 +20,33 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ +/** +* @see Zend_Service_Console_Command +*/ +require_once 'Zend/Service/Console/Command.php'; + +/** +* @see Zend_Service_WindowsAzure_Management_Client +*/ +require_once 'Zend/Service/WindowsAzure/Management/Client.php'; /** * Service commands - * + * * @category Zend * @package Zend_Service_WindowsAzure_CommandLine * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * + * * @command-handler service * @command-handler-description Windows Azure Service commands * @command-handler-header Windows Azure SDK for PHP * @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com) - * @command-handler-footer Note: Parameters that are common across all commands can be stored + * @command-handler-footer Note: Parameters that are common across all commands can be stored * @command-handler-footer in two dedicated environment variables. * @command-handler-footer - SubscriptionId: The Windows Azure Subscription Id to operate on. * @command-handler-footer - Certificate The Windows Azure .cer Management Certificate. - * @command-handler-footer + * @command-handler-footer * @command-handler-footer All commands support the --ConfigurationFile or -F parameter. * @command-handler-footer The parameter file is a simple INI file carrying one parameter * @command-handler-footer value per line. It accepts the same parameters as one can @@ -45,10 +54,10 @@ */ class Zend_Service_WindowsAzure_CommandLine_Service extends Zend_Service_Console_Command -{ +{ /** * List hosted service accounts for a specified subscription. - * + * * @command-name List * @command-description List hosted service accounts for a specified subscription. * @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. @@ -69,10 +78,10 @@ public function listCommand($subscriptionId, $certificate, $certificatePassphras $this->_displayObjectInformation($object, array('ServiceName', 'Url')); } } - + /** * Get hosted service account properties. - * + * * @command-name GetProperties * @command-description Get hosted service account properties. * @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. @@ -87,13 +96,13 @@ public function getPropertiesCommand($subscriptionId, $certificate, $certificate { $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); $result = $client->getHostedServiceProperties($serviceName); - + $this->_displayObjectInformation($result, array('ServiceName', 'Label', 'AffinityGroup', 'Location')); } - + /** * Get hosted service account property. - * + * * @command-name GetProperty * @command-description Get storage account property. * @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. @@ -109,13 +118,13 @@ public function getPropertyCommand($subscriptionId, $certificate, $certificatePa { $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); $result = $client->getHostedServiceProperties($serviceName); - + printf("%s\r\n", $result->$property); } - + /** * Create hosted service account. - * + * * @command-name Create * @command-description Create hosted service account. * @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. @@ -139,10 +148,10 @@ public function createCommand($subscriptionId, $certificate, $certificatePassphr } echo $client->getLastRequestId(); } - + /** * Update hosted service account. - * + * * @command-name Update * @command-description Update hosted service account. * @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. @@ -164,10 +173,10 @@ public function updateCommand($subscriptionId, $certificate, $certificatePassphr } echo $client->getLastRequestId(); } - + /** * Delete hosted service account. - * + * * @command-name Delete * @command-description Delete hosted service account. * @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. diff --git a/library/Zend/Service/WindowsAzure/CommandLine/Storage.php b/library/Zend/Service/WindowsAzure/CommandLine/Storage.php index 2bb14f54e3..9d17b2a580 100644 --- a/library/Zend/Service/WindowsAzure/CommandLine/Storage.php +++ b/library/Zend/Service/WindowsAzure/CommandLine/Storage.php @@ -20,24 +20,33 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ +/** +* @see Zend_Service_Console_Command +*/ +require_once 'Zend/Service/Console/Command.php'; + +/** +* @see Zend_Service_WindowsAzure_Management_Client +*/ +require_once 'Zend/Service/WindowsAzure/Management/Client.php'; /** * Storage commands - * + * * @category Zend * @package Zend_Service_WindowsAzure_CommandLine * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * + * * @command-handler storage * @command-handler-description Windows Azure Storage commands * @command-handler-header Windows Azure SDK for PHP * @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com) - * @command-handler-footer Note: Parameters that are common across all commands can be stored + * @command-handler-footer Note: Parameters that are common across all commands can be stored * @command-handler-footer in two dedicated environment variables. * @command-handler-footer - SubscriptionId: The Windows Azure Subscription Id to operate on. * @command-handler-footer - Certificate The Windows Azure .cer Management Certificate. - * @command-handler-footer + * @command-handler-footer * @command-handler-footer All commands support the --ConfigurationFile or -F parameter. * @command-handler-footer The parameter file is a simple INI file carrying one parameter * @command-handler-footer value per line. It accepts the same parameters as one can @@ -45,10 +54,10 @@ */ class Zend_Service_WindowsAzure_CommandLine_Storage extends Zend_Service_Console_Command -{ +{ /** * List storage accounts for a specified subscription. - * + * * @command-name ListAccounts * @command-description List storage accounts for a specified subscription. * @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. @@ -69,10 +78,10 @@ public function listAccountsCommand($subscriptionId, $certificate, $certificateP $this->_displayObjectInformation($object, array('ServiceName', 'Url')); } } - + /** * Get storage account properties. - * + * * @command-name GetProperties * @command-description Get storage account properties. * @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. @@ -87,13 +96,13 @@ public function getPropertiesCommand($subscriptionId, $certificate, $certificate { $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); $result = $client->getStorageAccountProperties($accountName); - + $this->_displayObjectInformation($result, array('ServiceName', 'Label', 'AffinityGroup', 'Location')); } - + /** * Get storage account property. - * + * * @command-name GetProperty * @command-description Get storage account property. * @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. @@ -109,13 +118,13 @@ public function getPropertyCommand($subscriptionId, $certificate, $certificatePa { $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); $result = $client->getStorageAccountProperties($accountName); - + printf("%s\r\n", $result->$property); } - + /** * Get storage account keys. - * + * * @command-name GetKeys * @command-description Get storage account keys. * @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. @@ -130,14 +139,14 @@ public function getKeysCommand($subscriptionId, $certificate, $certificatePassph { $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); $result = $client->getStorageAccountKeys($accountName); - + $this->_displayObjectInformation((object)array('Key' => 'primary', 'Value' => $result[0]), array('Key', 'Value')); $this->_displayObjectInformation((object)array('Key' => 'secondary', 'Value' => $result[1]), array('Key', 'Value')); } - + /** * Get storage account key. - * + * * @command-name GetKey * @command-description Get storage account key. * @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. @@ -153,16 +162,16 @@ public function getKeyCommand($subscriptionId, $certificate, $certificatePassphr { $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); $result = $client->getStorageAccountKeys($accountName); - + if (strtolower($key) == 'secondary') { printf("%s\r\n", $result[1]); } printf("%s\r\n", $result[0]); } - + /** * Regenerate storage account keys. - * + * * @command-name RegenerateKeys * @command-description Regenerate storage account keys. * @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.