Skip to content

Commit d6ac7d6

Browse files
committed
Now we use DO API V2 by default.
1 parent ef52a69 commit d6ac7d6

File tree

11 files changed

+43
-44
lines changed

11 files changed

+43
-44
lines changed

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
Use this tool to backup DigitalOcean droplet's via snapshot method, on the fly!
1414

15+
## Breaking changes: now we use DO API V2 by default, due V1 deprecation at 11.2015.
16+
1517
Here some features:
1618

1719
- Multiple threads out of the box. No matter how much droplet's you have.
@@ -48,7 +50,7 @@ Install it yourself as:
4850

4951
$ gem install do_snapshot
5052

51-
Or System Wide Install (OSX, *nix):
53+
System Wide Install (OSX, *nix):
5254

5355
$ sudo gem install do_snapshot
5456
@@ -81,6 +83,15 @@ Mainly it's pretty simple:
8183

8284
### Setup
8385

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+
8495
### Digitalocean API V1:
8596
You'll need to generate an access token in Digital Ocean's control panel at https://cloud.digitalocean.com/api_access
8697

@@ -89,26 +100,17 @@ You'll need to generate an access token in Digital Ocean's control panel at http
89100

90101
If you want to set keys without environment, than set it via options when you run do_snapshot:
91102

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
102104

103105
### How-To (Here is also [Longren Tutorial](https://longren.io/automate-making-snapshots-of-your-digitalocean-droplets/))
104106

105107
Here we `keeping` only 5 **latest** snapshots and cleanup older after new one is created. If creation of snapshots failed no one will be deleted. By default we keeping `10` droplets.
106108

107109
$ do_snapshot --keep 5 -c
108110

109-
Using API V2:
111+
Using API V1:
110112

111-
$ do_snapshot -p 2
113+
$ do_snapshot -p 1
112114

113115
Keep latest 3 from selected droplet:
114116

@@ -162,7 +164,7 @@ For working mailer you need to set e-mail settings via run options.
162164

163165
Options:
164166
-p, [--protocol=1] # Select api version.
165-
# Default: 1
167+
# Default: 2
166168
-o, [--only=123456 123456 123456] # Select some droplets.
167169
-e, [--exclude=123456 123456 123456] # Except some droplets.
168170
-k, [--keep=5] # How much snapshots you want to keep?

lib/do_snapshot/adapter.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ module DoSnapshot
1010
module Adapter
1111
def api(protocol, options)
1212
case protocol
13-
when 2
14-
return DigitaloceanV2.new(options)
15-
else
13+
when 1
1614
return Digitalocean.new(options)
15+
else
16+
return DigitaloceanV2.new(options)
1717
end
1818
end
1919
module_function :api

lib/do_snapshot/cli.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def initialize(*args)
4242
4343
Select api version (1, 2):
4444
45-
$ do_snapshot -a 2
45+
$ do_snapshot -p 1
4646
4747
Set DigitalOcean keys:
4848
@@ -78,7 +78,7 @@ def initialize(*args)
7878
LONGDESC
7979
method_option :protocol,
8080
type: :numeric,
81-
default: 1,
81+
default: 2,
8282
aliases: %w( -p ),
8383
banner: '1',
8484
desc: 'Select api version.'

spec/do_snapshot/adapter/digitalocean_v2_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
subject(:api) { described_class }
99
subject(:log) { DoSnapshot::Log }
1010

11-
let(:event_id) { '7499' }
12-
1311
describe '.initialize' do
1412
describe '#delay' do
1513
let(:delay) { 5 }

spec/do_snapshot/cli_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
RSpec.describe DoSnapshot::CLI do
55
include_context 'spec'
6-
include_context 'api_v1_helpers'
6+
include_context 'api_v2_helpers'
77

88
subject(:cli) { described_class }
99
subject(:api) { DoSnapshot::Adapter::Digitalocean }

spec/do_snapshot/command_spec.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
subject(:cmd) { DoSnapshot::Command.new }
99
subject(:log) { DoSnapshot::Log }
1010

11-
describe 'V2' do
12-
include_context 'api_v2_helpers'
13-
end
14-
1511
describe 'V1' do
1612
include_context 'api_v1_helpers'
13+
end
14+
15+
describe 'V2' do
16+
include_context 'api_v2_helpers'
1717

1818
describe '.snap' do
1919
context 'when success' do
@@ -215,8 +215,7 @@
215215

216216
it 'with start error' do
217217
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)
220219

221220
expect { cmd.fail_power_off(DoSnapshot::DropletShutdownError.new(droplet_id)) }
222221
.not_to raise_error
@@ -234,8 +233,8 @@
234233
end
235234

236235
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])
239238
end
240239

241240
def snap_runner

spec/do_snapshot/runner_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,6 @@
185185
end
186186

187187
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-
192188
include_context 'api_v2_helpers'
193189
it_behaves_like '.snap methods'
194190

@@ -216,6 +212,9 @@
216212
end
217213

218214
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+
219218
include_context 'api_v1_helpers'
220219
it_behaves_like '.snap methods'
221220

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"status": "OK",
3-
"event_id": 7501
3+
"event_id": 7499
44
}

spec/shared/api_v2_helpers.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ def stub_droplet_inactive(id)
5050
def stub_droplet_stop(id)
5151
stub_with_id(droplet_stop_uri, id, 'v2/show_event_power_off_start', :post,
5252
type: 'power_off'
53-
5453
)
5554
end
5655

@@ -66,16 +65,18 @@ def stub_droplet_stop_fail(id)
6665
def stub_droplet_start(id)
6766
stub_with_id(droplet_start_uri, id, 'v2/show_event_power_on_start', :post,
6867
type: 'power_on'
68+
)
69+
end
6970

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'
7074
)
7175
end
7276

7377
def stub_droplet_start_fail(id)
7478
stub_with_id(droplet_start_uri, id, 'v2/error_message', :post,
75-
{
76-
type: 'power_on'
77-
},
78-
404
79+
type: 'power_on'
7980
)
8081
end
8182

@@ -85,7 +86,6 @@ def stub_droplet_snapshot(id, name)
8586
stub_with_id_name(snapshot_uri, id, name, 'v2/response_event', :post,
8687
type: 'snapshot',
8788
name: name
88-
8989
)
9090
end
9191

spec/shared/environment.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ def do_not_send_email
1111
let(:client_key) { 'foo' }
1212
let(:api_key) { 'bar' }
1313
let(:access_token) { 'sometoken' }
14-
let(:event_id) { '7501' }
14+
let(:event_id) { '7499' }
1515
let(:droplet_id) { '100823' }
1616
let(:image_id) { '5019770' }
1717
let(:image_id2) { '5019903' }
1818
let(:cli_env_nil) { Hash['DIGITAL_OCEAN_CLIENT_ID' => nil, 'DIGITAL_OCEAN_API_KEY' => nil, 'DIGITAL_OCEAN_ACCESS_TOKEN' => nil] }
1919
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) }
2020
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] }
2323
let(:default_options_cli) { default_options.reject { |key, _| %w( droplets threads ).include?(key.to_s) } }
2424
let(:no_exclude) { [] }
2525
let(:exclude) { %w( 100824 100825 ) }

0 commit comments

Comments
 (0)