Ejemplo n.º 1
0
 def testList(self):
     operation = self.msgs.Operation()
     response = self.msgs.ListOperationsResponse(operations=[operation])
     ref = resources.REGISTRY.Parse('insId',
                                    params={'projectsId': self.Project()},
                                    collection='spanner.projects.instances')
     self.client.projects_instances_operations.List.Expect(
         request=self.msgs.SpannerProjectsInstancesOperationsListRequest(
             name=ref.RelativeName() + '/operations', pageSize=100),
         response=response)
     self.assertCountEqual(instance_operations.List('insId'), [operation])
Ejemplo n.º 2
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.
    """
        if args.database:
            return database_operations.List(args.instance, args.database)
        else:
            return instance_operations.List(args.instance)
def _CommonRun(args):
  """Performs run actions common to all List stages."""
  is_database_type = (
      args.type == 'DATABASE_RESTORE' or args.type == 'DATABASE' or
      args.type == 'DATABASE_CREATE' or args.type == 'DATABASE_UPDATE_DDL')

  if args.backup or args.type == 'BACKUP':
    # Update output table for backup operations.
    # pylint:disable=protected-access
    args._GetParser().ai.display_info.AddFormat("""
          table(
            name.basename():label=OPERATION_ID,
            done():label=DONE,
            metadata.'@type'.split('.').slice(-1:).join(),
            metadata.name.split('/').slice(-1:).join():label=BACKUP,
            metadata.database.split('/').slice(-1).join():label=SOURCE_DATABASE,
            metadata.progress.startTime:label=START_TIME,
            metadata.progress.endTime:label=END_TIME
          )
        """)

  if args.type == 'DATABASE_RESTORE':
    # Update output table for restore operations.
    # pylint:disable=protected-access
    args._GetParser().ai.display_info.AddFormat("""
          table(
            name.basename():label=OPERATION_ID,
            done():label=DONE,
            metadata.'@type'.split('.').slice(-1:).join(),
            metadata.name.split('/').slice(-1:).join():label=RESTORED_DATABASE,
            metadata.backupInfo.backup.split('/').slice(-1).join():label=SOURCE_BACKUP,
            metadata.progress.startTime:label=START_TIME,
            metadata.progress.endTime:label=END_TIME
          )
        """)
  elif is_database_type:
    # Update output table for database operations.
    # pylint:disable=protected-access
    args._GetParser().ai.display_info.AddFormat("""
          table(
            name.basename():label=OPERATION_ID,
            metadata.statements.join(sep="\n"),
            done():label=DONE,
            metadata.'@type'.split('.').slice(-1:).join(),
            database().split('/').slice(-1:).join():label=DATABASE_ID
          )
        """)

  # Checks that user only specified either database or backup flag.
  if (args.IsSpecified('database') and args.IsSpecified('backup')):
    raise c_exceptions.InvalidArgumentException(
        '--database or --backup',
        'Must specify either --database or --backup. To search backups for a '
        'specific database, use the --database flag with --type=BACKUP')

  # Checks that the user did not specify the backup flag with the type filter
  # set to a database operation type.
  if (args.IsSpecified('backup') and is_database_type):
    raise c_exceptions.InvalidArgumentException(
        '--backup or --type',
        'The backup flag cannot be used with the type flag set to a '
        'database operation type.')

  if args.type == 'INSTANCE':
    if args.IsSpecified('database'):
      raise c_exceptions.InvalidArgumentException(
          '--database or --type',
          'The `--database` flag cannot be used with `--type=INSTANCE`.')
    if args.IsSpecified('backup'):
      raise c_exceptions.InvalidArgumentException(
          '--backup or --type',
          'The `--backup` flag cannot be used with `--type=INSTANCE`.')

  if args.type == 'BACKUP':
    if args.database:
      db_filter = backup_operations.BuildDatabaseFilter(args.instance,
                                                        args.database)
      return backup_operations.List(args.instance, db_filter)
    if args.backup:
      return backup_operations.ListGeneric(args.instance, args.backup)
    return backup_operations.List(args.instance)

  if is_database_type:
    type_filter = database_operations.BuildDatabaseOperationTypeFilter(
        args.type)
    return database_operations.ListDatabaseOperations(args.instance,
                                                      args.database,
                                                      type_filter)

  if args.backup:
    return backup_operations.ListGeneric(args.instance, args.backup)
  if args.database:
    return database_operations.List(args.instance, args.database)

  return instance_operations.List(args.instance)