def Run(self, args): """Run 'operations wait'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Raises: HttpException: An http error response was received while executing api request. Raises: DeploymentManagerError: Operation finished with error(s) or timed out. """ client = self.context['deploymentmanager-client'] messages = self.context['deploymentmanager-messages'] project = properties.VALUES.core.project.Get(required=True) failed_ops = [] for operation_name in args.operation_name: try: dm_v2_util.WaitForOperation(client, messages, operation_name, project, '', OPERATION_TIMEOUT) except DeploymentManagerError: failed_ops.append(operation_name) if failed_ops: if len(failed_ops) == 1: raise DeploymentManagerError( 'Operation %s failed to complete or has errors.' % failed_ops[0]) else: raise DeploymentManagerError( 'Some operations failed to complete without errors:\n' + '\n'.join(failed_ops)) else: log.status.Print('All operations completed successfully.')
def Run(self, args): """Run 'operations wait'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Raises: HttpException: An http error response was received while executing api request. Raises: OperationError: Operation finished with error(s) or timed out. """ failed_ops = [] for operation_name in args.operation_name: try: dm_v2_util.WaitForOperation(self.client, self.messages, operation_name, self.project, '', OPERATION_TIMEOUT) except exceptions.OperationError: failed_ops.append(operation_name) if failed_ops: if len(failed_ops) == 1: raise exceptions.OperationError( 'Operation %s failed to complete or has errors.' % failed_ops[0]) else: raise exceptions.OperationError( 'Some operations failed to complete without errors:\n' + '\n'.join(failed_ops)) else: log.status.Print('All operations completed successfully.')
def Run(self, args): """Run 'deployments create'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: If --async=true, returns Operation to poll. Else, returns a struct containing the list of resources and list of outputs in the deployment. Raises: HttpException: An http error response was received while executing api request. ToolException: Config file could not be read or parsed, or the deployment creation operation encountered an error. """ client = self.context['deploymentmanager-client'] messages = self.context['deploymentmanager-messages'] project = properties.VALUES.core.project.Get(required=True) deployment = messages.Deployment( name=args.deployment_name, target=importer.BuildTargetConfig( messages, args.config, args.properties), ) if args.description: deployment.description = args.description try: operation = client.deployments.Insert( messages.DeploymentmanagerDeploymentsInsertRequest( project=project, deployment=deployment, preview=args.preview, ) ) except apitools_exceptions.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error)) if args.async: return operation else: op_name = operation.name try: dm_v2_util.WaitForOperation(op_name, project, self.context, 'create', OPERATION_TIMEOUT) log.status.Print('Create operation ' + op_name + ' completed successfully.') except exceptions.ToolException: # Operation timed out or had errors. Print this warning, then still # show whatever operation can be gotten. log.error('Create operation ' + op_name + ' has errors or failed to complete within ' + str(OPERATION_TIMEOUT) + ' seconds.') except apitools_exceptions.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error)) return dm_v2_util.FetchResourcesAndOutputs(client, messages, project, args.deployment_name)
def Run(self, args): """Run 'deployments create'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: If --async=true, returns Operation to poll. Else, returns a struct containing the list of resources and list of outputs in the deployment. Raises: HttpException: An http error response was received while executing api request. ConfigError: Config file could not be read or parsed, or the deployment creation operation encountered an error. """ deployment = self.messages.Deployment( name=args.deployment_name, target=importer.BuildTargetConfig(self.messages, args.config, args.properties), ) if args.description: deployment.description = args.description try: operation = self.client.deployments.Insert( self.messages.DeploymentmanagerDeploymentsInsertRequest( project=self.project, deployment=deployment, preview=args.preview, )) except apitools_exceptions.HttpError as error: raise exceptions.HttpException(error, dm_v2_util.HTTP_ERROR_FORMAT) if args. async: return operation else: op_name = operation.name try: dm_v2_util.WaitForOperation(self.client, self.messages, op_name, self.project, 'create', OPERATION_TIMEOUT) log.status.Print('Create operation ' + op_name + ' completed successfully.') except apitools_exceptions.HttpError as error: raise exceptions.HttpException(error, dm_v2_util.HTTP_ERROR_FORMAT) return dm_v2_util.FetchResourcesAndOutputs(self.client, self.messages, self.project, args.deployment_name)
def Run(self, args): """Run 'deployments update'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: If --async=true, returns Operation to poll. Else, returns a struct containing the list of resources and list of outputs in the deployment. Raises: HttpException: An http error response was received while executing api request. ToolException: Config file could not be read or parsed, or the deployment creation operation encountered an error. """ client = self.context['deploymentmanager-client'] messages = self.context['deploymentmanager-messages'] project = properties.VALUES.core.project.Get(required=True) deployment = messages.Deployment( name=args.deployment_name, ) if args.config: deployment.target = importer.BuildTargetConfig( messages, args.config, args.properties) elif (self.ReleaseTrack() in [base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA] and args.manifest_id): deployment.target = importer.BuildTargetConfigFromManifest( client, messages, project, args.deployment_name, args.manifest_id, args.properties) # Get the fingerprint from the deployment to update. try: current_deployment = client.deployments.Get( messages.DeploymentmanagerDeploymentsGetRequest( project=project, deployment=args.deployment_name ) ) # If no fingerprint is present, default to an empty fingerprint. # This empty default can be removed once the fingerprint change is # fully implemented and all deployments have fingerprints. deployment.fingerprint = current_deployment.fingerprint or '' except apitools_exceptions.HttpError as error: raise exceptions.HttpException(error, dm_v2_util.HTTP_ERROR_FORMAT) try: operation = client.deployments.Update( messages.DeploymentmanagerDeploymentsUpdateRequest( deploymentResource=deployment, project=project, deployment=args.deployment_name, preview=args.preview, createPolicy=(messages.DeploymentmanagerDeploymentsUpdateRequest .CreatePolicyValueValuesEnum(args.create_policy)), deletePolicy=(messages.DeploymentmanagerDeploymentsUpdateRequest .DeletePolicyValueValuesEnum(args.delete_policy)), ) ) except apitools_exceptions.HttpError as error: raise exceptions.HttpException(error, dm_v2_util.HTTP_ERROR_FORMAT) if args.async: return operation else: op_name = operation.name try: dm_v2_util.WaitForOperation(client, messages, op_name, project, 'update', OPERATION_TIMEOUT) log.status.Print('Update operation ' + op_name + ' completed successfully.') except exceptions.ToolException: # Operation timed out or had errors. Print this warning, then still # show whatever operation can be gotten. log.error('Update operation ' + op_name + ' has errors or failed to complete within ' + str(OPERATION_TIMEOUT) + ' seconds.') except apitools_exceptions.HttpError as error: raise exceptions.HttpException(error, dm_v2_util.HTTP_ERROR_FORMAT) return dm_v2_util.FetchResourcesAndOutputs(client, messages, project, args.deployment_name)
def Run(self, args): """Run 'deployments delete'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: If --async=true, returns Operation to poll. Else, returns boolean indicating whether insert operation succeeded. Raises: HttpException: An http error response was received while executing api request. ToolException: The deployment deletion operation encountered an error. """ client = self.context['deploymentmanager-client'] messages = self.context['deploymentmanager-messages'] project = properties.VALUES.core.project.Get(required=True) prompt_message = ('The following deployments will be deleted:\n- ' + '\n- '.join(args.deployment_name)) if not args.quiet: if not console_io.PromptContinue(message=prompt_message, default=False): raise exceptions.ToolException('Deletion aborted by user.') operations = [] for deployment_name in args.deployment_name: try: operation = client.deployments.Delete( messages.DeploymentmanagerDeploymentsDeleteRequest( project=project, deployment=deployment_name, )) except apitools_exceptions.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error)) if args. async: operations.append(operation) else: op_name = operation.name try: dm_v2_util.WaitForOperation(client, messages, op_name, project, 'delete', OPERATION_TIMEOUT) log.status.Print('Delete operation ' + op_name + ' completed successfully.') except (exceptions.ToolException, DeploymentManagerError): log.error('Delete operation ' + op_name + ' has errors or failed to complete within in ' + str(OPERATION_TIMEOUT) + ' seconds.') except apitools_exceptions.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error)) try: completed_operation = client.operations.Get( messages.DeploymentmanagerOperationsGetRequest( project=project, operation=op_name, )) except apitools_exceptions.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error)) operations.append(completed_operation) return operations
def Run(self, args): """Run 'deployments delete'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: If --async=true, returns Operation to poll. Else, returns boolean indicating whether insert operation succeeded. Raises: HttpException: An http error response was received while executing api request. """ prompt_message = ('The following deployments will be deleted:\n- ' + '\n- '.join(args.deployment_name)) if not args.quiet: if not console_io.PromptContinue(message=prompt_message, default=False): raise exceptions.OperationError('Deletion aborted by user.') operations = [] for deployment_name in args.deployment_name: try: operation = self.client.deployments.Delete( self.messages.DeploymentmanagerDeploymentsDeleteRequest( project=self.project, deployment=deployment_name, )) except apitools_exceptions.HttpError as error: raise api_exceptions.HttpException( error, dm_v2_util.HTTP_ERROR_FORMAT) if args. async: operations.append(operation) else: op_name = operation.name try: dm_v2_util.WaitForOperation(self.client, self.messages, op_name, self.project, 'delete', OPERATION_TIMEOUT) log.status.Print('Delete operation ' + op_name + ' completed successfully.') except exceptions.OperationError as e: log.error(u'Delete operation {0} failed.\n{1}'.format( op_name, e)) except apitools_exceptions.HttpError as error: raise api_exceptions.HttpException( error, dm_v2_util.HTTP_ERROR_FORMAT) try: completed_operation = self.client.operations.Get( self.messages.DeploymentmanagerOperationsGetRequest( project=self.project, operation=op_name, )) except apitools_exceptions.HttpError as error: raise api_exceptions.HttpException( error, dm_v2_util.HTTP_ERROR_FORMAT) operations.append(completed_operation) return operations
def Run(self, args): """Run 'deployments stop'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: If --async=true, returns Operation to poll. Else, returns boolean indicating whether stop operation succeeded. Raises: HttpException: An http error response was received while executing api request. """ # Get the fingerprint from the deployment to stop. try: current_deployment = self.client.deployments.Get( self.messages.DeploymentmanagerDeploymentsGetRequest( project=self.project, deployment=args.deployment_name)) # If no fingerprint is present, default to an empty fingerprint. # This empty default can be removed once the fingerprint change is # fully implemented and all deployments have fingerprints. fingerprint = current_deployment.fingerprint or '' except apitools_exceptions.HttpError as error: raise exceptions.HttpException(error, dm_v2_util.HTTP_ERROR_FORMAT) try: operation = self.client.deployments.Stop( self.messages.DeploymentmanagerDeploymentsStopRequest( project=self.project, deployment=args.deployment_name, deploymentsStopRequest=self.messages. DeploymentsStopRequest(fingerprint=fingerprint, ), )) except apitools_exceptions.HttpError as error: raise exceptions.HttpException(error, dm_v2_util.HTTP_ERROR_FORMAT) if args. async: return operation else: op_name = operation.name try: dm_v2_util.WaitForOperation(self.client, self.messages, op_name, self.project, 'stop', OPERATION_TIMEOUT) log.status.Print('Stop operation ' + op_name + ' completed successfully.') except apitools_exceptions.HttpError as error: raise exceptions.HttpException(error, dm_v2_util.HTTP_ERROR_FORMAT) try: # Fetch a list of the stopped resources. response = self.client.resources.List( self.messages.DeploymentmanagerResourcesListRequest( project=self.project, deployment=args.deployment_name, )) # TODO(user): Pagination return response.resources if response.resources else [] except apitools_exceptions.HttpError as error: raise exceptions.HttpException(error, dm_v2_util.HTTP_ERROR_FORMAT)
def Run(self, args): """Run 'deployments stop'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: If --async=true, returns Operation to poll. Else, returns boolean indicating whether stop operation succeeded. Raises: HttpException: An http error response was received while executing api request. ToolException: The stop operation encountered an error. """ client = self.context['deploymentmanager-client'] messages = self.context['deploymentmanager-messages'] project = properties.VALUES.core.project.Get(required=True) # Get the fingerprint from the deployment to stop. try: current_deployment = client.deployments.Get( messages.DeploymentmanagerDeploymentsGetRequest( project=project, deployment=args.deployment_name ) ) # If no fingerprint is present, default to an empty fingerprint. # This empty default can be removed once the fingerprint change is # fully implemented and all deployments have fingerprints. fingerprint = current_deployment.fingerprint or '' except apitools_base.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error)) try: operation = client.deployments.Stop( messages.DeploymentmanagerDeploymentsStopRequest( project=project, deployment=args.deployment_name, deploymentsStopRequest=messages.DeploymentsStopRequest( fingerprint=fingerprint, ), ) ) except apitools_base.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error)) if args.async: return operation else: op_name = operation.name try: dm_v2_util.WaitForOperation(op_name, project, self.context, 'stop', OPERATION_TIMEOUT) log.status.Print('Stop operation ' + op_name + ' completed successfully.') except exceptions.ToolException: # Operation timed out or had errors. Print this warning, then still # show whatever operation can be gotten. log.error('Stop operation ' + op_name + ' has errors or failed to complete within ' + str(OPERATION_TIMEOUT) + ' seconds.') except apitools_base.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error)) try: # Fetch a list of the stopped resources. response = client.resources.List( messages.DeploymentmanagerResourcesListRequest( project=project, deployment=args.deployment_name, ) ) # TODO(munutzer): Pagination return response.resources if response.resources else [] except apitools_base.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error))
def Run(self, args): """Run 'deployments update'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: If --async=true, returns Operation to poll. Else, returns a struct containing the list of resources and list of outputs in the deployment. Raises: HttpException: An http error response was received while executing api request. """ deployment = self.messages.Deployment(name=args.deployment_name, ) if args.config: deployment.target = importer.BuildTargetConfig( self.messages, args.config, args.properties) elif (self.ReleaseTrack() in [base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA] and args.manifest_id): deployment.target = importer.BuildTargetConfigFromManifest( self.client, self.messages, self.project, args.deployment_name, args.manifest_id, args.properties) # Get the fingerprint from the deployment to update. try: current_deployment = self.client.deployments.Get( self.messages.DeploymentmanagerDeploymentsGetRequest( project=self.project, deployment=args.deployment_name)) # If no fingerprint is present, default to an empty fingerprint. # This empty default can be removed once the fingerprint change is # fully implemented and all deployments have fingerprints. deployment.fingerprint = current_deployment.fingerprint or '' except apitools_exceptions.HttpError as error: raise exceptions.HttpException(error, dm_v2_util.HTTP_ERROR_FORMAT) try: operation = self.client.deployments.Update( self.messages.DeploymentmanagerDeploymentsUpdateRequest( deploymentResource=deployment, project=self.project, deployment=args.deployment_name, preview=args.preview, createPolicy=( self.messages.DeploymentmanagerDeploymentsUpdateRequest .CreatePolicyValueValuesEnum(args.create_policy)), deletePolicy=( self.messages.DeploymentmanagerDeploymentsUpdateRequest .DeletePolicyValueValuesEnum(args.delete_policy)), )) except apitools_exceptions.HttpError as error: raise exceptions.HttpException(error, dm_v2_util.HTTP_ERROR_FORMAT) if args. async: return operation else: op_name = operation.name try: dm_v2_util.WaitForOperation(self.client, self.messages, op_name, self.project, 'update', OPERATION_TIMEOUT) log.status.Print('Update operation ' + op_name + ' completed successfully.') except apitools_exceptions.HttpError as error: raise exceptions.HttpException(error, dm_v2_util.HTTP_ERROR_FORMAT) return dm_v2_util.FetchResourcesAndOutputs(self.client, self.messages, self.project, args.deployment_name)
def Run(self, args): """Run 'deployments update'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: If --async=true, returns Operation to poll. Else, returns boolean indicating whether update operation succeeded. Raises: HttpException: An http error response was received while executing api request. ToolException: Config file could not be read or parsed, or the deployment creation operation encountered an error. """ client = self.context['deploymentmanager-client'] messages = self.context['deploymentmanager-messages'] project = properties.VALUES.core.project.Get(required=True) deployment = messages.Deployment(name=args.deployment_name, ) if args.config: deployment.target = importer.BuildTargetConfig( messages, args.config, args.properties) # Get the fingerprint from the deployment to update. try: current_deployment = client.deployments.Get( messages.DeploymentmanagerDeploymentsGetRequest( project=project, deployment=args.deployment_name)) # If no fingerprint is present, default to an empty fingerprint. # This empty default can be removed once the fingerprint change is # fully implemented and all deployments have fingerprints. deployment.fingerprint = current_deployment.fingerprint or '' except apitools_exceptions.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error)) try: operation = client.deployments.Update( messages.DeploymentmanagerDeploymentsUpdateRequest( deploymentResource=deployment, project=project, deployment=args.deployment_name, preview=args.preview, createPolicy=( messages.DeploymentmanagerDeploymentsUpdateRequest. CreatePolicyValueValuesEnum(args.create_policy)), deletePolicy=( messages.DeploymentmanagerDeploymentsUpdateRequest. DeletePolicyValueValuesEnum(args.delete_policy)), )) except apitools_exceptions.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error)) if args. async: return operation else: op_name = operation.name try: dm_v2_util.WaitForOperation(op_name, project, self.context, 'update', OPERATION_TIMEOUT) log.status.Print('Update operation ' + op_name + ' completed successfully.') except exceptions.ToolException: # Operation timed out or had errors. Print this warning, then still # show whatever operation can be gotten. log.error('Update operation ' + op_name + ' has errors or failed to complete within ' + str(OPERATION_TIMEOUT) + ' seconds.') except apitools_exceptions.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error)) try: # Fetch a list of the previewed or updated resources. response = client.resources.List( messages.DeploymentmanagerResourcesListRequest( project=project, deployment=args.deployment_name, )) # TODO(user): Pagination return response.resources if response.resources else [] except apitools_exceptions.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error))