add destroy option to lxc-snapshot

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
S.Çağlar Onur 2013-12-03 15:13:22 -05:00 committed by Serge Hallyn
parent 2b25068a3d
commit 00194067f1

View File

@ -41,6 +41,7 @@ char *snapshot;
#define DO_SNAP 0 #define DO_SNAP 0
#define DO_LIST 1 #define DO_LIST 1
#define DO_RESTORE 2 #define DO_RESTORE 2
#define DO_DESTROY 3
int action; int action;
int print_comments; int print_comments;
char *commentfile; char *commentfile;
@ -100,7 +101,7 @@ int do_list_snapshots(struct lxc_container *c)
return 0; return 0;
} }
int do_restore_snapshots(struct lxc_container *c, char *snap, char *new) int do_restore_snapshots(struct lxc_container *c)
{ {
if (c->snapshot_restore(c, snapshot, newname)) if (c->snapshot_restore(c, snapshot, newname))
return 0; return 0;
@ -109,11 +110,21 @@ int do_restore_snapshots(struct lxc_container *c, char *snap, char *new)
return -1; return -1;
} }
int do_destroy_snapshots(struct lxc_container *c)
{
if (c->snapshot_destroy(c, snapshot))
return 0;
ERROR("Error destroying snapshot %s", snapshot);
return -1;
}
static int my_parser(struct lxc_arguments* args, int c, char* arg) static int my_parser(struct lxc_arguments* args, int c, char* arg)
{ {
switch (c) { switch (c) {
case 'L': action = DO_LIST; break; case 'L': action = DO_LIST; break;
case 'r': snapshot = arg; action = DO_RESTORE; break; case 'r': snapshot = arg; action = DO_RESTORE; break;
case 'd': snapshot = arg; action = DO_DESTROY; break;
case 'c': commentfile = arg; break; case 'c': commentfile = arg; break;
case 'C': print_comments = true; break; case 'C': print_comments = true; break;
} }
@ -123,6 +134,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
static const struct option my_longopts[] = { static const struct option my_longopts[] = {
{"list", no_argument, 0, 'L'}, {"list", no_argument, 0, 'L'},
{"restore", required_argument, 0, 'r'}, {"restore", required_argument, 0, 'r'},
{"destroy", required_argument, 0, 'd'},
{"comment", required_argument, 0, 'c'}, {"comment", required_argument, 0, 'c'},
{"showcomments", no_argument, 0, 'C'}, {"showcomments", no_argument, 0, 'C'},
LXC_COMMON_OPTIONS LXC_COMMON_OPTIONS
@ -141,7 +153,8 @@ Options :\n\
-L, --list list snapshots\n\ -L, --list list snapshots\n\
-C, --showcomments show snapshot comments in list\n\ -C, --showcomments show snapshot comments in list\n\
-c, --comment=file add file as a comment\n\ -c, --comment=file add file as a comment\n\
-r, --restore=name restore snapshot name, i.e. 'snap0'\n", -r, --restore=name restore snapshot name, i.e. 'snap0'\n\
-d, --destroy=name destroy snapshot name, i.e. 'snap0'\n",
.options = my_longopts, .options = my_longopts,
.parser = my_parser, .parser = my_parser,
.checker = NULL, .checker = NULL,
@ -202,7 +215,10 @@ int main(int argc, char *argv[])
ret = do_list_snapshots(c); ret = do_list_snapshots(c);
break; break;
case DO_RESTORE: case DO_RESTORE:
ret = do_restore_snapshots(c, snapshot, newname); ret = do_restore_snapshots(c);
break;
case DO_DESTROY:
ret = do_destroy_snapshots(c);
break; break;
} }