aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-04-23 22:39:55 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2013-04-23 22:52:39 +0300
commitafc70c70f2f078d18964c81a98dfb5d4ef519ec3 (patch)
tree24c666c5b2d7052618066d299133b1fce809f870
parent242c88381ec13fb81a5b36f50c19bf4fc3881dd6 (diff)
downloadeclat-afc70c70f2f078d18964c81a98dfb5d4ef519ec3.tar.gz
eclat-afc70c70f2f078d18964c81a98dfb5d4ef519ec3.tar.bz2
Implement copy-image and copy-snapshot.
* TODO: Update. * lib/libeclat.h (EC2_API_VERSION): Update. * src/Makefile.am: Add new file. * src/cpimg-cl.opt: New file. * src/cpimg.c: New file. * src/cpsnap-cl.opt: New file. * src/cpsnap.c: New file. * src/eclat.c (cmdtab): Add new commands. * src/eclat.h (eclat_copy_image) (eclat_copy_snapshot): New protos. * etc/copy-snapshot.fln: New file. * etc/copy-image.fln: New file. * etc/Makefile.am (FLNFILES): Add copy-image.fln
-rw-r--r--TODO2
-rw-r--r--etc/Makefile.am2
-rw-r--r--etc/copy-image.fln19
-rw-r--r--etc/copy-snapshot.fln19
-rw-r--r--lib/libeclat.h2
-rw-r--r--src/Makefile.am4
-rw-r--r--src/cpimg-cl.opt56
-rw-r--r--src/cpimg.c33
-rw-r--r--src/cpsnap-cl.opt47
-rw-r--r--src/cpsnap.c32
-rw-r--r--src/eclat.c4
-rw-r--r--src/eclat.h2
12 files changed, 221 insertions, 1 deletions
diff --git a/TODO b/TODO
index ddb46d1..119f304 100644
--- a/TODO
+++ b/TODO
@@ -26,6 +26,8 @@ CancelExportTask - [ ] [ ]
CancelReservedInstancesListing - [ ] [ ]
CancelSpotInstanceRequests - [ ] [ ]
ConfirmProductInstance - [ ] [ ]
+CopyImage cpimg [X] [ ]
+CopySnapshot cpsnap [X] [ ]
CreateCustomerGateway - [ ] [ ]
CreateDhcpOptions - [ ] [ ]
CreateImage mkimg [X] [X]
diff --git a/etc/Makefile.am b/etc/Makefile.am
index 00c34a1..9fe475e 100644
--- a/etc/Makefile.am
+++ b/etc/Makefile.am
@@ -20,6 +20,8 @@ FLNFILES=\
allocate-address.fln\
attach-volume.fln\
associate-address.fln\
+ copy-image.fln\
+ copy-snapshot.fln\
create-image.fln\
create-snapshot.fln\
create-tags.fln\
diff --git a/etc/copy-image.fln b/etc/copy-image.fln
new file mode 100644
index 0000000..eb0265e
--- /dev/null
+++ b/etc/copy-image.fln
@@ -0,0 +1,19 @@
+/* This file is part of Eclat.
+ Copyright (C) 2013 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 (.CopyImageResponse) {
+ print(last.imageId,"\n");
+}
diff --git a/etc/copy-snapshot.fln b/etc/copy-snapshot.fln
new file mode 100644
index 0000000..08e69a1
--- /dev/null
+++ b/etc/copy-snapshot.fln
@@ -0,0 +1,19 @@
+/* This file is part of Eclat.
+ Copyright (C) 2013 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 (.CopySnapshotResponse) {
+ print(last.snapshotId,"\n");
+}
diff --git a/lib/libeclat.h b/lib/libeclat.h
index 7c0d2fb..733a46d 100644
--- a/lib/libeclat.h
+++ b/lib/libeclat.h
@@ -68,7 +68,7 @@ struct ec2_param {
char *value;
};
-#define EC2_API_VERSION "2012-08-15"
+#define EC2_API_VERSION "2013-02-01"
#define EC2_QF_HTTPS 0x01
#define EC2_QF_POST 0x02
diff --git a/src/Makefile.am b/src/Makefile.am
index 5ee1096..ee9eece 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -23,6 +23,8 @@ eclat_SOURCES=\
atvol.c\
cmdline.h\
config.c\
+ cpimg.c\
+ cpsnap.c\
deimg.c\
devol.c\
disasaddr.c\
@@ -66,6 +68,8 @@ AM_CPPFLAGS = \
OPTFILES=\
allocaddr-cl.opt\
asscaddr-cl.opt\
+ cpimg-cl.opt\
+ cpsnap-cl.opt\
detvol-cl.opt\
disasaddr-cl.opt\
freeaddr-cl.opt\
diff --git a/src/cpimg-cl.opt b/src/cpimg-cl.opt
new file mode 100644
index 0000000..0fb4514
--- /dev/null
+++ b/src/cpimg-cl.opt
@@ -0,0 +1,56 @@
+/* This file is part of Eclat.
+ Copyright (C) 2013 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/>. */
+
+char *region;
+char *image;
+char *name;
+char *descr;
+
+OPTIONS_BEGIN("eclat copy-image",
+ [<copy an AMI from another region>],
+ [<REGION AMI-ID>],
+ [<gnu>])
+
+OPTION(name,n,[<NAME>],
+ [<assign name to the new image>])
+BEGIN
+ name = optarg;
+END
+
+OPTION(description,d,[<descr>],
+ [<description for the new image>])
+BEGIN
+ descr = optarg;
+END
+
+/* FIXME: The idempotency token */
+
+OPTIONS_END
+
+static void
+parse_options(int argc, char *argv[])
+{
+ int idx;
+
+ GETOPT(argc, argv, idx, exit(EX_USAGE))
+ argc -= idx;
+ argv += idx;
+ if (argc != 2)
+ die(EX_USAGE, "bad number of arguments");
+ translate_ids(1, argv+1, "ImageId");
+ region = argv[0];
+ image = argv[1];
+}
diff --git a/src/cpimg.c b/src/cpimg.c
new file mode 100644
index 0000000..53e7d3f
--- /dev/null
+++ b/src/cpimg.c
@@ -0,0 +1,33 @@
+/* This file is part of Eclat.
+ Copyright (C) 2013 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 "cpimg-cl.h"
+
+int
+eclat_copy_image(eclat_command_env_t *env, int argc, char **argv)
+{
+ struct ec2_query *q = env->query;
+ parse_options(argc, argv);
+
+ eclat_query_add_param(q, "SourceRegion", region);
+ eclat_query_add_param(q, "SourceImageId", image);
+ if (name)
+ eclat_query_add_param(q, "Name", name);
+ if (descr)
+ eclat_query_add_param(q, "Description", descr);
+ return 0;
+}
diff --git a/src/cpsnap-cl.opt b/src/cpsnap-cl.opt
new file mode 100644
index 0000000..be3adaa
--- /dev/null
+++ b/src/cpsnap-cl.opt
@@ -0,0 +1,47 @@
+/* This file is part of Eclat.
+ Copyright (C) 2013 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/>. */
+
+char *region;
+char *image;
+char *descr;
+
+OPTIONS_BEGIN("eclat copy-snapshot",
+ [<copy snapshot from another region>],
+ [<REGION SNAP-ID>],
+ [<gnu>])
+
+OPTION(description,d,[<descr>],
+ [<description for the new image>])
+BEGIN
+ descr = optarg;
+END
+
+OPTIONS_END
+
+static void
+parse_options(int argc, char *argv[])
+{
+ int idx;
+
+ GETOPT(argc, argv, idx, exit(EX_USAGE))
+ argc -= idx;
+ argv += idx;
+ if (argc != 2)
+ die(EX_USAGE, "bad number of arguments");
+ translate_ids(1, argv+1, "SnapshotId");
+ region = argv[0];
+ image = argv[1];
+}
diff --git a/src/cpsnap.c b/src/cpsnap.c
new file mode 100644
index 0000000..2f0a624
--- /dev/null
+++ b/src/cpsnap.c
@@ -0,0 +1,32 @@
+/* This file is part of Eclat.
+ Copyright (C) 2013 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 "cpsnap-cl.h"
+
+int
+eclat_copy_snapshot(eclat_command_env_t *env, int argc, char **argv)
+{
+ struct ec2_query *q = env->query;
+
+ parse_options(argc, argv);
+
+ eclat_query_add_param(q, "SourceRegion", region);
+ eclat_query_add_param(q, "SourceSnapshotId", image);
+ if (descr)
+ eclat_query_add_param(q, "Description", descr);
+ return 0;
+}
diff --git a/src/eclat.c b/src/eclat.c
index 30f0b70..5df504e 100644
--- a/src/eclat.c
+++ b/src/eclat.c
@@ -272,6 +272,10 @@ struct eclat_command cmdtab[] = {
eclat_create_image, CMD_MOD },
{ "deimg", "deregister-image", "DeregisterImage",
eclat_deregister_image, CMD_MOD|CMD_DESTR },
+ { "cpimg", "copy-image", "CopyImage",
+ eclat_copy_image },
+ { "cpsnap", "copy-snapshot", "CopySnapshot",
+ eclat_copy_snapshot },
{ "lsattr", NULL, NULL,
eclat_lsattr, CMD_NOQRY },
};
diff --git a/src/eclat.h b/src/eclat.h
index b171b3b..73bf25c 100644
--- a/src/eclat.h
+++ b/src/eclat.h
@@ -125,6 +125,8 @@ int eclat_run_instances(eclat_command_env_t *env, int argc, char **argv);
int eclat_describe_images(eclat_command_env_t *env, int argc, char **argv);
int eclat_create_image(eclat_command_env_t *env, int argc, char **argv);
int eclat_deregister_image(eclat_command_env_t *env, int argc, char **argv);
+int eclat_copy_image(eclat_command_env_t *env, int argc, char **argv);
+int eclat_copy_snapshot(eclat_command_env_t *env, int argc, char **argv);
int eclat_lsattr(eclat_command_env_t *env, int argc, char **argv);

Return to:

Send suggestions and report system problems to the System administrator.