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. Returns: None Raises: FunctionsError: If the user doesn't confirm on prompt. """ client = self.context['functions_client'] messages = self.context['functions_messages'] project = properties.VALUES.core.project.Get(required=True) name = 'projects/{0}/locations/{1}/functions/{2}'.format( project, args.region, args.name) prompt_message = 'Resource [{0}] will be deleted.'.format(name) if not console_io.PromptContinue(message=prompt_message): raise exceptions.FunctionsError('Deletion aborted by user.') # TODO(user): Use resources.py here after b/21908671 is fixed. op = client.projects_locations_functions.Delete( messages.CloudfunctionsProjectsLocationsFunctionsDeleteRequest( name=name)) operations.Wait(op, messages, client) log.DeletedResource(name)
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. Returns: None Raises: FunctionsError: If the user doesn't confirm on prompt. """ client = self.context['functions_client'] messages = self.context['functions_messages'] registry = self.context['registry'] project = properties.VALUES.core.project.Get(required=True) function_ref = registry.Parse( args.name, params={'projectsId': project, 'locationsId': args.region}, collection='cloudfunctions.projects.locations.functions') 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.') # TODO(user): Use resources.py here after b/21908671 is fixed. op = client.projects_locations_functions.Delete( messages.CloudfunctionsProjectsLocationsFunctionsDeleteRequest( name=function__url)) operations.Wait(op, messages, client) log.DeletedResource(function__url)
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. Returns: None Raises: FunctionsError: If the user doesn't confirm on prompt. """ client = util.GetApiClientInstance() messages = client.MESSAGES_MODULE function_ref = resources.REGISTRY.Parse( args.name, params={ 'projectsId': properties.VALUES.core.project.GetOrFail, 'locationsId': properties.VALUES.functions.region.GetOrFail }, collection='cloudfunctions.projects.locations.functions') 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 _UpdateFunction(self, unused_location, function): client = self.context['functions_client'] messages = self.context['functions_messages'] # TODO(user): Use resources.py here after b/21908671 is fixed. op = client.projects_regions_functions.Update(function) operations.Wait(op, messages, client) return self._GetExistingFunction(function.name)
def CreateFunction(function, location): client = GetApiClientInstance() messages = client.MESSAGES_MODULE op = client.projects_locations_functions.Create( messages.CloudfunctionsProjectsLocationsFunctionsCreateRequest( location=location, cloudFunction=function)) operations.Wait(op, messages, client, _DEPLOY_WAIT_NOTICE) return GetFunction(function.name)
def WaitForFunctionUpdateOperation(op): """Wait for the specied function update to complete. Args: op: Cloud operation to wait on. """ client = GetApiClientInstance() operations.Wait(op, client.MESSAGES_MODULE, client, _DEPLOY_WAIT_NOTICE)
def _UpdateFunction(self, unused_location, function): client = util.GetApiClientInstance() messages = client.MESSAGES_MODULE op = client.projects_locations_functions.Update(function) with progress_tracker.ProgressTracker( 'Deploying function (may take a while - up to 2 minutes)'): operations.Wait(op, messages, client) return self._GetExistingFunction(function.name)
def _UpdateFunction(self, unused_location, function): client = self.context['functions_client'] messages = self.context['functions_messages'] op = client.projects_locations_functions.Update(function) with progress_tracker.ProgressTracker( 'Deploying function (may take a while - up to 2 minutes)'): operations.Wait(op, messages, client) return self._GetExistingFunction(function.name)
def _CreateFunction(self, location, function): client = self.context['functions_client'] messages = self.context['functions_messages'] # TODO(user): Use resources.py here after b/21908671 is fixed. op = client.projects_regions_functions.Create( messages.CloudfunctionsProjectsRegionsFunctionsCreateRequest( location=location, hostedFunction=function)) operations.Wait(op, messages, client) return self._GetExistingFunction(function.name)
def WaitForFunctionUpdateOperation(op, do_every_poll=None): """Wait for the specied function update to complete. Args: op: Cloud operation to wait on. do_every_poll: function, A function to execute every time we poll. """ client = GetApiClientInstance() operations.Wait(op, client.MESSAGES_MODULE, client, _DEPLOY_WAIT_NOTICE, do_every_poll=do_every_poll)
def _CreateFunction(self, location, function): client = util.GetApiClientInstance() messages = client.MESSAGES_MODULE op = client.projects_locations_functions.Create( messages.CloudfunctionsProjectsLocationsFunctionsCreateRequest( location=location, cloudFunction=function)) with progress_tracker.ProgressTracker( 'Deploying function (may take a while - up to 2 minutes)'): operations.Wait(op, messages, client) return self._GetExistingFunction(function.name)
def _CreateFunction(self, location, function): client = self.context['functions_client'] messages = self.context['functions_messages'] op = client.projects_locations_functions.Create( messages.CloudfunctionsProjectsLocationsFunctionsCreateRequest( location=location, cloudFunction=function)) with progress_tracker.ProgressTracker( 'Deploying function (may take a while - up to 2 minutes)'): operations.Wait(op, messages, client) return self._GetExistingFunction(function.name)
def _UpdateFunction(self, unused_location, function): client = util.GetApiClientInstance() messages = client.MESSAGES_MODULE op = client.projects_locations_functions.Patch( messages.CloudfunctionsProjectsLocationsFunctionsPatchRequest( cloudFunction=function, name=function.name, updateMask=None, )) operations.Wait(op, messages, client, _DEPLOY_WAIT_NOTICE) return self._GetExistingFunction(function.name)
def WaitForFunctionUpdateOperation(op, try_set_invoker=None, on_every_poll=None): """Wait for the specied function update to complete. Args: op: Cloud operation to wait on. try_set_invoker: function to try setting invoker, see above TODO. on_every_poll: list of functions to execute every time we poll. Functions should take in Operation as an argument. """ client = GetApiClientInstance() operations.Wait(op, client.MESSAGES_MODULE, client, _DEPLOY_WAIT_NOTICE, try_set_invoker=try_set_invoker, on_every_poll=on_every_poll)
def PatchFunction(function, fields_to_patch): """Call the api to patch a function based on updated fields. Args: function: the function to patch fields_to_patch: the fields to patch on the function Returns: The patched function. """ client = GetApiClientInstance() messages = client.MESSAGES_MODULE fields_to_patch_str = ','.join(sorted(fields_to_patch)) op = client.projects_locations_functions.Patch( messages.CloudfunctionsProjectsLocationsFunctionsPatchRequest( cloudFunction=function, name=function.name, updateMask=fields_to_patch_str, )) operations.Wait(op, messages, client, _DEPLOY_WAIT_NOTICE) return GetFunction(function.name)
def _UpdateFunction(self, unused_location, function): client = util.GetApiClientInstance() messages = client.MESSAGES_MODULE op = client.projects_locations_functions.Update(function) operations.Wait(op, messages, client, _DEPLOY_WAIT_NOTICE) return self._GetExistingFunction(function.name)