diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/cresnap.c | 62 | ||||
-rw-r--r-- | src/delsnap.c | 40 | ||||
-rw-r--r-- | src/dscrsnap-cl.opt | 61 | ||||
-rw-r--r-- | src/dscrsnap.c | 52 | ||||
-rw-r--r-- | src/eclat.c | 8 | ||||
-rw-r--r-- | src/eclat.h | 3 |
7 files changed, 229 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index c7672e5..9f0407e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,8 +22,11 @@ eclat_SOURCES=\ cmdline.h\ config.c\ cretags.c\ + cresnap.c\ + delsnap.c\ disassaddr.c\ dscraddrs.c\ + dscrsnap.c\ dscrtags.c\ dscrinstattr.c\ dscrinsts.c\ @@ -52,6 +55,7 @@ OPTFILES=\ dscraddrs-cl.opt\ dscrinststat-cl.opt\ dscrsecgrps-cl.opt\ + dscrsnap-cl.opt\ generic-cl.opt eclat_SOURCES += $(OPTFILES:.opt=.h) 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; +} + + + diff --git a/src/delsnap.c b/src/delsnap.c new file mode 100644 index 0000000..d596566 --- /dev/null +++ b/src/delsnap.c @@ -0,0 +1,40 @@ +/* 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_delete_snapshot(CURL *curl, int argc, char **argv) +{ + int i; + struct ec2_query *q; + + generic_proginfo->args_doc = "SNAP-ID"; + generic_parse_options("eclat delete-snapshot", + "delete a EC2 volume snapshot", + argc, argv, &i); + argc -= i; + argv += i; + if (argc != 1) + die(EX_USAGE, "bad number of arguments"); + translate_ids(argc, argv, "SnapshotId"); + q = eclat_query_create(use_ssl ? EC2_QF_HTTPS : 0, endpoint, "/"); + eclat_query_add_param(q, "Action", "DeleteSnapshot"); + eclat_query_add_param(q, "SnapshotId", argv[0]); + return eclat_send_query(curl, q); +} + + diff --git a/src/dscrsnap-cl.opt b/src/dscrsnap-cl.opt new file mode 100644 index 0000000..7372daf --- /dev/null +++ b/src/dscrsnap-cl.opt @@ -0,0 +1,61 @@ +/* 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/>. */ + +struct grecs_list *parmlist; + +struct param { + char *name; + unsigned idx; + char *value; +}; + +static unsigned owner_idx = 1, rstby_idx = 1; + +OPTIONS_BEGIN("eclat describe-snapshots", + [<describe EC2 snapshots>], + [<[SNAP-ID...] [TAG[=VALUE...]]>], + [<gnu>], + [<nousage>], + [<noversion>]) + +OPTION(owner,u,[<ID>], + [<return the snapshots owned by the specified owner>]) +BEGIN + struct param *p = grecs_malloc(sizeof(*p)); + p->name = "Owner"; + p->idx = owner_idx++; + p->value = optarg; + grecs_list_append(parmlist, p); +END + +OPTION(restorable-by,r,[<ID>], + [<returns snapshots that can be restored by thid ID>]) +BEGIN + struct param *p = grecs_malloc(sizeof(*p)); + p->name = "RestorableBy"; + p->idx = rstby_idx++; + p->value = optarg; + grecs_list_append(parmlist, p); +END + +OPTIONS_END + +static void +parse_options(int argc, char *argv[], int *index) +{ + parmlist = grecs_list_create(); + GETOPT(argc, argv, *index, exit(EX_USAGE)) +} diff --git a/src/dscrsnap.c b/src/dscrsnap.c new file mode 100644 index 0000000..52c0264 --- /dev/null +++ b/src/dscrsnap.c @@ -0,0 +1,52 @@ +/* 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" +#include "dscrsnap-cl.h" + +int +eclat_describe_snapshots(CURL *curl, int argc, char **argv) +{ + int i; + struct ec2_query *q; + struct grecs_list_entry *ep; + char *buf = NULL; + size_t size = 0; + + parse_options(argc, argv, &i); + argc -= i; + argv += i; + translate_ids(argc, argv, "SnapshotId"); + + q = describe_query_create(curl, "DescribeSnapshots", argc, argv, + "SnapshotId"); + + if (parmlist) { + for (ep = parmlist->head; ep; ep = ep->next) { + struct param *param = ep->data; + grecs_asprintf(&buf, &size, "%s.%u", + param->name, param->idx); + eclat_query_add_param(q, buf, param->value); + } + } + grecs_list_free(parmlist); + + return eclat_send_query(curl, q); +} + + + + diff --git a/src/eclat.c b/src/eclat.c index ed9e3ae..e3c3f76 100644 --- a/src/eclat.c +++ b/src/eclat.c @@ -228,7 +228,13 @@ struct command cmdtab[] = { { "get-console-output", "GetConsoleOutput", eclat_get_console_output }, { "describe-security-groups", "DescribeSecurityGroups", - eclat_describe_security_groups } + eclat_describe_security_groups }, + { "create-snapshot", "CreateSnapshot", + eclat_create_snapshot }, + { "describe-snapshots", "DescribeSnapshots", + eclat_describe_snapshots }, + { "delete-snapshot", "DeleteSnapshot", + eclat_delete_snapshot } }; size_t cmdcnt = sizeof(cmdtab) / sizeof(cmdtab[0]); diff --git a/src/eclat.h b/src/eclat.h index bf98828..5ddd39a 100644 --- a/src/eclat.h +++ b/src/eclat.h @@ -74,6 +74,9 @@ int eclat_describe_instance_attribute(CURL *curl, int argc, char **argv); int eclat_create_tags(CURL *curl, int argc, char **argv); int eclat_delete_tags(CURL *curl, int argc, char **argv); int eclat_describe_security_groups(CURL *curl, int argc, char **argv); +int eclat_create_snapshot(CURL *curl, int argc, char **argv); +int eclat_describe_snapshots(CURL *curl, int argc, char **argv); +int eclat_delete_snapshot(CURL *curl, int argc, char **argv); char *region_to_endpoint(const char *region); |