do_snapshot 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/do_snapshot/api.rb +1 -1
- data/lib/do_snapshot/command.rb +3 -10
- data/lib/do_snapshot/log.rb +5 -1
- data/lib/do_snapshot/version.rb +1 -1
- data/spec/do_snapshot/api_spec.rb +0 -4
- data/spec/do_snapshot/command_spec.rb +18 -25
- data/spec/shared/environment.rb +1 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8803902d64a76db013fb9c2866ef0e04c79ef2de
|
4
|
+
data.tar.gz: 22589c3aa8c1eef2af78aefd89f6cf04b959340b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcb151a013ef7ec0d78dd35132c5f9e6c9cfdce35e55ec0d918331247f63d616f330b8713d0b11101d7d503fff80d39677f1873a7d044961b0c15425726a3cc8
|
7
|
+
data.tar.gz: 1b300fb97331704010d0167949345fcb238296d82321e907fa62d13808816227ed2d30476d6ace14db77b7b437300dacb2a76558273927c4e92106c8dbe37f1d
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ Here some features:
|
|
27
27
|
|
28
28
|
Ruby versions: 1.9.3 and higher. JRuby in 1.9 mode is also supported.
|
29
29
|
|
30
|
-
|
30
|
+
<img src="https://raw.githubusercontent.com/merqlove/do_snapshot/master/assets/example.png" style="max-width:100%" alt="DoSnaphot example">
|
31
31
|
|
32
32
|
### You can ask me, "Why you made this tool?"
|
33
33
|
|
@@ -45,7 +45,7 @@ Install it yourself as:
|
|
45
45
|
|
46
46
|
$ gem install do_snapshot
|
47
47
|
|
48
|
-
For **OSX** users ([Homebrew Tap](http://github.com/merqlove/
|
48
|
+
For **OSX** users ([Homebrew Tap](http://github.com/merqlove/homebrew-do-snapshot)):
|
49
49
|
|
50
50
|
$ brew tap merqlove/do-snapshot && brew install do_snapshot
|
51
51
|
|
@@ -97,7 +97,7 @@ Keep latest 5 snapshots, send mail notification instead of creating new one:
|
|
97
97
|
|
98
98
|
$ do_snapshot --keep 10 --stop --mail to:yourmail@example.com
|
99
99
|
|
100
|
-
|
100
|
+
<img src="https://raw.githubusercontent.com/merqlove/do_snapshot/master/assets/safe_mode.png" style="max-width:100%" alt="DoSnapshot Safe Mode Example">
|
101
101
|
|
102
102
|
E-mail notifications disabled out of the box.
|
103
103
|
For working mailer you need to set e-mail settings via run options.
|
data/lib/do_snapshot/api.rb
CHANGED
@@ -117,7 +117,7 @@ module DoSnapshot
|
|
117
117
|
# Before snapshot we to know that machine has powered off.
|
118
118
|
#
|
119
119
|
def get_event_status(id, time)
|
120
|
-
return true if (Time.now
|
120
|
+
return true if (Time.now - time) > timeout
|
121
121
|
event = Digitalocean::Event.find(id)
|
122
122
|
fail event.message unless event.status.include?('OK')
|
123
123
|
# noinspection RubyResolve,RubyResolve
|
data/lib/do_snapshot/command.rb
CHANGED
@@ -31,9 +31,9 @@ module DoSnapshot
|
|
31
31
|
protected
|
32
32
|
|
33
33
|
attr_accessor :droplets, :exclude, :only
|
34
|
-
attr_accessor :keep, :quiet, :stop, :clean
|
34
|
+
attr_accessor :keep, :quiet, :stop, :clean, :timeout, :delay
|
35
35
|
|
36
|
-
attr_writer :notify, :
|
36
|
+
attr_writer :notify, :threads, :api
|
37
37
|
|
38
38
|
def api
|
39
39
|
@api ||= API.new(delay: delay, timeout: timeout)
|
@@ -47,14 +47,6 @@ module DoSnapshot
|
|
47
47
|
@threads ||= []
|
48
48
|
end
|
49
49
|
|
50
|
-
def timeout
|
51
|
-
@timeout ||= 600
|
52
|
-
end
|
53
|
-
|
54
|
-
def delay
|
55
|
-
@delay ||= 10
|
56
|
-
end
|
57
|
-
|
58
50
|
# Working with list of droplets.
|
59
51
|
#
|
60
52
|
def work_with_droplets
|
@@ -80,6 +72,7 @@ module DoSnapshot
|
|
80
72
|
next if exclude.include? id
|
81
73
|
next if !only.empty? && !only.include?(id)
|
82
74
|
|
75
|
+
Log.debug "Droplet id: #{id} name: #{droplet.name} "
|
83
76
|
instance = api.droplet id
|
84
77
|
|
85
78
|
prepare_instance instance.droplet
|
data/lib/do_snapshot/log.rb
CHANGED
@@ -35,7 +35,11 @@ module DoSnapshot
|
|
35
35
|
buffer << message
|
36
36
|
logger.send(type, message) if logger
|
37
37
|
|
38
|
-
say message, color(type) unless (type
|
38
|
+
say message, color(type) unless print?(type)
|
39
|
+
end
|
40
|
+
|
41
|
+
def print?(type)
|
42
|
+
(type == :debug && !verbose) || quiet
|
39
43
|
end
|
40
44
|
|
41
45
|
def say(message, color)
|
data/lib/do_snapshot/version.rb
CHANGED
@@ -46,30 +46,23 @@ describe DoSnapshot::Command do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
#
|
67
|
-
# expect { snap_runner }
|
68
|
-
# .to raise_error(DoSnapshot::SnapshotCreateError)
|
69
|
-
#
|
70
|
-
# # remove_request_stub(no_snapshot)
|
71
|
-
# end
|
72
|
-
# end
|
49
|
+
context 'when droplet failed for shutdown' do
|
50
|
+
it 'raised with error' do
|
51
|
+
stub_droplet_stop_fail(droplet_id)
|
52
|
+
|
53
|
+
expect { snap_runner }
|
54
|
+
.to raise_error(DoSnapshot::DropletShutdownError)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when no snapshot created' do
|
59
|
+
it 'raised with error' do
|
60
|
+
stub_droplet_snapshot_fail(droplet_id, snapshot_name)
|
61
|
+
|
62
|
+
expect { snap_runner }
|
63
|
+
.to raise_error(DoSnapshot::SnapshotCreateError)
|
64
|
+
end
|
65
|
+
end
|
73
66
|
end
|
74
67
|
|
75
68
|
describe '.fail_power_off' do
|
@@ -106,7 +99,6 @@ describe DoSnapshot::Command do
|
|
106
99
|
end
|
107
100
|
|
108
101
|
before(:each) do
|
109
|
-
# @cmd = DoSnapshot::Command
|
110
102
|
stub_all_api(nil, true)
|
111
103
|
log.buffer = %w()
|
112
104
|
log.verbose = false
|
@@ -115,6 +107,7 @@ describe DoSnapshot::Command do
|
|
115
107
|
|
116
108
|
def snap_runner(options = nil)
|
117
109
|
options ||= default_options
|
110
|
+
cmd.send('api=', nil)
|
118
111
|
cmd.snap(options, [:log, :mail, :smtp, :trace, :digital_ocean_client_id, :digital_ocean_api_key])
|
119
112
|
end
|
120
113
|
end
|
data/spec/shared/environment.rb
CHANGED
@@ -12,7 +12,7 @@ shared_context 'spec' do
|
|
12
12
|
let(:image_id2) { '5019903' }
|
13
13
|
let(:cli_keys) { Thor::CoreExt::HashWithIndifferentAccess.new(digital_ocean_client_id: 'NOTFOO', digital_ocean_client_bar: 'NOTBAR') }
|
14
14
|
let(:snapshot_name) { "foo_#{DateTime.now.strftime('%Y_%m_%d')}" }
|
15
|
-
let(:default_options) { Hash[only: %w( 100823 ), exclude: %w(), keep: 3, trace: true, clean: true, delay: 0, timeout: 600, droplets: nil, threads: []] }
|
15
|
+
let(:default_options) { Hash[only: %w( 100823 ), exclude: %w(), keep: 3, stop: false, trace: true, clean: true, delay: 0, timeout: 600, droplets: nil, threads: []] }
|
16
16
|
let(:no_exclude) { [] }
|
17
17
|
let(:exclude) { %w( 100824 100825 ) }
|
18
18
|
let(:no_only) { [] }
|
@@ -88,12 +88,7 @@ shared_context 'spec' do
|
|
88
88
|
WebMock.reset!
|
89
89
|
end
|
90
90
|
|
91
|
-
after(:all) do
|
92
|
-
# sleep(1)
|
93
|
-
end
|
94
|
-
|
95
91
|
before(:each) do
|
96
|
-
# stub_cleanup
|
97
92
|
ENV['DIGITAL_OCEAN_API_KEY'] = api_key
|
98
93
|
ENV['DIGITAL_OCEAN_CLIENT_ID'] = client_key
|
99
94
|
end
|