Example #1
0
def Await(op_ref, message, release_track, creates_resource=True):
  """Waits for the given google.longrunning.Operation to complete.

  Args:
    op_ref: The operation to poll.
    message: String to display for default progress_tracker.
    release_track: The API release track (e.g. ALPHA, BETA, etc.)
    creates_resource: Whether or not the operation creates a resource

  Raises:
    apitools.base.py.HttpError: if the request returns an HTTP error

  Returns:
    The Operation or the Resource the Operation is associated with.
  """
  client = api_util.AlloyDBClient(release_track)
  alloydb_client = client.alloydb_client
  if creates_resource:
    poller = waiter.CloudOperationPoller(
        alloydb_client.projects_locations_clusters_instances,
        alloydb_client.projects_locations_operations)
  else:
    poller = waiter.CloudOperationPollerNoResources(
        alloydb_client.projects_locations_operations)
  return waiter.WaitFor(
      poller, op_ref, message, exponential_sleep_multiplier=1.0, sleep_ms=10000)
  def Run(self, args):
    """Constructs and sends request.

    Args:
      args: argparse.Namespace, An object that contains the values for the
          arguments specified in the .Args() method.

    Returns:
      ProcessHttpResponse of the request made.
    """
    client = api_util.AlloyDBClient(self.ReleaseTrack())
    alloydb_client = client.alloydb_client
    alloydb_messages = client.alloydb_messages
    cluster_ref = client.resource_parser.Create(
        'alloydb.projects.locations.clusters',
        projectsId=properties.VALUES.core.project.GetOrFail,
        locationsId=args.region,
        clustersId=args.cluster)

    result = list_pager.YieldFromList(
        alloydb_client.projects_locations_clusters_instances,
        alloydb_messages
        .AlloydbProjectsLocationsClustersInstancesListRequest(
            parent=cluster_ref.RelativeName()),
        field='instances',
        limit=args.limit,
        batch_size=args.page_size,
        batch_size_attribute='pageSize')

    return result
Example #3
0
def Await(operation, message, creates_resource=True):
  """Waits for the given google.longrunning.Operation to complete.

  Args:
    operation: The operation to poll.
    message: String to display for default progress_tracker.
    creates_resource: Whether or not the operation creates a resource.

  Raises:
    apitools.base.py.HttpError: If the request returns an HTTP error.

  Returns:
    The Operation or the Resource the Operation is associated with.
  """
  client = api_util.AlloyDBClient(api_util.API_VERSION_DEFAULT)
  alloydb_client = client.alloydb_client
  if creates_resource:
    poller = waiter.CloudOperationPoller(
        alloydb_client.projects_locations_clusters,
        alloydb_client.projects_locations_operations)
  else:
    poller = waiter.CloudOperationPollerNoResources(
        alloydb_client.projects_locations_operations)
  ref = resources.REGISTRY.ParseRelativeName(
      operation.name,
      collection='alloydbadmin.projects.locations.operations')
  return waiter.WaitFor(poller, ref, message)
    def Run(self, args):
        """Constructs and sends request.

    Args:
      args: argparse.Namespace, An object that contains the values for the
          arguments specified in the .Args() method.

    Returns:
      ProcessHttpResponse of the request made.
    """
        client = api_util.AlloyDBClient(self.ReleaseTrack())
        alloydb_client = client.alloydb_client
        alloydb_messages = client.alloydb_messages
        cluster_ref = client.resource_parser.Create(
            'alloydb.projects.locations.clusters',
            projectsId=properties.VALUES.core.project.GetOrFail,
            locationsId=args.region,
            clustersId=args.cluster)

        prompt_message = (
            'All of the cluster data will be lost when the cluster is deleted.'
        )
        if not console_io.PromptContinue(message=prompt_message):
            return None

        req = alloydb_messages.AlloydbProjectsLocationsClustersDeleteRequest(
            name=cluster_ref.RelativeName(), force=args.force)
        op = alloydb_client.projects_locations_clusters.Delete(req)
        op_ref = resources.REGISTRY.ParseRelativeName(
            op.name, collection='alloydb.projects.locations.operations')
        log.status.Print('Operation ID: {}'.format(op_ref.Name()))
        if not args.async_:
            cluster_operations.Await(op_ref, 'Deleting cluster',
                                     self.ReleaseTrack(), False)
        return op
Example #5
0
    def Run(self, args):
        """Constructs and sends request.

    Args:
      args: argparse.Namespace, An object that contains the values for the
        arguments specified in the .Args() method.

    Returns:
      ProcessHttpResponse of the request made.
    """
        client = api_util.AlloyDBClient(self.ReleaseTrack())
        alloydb_client = client.alloydb_client
        alloydb_messages = client.alloydb_messages
        cluster_ref = client.resource_parser.Create(
            'alloydb.projects.locations.clusters',
            projectsId=properties.VALUES.core.project.GetOrFail,
            locationsId=args.region,
            clustersId=args.cluster)
        req = cluster_helper.ConstructPatchRequestFromArgs(
            alloydb_messages, cluster_ref, args)
        if not req.updateMask:
            parameters = [
                ('--automated-backup-* | --disable-automated-backup | '
                 '--clear-automated-backup')
            ]
            raise exceptions.MinimumArgumentException(
                parameters, 'Please specify at least one property to update')
        op = alloydb_client.projects_locations_clusters.Patch(req)
        op_ref = resources.REGISTRY.ParseRelativeName(
            op.name, collection='alloydb.projects.locations.operations')
        log.status.Print('Operation ID: {}'.format(op_ref.Name()))
        if not args.async_:
            cluster_operations.Await(op_ref, 'Updating cluster',
                                     self.ReleaseTrack(), False)
        return op
