diff options
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | etc/Makefile.am | 2 | ||||
-rw-r--r-- | etc/attach-volume.fln | 22 | ||||
-rw-r--r-- | etc/detach-volume.fln | 22 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/attvol.c | 46 | ||||
-rw-r--r-- | src/detvol-cl.opt | 36 | ||||
-rw-r--r-- | src/detvol.c | 48 | ||||
-rw-r--r-- | src/eclat.c | 4 | ||||
-rw-r--r-- | src/eclat.h | 2 | ||||
-rw-r--r-- | src/util.c | 4 |
11 files changed, 189 insertions, 4 deletions
@@ -14,7 +14,7 @@ AssociateDhcpOptions ASSCDHCPOPTS [ ] [ ] AssociateRouteTable ASSCROUTTAB [ ] [ ] AttachInternetGateway ATTINETGW [ ] [ ] AttachNetworkInterface ATTNETIF [ ] [ ] -AttachVolume ATTVOL [ ] [ ] +AttachVolume ATTVOL [X] [ ] AttachVpnGateway ATTVPNGW [ ] [ ] AuthorizeSecurityGroupEgress AUTHSECGRPEG [ ] [ ] AuthorizeSecurityGroupIngress AUTHSECGRPIG [ ] [ ] @@ -108,7 +108,7 @@ DescribeVpnConnections DSCRVPNCNCTS [ ] [ ] DescribeVpnGateways DSCRVPNGWS [ ] [ ] DetachInternetGateway DETINETGW [ ] [ ] DetachNetworkInterface DETNETIF [ ] [ ] -DetachVolume DETVOL [ ] [ ] +DetachVolume DETVOL [X] [ ] DetachVpnGateway DETVPNGW [ ] [ ] DisableVgwRoutePropagation DISVGWROUTPRPG [ ] [ ] DisassociateAddress DSSCADR [X] [X] diff --git a/etc/Makefile.am b/etc/Makefile.am index 236b43d..577441b 100644 --- a/etc/Makefile.am +++ b/etc/Makefile.am @@ -18,6 +18,7 @@ noinst_PROGRAMS = flncat FLNFILES=\ allocate-address.fln\ + attach-volume.fln\ associate-address.fln\ create-snapshot.fln\ create-tags.fln\ @@ -35,6 +36,7 @@ FLNFILES=\ describe-snapshots.fln\ describe-tags.fln\ describe-volumes.fln\ + detach-volume.fln\ disassociate-address.fln\ get-console-output.fln\ reboot-instances.fln\ diff --git a/etc/attach-volume.fln b/etc/attach-volume.fln new file mode 100644 index 0000000..21905c6 --- /dev/null +++ b/etc/attach-volume.fln @@ -0,0 +1,22 @@ +/* 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/>. */ + +if (.AttachVolumeResponse) { + print(.AttachVolumeResponse.volumeId,"\t", + .AttachVolumeResponse.status,"\t", + .AttachVolumeResponse.instanceId,"\t", + .AttachVolumeResponse.device,"\n"); +} diff --git a/etc/detach-volume.fln b/etc/detach-volume.fln new file mode 100644 index 0000000..5303c1f --- /dev/null +++ b/etc/detach-volume.fln @@ -0,0 +1,22 @@ +/* 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/>. */ + +if (.DetachVolumeResponse) { + print(.DetachVolumeResponse.volumeId,"\t", + .DetachVolumeResponse.status,"\t", + .DetachVolumeResponse.instanceId,"\t", + .DetachVolumeResponse.device,"\n"); +} diff --git a/src/Makefile.am b/src/Makefile.am index b77e286..9756ff3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,6 +20,7 @@ eclat_SOURCES=\ accfile.c\ allocaddr.c\ asscaddr.c\ + attvol.c\ cmdline.h\ config.c\ cretags.c\ @@ -27,6 +28,7 @@ eclat_SOURCES=\ crevol.c\ delsnap.c\ delvol.c\ + detvol.c\ disassaddr.c\ dscraddrs.c\ dscrazs.c\ @@ -59,6 +61,7 @@ OPTFILES=\ asscaddr-cl.opt\ cretags-cl.opt\ crevol-cl.opt\ + detvol-cl.opt\ disassaddr-cl.opt\ dscraddrs-cl.opt\ dscrinststat-cl.opt\ diff --git a/src/attvol.c b/src/attvol.c new file mode 100644 index 0000000..25fb160 --- /dev/null +++ b/src/attvol.c @@ -0,0 +1,46 @@ +/* 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_attach_volume(CURL *curl, int argc, char **argv) +{ + int i; + struct ec2_query *q; + + generic_proginfo->args_doc = "VOL-ID INST-ID DEV-NAME"; + generic_parse_options("eclat attach-volume", + "attach a volume to an instance", + argc, argv, &i); + + argc -= i; + argv += i; + + if (argc != 3) + die(EX_USAGE, "bad number of arguments"); + + translate_ids(1, argv, "VolumeId"); + translate_ids(1, argv + 1, "InstanceId"); + + q = eclat_query_create(use_ssl ? EC2_QF_HTTPS : 0, endpoint, "/"); + eclat_query_add_param(q, "Action", "AttachVolume"); + eclat_query_add_param(q, "VolumeId", argv[0]); + eclat_query_add_param(q, "InstanceId", argv[1]); + eclat_query_add_param(q, "Device", argv[2]); + + return eclat_send_query(curl, q); +} diff --git a/src/detvol-cl.opt b/src/detvol-cl.opt new file mode 100644 index 0000000..baced3f --- /dev/null +++ b/src/detvol-cl.opt @@ -0,0 +1,36 @@ +/* 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/>. */ + +OPTIONS_BEGIN("eclat detach-volume", + [<detach a volume from instance>], + [<VOL-ID [INST-ID [DEV-NAME]]>], + [<gnu>], + [<nousage>], + [<noversion>]) + +OPTION(force,f,, + [<force detachment>]) +BEGIN + force = 1; +END + +OPTIONS_END + +static void +parse_options(int argc, char *argv[], int *index) +{ + GETOPT(argc, argv, *index, exit(EX_USAGE)) +} diff --git a/src/detvol.c b/src/detvol.c new file mode 100644 index 0000000..e9f47de --- /dev/null +++ b/src/detvol.c @@ -0,0 +1,48 @@ +/* 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 force; +#include "detvol-cl.h" + +int +eclat_detach_volume(CURL *curl, int argc, char **argv) +{ + int i; + struct ec2_query *q; + + parse_options(argc, argv, &i); + argc -= i; + argv += i; + + if (argc < 1 || argc > 3) + die(EX_USAGE, "bad number of arguments"); + + translate_ids(1, argv, "VolumeId"); + + q = eclat_query_create(use_ssl ? EC2_QF_HTTPS : 0, endpoint, "/"); + eclat_query_add_param(q, "Action", "DetachVolume"); + eclat_query_add_param(q, "VolumeId", argv[0]); + if (argc > 1) { + translate_ids(1, argv + 1, "InstanceId"); + eclat_query_add_param(q, "InstanceId", argv[1]); + if (argc > 2) + eclat_query_add_param(q, "Device", argv[2]); + } + if (force) + eclat_query_add_param(q, "Force", "true"); + return eclat_send_query(curl, q); +} diff --git a/src/eclat.c b/src/eclat.c index ef9dfd5..5d6644e 100644 --- a/src/eclat.c +++ b/src/eclat.c @@ -259,6 +259,10 @@ struct command cmdtab[] = { eclat_create_volume, CMD_MOD }, { "delete-volume", "DeleteVolume", eclat_delete_volume, CMD_MOD|CMD_DESTR }, + { "attach-volume", "AttachVolume", + eclat_attach_volume, CMD_MOD }, + { "detach-volume", "DetachVolume", + eclat_detach_volume, CMD_MOD|CMD_DESTR }, }; size_t cmdcnt = sizeof(cmdtab) / sizeof(cmdtab[0]); diff --git a/src/eclat.h b/src/eclat.h index 40c4014..9a21835 100644 --- a/src/eclat.h +++ b/src/eclat.h @@ -89,6 +89,8 @@ int eclat_describe_avaialbility_zones(CURL *curl, int argc, char **argv); int eclat_describe_regions(CURL *curl, int argc, char **argv); int eclat_create_volume(CURL *curl, int argc, char **argv); int eclat_delete_volume(CURL *curl, int argc, char **argv); +int eclat_attach_volume(CURL *curl, int argc, char **argv); +int eclat_detach_volume(CURL *curl, int argc, char **argv); char *region_to_endpoint(const char *region); @@ -28,7 +28,7 @@ translate_ids(int argc, char **argv, const char *mapname) struct eclat_map *map; char *val; - if (!translate_option) + if (!translate_option || argc == 0) return; if (custom_map) mapname = custom_map; @@ -72,7 +72,7 @@ translate_resource_ids(int argc, char **argv) struct wordsplit ws; int wsflags = WRDSF_DEFFLAGS|WRDSF_DELIM; - if (!translate_option) + if (!translate_option || argc == 0) return; ws.ws_delim = ","; for (i = 0; i < argc; i++) { |