guignol 0.1.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.rspec +2 -1
- data/Gemfile.lock +29 -18
- data/LICENCE +26 -0
- data/README.md +67 -38
- data/Rakefile +0 -26
- data/bin/guignol +3 -33
- data/guignol.gemspec +4 -30
- data/lib/core_ext/array/collect_key.rb +6 -0
- data/lib/core_ext/hash/map_to_hash.rb +31 -0
- data/lib/guignol.rb +15 -35
- data/lib/guignol/commands/base.rb +53 -66
- data/lib/guignol/commands/clone.rb +49 -0
- data/lib/guignol/commands/create.rb +14 -33
- data/lib/guignol/commands/execute.rb +69 -0
- data/lib/guignol/commands/fix_dns.rb +12 -33
- data/lib/guignol/commands/kill.rb +18 -36
- data/lib/guignol/commands/list.rb +19 -45
- data/lib/guignol/commands/start.rb +14 -33
- data/lib/guignol/commands/stop.rb +18 -37
- data/lib/guignol/commands/uuid.rb +19 -32
- data/lib/guignol/configuration.rb +43 -0
- data/lib/guignol/connection.rb +33 -0
- data/lib/guignol/env.rb +19 -0
- data/lib/guignol/logger.rb +29 -0
- data/lib/guignol/models/base.rb +125 -0
- data/lib/guignol/models/instance.rb +244 -0
- data/lib/guignol/models/volume.rb +91 -0
- data/lib/guignol/shell.rb +27 -42
- data/lib/guignol/tty_spinner.rb +6 -29
- data/lib/guignol/version.rb +1 -27
- data/spec/guignol/configuration_spec.rb +72 -0
- data/spec/guignol/instance_spec.rb +48 -8
- data/spec/guignol/volume_spec.rb +17 -0
- data/spec/spec_helper.rb +12 -0
- data/tmp/.keepme +0 -0
- metadata +79 -52
- data/lib/guignol/array/collect_key.rb +0 -32
- data/lib/guignol/commands.rb +0 -48
- data/lib/guignol/commands/help.rb +0 -77
- data/lib/guignol/instance.rb +0 -270
- data/lib/guignol/shared.rb +0 -80
- data/lib/guignol/volume.rb +0 -124
data/lib/guignol/volume.rb
DELETED
@@ -1,124 +0,0 @@
|
|
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
|