~ubuntu-branches/ubuntu/quantal/ceph/quantal

« back to all changes in this revision

Viewing changes to src/rgw/rgw_admin.cc

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-08-27 08:23:21 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20120827082321-2cfej6ddvk63vsqq
Tags: upstream-0.48.1
ImportĀ upstreamĀ versionĀ 0.48.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
  cerr << "                             + bucket-id)\n";
56
56
  cerr << "  log rm                     remove log object\n";
57
57
  cerr << "  usage show                 show usage (by user, date range)\n";
58
 
  cerr << "  usage trim                 show usage (by user, date range)\n";
 
58
  cerr << "  usage trim                 trim usage (by user, date range)\n";
59
59
  cerr << "  temp remove                remove temporary objects that were created up to\n";
60
60
  cerr << "                             specified date (and optional time)\n";
61
61
  cerr << "options:\n";
74
74
  cerr << "   --bucket=<bucket>\n";
75
75
  cerr << "   --pool=<pool>\n";
76
76
  cerr << "   --object=<object>\n";
77
 
  cerr << "   --date=<yyyy-mm-dd>\n";
78
 
  cerr << "   --start-date=<yyyy-mm-dd>\n";
79
 
  cerr << "   --end-date=<yyyy-mm-dd>\n";
80
 
  cerr << "   --time=<HH:MM:SS>\n";
 
77
  cerr << "   --date=<date>\n";
 
78
  cerr << "   --start-date=<date>\n";
 
79
  cerr << "   --end-date=<date>\n";
81
80
  cerr << "   --bucket-id=<bucket-id>\n";
82
81
  cerr << "   --format=<format>         specify output format for certain operations: xml,\n";
83
82
  cerr << "                             json\n";
90
89
  cerr << "   --skip-zero-entries       log show only dumps entries that don't have zero value\n";
91
90
  cerr << "                             in one of the numeric field\n";
92
91
  cerr << "   --yes-i-really-mean-it    required for certain operations\n";
 
92
  cerr << "\n";
 
93
  cerr << "<date> := \"YYYY-MM-DD[ hh:mm:ss]\"\n";
 
94
  cerr << "\n";
93
95
  generic_client_usage();
94
96
}
95
97
 
514
516
  KEY_TYPE_S3,
515
517
};
516
518
 
517
 
static void parse_date(string& date, uint64_t *epoch)
 
