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:
      Some value that we want to have printed later.
    """
    source_backup_ref = args.CONCEPTS.source.Parse()
    destination_backup_ref = args.CONCEPTS.destination.Parse()
    op = backups.CopyBackup(source_backup_ref, destination_backup_ref, args)

    operation_ref = util.GetOperationRef(op)
    if args.async_:
      log.status.Print('Copy request issued from [{}] to [{}]\n'
                       'Check operation [{}] for status.'.format(
                           source_backup_ref.RelativeName(),
                           destination_backup_ref.RelativeName(), op.name))
      return op

    op_result = util.AwaitBackup(
        operation_ref, 'Waiting for operation [{}] to complete'.format(op.name))
    if op.error is None:
      log.CreatedResource(op_result)
    return op_result
    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.

    Raises:
      ConflictingArgumentsException:
          If both cluster and multi_cluster are present.
          If both multi_cluster and transactional_writes are present.
      OneOfArgumentsRequiredException: If neither cluster or multi_cluster are
          present.

    Returns:
      Updated resource.
    """
        app_profile_ref = args.CONCEPTS.app_profile.Parse()
        try:
            result = self._UpdateAppProfile(app_profile_ref, args)
        except HttpError as e:
            util.FormatErrorMessages(e)
        else:
            operation_ref = util.GetOperationRef(result)

            if args.async_:
                log.UpdatedResource(operation_ref,
                                    kind='bigtable app profile {0}'.format(
                                        app_profile_ref.Name()),
                                    is_async=True)
                return result

            return util.AwaitAppProfile(
                operation_ref, 'Updating bigtable app profile {0}'.format(
                    app_profile_ref.Name()))
Exemplo n.º 3
0
    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:
      Some value that we want to have printed later.
    """
        cli = bigtable_util.GetAdminClient()
        ref = bigtable_util.GetInstanceRef(args.instance)
        parent_ref = resources.REGISTRY.Create('bigtableadmin.projects',
                                               projectId=ref.projectsId)
        msgs = bigtable_util.GetAdminMessages()

        instance_type = msgs.Instance.TypeValueValuesEnum(args.instance_type)
        num_nodes = arguments.ProcessInstanceTypeAndNodes(args, instance_type)

        msg = msgs.CreateInstanceRequest(
            instanceId=ref.Name(),
            parent=parent_ref.RelativeName(),
            instance=msgs.Instance(displayName=args.display_name,
                                   type=msgs.Instance.TypeValueValuesEnum(
                                       args.instance_type)),
            clusters=msgs.CreateInstanceRequest.
            ClustersValue(additionalProperties=[
                msgs.CreateInstanceRequest.ClustersValue.AdditionalProperty(
                    key=args.cluster,
                    value=msgs.Cluster(
                        serveNodes=num_nodes,
                        defaultStorageType=(
                            msgs.Cluster.DefaultStorageTypeValueValuesEnum(
                                args.cluster_storage_type.upper())),
                        # TODO(b/36056455): switch location to resource
                        # when b/29566669 is fixed on API
                        location=bigtable_util.LocationUrl(args.cluster_zone)))
            ]))
        result = cli.projects_instances.Create(msg)
        operation_ref = bigtable_util.GetOperationRef(result)

        if args.async_:
            log.CreatedResource(operation_ref,
                                kind='bigtable instance {0}'.format(
                                    ref.Name()),
                                is_async=True)
            return result

        return bigtable_util.AwaitInstance(
            operation_ref, 'Creating bigtable instance {0}'.format(ref.Name()))
Exemplo n.º 4
0
    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:
      Some value that we want to have printed later.
    """
        cli = util.GetAdminClient()
        ref = args.CONCEPTS.instance.Parse()
        # TODO(b/153576330): This is a workaround for inconsistent collection names.
        parent_ref = resources.REGISTRY.Create('bigtableadmin.projects',
                                               projectId=ref.projectsId)
        msgs = util.GetAdminMessages()
        instance_type = msgs.Instance.TypeValueValuesEnum(args.instance_type)

        clusters = self._Clusters(args)
        clusters_properties = []
        for cluster_id, cluster in sorted(clusters.items()):
            clusters_properties.append(
                msgs.CreateInstanceRequest.ClustersValue.AdditionalProperty(
                    key=cluster_id, value=cluster))

        msg = msgs.CreateInstanceRequest(
            instanceId=ref.Name(),
            parent=parent_ref.RelativeName(),
            instance=msgs.Instance(displayName=args.display_name,
                                   type=instance_type),
            clusters=msgs.CreateInstanceRequest.ClustersValue(
                additionalProperties=clusters_properties))
        result = cli.projects_instances.Create(msg)
        operation_ref = util.GetOperationRef(result)

        if args.async_:
            log.CreatedResource(operation_ref.RelativeName(),
                                kind='bigtable instance {0}'.format(
                                    ref.Name()),
                                is_async=True)
            return result

        return util.AwaitInstance(
            operation_ref, 'Creating bigtable instance {0}'.format(ref.Name()))
