def Run(self, args): cluster = args.CONCEPTS.cluster.Parse() client = ClustersClient() is_async = args.async_ operation = client.Delete(cluster) if is_async: log.DeletedResource(operation.name, kind='cluster', is_async=True) return operation return client.WaitForOperation( operation_ref=client.GetOperationRef(operation), message='waiting for cluster [{}] to be deleted'.format( cluster.RelativeName()), has_result=False)
def Run(self, args): """Deletes a backup of a Cloud SQL instance. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: A dict object representing the operations resource describing the delete operation if the api request was successful. Raises: HttpException: A http error response was received while executing api request. ToolException: An error other than http error occured while executing the command. """ client = api_util.SqlClient(api_util.API_VERSION_DEFAULT) sql_client = client.sql_client sql_messages = client.sql_messages operation_ref = None validate.ValidateInstanceName(args.instance) instance_ref = client.resource_parser.Parse(args.instance, collection='sql.instances') # TODO(b/36051078): validate on FE that a backup run id is valid. console_io.PromptContinue( message='The backup will be deleted. You cannot undo this action.', default=True, cancel_on_no=True) result = sql_client.backupRuns.Delete( sql_messages.SqlBackupRunsDeleteRequest( project=instance_ref.project, instance=instance_ref.instance, id=args.id)) operation_ref = client.resource_parser.Create( 'sql.operations', operation=result.name, project=instance_ref.project) operations.OperationsV1Beta4.WaitForOperation(sql_client, operation_ref, 'Deleting backup run') log.DeletedResource(args.id, 'backup run')
def Run(self, args): patch_deployment_ref = args.CONCEPTS.patch_deployment.Parse() patch_deployment_name = patch_deployment_ref.RelativeName() release_track = self.ReleaseTrack() client = osconfig_api_utils.GetClientInstance(release_track) messages = osconfig_api_utils.GetClientMessages(release_track) request = messages.OsconfigProjectsPatchDeploymentsDeleteRequest( name=patch_deployment_name) response = client.projects_patchDeployments.Delete(request) log.DeletedResource(patch_deployment_name) return response
def Run(self, args): """Delete a revision.""" conn_context = connection_context.GetConnectionContext(args) revision_ref = args.CONCEPTS.revision.Parse() console_io.PromptContinue( message='Revision [{}] will be deleted.'.format( revision_ref.revisionsId), throw_if_unattended=True, cancel_on_no=True) with serverless_operations.Connect(conn_context) as client: client.DeleteRevision(revision_ref) log.DeletedResource(revision_ref.revisionsId, 'revision')
def Run(self, args): """Delete a service.""" conn_context = connection_context.GetConnectionContext( args, self.ReleaseTrack()) service_ref = flags.GetService(args) console_io.PromptContinue( message='Service [{service}] will be deleted.'.format( service=service_ref.servicesId), throw_if_unattended=True, cancel_on_no=True) with serverless_operations.Connect(conn_context) as client: client.DeleteService(service_ref) log.DeletedResource(service_ref.servicesId, 'service')
def Run(self, args): """Delete an execution.""" conn_context = connection_context.GetConnectionContext( args, flags.Product.RUN, self.ReleaseTrack()) ex_ref = args.CONCEPTS.execution.Parse() console_io.PromptContinue( message='Execution [{}] will be deleted.'.format(ex_ref.executionsId), throw_if_unattended=True, cancel_on_no=True) with serverless_operations.Connect(conn_context) as client: client.DeleteExecution(ex_ref) log.DeletedResource(ex_ref.executionsId, 'execution')
def Run(self, args): """Deletes a Cloud SQL instance. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: A dict object representing the operations resource describing the delete operation if the delete was successful. Raises: HttpException: A http error response was received while executing api request. ToolException: An error other than http error occured while executing the command. """ client = api_util.SqlClient(api_util.API_VERSION_FALLBACK) sql_client = client.sql_client sql_messages = client.sql_messages operation_ref = None validate.ValidateInstanceName(args.instance) instance_ref = client.resource_parser.Parse( args.instance, params={'project': properties.VALUES.core.project.GetOrFail}, collection='sql.instances') if not console_io.PromptContinue( 'All of the instance data will be lost when the instance is deleted.'): return None try: result = sql_client.instances.Delete( sql_messages.SqlInstancesDeleteRequest( instance=instance_ref.instance, project=instance_ref.project)) operation_ref = client.resource_parser.Create( 'sql.operations', operation=result.operation, project=instance_ref.project, instance=instance_ref.instance, ) log.DeletedResource(instance_ref) cache = remote_completion.RemoteCompletion() cache.DeleteFromCache(instance_ref.SelfLink()) except exceptions.HttpError: log.debug('operation : %s', str(operation_ref)) raise
def Run(args): """Delete a Google Cloud Function.""" client = util.GetApiClientInstance() messages = client.MESSAGES_MODULE function_ref = args.CONCEPTS.name.Parse() function__url = function_ref.RelativeName() prompt_message = 'Resource [{0}] will be deleted.'.format(function__url) if not console_io.PromptContinue(message=prompt_message): raise exceptions.FunctionsError('Deletion aborted by user.') op = client.projects_locations_functions.Delete( messages.CloudfunctionsProjectsLocationsFunctionsDeleteRequest( name=function__url)) operations.Wait(op, messages, client) log.DeletedResource(function__url)
def Run(self, args): project_ref = command_lib_util.ParseProject(args.id) if not console_io.PromptContinue('Your project will be deleted.'): return None result = projects_api.Delete(project_ref) log.DeletedResource(project_ref) # Print this here rather than in Epilog because Epilog doesn't have access # to the deleted resource. # We can't be more specific than "limited period" because the API says # "at an unspecified time". log.status.Print( '\nYou can undo this operation for a limited period by running:\n' ' $ gcloud projects undelete {0}'.format(args.id)) return result
def Run(self_, args): ref, response = self._CommonRun(args) if self.spec.async: response = self._HandleAsync( args, ref, response, request_string='Delete request issued for: [{{{}}}]' .format(yaml_command_schema.NAME_FORMAT_KEY), extract_resource_result=False) if args.async: return self._HandleResponse(response, args) response = self._HandleResponse(response, args) log.DeletedResource(ref.Name(), kind=self.resource_type) return response
def Run(self, args): """Executes when the user runs the delete command.""" conn_context = connection_context.GetConnectionContext( args, product=connection_context.Product.EVENTS) trigger_ref = args.CONCEPTS.trigger.Parse() console_io.PromptContinue( message='Trigger [{}] will be deleted.'.format(trigger_ref.Name()), throw_if_unattended=True, cancel_on_no=True) with eventflow_operations.Connect(conn_context) as client: client.DeleteTrigger(trigger_ref) log.DeletedResource(trigger_ref.Name(), 'trigger')
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. """ asset_ref = args.CONCEPTS.asset.Parse() annotation_ref = args.CONCEPTS.annotation.Parse() sub_asset = args.sub_asset if console_io.PromptContinue(cancel_on_no=True): assets.DeleteAnnotationTag(asset_ref, annotation_ref, sub_asset) log.DeletedResource(annotation_ref.RelativeName(), 'annotation tag')
def Run(self, args): """Deletes a Cloud SQL instance. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: A dict object representing the operations resource describing the delete operation if the delete was successful. Raises: HttpException: A http error response was received while executing api request. ToolException: An error other than http error occured while executing the command. """ sql_client = self.context['sql_client'] sql_messages = self.context['sql_messages'] resources = self.context['registry'] operation_ref = None util.ValidateInstanceName(args.instance) instance_ref = resources.Parse(args.instance, collection='sql.instances') if not console_io.PromptContinue( 'All of the instance data will be lost when the instance is deleted.'): return None try: result = sql_client.instances.Delete( sql_messages.SqlInstancesDeleteRequest( instance=instance_ref.instance, project=instance_ref.project)) operation_ref = resources.Create( 'sql.operations', operation=result.operation, project=instance_ref.project, instance=instance_ref.instance, ) unused_operation = sql_client.operations.Get(operation_ref.Request()) log.DeletedResource(instance_ref) cache = remote_completion.RemoteCompletion() cache.DeleteFromCache(instance_ref.SelfLink()) except apitools_base.HttpError: log.debug('operation : %s', str(operation_ref)) raise
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. """ util.GetClient().projects_locations_buckets_views.Delete( util.GetMessages( ).LoggingProjectsLocationsBucketsViewsDeleteRequest( name=util.CreateResourceName( util.CreateResourceName( util.GetBucketLocationFromArgs(args), 'buckets', args.bucket), 'views', args.VIEW_ID))) log.DeletedResource(args.VIEW_ID)
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. """ console_io.PromptContinue( 'Really delete metric [%s]?' % args.metric_name, cancel_on_no=True) util.GetClient().projects_metrics.Delete( util.GetMessages().LoggingProjectsMetricsDeleteRequest( metricName=util.CreateResourceName( util.GetCurrentProjectParent(), 'metrics', args.metric_name))) log.DeletedResource(args.metric_name)
def Run(self, args): dns = apis.GetClientInstance('dns', 'v1beta2') zone_ref = util.GetRegistry('v1beta2').Parse( args.dns_zone, params={ 'project': properties.VALUES.core.project.GetOrFail, }, collection='dns.managedZones') result = dns.managedZones.Delete( dns.MESSAGES_MODULE.DnsManagedZonesDeleteRequest( managedZone=zone_ref.managedZone, project=zone_ref.project)) log.DeletedResource(zone_ref) return result
def Run(self, args): priority = firewall_rules_util.ParsePriority(args.priority) if priority == firewall_rules_util.DEFAULT_RULE_PRIORITY: raise exceptions.InvalidArgumentException( 'priority', 'The `default` can not be deleted, only updated.') console_io.PromptContinue( prompt_string='You are about to delete rule [{0}].'.format(priority), cancel_on_no=True) client = api_client.GetApiClientForTrack(self.ReleaseTrack()) resource = firewall_rules_util.ParseFirewallRule(client, priority) client.Delete(resource) log.DeletedResource(priority)
def Run(self, args): client = networkconnectivity_api.SpokesClient( release_track=self.ReleaseTrack()) spoke_ref = args.CONCEPTS.spoke.Parse() console_io.PromptContinue( message=('You are about to delete spoke [{}]'.format( spoke_ref.Name())), cancel_on_no=True) op_ref = client.Delete(spoke_ref) log.status.Print('Delete request issued for: [{}]'.format( spoke_ref.Name())) if op_ref.done: log.DeletedResource(spoke_ref.Name(), kind='spoke') return op_ref if args.async_: log.status.Print('Check operation [{}] for status.'.format( op_ref.name)) return op_ref api_version = networkconnectivity_util.VERSION_MAP[self.ReleaseTrack()] op_resource = resources.REGISTRY.ParseRelativeName( op_ref.name, collection='networkconnectivity.projects.locations.operations', api_version=api_version) poller = waiter.CloudOperationPollerNoResources( client.operation_service) res = waiter.WaitFor( poller, op_resource, 'Waiting for operation [{}] to complete'.format(op_ref.name)) log.DeletedResource(spoke_ref.Name(), kind='spoke') return res
def _Run(args, legacy_output=False): """Deletes one or more topics.""" client = topics.TopicsClient() failed = [] for topic_ref in args.CONCEPTS.topic.Parse(): try: result = client.Delete(topic_ref) except api_ex.HttpError as error: exc = exceptions.HttpException(error) log.DeletedResource(topic_ref.RelativeName(), kind='topic', failed=exc.payload.status_message) failed.append(topic_ref.topicsId) continue topic = client.messages.Topic(name=topic_ref.RelativeName()) if legacy_output: result = util.TopicDisplayDict(topic) log.DeletedResource(topic_ref.RelativeName(), kind='topic') yield result if failed: raise util.RequestsFailedError(failed, 'delete')
def Run(self, args): client = certificate_maps.CertificateMapClient() map_ref = args.CONCEPTS.map.Parse() console_io.PromptContinue( 'You are about to delete certificate map \'{}\''.format( map_ref.certificateMapsId), throw_if_unattended=True, cancel_on_no=True) response = client.Delete(map_ref) response = util.WaitForOperation(response, is_async=args.async_) log.DeletedResource(map_ref.Name(), 'map', is_async=args.async_) return response
def Run(self, args): network_policy = args.CONCEPTS.network_policy.Parse() client = NetworkPoliciesClient() is_async = args.async_ operation = client.Delete(network_policy) if is_async: log.DeletedResource(operation.name, kind='VMware Engine network policy', is_async=True) return operation return client.WaitForOperation( operation_ref=client.GetOperationRef(operation), message='waiting for network policy [{}] to be deleted'.format( network_policy.RelativeName()))
def Run(self, args): """Deletes a job template.""" client = templates.TemplatesClient(self.ReleaseTrack()) template_ref = args.CONCEPTS.template_id.Parse() console_io.PromptContinue( 'You are about to delete template [{}]'.format( template_ref.jobTemplatesId), throw_if_unattended=True, cancel_on_no=True) result = client.Delete(template_ref) log.DeletedResource(template_ref.RelativeName(), kind='template') return result
def Run(self, args): dns = apis.GetClientInstance('dns', 'v1') messages = apis.GetMessagesModule('dns', 'v1') zone_ref = resources.REGISTRY.Parse( args.dns_zone, params={ 'project': properties.VALUES.core.project.GetOrFail, }, collection='dns.managedZones') result = dns.managedZones.Delete( messages.DnsManagedZonesDeleteRequest( managedZone=zone_ref.managedZone, project=zone_ref.project)) log.DeletedResource(zone_ref) return result
def Run(self, args): peering = args.CONCEPTS.network_peering.Parse() client = NetworkPeeringClient() is_async = args.async_ operation = client.Delete(peering) if is_async: log.DeletedResource(operation.name, kind='VPC network peering', is_async=True) return operation return client.WaitForOperation( operation_ref=client.GetOperationRef(operation), message='waiting for vpc peering [{}] to be deleted'.format( peering.RelativeName()), has_result=False)
def Run(self, args): """Executes when the user runs the delete command.""" conn_context = connection_context.GetConnectionContext(args) if conn_context.supports_one_platform: raise exceptions.UnsupportedArgumentError( 'Events are only available with Cloud Run for Anthos.') trigger_ref = args.CONCEPTS.trigger.Parse() console_io.PromptContinue( message='Trigger [{}] will be deleted.'.format(trigger_ref.Name()), throw_if_unattended=True, cancel_on_no=True) with eventflow_operations.Connect(conn_context) as client: client.DeleteTrigger(trigger_ref) log.DeletedResource(trigger_ref.Name(), 'trigger')
def Run(self, args): """Delete a service.""" conn_context = connection_context.GetConnectionContext( args, flags.Product.RUN, self.ReleaseTrack()) service_ref = args.CONCEPTS.service.Parse() flags.ValidateResource(service_ref) console_io.PromptContinue( message='Service [{service}] will be deleted.'.format( service=service_ref.servicesId), throw_if_unattended=True, cancel_on_no=True) with serverless_operations.Connect(conn_context) as client: deletion.Delete(service_ref, client.GetService, client.DeleteService, args.async_) log.DeletedResource(service_ref.servicesId, 'service')
def Run(self, args): """See base class.""" release_track = self.ReleaseTrack() client = osconfig_api_utils.GetClientInstance(release_track) messages = osconfig_api_utils.GetClientMessages(release_track) project = properties.VALUES.core.project.GetOrFail() guest_policy_name = osconfig_command_utils.GetGuestPolicyUriPath( 'projects', project, args.POLICY_ID) request = messages.OsconfigProjectsGuestPoliciesDeleteRequest( name=guest_policy_name) service = client.projects_guestPolicies response = service.Delete(request) log.DeletedResource(guest_policy_name) return response
def Run(self, args): privatecloud = args.CONCEPTS.private_cloud.Parse() client = PrivateCloudsClient() is_async = args.async_ operation = client.Delete(privatecloud, args.delay_hours) if is_async: log.DeletedResource(operation.name, kind='private cloud', is_async=True) return operation return client.WaitForOperation( operation_ref=client.GetOperationRef(operation), message='waiting for private cloud [{}] to be deleted'.format( privatecloud.RelativeName()), has_result=False)
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. """ if not console_io.PromptContinue( 'Really delete all log entries from [%s]?' % args.log_name): raise exceptions.ToolException('action canceled by user') util.GetClient().projects_logs.Delete( util.GetMessages().LoggingProjectsLogsDeleteRequest( logName=util.CreateLogResourceName( util.GetCurrentProjectParent(), args.log_name))) log.DeletedResource(args.log_name)
def Run(self, args): project = properties.VALUES.core.project.GetOrFail() patch_deployment_ref = args.CONCEPTS.patch_deployment.Parse() patch_deployment_name = osconfig_command_utils.GetPatchDeploymentUriPath( project, patch_deployment_ref.Name()) release_track = self.ReleaseTrack() client = osconfig_api_utils.GetClientInstance(release_track) messages = osconfig_api_utils.GetClientMessages(release_track) request = messages.OsconfigProjectsPatchDeploymentsDeleteRequest( name=patch_deployment_name) response = client.projects_patchDeployments.Delete(request) log.DeletedResource(patch_deployment_name) return response