def Run(self, args): """Run 'services disable'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: Nothing. """ project = properties.VALUES.core.project.Get(required=True) for service_name in args.service: service_name = arg_parsers.GetServiceNameFromArg(service_name) op = serviceusage.DisableApiCall(project, service_name, args.force) if op.done: return if args. async: cmd = OP_WAIT_CMD.format(op.name) log.status.Print('Asynchronous operation is in progress... ' 'Use the following command to wait for its ' 'completion:\n {0}'.format(cmd)) return op = services_util.WaitOperation(op.name, serviceusage.GetOperation) services_util.PrintOperation(op)
def testDisableApiCall_FailedPrecondition(self): """Test DisableApiCall with failed precondition error.""" server_error = http_error.MakeDetailedHttpError(code=400, message='Error.') self.ExpectDisableApiCall(None, error=server_error) with self.assertRaisesRegex(exceptions.Error, r'Error.'): serviceusage.DisableApiCall(self.PROJECT_NAME, self.DEFAULT_SERVICE) self.AssertErrContains('--force')
def testDisableApiCall_Success(self): """Test DisableApiCall returns operation when successful.""" want = self.services_messages.Operation( name=self.OPERATION_NAME, done=False) self.ExpectDisableApiCall(self.OPERATION_NAME) got = serviceusage.DisableApiCall(self.PROJECT_NAME, self.DEFAULT_SERVICE) self.assertEqual(got, want)
def DisableService(project, service_name, force=False): """Disable service. Args: project: The project for which to disable the service. service_name: The identifier of the service to disable, for example 'serviceusage.googleapis.com'. force: disable the service even if there are enabled services which depend on it. This also disables the services which depend on the service to be disabled. Raises: exceptions.EnableServicePermissionDeniedException: when disabling API fails. apitools_exceptions.HttpError: Another miscellaneous error with the service. Returns: The service configuration. """ op = serviceusage.DisableApiCall(project, service_name, force) if op.done: return op = services_util.WaitOperation(op.name, serviceusage.GetOperation) services_util.PrintOperation(op)
def Run(self, args): """Run 'services disable'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: Nothing. """ project = properties.VALUES.core.project.Get(required=True) for service_name in args.service: service_name = arg_parsers.GetServiceNameFromArg(service_name) protected_msg = serviceusage.GetProtectedServiceWarning( service_name) if protected_msg: if args.IsSpecified('quiet'): raise console_io.RequiredPromptError() do_disable = console_io.PromptContinue( protected_msg, default=False, throw_if_unattended=True) if not do_disable: continue op = serviceusage.DisableApiCall(project, service_name, args.force) if op.done: continue if args.async_: cmd = OP_WAIT_CMD.format(op.name) log.status.Print('Asynchronous operation is in progress... ' 'Use the following command to wait for its ' 'completion:\n {0}'.format(cmd)) continue op = services_util.WaitOperation(op.name, serviceusage.GetOperation) services_util.PrintOperation(op)