aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-12-10 17:40:21 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2012-12-10 17:40:21 +0200
commit980d465d9ea87e2123bd9a3045de5c0a45e84cd7 (patch)
treeb7de616658bd27bfed159bcb82a43d71721df6da /src
parent5a7b73860974384d8e00065105435403b0842ab0 (diff)
downloadeclat-980d465d9ea87e2123bd9a3045de5c0a45e84cd7.tar.gz
eclat-980d465d9ea87e2123bd9a3045de5c0a45e84cd7.tar.bz2
Implement attach-volume and detach-volume
* TODO: Update * etc/attach-volume.fln: New file. * etc/detach-volume.fln: New file. * etc/Makefile.am: Add new files. * src/attvol.c: New file. * src/detvol-cl.opt: New file. * src/detvol.c: New file. * src/Makefile.am: Add new files. * src/eclat.c: Add new commands. * src/eclat.h: Add new protos. * src/util.c (translate_ids) (translate_resource_ids): Do nothing id argc is 0.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am3
-rw-r--r--src/attvol.c46
-rw-r--r--src/detvol-cl.opt36
-rw-r--r--src/detvol.c48
-rw-r--r--src/eclat.c4
-rw-r--r--src/eclat.h2
-rw-r--r--src/util.c4
7 files changed, 141 insertions, 2 deletions
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);
diff --git a/src/util.c b/src/util.c
index b4af99f..15d60f5 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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++) {

Return to:

Send suggestions and report system problems to the System administrator.