-
Notifications
You must be signed in to change notification settings - Fork 89
/
middleware.rb
326 lines (299 loc) · 8.87 KB
/
middleware.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
require 'middleware'
module Tugboat
module Middleware
autoload :AddKey, 'tugboat/middleware/add_key'
autoload :AskForCredentials, 'tugboat/middleware/ask_for_credentials'
autoload :Base, 'tugboat/middleware/base'
autoload :BackupConfig, 'tugboat/middleware/backup_setting'
autoload :CheckConfiguration, 'tugboat/middleware/check_configuration'
autoload :CheckCredentials, 'tugboat/middleware/check_credentials'
autoload :CheckDropletActive, 'tugboat/middleware/check_droplet_active'
autoload :CheckDropletInactive, 'tugboat/middleware/check_droplet_inactive'
autoload :CheckSnapshotParameters, 'tugboat/middleware/check_snapshot_parameters'
autoload :Config, 'tugboat/middleware/config'
autoload :ConfirmAction, 'tugboat/middleware/confirm_action'
autoload :CreateDroplet, 'tugboat/middleware/create_droplet'
autoload :RebuildDroplet, 'tugboat/middleware/rebuild_droplet'
autoload :DestroyDroplet, 'tugboat/middleware/destroy_droplet'
autoload :DestroyImage, 'tugboat/middleware/destroy_image'
autoload :FindDroplet, 'tugboat/middleware/find_droplet'
autoload :FindImage, 'tugboat/middleware/find_image'
autoload :HaltDroplet, 'tugboat/middleware/halt_droplet'
autoload :InfoDroplet, 'tugboat/middleware/info_droplet'
autoload :InfoImage, 'tugboat/middleware/info_image'
autoload :InjectClient, 'tugboat/middleware/inject_client'
autoload :InjectConfiguration, 'tugboat/middleware/inject_configuration'
autoload :ListDroplets, 'tugboat/middleware/list_droplets'
autoload :ListImages, 'tugboat/middleware/list_images'
autoload :ListRegions, 'tugboat/middleware/list_regions'
autoload :ListSizes, 'tugboat/middleware/list_sizes'
autoload :ListSnapshots, 'tugboat/middleware/list_snapshots'
autoload :ListSSHKeys, 'tugboat/middleware/list_ssh_keys'
autoload :PasswordReset, 'tugboat/middleware/password_reset'
autoload :ResizeDroplet, 'tugboat/middleware/resize_droplet'
autoload :RestartDroplet, 'tugboat/middleware/restart_droplet'
autoload :SnapshotDroplet, 'tugboat/middleware/snapshot_droplet'
autoload :SSHDroplet, 'tugboat/middleware/ssh_droplet'
autoload :SCPDroplet, 'tugboat/middleware/scp_droplet'
autoload :StartDroplet, 'tugboat/middleware/start_droplet'
autoload :WaitForState, 'tugboat/middleware/wait_for_state'
# Start the authorization flow.
# This writes a ~/.tugboat file, which can be edited manually.
def self.sequence_authorize
::Middleware::Builder.new do
use InjectConfiguration
use AskForCredentials
use InjectConfiguration
use CheckConfiguration
use InjectClient
use CheckCredentials
end
end
def self.sequence_backup_config
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use FindDroplet
use BackupConfig
end
end
# This checks that the credentials in ~/.tugboat are valid
def self.sequence_verify
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use CheckCredentials
end
end
# Display a list of droplets
def self.sequence_list_droplets
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use ListDroplets
end
end
# Display a list of images
def self.sequence_list_images
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use ListImages
end
end
# Restart a droplet
def self.sequence_restart_droplet
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use FindDroplet
use RestartDroplet
end
end
# Start a droplet
def self.sequence_start_droplet
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use FindDroplet
use CheckDropletInactive
use StartDroplet
end
end
# Shutdown a droplet
def self.sequence_halt_droplet
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use FindDroplet
use CheckDropletActive
use HaltDroplet
end
end
# Show information about a droplet
def self.sequence_info_droplet
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use FindDroplet
use InfoDroplet
end
end
# Show information about an image
def self.sequence_info_image
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use FindImage
use InfoImage
end
end
# SSH into a droplet
def self.sequence_ssh_droplet
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use FindDroplet
use CheckDropletActive
use SSHDroplet
end
end
# SSH into a droplet
def self.sequence_scp_droplet
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use FindDroplet
use CheckDropletActive
use SCPDroplet
end
end
# Create a droplet
def self.sequence_create_droplet
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use CreateDroplet
end
end
# Rebuild a droplet
def self.sequence_rebuild_droplet
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use FindDroplet
use FindImage
use ConfirmAction
use RebuildDroplet
end
end
# Destroy a droplet
def self.sequence_destroy_droplet
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use FindDroplet
use ConfirmAction
use DestroyDroplet
end
end
# Destroy an image
def self.sequence_destroy_image
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use FindImage
use ConfirmAction
use DestroyImage
end
end
# Snapshot a droplet
def self.sequence_snapshot_droplet
::Middleware::Builder.new do
use CheckSnapshotParameters
use InjectConfiguration
use CheckConfiguration
use InjectClient
use FindDroplet
use CheckDropletInactive
use SnapshotDroplet
end
end
# Display a list of available SSH keys
def self.sequence_ssh_keys
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use ListSSHKeys
end
end
# Display a list of available SSH keys
def self.sequence_list_snapshots
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use ListSnapshots
end
end
# Create a droplet
def self.sequence_add_key
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use AddKey
end
end
# Display a list of regions
def self.sequence_regions
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use ListRegions
end
end
# Display a list of droplet sizes
def self.sequence_sizes
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use ListSizes
end
end
# Resize a droplet
def self.sequence_resize_droplet
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use FindDroplet
use ResizeDroplet
end
end
# Reset root password
def self.sequence_password_reset
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use FindDroplet
use PasswordReset
end
end
# Returns current used config
def self.sequence_config
::Middleware::Builder.new do
use Config
end
end
# Wait for a droplet to enter a desired state
def self.sequence_wait
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use FindDroplet
use WaitForState
end
end
end
end