519
static void parse_date(string& date, uint64_t *epoch, string *out_date = NULL, string *out_time = NULL)
518
520
{
519
521
  struct tm tm;
520
522
 
521
523
  memset(&tm, 0, sizeof(tm));
522
524
 
523
525
  const char *p = strptime(date.c_str(), "%Y-%m-%d", &tm);
524
 
  if (p && !*p) { // success!
525
 
    time_t t = timegm(&tm);
 
526
  if (p) {
 
527
    if (*p == ' ') {
 
528
      p++;
 
529
      strptime(p, " %H:%M:%S", &tm);
 
530
    }
 
531
  } else {
 
532
    return;
 
533
  }
 
534
  time_t t = timegm(&tm);
 
535
  if (epoch)
526
536
    *epoch = (uint64_t)t;
 
537
 
 
538
  if (out_date) {
 
539
    char buf[32];
 
540
    strftime(buf, sizeof(buf), "%F", &tm);
 
541
    *out_date = buf;
 
542
  }
 
543
  if (out_time) {
 
544
    char buf[32];
 
545
    strftime(buf, sizeof(buf), "%T", &tm);
 
546
    *out_time = buf;
527
547
  }
528
548
}
529
549
 
538
558
 
539
559
  std::string user_id, access_key, secret_key, user_email, display_name;
540
560
  std::string bucket_name, pool_name, object;
541
 
  std::string date, time, subuser, access, format;
 
561
  std::string date, subuser, access, format;
542
562
  std::string start_date, end_date;
543
563
  std::string key_type_str;
544
564
  ObjectKeyType key_type = KEY_TYPE_S3;
545
565
  rgw_bucket bucket;
546
566
  uint32_t perm_mask = 0;
 
567
  bool specified_perm_mask = false;
547
568
  uint64_t auid = -1;
548
569
  RGWUserInfo info;
549
570
  RGWRados *store;
623
644
      auid = tmp;
624
645
    } else if (ceph_argparse_witharg(args, i, &val, "--max-buckets", (char*)NULL)) {
625
646
      max_buckets = atoi(val.c_str());
626
 
    } else if (ceph_argparse_witharg(args, i, &val, "--date", (char*)NULL)) {
 
647
    } else if (ceph_argparse_witharg(args, i, &val, "--date", "--time", (char*)NULL)) {
627
648
      date = val;
628
649
      if (end_date.empty())
629
650
        end_date = date;
630
 
    } else if (ceph_argparse_witharg(args, i, &val, "--start-date", (char*)NULL)) {
 
651
    } else if (ceph_argparse_witharg(args, i, &val, "--start-date", "--start-time", (char*)NULL)) {
631
652
      start_date = val;
632
 
    } else if (ceph_argparse_witharg(args, i, &val, "--end-date", (char*)NULL)) {
 
653
    } else if (ceph_argparse_witharg(args, i, &val, "--end-date", "--end-time", (char*)NULL)) {
633
654
      end_date = val;
634
 
    } else if (ceph_argparse_witharg(args, i, &val, "--time", (char*)NULL)) {
635
 
      time = val;
636
655
    } else if (ceph_argparse_witharg(args, i, &val, "--access", (char*)NULL)) {
637
656
      access = val;
638
657
      perm_mask = str_to_perm(access.c_str());
 
658
      specified_perm_mask = true;
639
659
    } else if (ceph_argparse_witharg(args, i, &val, "--bucket-id", (char*)NULL)) {
640
660
      bucket_id = val;
641
661
      if (bucket_id.empty()) {
845
865
  map<string, RGWSubUser>::iterator uiter;
846
866
  RGWUserInfo old_info = info;
847
867
 
848
 
  if ((!bucket_name.empty()) || !bucket_id.empty()) {
849
 
    if (!bucket_id.empty()) {
850
 
      int ret = rgwstore->get_bucket_info(NULL, bucket_id, bucket_info);
851
 
 
852
 
      if (ret < 0) {
853
 
        cerr << "could not retrieve bucket info for bucket_id=" << bucket_id << std::endl;
854
 
        return ret;
855
 
      }
856
 
      bucket = bucket_info.bucket;
857
 
      if ((!bucket_name.empty()) && bucket.name.compare(bucket_name.c_str()) != 0) {
858
 
        cerr << "bucket name does not match bucket id (expected bucket name: " << bucket.name << ")" << std::endl;
859
 
        return -EINVAL;
860
 
      }
861
 
    } else {
862
 
      string bucket_name_str = bucket_name;
863
 
      RGWBucketInfo bucket_info;
864
 
      int r = rgwstore->get_bucket_info(NULL, bucket_name_str, bucket_info);
865
 
      if (r < 0) {
866
 
        cerr << "could not get bucket info for bucket=" << bucket_name_str << std::endl;
867
 
        return r;
868
 
      }
869
 
      bucket = bucket_info.bucket;
870
 
      bucket_id = bucket.bucket_id;
 
868
  if (!bucket_name.empty()) {
 
869
    string bucket_name_str = bucket_name;
 
870
    RGWBucketInfo bucket_info;
 
871
    int r = rgwstore->get_bucket_info(NULL, bucket_name_str, bucket_info);
 
872
    if (r < 0) {
 
873
      cerr << "could not get bucket info for bucket=" << bucket_name_str << std::endl;
 
874
      return r;
871
875
    }
 
876
    bucket = bucket_info.bucket;
872
877
  }
873
878
 
874
879
  int err;
915
920
    if (auid != (uint64_t)-1)
916
921
      info.auid = auid;
917
922
    if (!subuser.empty()) {
918
 
      RGWSubUser u;
 
923
      RGWSubUser u = info.subusers[subuser];
919
924
      u.name = subuser;
920
 
      u.perm_mask = perm_mask;
 
925
      if (specified_perm_mask)
 
926
        u.perm_mask = perm_mask;
921
927
 
922
928
      info.subusers[subuser] = u;
923
929
    }
1093
1099
      cerr << "date wasn't specified" << std::endl;
1094
1100
      return usage();
1095
1101
    }
1096
 
    int r = store->remove_temp_objects(date, time);
 
1102
    string parsed_date, parsed_time;
 
1103
    parse_date(date, NULL, &parsed_date, &parsed_time);
 
1104
    int r = store->remove_temp_objects(parsed_date, parsed_time);
1097
1105
    if (r < 0) {
1098
1106
      cerr << "failure removing temp objects: " << cpp_strerror(r) << std::endl;
1099
1107
      return 1;
1305
1313
  }
1306
1314
 
1307
1315
  if (opt_cmd == OPT_BUCKET_STATS) {
1308
 
    if (bucket_name.empty() && bucket_id.empty() && user_id.empty()) {
1309
 
      cerr << "either bucket or bucket-id or uid needs to be specified" << std::endl;
 
1316
    if (bucket_name.empty() && user_id.empty()) {
 
1317
      cerr << "either bucket or uid needs to be specified" << std::endl;
1310
1318
      return usage();
1311
1319
    }
1312
1320
    formatter->reset();