do_snapshot 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f793635439ffb9a56d8f4c2e9be57a1e9f98ab5
4
- data.tar.gz: 6f2680b1346011ac73bae361e70015dd12566cad
3
+ metadata.gz: 77cc4c07beb253d0aa7fbe1870fb45f014c6f339
4
+ data.tar.gz: 0c2acaaaddadd3626423894aaf25c8fc3a84dfb1
5
5
  SHA512:
6
- metadata.gz: d26d8f14434a1471f12fbea7db98be706a169c78d16f04dcc7105954b5358f33fed013f7d67b0d5a629622748be9dc68f6f2193944fe225f81f7d99628fdcc60
7
- data.tar.gz: 58fccbd707e2cf5c97d725b39ad5a29caa38d2b92ce977d5bbb1c372029bca3cd9154819344695e3ad9d566b7db2b4b4f4b046c6d783a0cc24977fc1755263e0
6
+ metadata.gz: a15514139088299e98b567a227205cc14f6d3e71b7a19707bf1ad9520690962104b57dc3f8b80bb3bae9fa515d511b082f96adfd94ab4d8909d17a846c265369
7
+ data.tar.gz: 33e4c117829a0ede9809c7930426811e8110ac9fb3d8b6ee35894e0f622535cf285205ccd263d7fd66d17ee6efc82cffeecebac2805d95e292752e8bbed0ec42
data/README.md CHANGED
@@ -12,6 +12,8 @@
12
12
 
13
13
  Use this tool to backup DigitalOcean droplet's via snapshot method, on the fly!
14
14
 
15
+ ## Breaking changes: now we use DO API V2 by default, due V1 deprecation at 11.2015.
16
+
15
17
  Here some features:
16
18
 
17
19
  - Multiple threads out of the box. No matter how much droplet's you have.
@@ -48,7 +50,7 @@ Install it yourself as:
48
50
 
49
51
  $ gem install do_snapshot
50
52
 
51
- Or System Wide Install (OSX, *nix):
53
+ System Wide Install (OSX, *nix):
52
54
 
53
55
  $ sudo gem install do_snapshot
54
56
 
@@ -81,6 +83,15 @@ Mainly it's pretty simple:
81
83
 
82
84
  ### Setup
83
85
 
86
+ ### Digitalocean API V2 (default):
87
+ You'll need to generate an access token in Digital Ocean's control panel at https://cloud.digitalocean.com/settings/applications
88
+
89
+ $ export DIGITAL_OCEAN_ACCESS_TOKEN="SOMETOKEN"
90
+
91
+ If you want to set keys without environment, than set it via options when you run do_snapshot:
92
+
93
+ $ do_snapshot --digital-ocean-access-token YOURLONGTOKEN
94
+
84
95
  ### Digitalocean API V1:
85
96
  You'll need to generate an access token in Digital Ocean's control panel at https://cloud.digitalocean.com/api_access
86
97
 
@@ -89,16 +100,7 @@ You'll need to generate an access token in Digital Ocean's control panel at http
89
100
 
90
101
  If you want to set keys without environment, than set it via options when you run do_snapshot:
91
102
 
92
- $ do_snapshot --digital-ocean-client-id YOURLONGAPICLIENTID --digital-ocean-api-key YOURLONGAPIKEY
93
-
94
- ### Digitalocean API V2:
95
- You'll need to generate an access token in Digital Ocean's control panel at https://cloud.digitalocean.com/settings/applications
96
-
97
- $ export DIGITAL_OCEAN_ACCESS_TOKEN="SOMETOKEN"
98
-
99
- If you want to set keys without environment, than set it via options when you run do_snapshot:
100
-
101
- $ do_snapshot --digital-ocean-access-token YOURLONGTOKEN
103
+ $ do_snapshot --digital-ocean-client-id YOURLONGAPICLIENTID --digital-ocean-api-key YOURLONGAPIKEY
102
104
 
103
105
  ### How-To (Here is also [Longren Tutorial](https://longren.io/automate-making-snapshots-of-your-digitalocean-droplets/))
104
106
 
@@ -106,9 +108,9 @@ Here we `keeping` only 5 **latest** snapshots and cleanup older after new one is
106
108
 
107
109
  $ do_snapshot --keep 5 -c
108
110
 
109
- Using API V2:
111
+ Using API V1:
110
112
 
111
- $ do_snapshot -p 2
113
+ $ do_snapshot -p 1
112
114
 
113
115
  Keep latest 3 from selected droplet:
114
116
 
