guignol 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +60 -0
- data/README.md +185 -0
- data/Rakefile +32 -0
- data/bin/guignol +43 -0
- data/guignol.gemspec +61 -0
- data/lib/guignol/array/collect_key.rb +32 -0
- data/lib/guignol/commands/base.rb +88 -0
- data/lib/guignol/commands/create.rb +42 -0
- data/lib/guignol/commands/help.rb +77 -0
- data/lib/guignol/commands/kill.rb +48 -0
- data/lib/guignol/commands/list.rb +60 -0
- data/lib/guignol/commands/start.rb +42 -0
- data/lib/guignol/commands/stop.rb +48 -0
- data/lib/guignol/commands/uuid.rb +41 -0
- data/lib/guignol/commands.rb +46 -0
- data/lib/guignol/instance.rb +270 -0
- data/lib/guignol/shared.rb +80 -0
- data/lib/guignol/shell.rb +50 -0
- data/lib/guignol/tty_spinner.rb +52 -0
- data/lib/guignol/version.rb +30 -0
- data/lib/guignol/volume.rb +124 -0
- data/lib/guignol.rb +38 -0
- metadata +224 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
guignol (0.1)
|
5
|
+
active_support
|
6
|
+
fog (~> 1.1.2)
|
7
|
+
parallel (~> 0.5.14)
|
8
|
+
term-ansicolor
|
9
|
+
uuidtools
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: http://rubygems.org/
|
13
|
+
specs:
|
14
|
+
active_support (3.0.0)
|
15
|
+
activesupport (= 3.0.0)
|
16
|
+
activesupport (3.0.0)
|
17
|
+
awesome_print (1.0.2)
|
18
|
+
builder (3.0.0)
|
19
|
+
diff-lcs (1.1.3)
|
20
|
+
excon (0.9.6)
|
21
|
+
fog (1.1.2)
|
22
|
+
builder
|
23
|
+
excon (~> 0.9.0)
|
24
|
+
formatador (~> 0.2.0)
|
25
|
+
mime-types
|
26
|
+
multi_json (~> 1.0.3)
|
27
|
+
net-scp (~> 1.0.4)
|
28
|
+
net-ssh (>= 2.1.3)
|
29
|
+
nokogiri (~> 1.5.0)
|
30
|
+
ruby-hmac
|
31
|
+
formatador (0.2.1)
|
32
|
+
mime-types (1.17.2)
|
33
|
+
multi_json (1.0.4)
|
34
|
+
net-scp (1.0.4)
|
35
|
+
net-ssh (>= 1.99.1)
|
36
|
+
net-ssh (2.3.0)
|
37
|
+
nokogiri (1.5.0)
|
38
|
+
parallel (0.5.15)
|
39
|
+
rake (0.9.2.2)
|
40
|
+
rspec (2.4.0)
|
41
|
+
rspec-core (~> 2.4.0)
|
42
|
+
rspec-expectations (~> 2.4.0)
|
43
|
+
rspec-mocks (~> 2.4.0)
|
44
|
+
rspec-core (2.4.0)
|
45
|
+
rspec-expectations (2.4.0)
|
46
|
+
diff-lcs (~> 1.1.2)
|
47
|
+
rspec-mocks (2.4.0)
|
48
|
+
ruby-hmac (0.4.0)
|
49
|
+
term-ansicolor (1.0.7)
|
50
|
+
uuidtools (2.1.2)
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
ruby
|
54
|
+
|
55
|
+
DEPENDENCIES
|
56
|
+
awesome_print
|
57
|
+
bundler (>= 1.0.0)
|
58
|
+
guignol!
|
59
|
+
rake
|
60
|
+
rspec (~> 2.4.0)
|
data/README.md
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
# Guignol
|
2
|
+
|
3
|
+
Be the puppeteer. Order your EC2 instances to start, stop, die, or be created from the command line. Let Guignol deal with DNS mappings and attaching EBS volumes.
|
4
|
+
|
5
|
+
Released under the [Simplified BSD License](http://en.wikipedia.org/wiki/BSD_licenses#2-clause_license_.28.22Simplified_BSD_License.22_or_.22FreeBSD_License.22.29).
|
6
|
+
|
7
|
+
|
8
|
+
## Getting started
|
9
|
+
|
10
|
+
Install `guignol`:
|
11
|
+
|
12
|
+
$ gem install guignol
|
13
|
+
|
14
|
+
Guignol relies on the excellent [Fog gem](http://fog.io/) to connect to Amazon's APIs.
|
15
|
+
Start by setting up your `~/.fog`:
|
16
|
+
|
17
|
+
---- ~/.fog ----
|
18
|
+
:default:
|
19
|
+
:aws_access_key_id: ABCDEF....
|
20
|
+
:aws_secret_access_key: 123456....
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
## Creating, starting and stopping machines
|
25
|
+
|
26
|
+
Guignol doesn't care about the list of instances that live on your EC2 account,
|
27
|
+
only what it's configured to deal with.
|
28
|
+
|
29
|
+
This should prevent destroying other's instances when using (for instance) a
|
30
|
+
shared AWS/IAM account !
|
31
|
+
|
32
|
+
Teach Guignol about your instances by adding them to its config file.
|
33
|
+
Each instance needs at least a name an a UUID (both will become tags on your
|
34
|
+
instance):
|
35
|
+
|
36
|
+
---- ~/.guignol.yml ----
|
37
|
+
---
|
38
|
+
- :name: hello-world
|
39
|
+
:uuid: AF123799-3F55-4F0B-8E58-87C67A5977BA
|
40
|
+
|
41
|
+
Guignol will read it's configuration from `./config/guignol.yml`, `./guignol.yml`, or `~/.guignol.yml`.
|
42
|
+
|
43
|
+
`guignol uuid` will output a new UUID if you need one.
|
44
|
+
You can also use `uuidgen` if your distro come with it.
|
45
|
+
|
46
|
+
And that's it for configuration!
|
47
|
+
|
48
|
+
Now create your instance:
|
49
|
+
|
50
|
+
$ guignol create hello-world
|
51
|
+
hello-world: building server...
|
52
|
+
hello-world: updating server tags
|
53
|
+
hello-world: waiting for public dns to be set up...
|
54
|
+
hello-world: updating root volume tags
|
55
|
+
hello-world: created as ec2-46-137-53-32.eu-west-1.compute.amazonaws.com
|
56
|
+
|
57
|
+
You can log in as soon as the command returns.
|
58
|
+
|
59
|
+
Of course, you can `stop`, `start`, or `kill` your instance.
|
60
|
+
|
61
|
+
|
62
|
+
### One more thing
|
63
|
+
|
64
|
+
You can run any command against multiple instances by listing names and (ruby)
|
65
|
+
regular expressions to designate lists of instances.
|
66
|
+
|
67
|
+
$ guignol kill "hello.*"
|
68
|
+
hello-world: tearing server down...
|
69
|
+
hello-world: waiting for instance to become stopped or terminated...
|
70
|
+
hello-world: instance now shutting-down
|
71
|
+
hello-world: instance now terminated
|
72
|
+
|
73
|
+
If targeting multiple machines, guignol will run **in parallel**.
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
## Optional configuration
|
78
|
+
|
79
|
+
- `:domain`
|
80
|
+
The machine's domain name. If specified, Guignol will setup a
|
81
|
+
CNAME in Route53 mapping *name*.*domain* to your EC2 instance where it
|
82
|
+
starts it (and tear it down when stopping it.)
|
83
|
+
|
84
|
+
- `:region`
|
85
|
+
The EC2 region. Defaults to `eu-west-1`.
|
86
|
+
|
87
|
+
- `:image_id`
|
88
|
+
The AMI to use when creating this instance. Defaults to whatever Amazon defaults it to.
|
89
|
+
|
90
|
+
- `:flavor_id`
|
91
|
+
The type of instance to start. Defaults to `t1.micro` (the one with a free tier).
|
92
|
+
|
93
|
+
- `:key_name`
|
94
|
+
The keypair to deploy to this instance. Default to not deploying any for security reasons (meaning you probably won't be able to log in if unset, depending on the AMI you're using).
|
95
|
+
|
96
|
+
- `:security_group_ids`
|
97
|
+
A list of security groups you want your instance to be a member of.
|
98
|
+
|
99
|
+
- `:user_data`
|
100
|
+
A script to run when an instance is created.
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
## EBS Volumes
|
105
|
+
|
106
|
+
Yes, Guignol will also create and attach your EBS volumes when starting up instances.
|
107
|
+
Just add a `:volumes` entry to your instance configuration:
|
108
|
+
|
109
|
+
:volumes:
|
110
|
+
- :name: fubar-swap
|
111
|
+
:uuid: 9D5A278E-432C-41DB-9FB5-8AF5C1BD021F
|
112
|
+
:dev: /dev/sdf
|
113
|
+
:size: 4
|
114
|
+
:delete_on_termination: true
|
115
|
+
- :name: fubar-data
|
116
|
+
:uuid: E180203F-9DE1-4C6A-B09B-33B2FAC8F36E
|
117
|
+
:dev: /dev/sdg
|
118
|
+
:size: 20
|
119
|
+
:delete_on_termination: false
|
120
|
+
|
121
|
+
Guignol will take care of creating your instances in the right availability zone if its volumes already exist.
|
122
|
+
|
123
|
+
Note that Guignol does not delete volumes when tearing down instances.
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
## Managing existing instances
|
128
|
+
|
129
|
+
|
130
|
+
You can start/stop instances even if you didn't create them with Guignol.
|
131
|
+
|
132
|
+
Simply
|
133
|
+
|
134
|
+
1. declare them in your `guignol.yml` ;
|
135
|
+
2. go to the console and add the corresponding UUID tag to the existing intances ;
|
136
|
+
3. there is no step three.
|
137
|
+
|
138
|
+
Now you can `guignol stop` your instances from the command line when not using them and save money.
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
## Complete config example
|
143
|
+
|
144
|
+
This one just contains 2 machines, `fubar.housetripdev.com.` and `gargantua.hosuetirpdev.com.`
|
145
|
+
|
146
|
+
---- ~/.guignol.yml ----
|
147
|
+
---
|
148
|
+
- :name: hello-world
|
149
|
+
:uuid: AF123799-3F55-4F0B-8E58-87C67A5977BA
|
150
|
+
- :name: fubar
|
151
|
+
:domain: housetripdev.com.
|
152
|
+
:uuid: 68C3C0C2-1BA3-465F-8626-E065E4EF9048
|
153
|
+
:region: eu-west-1
|
154
|
+
:image_id: ami-15f7c961 # 32 bits
|
155
|
+
:flavor_id: m1.small
|
156
|
+
:key_name: jtl-laptop
|
157
|
+
:security_group_ids:
|
158
|
+
- sg-7e638109 # housetrip-basic
|
159
|
+
:volumes:
|
160
|
+
- :name: fubar-swap
|
161
|
+
:uuid: 9D5A278E-432C-41DB-9FB5-8AF5C1BD021F
|
162
|
+
:dev: /dev/sdf
|
163
|
+
:size: 4
|
164
|
+
:delete_on_termination: true
|
165
|
+
- :name: fubar-data
|
166
|
+
:uuid: E180203F-9DE1-4C6A-B09B-33B2FAC8F36E
|
167
|
+
:dev: /dev/sdg
|
168
|
+
:size: 20
|
169
|
+
:delete_on_termination: false
|
170
|
+
:user_data: |
|
171
|
+
#!/bin/sh
|
172
|
+
set -x
|
173
|
+
if test -z "$LOGGING" ; then
|
174
|
+
export LOGGING=YES
|
175
|
+
exec "$0" > /tmp/user_data.log 2>&1
|
176
|
+
fi
|
177
|
+
|
178
|
+
mkswap -f /dev/xvdf > /dev/null && swapon /dev/xvdf
|
179
|
+
|
180
|
+
mount_data() {
|
181
|
+
mount -t ext4 /dev/xvdg /mnt
|
182
|
+
}
|
183
|
+
mount_data || { mkfs.ext4 /dev/xvdg && mount_data ; }
|
184
|
+
date >> /tmp/stamp
|
185
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Copyright (c) 2012, HouseTrip SA.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
# list of conditions and the following disclaimer.
|
9
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer in the documentation
|
11
|
+
# and/or other materials provided with the distribution.
|
12
|
+
#
|
13
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
16
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
17
|
+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
18
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
19
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
20
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
21
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
22
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
#
|
24
|
+
# The views and conclusions contained in the software and documentation are those
|
25
|
+
# of the authors and should not be interpreted as representing official policies,
|
26
|
+
# either expressed or implied, of the authors.
|
27
|
+
|
28
|
+
require 'bundler'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
Bundler::GemHelper.install_tasks
|
31
|
+
|
32
|
+
RSpec::Core::RakeTask.new(:spec)
|
data/bin/guignol
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Run Guignol commands
|
4
|
+
#
|
5
|
+
# Copyright (c) 2012, HouseTrip SA.
|
6
|
+
# All rights reserved.
|
7
|
+
#
|
8
|
+
# Redistribution and use in source and binary forms, with or without
|
9
|
+
# modification, are permitted provided that the following conditions are met:
|
10
|
+
#
|
11
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
12
|
+
# list of conditions and the following disclaimer.
|
13
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
14
|
+
# this list of conditions and the following disclaimer in the documentation
|
15
|
+
# and/or other materials provided with the distribution.
|
16
|
+
#
|
17
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
18
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
21
|
+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
#
|
28
|
+
# The views and conclusions contained in the software and documentation are those
|
29
|
+
# of the authors and should not be interpreted as representing official policies,
|
30
|
+
# either expressed or implied, of the authors.
|
31
|
+
|
32
|
+
File.expand_path(__FILE__ + '/../../lib').tap { |libdir| $:.include?(libdir) or $:.unshift(libdir) }
|
33
|
+
|
34
|
+
|
35
|
+
# Work around SSL certificate errors. Yeah, I know it's insecure.
|
36
|
+
require 'excon'
|
37
|
+
Excon.defaults[:ssl_verify_peer] = false
|
38
|
+
|
39
|
+
|
40
|
+
require 'guignol/shell'
|
41
|
+
|
42
|
+
command = ARGV.shift
|
43
|
+
Guignol::Shell.instance.execute(command, *ARGV)
|
data/guignol.gemspec
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# Copyright (c) 2012, HouseTrip SA.
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
# list of conditions and the following disclaimer.
|
10
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
15
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
16
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
17
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
18
|
+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
19
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
20
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
21
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
22
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
23
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
24
|
+
#
|
25
|
+
# The views and conclusions contained in the software and documentation are those
|
26
|
+
# of the authors and should not be interpreted as representing official policies,
|
27
|
+
# either expressed or implied, of the authors.
|
28
|
+
|
29
|
+
require File.expand_path("../lib/guignol/version", __FILE__)
|
30
|
+
|
31
|
+
Gem::Specification.new do |s|
|
32
|
+
s.name = "guignol"
|
33
|
+
s.version = Guignol::VERSION
|
34
|
+
s.platform = Gem::Platform::RUBY
|
35
|
+
s.authors = ["Julien Letessier"]
|
36
|
+
s.email = ["julien.letessier@gmail.com"]
|
37
|
+
s.homepage = "https://github.com/mezis/guignol"
|
38
|
+
s.summary = "Manipulate Amazon EC2 instances"
|
39
|
+
s.description = %Q{
|
40
|
+
Create, start, stop, destroy instances from the command line
|
41
|
+
based on a YAML description of your instances.
|
42
|
+
}
|
43
|
+
|
44
|
+
s.required_rubygems_version = ">= 1.3.6"
|
45
|
+
|
46
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
47
|
+
s.add_development_dependency "rspec", "~> 2.4.0"
|
48
|
+
s.add_development_dependency "rake"
|
49
|
+
s.add_development_dependency "awesome_print"
|
50
|
+
|
51
|
+
s.add_dependency "fog", "~> 1.1.2"
|
52
|
+
s.add_dependency "parallel", "~> 0.5.14"
|
53
|
+
s.add_dependency "active_support"
|
54
|
+
s.add_dependency "term-ansicolor"
|
55
|
+
s.add_dependency "uuidtools"
|
56
|
+
|
57
|
+
s.files = `git ls-files`.split("\n")
|
58
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
59
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
60
|
+
s.require_path = 'lib'
|
61
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Copyright (c) 2012, HouseTrip SA.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
# list of conditions and the following disclaimer.
|
9
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer in the documentation
|
11
|
+
# and/or other materials provided with the distribution.
|
12
|
+
#
|
13
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
16
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
17
|
+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
18
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
19
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
20
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
21
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
22
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
#
|
24
|
+
# The views and conclusions contained in the software and documentation are those
|
25
|
+
# of the authors and should not be interpreted as representing official policies,
|
26
|
+
# either expressed or implied, of the authors.
|
27
|
+
|
28
|
+
Array.class_eval do
|
29
|
+
def collect_key(key)
|
30
|
+
collect { |item| item.kind_of?(Hash) ? item[key] : nil }
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# Copyright (c) 2012, HouseTrip SA.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
# list of conditions and the following disclaimer.
|
9
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer in the documentation
|
11
|
+
# and/or other materials provided with the distribution.
|
12
|
+
#
|
13
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
16
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
17
|
+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
18
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
19
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
20
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
21
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
22
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
#
|
24
|
+
# The views and conclusions contained in the software and documentation are those
|
25
|
+
# of the authors and should not be interpreted as representing official policies,
|
26
|
+
# either expressed or implied, of the authors.
|
27
|
+
|
28
|
+
|
29
|
+
require 'pathname'
|
30
|
+
require 'parallel'
|
31
|
+
require 'guignol/instance'
|
32
|
+
require 'guignol/array/collect_key'
|
33
|
+
|
34
|
+
module Guignol::Commands
|
35
|
+
class Base
|
36
|
+
|
37
|
+
def initialize(*argv)
|
38
|
+
@all_configs = load_config_files
|
39
|
+
check_config_consistency
|
40
|
+
@configs = argv.map { |pattern|
|
41
|
+
@all_configs.select { |config|
|
42
|
+
config[:name] =~ /#{pattern}/
|
43
|
+
}
|
44
|
+
}.flatten.uniq
|
45
|
+
end
|
46
|
+
|
47
|
+
def run
|
48
|
+
before_run or return if respond_to?(:before_run)
|
49
|
+
|
50
|
+
Parallel.each(@configs) do |config|
|
51
|
+
run_on_server(config)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
protected
|
56
|
+
|
57
|
+
def confirm(message)
|
58
|
+
$stdout.print "#{message}? [y/N] "
|
59
|
+
$stdout.flush
|
60
|
+
answer = $stdin.gets
|
61
|
+
return answer.strip =~ /y/i
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
# Read & return the first available config.
|
67
|
+
def load_config_files
|
68
|
+
[
|
69
|
+
Pathname.new(ENV['GUIGNOL_YML'] || '/var/nonexistent'),
|
70
|
+
Pathname.new('guignol.yml'),
|
71
|
+
Pathname.new('config/guignol.yml'),
|
72
|
+
Pathname.new(ENV['HOME']).join('.guignol.yml')
|
73
|
+
].each do |pathname|
|
74
|
+
next unless pathname.exist?
|
75
|
+
return YAML.load(pathname.read)
|
76
|
+
end
|
77
|
+
return {}
|
78
|
+
end
|
79
|
+
|
80
|
+
def check_config_consistency
|
81
|
+
errors = []
|
82
|
+
errors << "Instance config lacks :name" unless @all_configs.collect_key(:name).all?
|
83
|
+
errors << "Instance config lacks :uuid" unless @all_configs.collect_key(:uuid).all?
|
84
|
+
errors << "Volume config lacks :uuid" unless @all_configs.collect_key(:volumes).collect_key(:uuid)
|
85
|
+
raise errors.join(', ') if errors.any?
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Copyright (c) 2012, HouseTrip SA.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
# list of conditions and the following disclaimer.
|
9
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer in the documentation
|
11
|
+
# and/or other materials provided with the distribution.
|
12
|
+
#
|
13
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
16
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
17
|
+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
18
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
19
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
20
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
21
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
22
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
#
|
24
|
+
# The views and conclusions contained in the software and documentation are those
|
25
|
+
# of the authors and should not be interpreted as representing official policies,
|
26
|
+
# either expressed or implied, of the authors.
|
27
|
+
|
28
|
+
require 'guignol/commands/base'
|
29
|
+
require 'guignol/instance'
|
30
|
+
|
31
|
+
module Guignol::Commands
|
32
|
+
class Create < Base
|
33
|
+
def run_on_server(config)
|
34
|
+
Guignol::Instance.new(config).create
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.short_usage
|
38
|
+
["<regexps>", "Create instances and volumes (unless they exist) then run start"]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# Copyright (c) 2012, HouseTrip SA.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
# list of conditions and the following disclaimer.
|
9
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer in the documentation
|
11
|
+
# and/or other materials provided with the distribution.
|
12
|
+
#
|
13
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
16
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
17
|
+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
18
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
19
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
20
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
21
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
22
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
#
|
24
|
+
# The views and conclusions contained in the software and documentation are those
|
25
|
+
# of the authors and should not be interpreted as representing official policies,
|
26
|
+
# either expressed or implied, of the authors.
|
27
|
+
|
28
|
+
require 'guignol/commands/base'
|
29
|
+
require 'guignol/instance'
|
30
|
+
|
31
|
+
module Guignol::Commands
|
32
|
+
class Help
|
33
|
+
def initialize(*argv)
|
34
|
+
if help_for = argv.shift
|
35
|
+
@command_class = Guignol::Commands::Map[help_for]
|
36
|
+
@command_class.nil? and raise "no such command '#{help_for}'"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def run
|
41
|
+
if @command_class.respond_to?(:long_usage)
|
42
|
+
puts @command_class.long_usage
|
43
|
+
else
|
44
|
+
usage
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def usage
|
49
|
+
puts "usage: guignol <command> [options] [patterns]"
|
50
|
+
puts "manipulate EC2 instances from your command line."
|
51
|
+
puts
|
52
|
+
puts "The commands are:"
|
53
|
+
command_table =
|
54
|
+
Guignol::Commands::Map.map { |command_name, command_class|
|
55
|
+
usage = command_class.short_usage
|
56
|
+
[command_name] + usage
|
57
|
+
}
|
58
|
+
puts format_table(command_table, :sep => " ")
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.short_usage
|
62
|
+
["", "You're reading it !"]
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
# Format a text table from an array of arrays. Rows separated by +sep+.
|
68
|
+
def format_table(table, options={})
|
69
|
+
sep = options.delete(:sep) || " | "
|
70
|
+
columns = table.map { |row| row.size }.max
|
71
|
+
widths = table.reduce([0] * columns) { |memo,row| row.map(&:size).zip(memo).map(&:max) }
|
72
|
+
format = widths.map { |width| "%-#{width}s" }.join(sep)
|
73
|
+
table.map { |row| format % row }.join("\n")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Copyright (c) 2012, HouseTrip SA.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
# list of conditions and the following disclaimer.
|
9
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer in the documentation
|
11
|
+
# and/or other materials provided with the distribution.
|
12
|
+
#
|
13
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
16
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
17
|
+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
18
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
19
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
20
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
21
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
22
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
#
|
24
|
+
# The views and conclusions contained in the software and documentation are those
|
25
|
+
# of the authors and should not be interpreted as representing official policies,
|
26
|
+
# either expressed or implied, of the authors.
|
27
|
+
|
28
|
+
require 'guignol/commands/base'
|
29
|
+
require 'guignol/instance'
|
30
|
+
|
31
|
+
module Guignol::Commands
|
32
|
+
class Kill < Base
|
33
|
+
def before_run
|
34
|
+
return true if @configs.empty?
|
35
|
+
names = @configs.map { |config| config[:name] }.join(", ")
|
36
|
+
confirm "Are you sure you want to destroy servers #{names}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def run_on_server(config)
|
40
|
+
Guignol::Instance.new(config).destroy
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.short_usage
|
44
|
+
["<regexps>", "Destroy instances (if they exist)"]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|