Skip to content
Browse files

Add cbc-bucket-delete command

Change-Id: I1b3c4a061118eeb41475191d10c1459614cbcbda
Reviewed-on: http://review.couchbase.org/17503
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
  • Loading branch information...
1 parent c131ec9 commit 32a2f6bfc07db9e56e95c3e3b93912c355c3098a @avsej avsej committed with trondn
Showing with 35 additions and 4 deletions.
  1. +4 −3 Makefile.am
  2. +31 −1 tools/cbc.cc
View
7 Makefile.am
@@ -247,9 +247,10 @@ example_pillowfight_SOURCES = tools/commandlineparser.cc example/pillowfight.cc
example_pillowfight_LDADD = libcouchbase.la
if BUILD_TOOLS
-CBC_LINKS = cbc-cat cbc-rm cbc-cp cbc-stats cbc-flush cbc-create \
- cbc-send cbc-receive cbc-version cbc-verify cbc-lock \
- cbc-unlock cbc-hash cbc-view cbc-admin cbc-bucket-create
+CBC_LINKS = cbc-cat cbc-rm cbc-cp cbc-stats cbc-flush cbc-create \
+ cbc-send cbc-receive cbc-version cbc-verify cbc-lock \
+ cbc-unlock cbc-hash cbc-view cbc-admin cbc-bucket-create \
+ cbc-bucket-delete
install-exec-hook:
cd $(DESTDIR)$(bindir) && \
View
32 tools/cbc.cc
@@ -59,7 +59,8 @@ enum cbc_command_t {
cbc_help,
cbc_view,
cbc_admin,
- cbc_bucket_create
+ cbc_bucket_create,
+ cbc_bucket_delete
};
extern "C" {
@@ -504,6 +505,24 @@ static bool admin_impl(libcouchbase_t instance, string &query, string &data,
return true;
}
+static bool bucket_delete_impl(libcouchbase_t instance, list<string> &names)
+{
+ libcouchbase_error_t rc;
+
+ for (list<string>::iterator iter = names.begin(); iter != names.end(); ++iter) {
+ string query = "/pools/default/buckets/" + *iter;
+ libcouchbase_make_management_request(instance, NULL, query.c_str(), query.length(),
+ NULL, 0, LIBCOUCHBASE_HTTP_METHOD_DELETE,
+ false, &rc);
+ if (rc != LIBCOUCHBASE_SUCCESS) {
+ cerr << "Failed to send requests: " << endl
+ << libcouchbase_strerror(instance, rc) << endl;
+ return false;
+ }
+ }
+ return true;
+}
+
static bool bucket_create_impl(libcouchbase_t instance, list<string> &names,
string &bucket_type, string &auth_type, int ram_quota,
string &sasl_password, int replica_num, int proxy_port)
@@ -1065,6 +1084,14 @@ static void handleCommandLineOptions(enum cbc_command_t cmd, int argc, char **ar
"a-z, 0-9 as well as underscore, period, dash & percent" << endl;
}
break;
+ case cbc_bucket_delete:
+ if (verifyBucketNames(getopt.arguments)) {
+ success = bucket_delete_impl(instance, getopt.arguments);
+ } else {
+ cerr << "Bucket name can only contain characters in range A-Z, "
+ "a-z, 0-9 as well as underscore, period, dash & percent" << endl;
+ }
+ break;
default:
cerr << "Not implemented" << endl;
success = false;
@@ -1132,6 +1159,8 @@ static cbc_command_t getBuiltin(string name)
return cbc_admin;
} else if (name.find("cbc-bucket-create") != string::npos) {
return cbc_bucket_create;
+ } else if (name.find("cbc-bucket-delete") != string::npos) {
+ return cbc_bucket_delete;
}
return cbc_illegal;
@@ -1156,6 +1185,7 @@ static void printHelp()
<< " view execute couchbase view (aka map/reduce) request" << endl
<< " admin execute request to management REST API" << endl
<< " bucket-create create data bucket on the cluster" << endl
+ << " bucket-delete delete data bucket" << endl
<< "Use 'cbc command --help' to show the options" << endl;
}

0 comments on commit 32a2f6b

Please sign in to comment.
Something went wrong with that request. Please try again.