diff options
Diffstat (limited to 'src/cresnap.c')
-rw-r--r-- | src/cresnap.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/cresnap.c b/src/cresnap.c new file mode 100644 index 0000000..04065fd --- /dev/null +++ b/src/cresnap.c @@ -0,0 +1,62 @@ +/* This file is part of Eclat. + Copyright (C) 2012 Sergey Poznyakoff. + + Eclat is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + Eclat is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Eclat. If not, see <http://www.gnu.org/licenses/>. */ + +#include "eclat.h" + +int +eclat_create_snapshot(CURL *curl, int argc, char **argv) +{ + int i, rc; + struct ec2_query *q; + struct grecs_txtacc *acc = NULL; + const char *descr = NULL; + + generic_proginfo->args_doc = "VOL-ID [DESCR]"; + generic_proginfo->docstring = "create a snapshot of an Amazon EBS volume"; + generic_parse_options("eclat create-snapshot", + "create a snapshot of an Amazon EBS volume", + argc, argv, &i); + argc -= i; + argv += i; + if (argc < 1) + die(EX_USAGE, "not enough arguments"); + translate_ids(1, argv, "VolumeId"); + if (argc == 2) + descr = argv[1]; + else if (argc > 2) { + acc = grecs_txtacc_create(); + for (i = 1; i < argc; i++) { + if (i > 1) + grecs_txtacc_grow_char(acc, ' '); + grecs_txtacc_grow(acc, argv[i], strlen(argv[i])); + } + grecs_txtacc_grow_char(acc, 0); + descr = grecs_txtacc_finish(acc, 0); + } + + q = eclat_query_create(use_ssl ? EC2_QF_HTTPS : 0, endpoint, "/"); + eclat_query_add_param(q, "Action", "CreateSnapshot"); + eclat_query_add_param(q, "VolumeId", argv[0]); + if (descr) + eclat_query_add_param(q, "Description", descr); + rc = eclat_send_query(curl, q); + if (acc) + grecs_txtacc_free(acc); + return rc; +} + + + |