def Run(self, args): """Run command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Returns: The response from the Undelete API call. """ client = apikeys.GetClientInstance() messages = client.MESSAGES_MODULE key_ref = args.CONCEPTS.key.Parse() request = messages.ApikeysProjectsKeysUndeleteRequest( name=key_ref.RelativeName()) op = client.projects_keys.Undelete(request) if not op.done: 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 op = services_util.WaitOperation(op.name, apikeys.GetOperation) log.status.Print('Operation [{0}] complete. Result: {1}'.format( op.name, json.dumps(encoding.MessageToDict(op.response), sort_keys=True, indent=4, separators=(',', ':'))))
def Run(self, args): """Run 'services enable'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: Nothing. """ project = properties.VALUES.core.project.Get(required=True) if len(args.service) == 1: op = serviceusage.EnableApiCall(project, args.service[0]) else: op = serviceusage.BatchEnableApiCall(project, args.service) 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 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 Run(self, args): """Run command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Returns: None """ client = apikeys.GetClientInstance() messages = client.MESSAGES_MODULE key_ref = args.CONCEPTS.key.Parse() request = messages.ApikeysProjectsKeysCloneRequest( name=key_ref.RelativeName()) op = client.projects_keys.Clone(request) if not op.done: 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 op = services_util.WaitOperation(op.name, apikeys.GetOperation) services_util.PrintOperationWithResponse(op)
def Run(self, args): """Run command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Returns: None """ client = apikeys.GetClientInstance() messages = client.MESSAGES_MODULE key_ref = args.CONCEPTS.key.Parse() update_mask = [] key_proto = messages.V2Key(name=key_ref.RelativeName(), restrictions=messages.V2Restrictions()) if args.IsSpecified('display_name'): update_mask.append('display_name') key_proto.displayName = args.display_name if args.IsSpecified('clear_restrictions'): update_mask.append('restrictions') else: if args.IsSpecified('allowed_referrers'): update_mask.append('restrictions.browser_key_restrictions') key_proto.restrictions.browserKeyRestrictions = messages.V2BrowserKeyRestrictions( allowedReferrers=args.allowed_referrers) elif args.IsSpecified('allowed_ips'): update_mask.append('restrictions.server_key_restrictions') key_proto.restrictions.serverKeyRestrictions = messages.V2ServerKeyRestrictions( allowedIps=args.allowed_ips) elif args.IsSpecified('allowed_bundle_ids'): update_mask.append('restrictions.ios_key_restrictions') key_proto.restrictions.iosKeyRestrictions = messages.V2IosKeyRestrictions( allowedBundleIds=args.allowed_bundle_ids) elif args.IsSpecified('allowed_application'): update_mask.append('restrictions.android_key_restrictions') key_proto.restrictions.androidKeyRestrictions = messages.V2AndroidKeyRestrictions( allowedApplications=apikeys.GetAllowedAndroidApplications( args, messages)) if args.IsSpecified('api_target'): update_mask.append('restrictions.api_targets') key_proto.restrictions.apiTargets = apikeys.GetApiTargets( args, messages) request = messages.ApikeysProjectsLocationsKeysPatchRequest( name=key_ref.RelativeName(), updateMask=','.join(update_mask), v2Key=key_proto) op = client.projects_locations_keys.Patch(request) if not op.done: 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 op = services_util.WaitOperation(op.name, apikeys.GetOperation) services_util.PrintOperationWithResponse(op) return op
def testWaitOperation(self): """Test WaitOperation returns operation when successful.""" op_name = 'operations/abc.0000000000' want = self.services_messages.Operation(name=op_name, done=True) self.ExpectOperation(op_name, 3) got = services_util.WaitOperation(op_name, serviceusage.GetOperation) self.assertEqual(got, want)
def enable_service(): project = properties.VALUES.core.project.Get(required=True) service_name = 'anthosconfigmanagement.googleapis.com' op = serviceusage.EnableApiCall(project, service_name) log.status.Print('Enabling service {0}'.format(service_name)) if op.done: return op = services_util.WaitOperation(op.name, serviceusage.GetOperation) services_util.PrintOperation(op)
def Run(self, args): """Run 'services operations wait'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: Nothing. """ op = services_util.WaitOperation(args.name, peering.GetOperation) services_util.PrintOperation(op)
def Run(self, args): """Run 'services operations wait'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: If successful, the response from the operations.Get API call. """ op = services_util.WaitOperation(args.operation, serviceusage.GetOperation) services_util.PrintOperation(op)
def Run(self, args): """Run command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Returns: None """ project_id = properties.VALUES.core.project.GetOrFail() client = apikeys.GetClientInstance() messages = client.MESSAGES_MODULE key_proto = messages.V2alpha1ApiKey( restrictions=messages.V2alpha1Restrictions()) if args.IsSpecified('display_name'): key_proto.displayName = args.display_name if args.IsSpecified('allowed_referrers'): key_proto.restrictions.browserKeyRestrictions = messages.V2alpha1BrowserKeyRestrictions( allowedReferrers=args.allowed_referrers) elif args.IsSpecified('allowed_ips'): key_proto.restrictions.serverKeyRestrictions = messages.V2alpha1ServerKeyRestrictions( allowedIps=args.allowed_ips) elif args.IsSpecified('allowed_bundle_ids'): key_proto.restrictions.iosKeyRestrictions = messages.V2alpha1IosKeyRestrictions( allowedBundleIds=args.allowed_bundle_ids) elif args.IsSpecified('allowed_application'): key_proto.restrictions.androidKeyRestrictions = messages.V2alpha1AndroidKeyRestrictions( allowedApplications=apikeys.GetAllowedAndroidApplications( args, messages)) if args.IsSpecified('api_target'): key_proto.restrictions.apiTargets = apikeys.GetApiTargets( args, messages) request = messages.ApikeysProjectsKeysCreateRequest( parent=apikeys.GetParentResourceName(project_id), v2alpha1ApiKey=key_proto) op = client.projects_keys.Create(request) if not op.done: 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 op = services_util.WaitOperation(op.name, apikeys.GetOperation) services_util.PrintOperationWithResponse(op)
def Run(self, args): """Run 'services operations wait'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: If successful, the response from the operations.Get API call. """ namespace = common_flags.get_operation_namespace(args.operation) get_op_func = _GET_OP_FUNC_MAP.get(namespace, serviceusage.GetOperation) op = services_util.WaitOperation(args.operation, get_op_func) services_util.PrintOperationWithResponse(op)
def Run(self, args): """Run 'endpoints quota delete'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: Nothing. """ op = scm.DeleteQuotaOverrideCall(args.service, args.consumer, args.metric, args.unit, args.override_id, args.force) if op.done: return op = services_util.WaitOperation(op.name, scm.GetOperation) services_util.PrintOperation(op)
def Run(self, args): """Run 'services vpc-peerings enable-vpc-service-controls'. Args: args: argparse.Namespace, The arguments that this command was invoked with. """ project = properties.VALUES.core.project.Get(required=True) project_number = _GetProjectNumber(project) op = peering.DisableVpcServiceControls(project_number, args.service, args.network) 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, peering.GetOperation) services_util.PrintOperation(op)
def _EnableMissingServices(project): """Enables any required services for the project.""" enabled_services = set( service.config.name for service in serviceusage.ListServices(project, True, 100, None)) missing_services = list( sorted(set(_CONTROL_PLANE_REQUIRED_SERVICES) - enabled_services)) if not missing_services: return formatted_services = '\n'.join( ['- {}'.format(s) for s in missing_services]) _PromptIfCanPrompt('\nThis will enable the following services:\n' '{}'.format(formatted_services)) if len(missing_services) == 1: op = serviceusage.EnableApiCall(project, missing_services[0]) else: op = serviceusage.BatchEnableApiCall(project, missing_services) if not op.done: op = services_util.WaitOperation(op.name, serviceusage.GetOperation) log.status.Print('Services successfully enabled.')
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 EnableService(project_id, service_name, is_async=False): """Enable a service without checking if it is already enabled. Args: project_id: The ID of the project for which to enable the service. service_name: The name of the service to enable on the project. is_async: bool, if True, print the operation ID and return immediately, without waiting for the op to complete. Raises: exceptions.EnableServicePermissionDeniedException: when enabling the API fails with a 403 or 404 error code. api_lib_exceptions.HttpException: Another miscellaneous error with the servicemanagement service. """ log.status.Print('Enabling service [{0}] on project [{1}]...'.format( service_name, project_id)) # Enable the service op = serviceusage.EnableApiCall(project_id, service_name) if not is_async and not op.done: op = services_util.WaitOperation(op.name, serviceusage.GetOperation) services_util.PrintOperation(op)
def Run(self, args): """Run 'services vpc-peerings connect'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: Nothing. """ project = properties.VALUES.core.project.Get(required=True) project_number = _GetProjectNumber(project) ranges = args.ranges.split(',') op = peering.CreateConnection(project_number, args.service, args.network, ranges) 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, peering.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)
def Run(self, args): """Run 'services peered-dns-domains create'. Args: args: argparse.Namespace, The arguments that this command was invoked with. """ project = properties.VALUES.core.project.Get(required=True) project_number = _GetProjectNumber(project) op = peering.CreatePeeredDnsDomain( project_number, args.service, args.network, args.name, args.dns_suffix, ) 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, peering.GetOperation) services_util.PrintOperation(op)