def Run(self, args): """Run 'manifests describe'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The requested manifest. Raises: HttpException: An http error response was received while executing api request. """ client = self.context['deploymentmanager-client'] messages = self.context['deploymentmanager-messages'] project = properties.VALUES.core.project.Get(required=True) try: return client.manifests.Get( messages.DeploymentmanagerManifestsGetRequest( project=project, deployment=args.deployment, manifest=args.manifest, )) except apitools_base.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error))
def Run(self, args): """Run 'types list'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The list of types for this project. Raises: HttpException: An http error response was received while executing api request. """ client = self.context['deploymentmanager-v2beta2'] messages = self.context['deploymentmanager-v2beta2-messages'] project = properties.VALUES.core.project.Get(required=True) try: response = client.types.List( messages.DeploymentmanagerTypesListRequest(project=project, )) if response.types: return response.types else: # No types found return [] except apitools_base.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error))
def Run(self, args): """Run 'manifests list'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The list of manifests for the specified deployment. Raises: HttpException: An http error response was received while executing api request. """ client = self.context['deploymentmanager-client'] messages = self.context['deploymentmanager-messages'] project = properties.VALUES.core.project.Get(required=True) if args.limit: limit = dm_v2_util.SanitizeLimitFlag(args.limit) request = messages.DeploymentmanagerManifestsListRequest( project=project, deployment=args.deployment, maxResults=limit, ) else: request = messages.DeploymentmanagerManifestsListRequest( project=project, deployment=args.deployment, ) # TODO(user): Pagination (b/17687147). try: response = client.manifests.List(request) if response.manifests: results = response.manifests if args.limit and len(results) > limit: results = results[0:limit] return results else: # No manifests found return [] except apitools_base.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error))
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(user): 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 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_base.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(op_name, project, self.context, '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_base.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_base.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error)) operations.append(completed_operation) return operations
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 boolean indicating whether create 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-v2beta2'] messages = self.context['deploymentmanager-v2beta2-messages'] project = properties.VALUES.core.project.Get(required=True) deployment = messages.Deployment( name=args.deployment_name, target=dm_v2_util.BuildTargetConfig(messages, args.config), ) if args.description: deployment.description = args.description if args.preview: deployment.intent = 'PREVIEW' try: operation = client.deployments.Insert( messages.DeploymentmanagerDeploymentsInsertRequest( project=project, deployment=deployment, ) ) 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, '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_base.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_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 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-v2beta2'] messages = self.context['deploymentmanager-v2beta2-messages'] project = properties.VALUES.core.project.Get(required=True) deployment = messages.Deployment( name=args.deployment_name, intent='PREVIEW' if args.preview else 'UPDATE', ) if args.config: deployment.target = dm_v2_util.BuildTargetConfig( messages, args.config) # 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_base.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, createPolicy=( messages.DeploymentmanagerDeploymentsUpdateRequest. CreatePolicyValueValuesEnum(args.create_policy)), deletePolicy=( messages.DeploymentmanagerDeploymentsUpdateRequest. DeletePolicyValueValuesEnum(args.delete_policy)), updatePolicy=( messages.DeploymentmanagerDeploymentsUpdateRequest. UpdatePolicyValueValuesEnum(args.update_policy)), )) 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, '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_base.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_base.HttpError as error: raise exceptions.HttpException(dm_v2_util.GetError(error))