Example #6
0
  def Run(self, args):
    """Constructs and sends request.

    Args:
      args: argparse.Namespace, An object that contains the values for the
          arguments specified in the .Args() method.

    Returns:
      ProcessHttpResponse of the request made.
    """
    client = api_util.AlloyDBClient(self.ReleaseTrack())
    alloydb_client = client.alloydb_client
    alloydb_messages = client.alloydb_messages
    project_ref = client.resource_parser.Create(
        'alloydb.projects.locations.clusters.instances',
        projectsId=properties.VALUES.core.project.GetOrFail,
        locationsId=args.region,
        clustersId=args.cluster,
        instancesId=args.instance)
    req = alloydb_messages.AlloydbProjectsLocationsClustersInstancesRestartRequest(
        name=project_ref.RelativeName())
    op = alloydb_client.projects_locations_clusters_instances.Restart(req)
    op_ref = resources.REGISTRY.ParseRelativeName(
        op.name, collection='alloydb.projects.locations.operations')
    log.status.Print('Operation ID: {}'.format(op_ref.Name()))
    if not args.async_:
      instance_operations.Await(op_ref, 'Restarting instance', self.ReleaseTrack(), False)
    return op
    def Run(self, args):
        """Constructs and sends request.

    Args:
      args: argparse.Namespace, An object that contains the values for the
          arguments specified in the .Args() method.

    Returns:
      ProcessHttpResponse of the request made.
    """
        client = api_util.AlloyDBClient(self.ReleaseTrack())
        alloydb_client = client.alloydb_client
        alloydb_messages = client.alloydb_messages
        location_ref = client.resource_parser.Create(
            'alloydb.projects.locations',
            projectsId=properties.VALUES.core.project.GetOrFail,
            locationsId=args.region)
        cluster_resource = alloydb_messages.Cluster()
        cluster_resource.network = args.network
        cluster_resource.initialUser = alloydb_messages.UserPassword(
            password=args.password, user='******')
        req = alloydb_messages.AlloydbProjectsLocationsClustersCreateRequest(
            cluster=cluster_resource,
            clusterId=args.cluster,
            parent=location_ref.RelativeName())
        op = alloydb_client.projects_locations_clusters.Create(req)
        op_ref = resources.REGISTRY.ParseRelativeName(
            op.name, collection='alloydb.projects.locations.operations')
        log.status.Print('Operation ID: {}'.format(op_ref.Name()))
        if not args.async_:
            cluster_operations.Await(op_ref, 'Creating cluster',
                                     self.ReleaseTrack())
        return op
Example #8
0
  def Run(self, args):
    """Constructs and sends request.

    Args:
      args: argparse.Namespace, An object that contains the values for the
          arguments specified in the .Args() method.

    Returns:
      ProcessHttpResponse of the request made.
    """
    client = api_util.AlloyDBClient(self.ReleaseTrack())
    alloydb_client = client.alloydb_client
    alloydb_messages = client.alloydb_messages
    location_ref = client.resource_parser.Create(
        'alloydb.projects.locations',
        projectsId=properties.VALUES.core.project.GetOrFail,
        locationsId=args.region)
    cluster_ref = client.resource_parser.Create(
        'alloydb.projects.locations.clusters',
        projectsId=properties.VALUES.core.project.GetOrFail,
        locationsId=args.region,
        clustersId=args.cluster)
    backup_ref = client.resource_parser.Create(
        'alloydb.projects.locations.backups',
        projectsId=properties.VALUES.core.project.GetOrFail,
        locationsId=args.region,
        backupsId=args.backup)

    backup_resource = alloydb_messages.Backup()
    backup_resource.name = backup_ref.RelativeName()
    backup_resource.type = _ParseBackupType(alloydb_messages, 'ON_DEMAND')
    backup_resource.clusterName = cluster_ref.RelativeName()

    req = alloydb_messages.AlloydbProjectsLocationsBackupsCreateRequest(
        backup=backup_resource,
        backupId=args.backup,
        parent=location_ref.RelativeName())
    op = alloydb_client.projects_locations_backups.Create(req)
    op_ref = resources.REGISTRY.ParseRelativeName(
        op.name, collection='alloydb.projects.locations.operations')
    log.status.Print('Operation ID: {}'.format(op_ref.Name()))
    if not args.async_:
      backup_operations.Await(op_ref, 'Creating backup', self.ReleaseTrack())
    return op
    def Run(self, args):
        """Constructs and sends request.

    Args:
      args: argparse.Namespace, An object that contains the values for the
          arguments specified in the .Args() method.

    Returns:
      ProcessHttpResponse of the request made.
    """
        client = api_util.AlloyDBClient(self.ReleaseTrack())
        operation_ref = client.resource_parser.Create(
            'alloydb.projects.locations.operations',
            projectsId=properties.VALUES.core.project.GetOrFail,
            locationsId=args.region,
            operationsId=args.operation)
        req = client.alloydb_messages.AlloydbProjectsLocationsOperationsGetRequest(
            name=operation_ref.RelativeName())
        return client.alloydb_client.projects_locations_operations.Get(req)