From 3e2360d383d8e7503a8afe07291ab8c0b1182a14 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Sat, 17 Nov 2018 17:54:07 +0200 Subject: Implement the terminate-instances command * TODO: Update. * doc/Makefile.inc: Add new files. * doc/eclat-mkinst.1: Mention the terminate command. * doc/eclat-terminate.1: New file. * etc/Makefile.am: Add new files. * etc/terminate-instances.fln: New file. * src/eclat.c (cmdtab): Register new command. * src/eclat.h (eclat_terminate_instances): New proto. * src/startstop.c (eclat_terminate_instances): New function. * tests/Makefile.am: Add new test. * tests/testsuite.at: Likewise. * tests/terminate-instances.at: New test. --- TODO | 2 +- doc/Makefile.inc | 1 + doc/eclat-mkinst.1 | 5 ++-- doc/eclat-reboot.1 | 4 +-- doc/eclat-terminate.1 | 58 ++++++++++++++++++++++++++++++++++++++++++++ etc/Makefile.am | 3 ++- etc/terminate-instances.fln | 23 ++++++++++++++++++ src/eclat.c | 4 +++ src/eclat.h | 1 + src/startstop.c | 14 ++++++++++- tests/Makefile.am | 1 + tests/terminate-instances.at | 39 +++++++++++++++++++++++++++++ tests/testsuite.at | 1 + 13 files changed, 149 insertions(+), 7 deletions(-) create mode 100644 doc/eclat-terminate.1 create mode 100644 etc/terminate-instances.fln create mode 100644 tests/terminate-instances.at diff --git a/TODO b/TODO index 4fa62d9..3e45bda 100644 --- a/TODO +++ b/TODO @@ -151,7 +151,7 @@ RevokeSecurityGroupIngress sg [X] [X] RunInstances mkinst [X] [X] StartInstances start [X] [X] StopInstances stop [X] [X] -TerminateInstances killinst [ ] [ ] +TerminateInstances terminate [X] [X] UnassignPrivateIpAddresses - [ ] [ ] UnmonitorInstances - [ ] [ ] diff --git a/doc/Makefile.inc b/doc/Makefile.inc index 143f579..43b62b3 100644 --- a/doc/Makefile.inc +++ b/doc/Makefile.inc @@ -61,6 +61,7 @@ MANPAGES1=\ eclat-sg.1\ eclat-start.1\ eclat-stop.1\ + eclat-terminate.1\ ispeek.1 MANPAGES5=\ diff --git a/doc/eclat-mkinst.1 b/doc/eclat-mkinst.1 index f934484..4db3c7e 100644 --- a/doc/eclat-mkinst.1 +++ b/doc/eclat-mkinst.1 @@ -13,7 +13,7 @@ .\" .\" You should have received a copy of the GNU General Public License .\" along with Eclat. If not, see . -.TH ECLAT-MKINST 1 "January 26, 2015" "ECLAT" "Eclat User Reference" +.TH ECLAT-MKINST 1 "November 17, 2018" "ECLAT" "Eclat User Reference" .SH NAME eclat-mkinst, eclat-run-instances \- launch new EC2 instances .SH SYNOPSIS @@ -166,6 +166,7 @@ instance in the same format as the command .SH "SEE ALSO" .BR eclat (1), +.BR eclat\-terminate (1), .BR eclat\-lsiattr (1), .BR eclat\-lsinst (1), .BR eclat\-lsistat (1), @@ -178,7 +179,7 @@ Sergey Poznyakoff .SH "BUG REPORTS" Report bugs to . .SH COPYRIGHT -Copyright \(co 2012-2015 Sergey Poznyakoff +Copyright \(co 2012-2018 Sergey Poznyakoff .br .na License GPLv3+: GNU GPL version 3 or later diff --git a/doc/eclat-reboot.1 b/doc/eclat-reboot.1 index 1addd87..d234808 100644 --- a/doc/eclat-reboot.1 +++ b/doc/eclat-reboot.1 @@ -13,7 +13,7 @@ .\" .\" You should have received a copy of the GNU General Public License .\" along with Eclat. If not, see . -.TH ECLAT-REBOOT 1 "January 26, 2015" "ECLAT" "Eclat User Reference" +.TH ECLAT-REBOOT 1 "November 17, 2018" "ECLAT" "Eclat User Reference" .SH NAME eclat-reboot, eclat-reboot-instances \- reboot EC2 instances .SH SYNOPSIS @@ -29,7 +29,7 @@ The command .B reboot reboots running Amazon EBS-backed instances. .SH OUTPUT -The default output format lists o each line the instance ID, its +The default output format lists on each line the instance ID, its previous and current states, separated by single horizontal tab characters. .SH "SEE ALSO" diff --git a/doc/eclat-terminate.1 b/doc/eclat-terminate.1 new file mode 100644 index 0000000..a70a1ee --- /dev/null +++ b/doc/eclat-terminate.1 @@ -0,0 +1,58 @@ +.\" This file is part of Eclat -*- nroff -*- +.\" Copyright (C) 2012-2018 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 . +.TH ECLAT-TERMINATE 1 "November 17, 2018" "ECLAT" "Eclat User Reference" +.SH NAME +eclat-terminate, eclat-terminate-instances \- terminate EC2 instances +.SH SYNOPSIS +.nh +.na +\fBeclat terminate\fR \fIID\fR [\fIID\fR...] +.PP +\fBeclat terminate\fR \fB\-\-help\fR +.ad +.hy +.SH DESCRIPTION +Terminates the listed Amazon EBS-backed instances. +.SH OUTPUT +The default output format lists on each line the instance ID, its +previous and current states, separated by single horizontal tab +characters. +.SH "SEE ALSO" +.BR eclat (1), +.BR eclat\-mkinst (1), +.BR eclat\-start (1), +.BR eclat\-stop (1). +.SH AUTHORS +Sergey Poznyakoff +.SH "BUG REPORTS" +Report bugs to . +.SH COPYRIGHT +Copyright \(co 2012-2018 Sergey Poznyakoff +.br +.na +License GPLv3+: GNU GPL version 3 or later +.br +.ad +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. +.\" Local variables: +.\" eval: (add-hook 'write-file-hooks 'time-stamp) +.\" time-stamp-start: ".TH [A-Z_][A-Z0-9_.\\-]* [0-9] \"" +.\" time-stamp-format: "%:B %:d, %:y" +.\" time-stamp-end: "\"" +.\" time-stamp-line-limit: 20 +.\" end: + diff --git a/etc/Makefile.am b/etc/Makefile.am index 21b958b..2376583 100644 --- a/etc/Makefile.am +++ b/etc/Makefile.am @@ -81,7 +81,8 @@ FLNFILES=\ run-instances.fln\ sg.fln\ start-instances.fln\ - stop-instances.fln + stop-instances.fln\ + terminate-instances.fln EXTRA_DIST=$(FLNFILES) default.fln eclat.cfin diff --git a/etc/terminate-instances.fln b/etc/terminate-instances.fln new file mode 100644 index 0000000..12995c3 --- /dev/null +++ b/etc/terminate-instances.fln @@ -0,0 +1,23 @@ +/* This file is part of Eclat. + Copyright (C) 2012-2018 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 . */ + +if (.TerminateInstancesResponse) { + for (var in .TerminateInstancesResponse.instancesSet.item) { + print(var.instanceId,": ", + var.previousState.name," => ", + var.currentState.name,"\n"); + } +} diff --git a/src/eclat.c b/src/eclat.c index 12b4dd1..26a8f9f 100644 --- a/src/eclat.c +++ b/src/eclat.c @@ -90,6 +90,9 @@ struct eclat_command cmdtab[] = { CMD_MOD }, { "reboot", "reboot-instances", "RebootInstances", eclat_reboot_instance, CMD_MOD }, + { "terminate", "terminate-instances", "TerminateInstances", + eclat_terminate_instances, CMD_MOD|CMD_DESTR }, + { "lsaddr", "describe-addresses", "DescribeAddresses", eclat_describe_addresses }, { "lstag", "describe-tags", "DescribeTags", eclat_describe_tags }, @@ -205,6 +208,7 @@ struct eclat_command cmdtab[] = { { "disasrtab", "disassociate-route-table", "DisassociateRouteTable", eclat_disassociate_route_table, CMD_MOD }, { "route", NULL, NULL, eclat_route }, + }; size_t cmdcnt = sizeof(cmdtab) / sizeof(cmdtab[0]); diff --git a/src/eclat.h b/src/eclat.h index 21e89e1..1948234 100644 --- a/src/eclat.h +++ b/src/eclat.h @@ -126,6 +126,7 @@ int eclat_trace_fun(CURL *handle, curl_infotype type, int eclat_start_instance(eclat_command_env_t *env, int argc, char **argv); int eclat_stop_instance(eclat_command_env_t *env, int argc, char **argv); int eclat_reboot_instance(eclat_command_env_t *env, int argc, char **argv); +int eclat_terminate_instances(eclat_command_env_t *env, int argc, char **argv); int eclat_describe_tags(eclat_command_env_t *env, int argc, char **argv); int eclat_describe_instance_status(eclat_command_env_t *env, int argc, char **argv); int eclat_describe_instances(eclat_command_env_t *env, int argc, char **argv); diff --git a/src/startstop.c b/src/startstop.c index 2460682..78c581c 100644 --- a/src/startstop.c +++ b/src/startstop.c @@ -44,7 +44,6 @@ start_stop_instance(eclat_command_env_t *env, int argc, char **argv) snprintf(bend, bs, "%lu", (unsigned long)(i + 1)); eclat_request_add_param(q, buf, argv[i]); } - return 0; } @@ -90,3 +89,16 @@ eclat_reboot_instance(eclat_command_env_t *env, int argc, char **argv) debug(ECLAT_DEBCAT_MAIN, 1, ("rebooting instances")); return start_stop_instance(env, argc - i, argv + i); } + +int +eclat_terminate_instances(eclat_command_env_t *env, int argc, char **argv) +{ + int i; + + parse_options(env->cmd, + "Terminate named instances", + argc, argv, &i); + + debug(ECLAT_DEBCAT_MAIN, 1, ("terminate instances")); + return start_stop_instance(env, argc - i, argv + i); +} diff --git a/tests/Makefile.am b/tests/Makefile.am index 61046ba..36927c7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -84,6 +84,7 @@ TESTSUITE_AT = \ sortts.at\ start-instances.at\ stop-instances.at\ + terminate-instances.at\ tagshairy.at\ testsuite.at\ urlenc01.at\ diff --git a/tests/terminate-instances.at b/tests/terminate-instances.at new file mode 100644 index 0000000..7242986 --- /dev/null +++ b/tests/terminate-instances.at @@ -0,0 +1,39 @@ +# This file is part of Eclat -*- Autotest -*- +# Copyright (C) 2012-2018 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 . + +ECLAT_TEST_FORMAT([TerminateInstances], +[TerminateInstances], +[terminate-instances.fln], +[ + 59dbff89-35bd-4eac-99ed-be587EXAMPLE + + + i-1234567890abcdef0 + + 32 + shutting-down + + + 16 + running + + + + +], +[i-1234567890abcdef0: running => shutting-down +]) + diff --git a/tests/testsuite.at b/tests/testsuite.at index 6583b89..0d25b97 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -78,6 +78,7 @@ m4_include([describe-volumes.at]) m4_include([get-console-output.at]) m4_include([start-instances.at]) m4_include([stop-instances.at]) +m4_include([terminate-instances.at]) AT_BANNER([Sort]) m4_include([sortstring.at]) -- cgit v1.2.1