guignol 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,30 @@
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
+ module Guignol
29
+ VERSION = "0.1"
30
+ end
@@ -0,0 +1,124 @@
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 'fog'
29
+ require 'active_support/core_ext/hash/slice'
30
+ require 'guignol'
31
+ require 'guignol/shared'
32
+
33
+
34
+ module Guignol
35
+ class Volume
36
+ include Shared
37
+
38
+
39
+ def initialize(options)
40
+ @options = options.dup
41
+ connection_options = DefaultConnectionOptions.dup.merge @options.slice(:region)
42
+
43
+ @connection = Fog::Compute.new(connection_options)
44
+ @subject = @connection.volumes.
45
+ select { |s| %w(in-use available).include?(s.state) }.
46
+ find { |s| s.tags['UUID'] == uuid }
47
+ end
48
+
49
+
50
+ def exist?
51
+ !!@subject
52
+ end
53
+
54
+
55
+ def name
56
+ @options[:name]
57
+ end
58
+
59
+
60
+ def uuid
61
+ @options[:uuid]
62
+ end
63
+
64
+
65
+ def availability_zone
66
+ @subject && @subject.availability_zone
67
+ end
68
+
69
+
70
+ def create
71
+ if exist?
72
+ log "volume already exists"
73
+ else
74
+ log "creating volume"
75
+ options = DefaultVolumeOptions.dup.merge @options.slice(:availability_zone, :size, :snapshot, :delete_on_termination)
76
+ @subject = @connection.volumes.create(options)
77
+ update_tags
78
+
79
+ wait_for_state 'available'
80
+ end
81
+ return self
82
+ rescue Exception => e
83
+ log "error while creating (#{e.class.name})"
84
+ destroy
85
+ raise
86
+ end
87
+
88
+
89
+ def destroy
90
+ if !exist?
91
+ log "volume does not exist"
92
+ else
93
+ log "destroying volume"
94
+ @subject.destroy
95
+ wait_for_state 'deleted'
96
+ # FIXME: remove tags here
97
+ end
98
+ @subject = nil
99
+ return self
100
+ end
101
+
102
+
103
+ def attach(server_id)
104
+ exist? or create
105
+ response = @connection.attach_volume(server_id, @subject.id, @options[:dev])
106
+ response.status == 200 or raise 'failed to attach volume'
107
+ update_tags
108
+ end
109
+
110
+
111
+
112
+ def update_tags
113
+ log "updating tags"
114
+ tags = { 'Name' => name, 'UUID' => uuid }
115
+ response = @connection.create_tags(@subject.id, tags)
116
+ unless response.status == 200
117
+ log "failed"
118
+ destroy and return
119
+ end
120
+ end
121
+
122
+
123
+ end
124
+ end
data/lib/guignol.rb ADDED
@@ -0,0 +1,38 @@
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
+ module Guignol
29
+ DefaultConnectionOptions = {
30
+ :provider => :aws,
31
+ :region => 'eu-west-1'
32
+ }
33
+ DefaultServerOptions = {
34
+ :flavor_id => 't1.micro',
35
+ :volumes => []
36
+ }
37
+ DefaultVolumeOptions = {}
38
+ end
metadata ADDED
@@ -0,0 +1,224 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guignol
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Julien Letessier
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-03-01 00:00:00 +00:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bundler
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 23
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 0
34
+ version: 1.0.0
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 31
46
+ segments:
47
+ - 2
48
+ - 4
49
+ - 0
50
+ version: 2.4.0
51
+ requirement: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rake
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirement: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: awesome_print
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirement: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: fog
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ hash: 23
90
+ segments:
91
+ - 1
92
+ - 1
93
+ - 2
94
+ version: 1.1.2
95
+ requirement: *id005
96
+ - !ruby/object:Gem::Dependency
97
+ name: parallel
98
+ type: :runtime
99
+ prerelease: false
100
+ version_requirements: &id006 !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ~>
104
+ - !ruby/object:Gem::Version
105
+ hash: 23
106
+ segments:
107
+ - 0
108
+ - 5
109
+ - 14
110
+ version: 0.5.14
111
+ requirement: *id006
112
+ - !ruby/object:Gem::Dependency
113
+ name: active_support
114
+ type: :runtime
115
+ prerelease: false
116
+ version_requirements: &id007 !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ requirement: *id007
126
+ - !ruby/object:Gem::Dependency
127
+ name: term-ansicolor
128
+ type: :runtime
129
+ prerelease: false
130
+ version_requirements: &id008 !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ hash: 3
136
+ segments:
137
+ - 0
138
+ version: "0"
139
+ requirement: *id008
140
+ - !ruby/object:Gem::Dependency
141
+ name: uuidtools
142
+ type: :runtime
143
+ prerelease: false
144
+ version_requirements: &id009 !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ hash: 3
150
+ segments:
151
+ - 0
152
+ version: "0"
153
+ requirement: *id009
154
+ description: "\n Create, start, stop, destroy instances from the command line\n based on a YAML description of your instances.\n "
155
+ email:
156
+ - julien.letessier@gmail.com
157
+ executables:
158
+ - guignol
159
+ extensions: []
160
+
161
+ extra_rdoc_files: []
162
+
163
+ files:
164
+ - Gemfile
165
+ - Gemfile.lock
166
+ - README.md
167
+ - Rakefile
168
+ - bin/guignol
169
+ - guignol.gemspec
170
+ - lib/guignol.rb
171
+ - lib/guignol/array/collect_key.rb
172
+ - lib/guignol/commands.rb
173
+ - lib/guignol/commands/base.rb
174
+ - lib/guignol/commands/create.rb
175
+ - lib/guignol/commands/help.rb
176
+ - lib/guignol/commands/kill.rb
177
+ - lib/guignol/commands/list.rb
178
+ - lib/guignol/commands/start.rb
179
+ - lib/guignol/commands/stop.rb
180
+ - lib/guignol/commands/uuid.rb
181
+ - lib/guignol/instance.rb
182
+ - lib/guignol/shared.rb
183
+ - lib/guignol/shell.rb
184
+ - lib/guignol/tty_spinner.rb
185
+ - lib/guignol/version.rb
186
+ - lib/guignol/volume.rb
187
+ has_rdoc: true
188
+ homepage: https://github.com/mezis/guignol
189
+ licenses: []
190
+
191
+ post_install_message:
192
+ rdoc_options: []
193
+
194
+ require_paths:
195
+ - lib
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ none: false
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ hash: 3
202
+ segments:
203
+ - 0
204
+ version: "0"
205
+ required_rubygems_version: !ruby/object:Gem::Requirement
206
+ none: false
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ hash: 23
211
+ segments:
212
+ - 1
213
+ - 3
214
+ - 6
215
+ version: 1.3.6
216
+ requirements: []
217
+
218
+ rubyforge_project:
219
+ rubygems_version: 1.6.2
220
+ signing_key:
221
+ specification_version: 3
222
+ summary: Manipulate Amazon EC2 instances
223
+ test_files: []
224
+