@@ -162,7 +164,7 @@ For working mailer you need to set e-mail settings via run options.
162
164
 
163
165
  Options:
164
166
  -p, [--protocol=1] # Select api version.
165
- # Default: 1
167
+ # Default: 2
166
168
  -o, [--only=123456 123456 123456] # Select some droplets.
167
169
  -e, [--exclude=123456 123456 123456] # Except some droplets.
168
170
  -k, [--keep=5] # How much snapshots you want to keep?
@@ -10,10 +10,10 @@ module DoSnapshot
10
10
  module Adapter
11
11
  def api(protocol, options)
12
12
  case protocol
13
- when 2
14
- return DigitaloceanV2.new(options)
15
- else
13
+ when 1
16
14
  return Digitalocean.new(options)
15
+ else
16
+ return DigitaloceanV2.new(options)
17
17
  end
18
18
  end
19
19
  module_function :api
@@ -42,7 +42,7 @@ module DoSnapshot
42
42
 
43
43
  Select api version (1, 2):
44
44
 
45
- $ do_snapshot -a 2
45
+ $ do_snapshot -p 1
46
46
 
47
47
  Set DigitalOcean keys:
48
48
 
@@ -78,7 +78,7 @@ module DoSnapshot
78
78
  LONGDESC
79
79
  method_option :protocol,
80
80
  type: :numeric,
81
- default: 1,
81
+ default: 2,
82
82
  aliases: %w( -p ),
83
83
  banner: '1',
84
84
  desc: 'Select api version.'
@@ -2,5 +2,5 @@
2
2
  # Current version
3
3
  #
4
4
  module DoSnapshot
5
- VERSION = '0.4.3'
5
+ VERSION = '0.5.0'
6
6
  end
@@ -8,8 +8,6 @@ RSpec.describe DoSnapshot::Adapter::DigitaloceanV2 do
8
8
  subject(:api) { described_class }
9
9
  subject(:log) { DoSnapshot::Log }
10
10
 
11
- let(:event_id) { '7499' }
12
-
13
11
  describe '.initialize' do
14
12
  describe '#delay' do
15
13
  let(:delay) { 5 }
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
 
4
4
  RSpec.describe DoSnapshot::CLI do
5
5
  include_context 'spec'
6
- include_context 'api_v1_helpers'
6
+ include_context 'api_v2_helpers'
7
7
 
8
8
  subject(:cli) { described_class }
9
9
  subject(:api) { DoSnapshot::Adapter::Digitalocean }
@@ -8,12 +8,12 @@ RSpec.describe DoSnapshot::Command do
8
8
  subject(:cmd) { DoSnapshot::Command.new }
9
9
  subject(:log) { DoSnapshot::Log }
10
10
 
11
- describe 'V2' do
12
- include_context 'api_v2_helpers'
13
- end
14
-
15
11
  describe 'V1' do
16
12
  include_context 'api_v1_helpers'
13
+ end
14
+
15
+ describe 'V2' do
16
+ include_context 'api_v2_helpers'
17
17
 
18
18
  describe '.snap' do
19
19
  context 'when success' do
@@ -215,8 +215,7 @@ RSpec.describe DoSnapshot::Command do
215
215
 
216
216
  it 'with start error' do
217
217
  stub_droplet_inactive(droplet_id)
218
- stub_droplet_start_fail(droplet_id)
219
- stub_event_fail(event_id)
218
+ stub_droplet_start_done(droplet_id)
220
219
 
221
220
  expect { cmd.fail_power_off(DoSnapshot::DropletShutdownError.new(droplet_id)) }
222
221
  .not_to raise_error
@@ -234,8 +233,8 @@ RSpec.describe DoSnapshot::Command do
234
233
  end
235
234
 
236
235
  def load_options(options = nil)
237
- options ||= default_options.merge(protocol: 1)
238
- cmd.load_options(options, [:log, :mail, :smtp, :trace, :digital_ocean_client_id, :digital_ocean_api_key])
236
+ options ||= default_options.merge(protocol: 2)
237
+ cmd.load_options(options, [:log, :mail, :smtp, :trace, :digital_ocean_access_token])
239
238
  end
240
239
 
241
240
  def snap_runner
@@ -185,10 +185,6 @@ RSpec.describe DoSnapshot::Runner, type: :aruba do
185
185
  end
186
186
 
187
187
  context 'API V2' do
188
- let(:default_options_cli) { default_options.reject { |key, _| %w( droplets threads ).include?(key.to_s) }.merge(protocol: 2) }
189
- let(:event_id) { '7499' }
190
- let(:snapshot_name) { "example.com_#{DateTime.now.strftime('%Y_%m_%d')}" }
191
-
192
188
  include_context 'api_v2_helpers'