Exemplo n.º 5
0
    def _Run(self, args):
        """Implements Run() with different possible features flags."""
        cluster_ref = args.CONCEPTS.cluster.Parse()
        operation = clusters.PartialUpdate(
            cluster_ref,
            nodes=args.num_nodes,
            autoscaling_min=args.autoscaling_min_nodes,
            autoscaling_max=args.autoscaling_max_nodes,
            autoscaling_cpu_target=args.autoscaling_cpu_target,
            disable_autoscaling=args.disable_autoscaling)
        if not args.async_:
            operation_ref = util.GetOperationRef(operation)
            return util.AwaitCluster(
                operation_ref,
                'Updating bigtable cluster {0}'.format(cluster_ref.Name()))

        log.UpdatedResource(cluster_ref.Name(),
                            kind='cluster',
                            is_async=args.async_)
        return None
Exemplo n.º 6
0
  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
    """
    cluster_ref = args.CONCEPTS.cluster.Parse()
    operation = clusters.Update(cluster_ref, args.num_nodes)
    if not args.async:
      operation_ref = util.GetOperationRef(operation)
      return util.AwaitCluster(
          operation_ref,
          'Updating bigtable cluster {0}'.format(cluster_ref.Name()))

    log.UpdatedResource(cluster_ref.Name(), kind='cluster', is_async=args.async)
    return None
Exemplo n.º 7
0
  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.

    Raises:
      exceptions.ConflictingArgumentsException: If the user provides
        --transactional-writes and --route-any.

    Returns:
      Created resource.
    """
    app_profile_ref = args.CONCEPTS.app_profile.Parse()
    try:
      result = app_profiles.Update(
          app_profile_ref,
          cluster=args.route_to,
          description=args.description,
          multi_cluster=args.route_any,
          transactional_writes=args.transactional_writes,
          force=args.force)
    except HttpError as e:
      util.FormatErrorMessages(e)
    else:
      operation_ref = util.GetOperationRef(result)

      if args.async:
        log.UpdatedResource(
            operation_ref,
            kind='bigtable app-profile {0}'.format(app_profile_ref.Name()),
            is_async=True)
        return result

      return util.AwaitAppProfile(
          operation_ref,
          'Updating bigtable app-profile {0}'.format(app_profile_ref.Name()))
Exemplo n.º 8
0
    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:
      Some value that we want to have printed later.
    """
        cli = util.GetAdminClient()
        msgs = util.GetAdminMessages()
        backup_ref = args.CONCEPTS.source.Parse()  # backup
        table_ref = args.CONCEPTS.destination.Parse()  # table

        restore_request = msgs.RestoreTableRequest(
            # Full backup name.
            backup=backup_ref.RelativeName(),
            # Table id
            tableId=table_ref.Name())

        msg = (
            msgs.BigtableadminProjectsInstancesTablesRestoreRequest(
                # The name of the instance in which to create the restored table.
                parent=table_ref.Parent().RelativeName(),
                restoreTableRequest=restore_request))

        operation = cli.projects_instances_tables.Restore(msg)
        operation_ref = util.GetOperationRef(operation)
        if args.async_:
            log.CreatedResource(operation_ref.RelativeName(),
                                kind='bigtable table {0}'.format(
                                    table_ref.Name()),
                                is_async=True)
            return
        return util.AwaitTable(
            operation_ref,
            'Creating bigtable table {0}'.format(table_ref.Name()))
Exemplo n.º 9
0
  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:
      Some value that we want to have printed later.
    """
    cluster_ref = args.CONCEPTS.cluster.Parse()
    operation = clusters.Create(
        cluster_ref, args.zone, serve_nodes=args.num_nodes)
    operation_ref = util.GetOperationRef(operation)
    if args.async_:
      log.CreatedResource(
          operation_ref,
          kind='bigtable cluster {0}'.format(cluster_ref.Name()),
          is_async=True)
      return
    return util.AwaitCluster(
        operation_ref,
        'Creating bigtable cluster {0}'.format(cluster_ref.Name()))
Exemplo n.º 10
0
    def _Run(self, args):
        """Implements Run() with different possible features flags."""

        cli = util.GetAdminClient()
        ref = args.CONCEPTS.instance.Parse()
        # TODO(b/153576330): This is a workaround for inconsistent collection names.
        parent_ref = resources.REGISTRY.Create('bigtableadmin.projects',
                                               projectId=ref.projectsId)
        msgs = util.GetAdminMessages()
        instance_type = msgs.Instance.TypeValueValuesEnum(args.instance_type)

        new_clusters = self._Clusters(args)
        clusters_properties = []
        for cluster_id, cluster in sorted(new_clusters.items()):
            clusters_properties.append(
                msgs.CreateInstanceRequest.ClustersValue.AdditionalProperty(
                    key=cluster_id, value=cluster))

        msg = msgs.CreateInstanceRequest(
            instanceId=ref.Name(),
            parent=parent_ref.RelativeName(),
            instance=msgs.Instance(displayName=args.display_name,
                                   type=instance_type),
            clusters=msgs.CreateInstanceRequest.ClustersValue(
                additionalProperties=clusters_properties))
        result = cli.projects_instances.Create(msg)
        operation_ref = util.GetOperationRef(result)

        if args.async_:
            log.CreatedResource(operation_ref.RelativeName(),
                                kind='bigtable instance {0}'.format(
                                    ref.Name()),
                                is_async=True)
            return result

        return util.AwaitInstance(
            operation_ref, 'Creating bigtable instance {0}'.format(ref.Name()))