def Run(self, args):
    apis = apis_client.ApiClient()
    api_configs = api_configs_client.ApiConfigClient()
    ops = operations_client.OperationsClient()

    api_config_ref = args.CONCEPTS.api_config.Parse()
    api_ref = api_config_ref.Parent()

    service_name = common_flags.ProcessApiRefToEndpointsService(api_ref)

    # Check if OP service exists with Api name, create if not, activate it
    if not endpoints.DoesServiceExist(service_name):
      endpoints.CreateService(service_name, api_ref.projectsId)

    # Check to see if Api exists, create if not
    if not apis.DoesExist(api_ref):
      res = apis.Create(api_ref, service_name)
      operations_util.PrintOperationResult(
          res.name, ops,
          wait_string='Waiting for API [{}] to be created'.format(
              api_ref.Name()))

    # Create OP ServiceConfig and Rollout

    # Creating a suffix to avoid name collisions on ServiceConfig IDs.
    suffix = '-' + str(int(time.time()))
    length = MAX_SERVICE_CONFIG_ID_LENGTH - len(suffix)
    config_id = api_config_ref.Name()[:length] + suffix

    if args.openapi_spec:
      service_config_id = self.__PushOpenApiServiceFile(
          args.openapi_spec,
          service_name,
          api_config_ref.projectsId,
          config_id=config_id)
    else:
      service_config_id = self.__PushGrpcConfigFiles(
          args.grpc_files,
          service_name,
          api_config_ref.projectsId,
          config_id=config_id)
    rollout = endpoints.CreateRollout(service_config_id, service_name)

    # Create ApiConfig object using the service config and rollout
    # Only piece affected by async right now
    resp = api_configs.Create(api_config_ref,
                              rollout['rolloutId'],
                              labels=args.labels,
                              display_name=args.display_name,
                              backend_auth=args.backend_auth_service_account)

    wait = 'Waiting for API Config [{}] to be created for API [{}]'.format(
        api_config_ref.Name(), api_ref.Name())

    return operations_util.PrintOperationResult(
        resp.name,
        ops,
        service=api_configs.service,
        wait_string=wait,
        is_async=args.async_)
    def Run(self, args):
        apis = apis_client.ApiClient()
        api_configs = api_configs_client.ApiConfigClient()
        ops = operations_client.OperationsClient()

        api_config_ref = args.CONCEPTS.api_config.Parse()
        api_ref = api_config_ref.Parent()

        service_name = '{}.apigateway.{}.cloud.goog'.format(
            api_ref.Name(), api_ref.projectsId)

        # Check if OP service exists with Api name, create if not, activate it
        if not endpoints.DoesServiceExist(service_name):
            endpoints.CreateService(service_name, api_ref.projectsId)

        # Check to see if Api exists, create if not
        if not apis.DoesExist(api_ref):
            res = apis.Create(api_ref, service_name)
            ops.GetOperationResult(res)

        # Create OP ServiceConfig and Rollout
        if args.openapi_spec:
            service_config_id = self.__PushOpenApiServiceFile(
                args.openapi_spec,
                service_name,
                api_config_ref.projectsId,
                config_id=api_config_ref.Name())
        else:
            service_config_id = self.__PushGrpcConfigFiles(
                args.grpc_files,
                service_name,
                api_config_ref.projectsId,
                config_id=api_config_ref.Name())
        rollout = endpoints.CreateRollout(service_config_id, service_name)

        # Create ApiConfig object using the service config and rollout
        # Only piece affected by async right now
        resp = api_configs.Create(
            api_config_ref,
            rollout['rolloutId'],
            labels=args.labels,
            display_name=args.display_name,
            backend_auth=args.backend_auth_service_account)

        return ops.GetOperationResult(resp, is_async=args.async_)
Exemple #3
0
    def Run(self, args):
        apis = apis_client.ApiClient()
        api_configs = api_configs_client.ApiConfigClient()
        ops = operations_client.OperationsClient()

        api_config_ref = args.CONCEPTS.api_config.Parse()
        api_ref = api_config_ref.Parent()

        service_name = '{}.apigateway.{}.cloud.goog'.format(
            api_ref.Name(), api_ref.projectsId)

        # Check if OP service exists with Api name, create if not, activate it
        if not endpoints.DoesServiceExist(service_name):
            endpoints.CreateService(service_name, api_ref.projectsId)

        # Check to see if Api exists, create if not
        if not apis.DoesExist(api_ref):
            res = apis.Create(api_ref, service_name)
            operation_ref = resources.REGISTRY.Parse(
                res.name,
                collection='apigateway.projects.locations.operations')

            ops.WaitForOperation(
                operation_ref,
                'Waiting for API [{}] to be created'.format(api_ref.Name()))

        # Create OP ServiceConfig and Rollout
        if args.openapi_spec:
            service_config_id = self.__PushOpenApiServiceFile(
                args.openapi_spec,
                service_name,
                api_config_ref.projectsId,
                config_id=api_config_ref.Name())
        else:
            service_config_id = self.__PushGrpcConfigFiles(
                args.grpc_files,
                service_name,
                api_config_ref.projectsId,
                config_id=api_config_ref.Name())
        rollout = endpoints.CreateRollout(service_config_id, service_name)

        # Create ApiConfig object using the service config and rollout
        # Only piece affected by async right now
        resp = api_configs.Create(
            api_config_ref,
            rollout['rolloutId'],
            labels=args.labels,
            display_name=args.display_name,
            backend_auth=args.backend_auth_service_account)
        operation_ref = resources.REGISTRY.Parse(
            resp.name, collection='apigateway.projects.locations.operations')

        # If async operation, simply log and return the result on passed in object
        if args.async_:
            operations_util.PrintOperationResultWithWaitEpilogue(
                operation_ref, 'Asynchronous operation is in progress')
            return resp

        return ops.WaitForOperation(
            operation_ref,
            'Waiting for API Config [{}] to be created for API [{}]'.format(
                api_config_ref.Name(), api_ref.Name()),
            api_configs.client.projects_locations_apis_configs)