193
189
  it_behaves_like '.snap methods'
194
190
 
@@ -216,6 +212,9 @@ RSpec.describe DoSnapshot::Runner, type: :aruba do
216
212
  end
217
213
 
218
214
  context 'API V1' do
215
+ let(:default_options_cli) { default_options.merge(protocol: 1) }
216
+ let(:snapshot_name) { "foo_#{DateTime.now.strftime('%Y_%m_%d')}" }
217
+
219
218
  include_context 'api_v1_helpers'
220
219
  it_behaves_like '.snap methods'
221
220
 
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "status": "OK",
3
- "event_id": 7501
3
+ "event_id": 7499
4
4
  }
@@ -50,7 +50,6 @@ shared_context 'api_v2_helpers' do
50
50
  def stub_droplet_stop(id)
51
51
  stub_with_id(droplet_stop_uri, id, 'v2/show_event_power_off_start', :post,
52
52
  type: 'power_off'
53
-
54
53
  )
55
54
  end
56
55
 
@@ -66,16 +65,18 @@ shared_context 'api_v2_helpers' do
66
65
  def stub_droplet_start(id)
67
66
  stub_with_id(droplet_start_uri, id, 'v2/show_event_power_on_start', :post,
68
67
  type: 'power_on'
68
+ )
69
+ end
69
70
 
71
+ def stub_droplet_start_done(id)
72
+ stub_with_id(droplet_start_uri, id, 'v2/show_event_power_on_done', :post,
73
+ type: 'power_on'
70
74
  )
71
75
  end
72
76
 
73
77
  def stub_droplet_start_fail(id)
74
78
  stub_with_id(droplet_start_uri, id, 'v2/error_message', :post,
75
- {
76
- type: 'power_on'
77
- },
78
- 404
79
+ type: 'power_on'
79
80
  )
80
81
  end
81
82
 
@@ -85,7 +86,6 @@ shared_context 'api_v2_helpers' do
85
86
  stub_with_id_name(snapshot_uri, id, name, 'v2/response_event', :post,
86
87
  type: 'snapshot',
87
88
  name: name
88
-
89
89
  )
90
90
  end
91
91
 
@@ -11,15 +11,15 @@ shared_context 'spec' do
11
11
  let(:client_key) { 'foo' }
12
12
  let(:api_key) { 'bar' }
13
13
  let(:access_token) { 'sometoken' }
14
- let(:event_id) { '7501' }
14
+ let(:event_id) { '7499' }
15
15
  let(:droplet_id) { '100823' }
16
16
  let(:image_id) { '5019770' }
17
17
  let(:image_id2) { '5019903' }
18
18
  let(:cli_env_nil) { Hash['DIGITAL_OCEAN_CLIENT_ID' => nil, 'DIGITAL_OCEAN_API_KEY' => nil, 'DIGITAL_OCEAN_ACCESS_TOKEN' => nil] }
19
19
  let(:cli_keys) { Thor::CoreExt::HashWithIndifferentAccess.new(digital_ocean_client_id: client_key, digital_ocean_api_key: api_key, digital_ocean_access_token: access_token) }
20
20
  let(:cli_keys_other) { Thor::CoreExt::HashWithIndifferentAccess.new(digital_ocean_client_id: 'NOTFOO', digital_ocean_api_key: 'NOTBAR', digital_ocean_access_token: 'NOTTOK') }
21
- let(:snapshot_name) { "foo_#{DateTime.now.strftime('%Y_%m_%d')}" }
22
- let(:default_options) { Hash[protocol: 1, only: %w( 100823 ), exclude: %w(), keep: 3, stop: false, trace: true, clean: true, delay: 0, timeout: 600, droplets: nil, threads: []] }
21
+ let(:snapshot_name) { "example.com_#{DateTime.now.strftime('%Y_%m_%d')}" }
22
+ let(:default_options) { Hash[protocol: 2, only: %w( 100823 ), exclude: %w(), keep: 3, stop: false, trace: true, clean: true, delay: 0, timeout: 600] }
23
23
  let(:default_options_cli) { default_options.reject { |key, _| %w( droplets threads ).include?(key.to_s) } }
24
24
  let(:no_exclude) { [] }
25
25
  let(:exclude) { %w( 100824 100825 ) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: do_snapshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Merkulov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-16 00:00:00.000000000 Z
11
+ date: 2015-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: digitalocean_c