knife-digital_ocean 2.5.0 → 2.6.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: 40163c61e89b1e5d4eaa012a5923eab7a6ddc928
4
- data.tar.gz: efe07cc6b432eae199dc2e2e3bd421ba290deb71
3
+ metadata.gz: 66a8cd4ff5cf4cda89f98ec8dcb19c1badfc5518
4
+ data.tar.gz: 02ca754f6d1a49a14bd187fd0823dc6a021527e6
5
5
  SHA512:
6
- metadata.gz: 7e607c8f249fb7eb2991cccfc4fcdbe70376367dbb3f300ca2375b635f5ac5dae7331cb9ded4c1a4f6655fa1569c2663a546561ace85f64d725dc21000511a7a
7
- data.tar.gz: c3af42a24737b8ab49c73557e24c15959ce4be5a1eb7571b4b59f412a1ff2f67de32f4c041c4334ffccae04b879649e33e33fd23113639a2d58776afe872937f
6
+ metadata.gz: a82f90a38e6979ff97bfd9b4a9b38ef9235abb06a17471c70c4c757541191f983979134ca13df47c4ef90acd41feb872268863130ab0637acedbb3ffec42d44e
7
+ data.tar.gz: dc88dccf3c4decac124bf5e66a06c74a01ac7a045efda63a8b0b842a82012baeabb84b2678f9b90699125dcb40c96993f0fc218fff567bf7ce94e720ae803668
@@ -1,9 +1,8 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.1.0
5
- - 2.2.2
6
- - 2.2.3
4
+ - 2.2.5
5
+ - 2.3.1
7
6
  env:
8
7
  - DIGITALOCEAN_ACCESS_TOKEN="fake_access_token"
9
8
  script: bundle exec rake spec
@@ -1,4 +1,4 @@
1
- # 2.5.0 / unreleased
1
+ # 2.5.0 / 2016-04-19
2
2
 
3
3
  * fix vcr cassettes (droplet_kit pagination)
4
4
  * drop support for Ruby 2.0.0
data/README.md CHANGED
@@ -43,7 +43,7 @@ This plugin provides the following sub-commands:
43
43
  * knife digital_ocean droplet list (options)
44
44
  **Lists currently running virtual machines**
45
45
 
46
- * knife digital_ocean droplet power (options)
46
+ * knife digital_ocean droplet power (options)
47
47
  **Turn a droplet On/Off**
48
48
 
49
49
  * knife digital_ocean droplet powercycle (options)
@@ -52,6 +52,9 @@ This plugin provides the following sub-commands:
52
52
  * knife digital_ocean droplet reboot (options)
53
53
  **Reboot a Droplet**
54
54
 
55
+ * knife digital_ocean droplet shutdown (options)
56
+ **Shutdown a droplet**
57
+
55
58
  * knife digital_ocean droplet snapshot (options)
56
59
  **Take a snapshot of a Droplet**
57
60
 
@@ -309,6 +312,12 @@ OK
309
312
  OK
310
313
  ```
311
314
 
315
+ #### Shutdown a droplet
316
+ ```shell
317
+ ➜ knife digital_ocean shutdown -I 1824315
318
+ OK
319
+ ```
320
+
312
321
  #### Create a droplet from a Snapshot
313
322
  ```shell
314
323
  ➜ knife digital_ocean snapshot -I 1824315 -N 'my-super-awesome-snapshot'
@@ -166,6 +166,13 @@ class Chef
166
166
  description: 'Enables ipv6 for the created droplet',
167
167
  default: false
168
168
 
169
+ option :user_data,
170
+ short: '-u USER_DATA_FILE',
171
+ long: '--user-data USER_DATA_FILE',
172
+ description: 'A file containing the user_data, this usually contains a cloud-config/cloud-init config',
173
+ proc: proc { |u| Chef::Config[:knife][:user_data] = File.read(u) },
174
+ default: ''
175
+
169
176
  def run
170
177
  $stdout.sync = true
171
178
 
@@ -221,7 +228,8 @@ class Chef
221
228
  ssh_keys: locate_config_value(:ssh_key_ids),
222
229
  private_networking: locate_config_value(:private_networking),
223
230
  backups: locate_config_value(:backups),
224
- ipv6: locate_config_value(:ipv6)
231
+ ipv6: locate_config_value(:ipv6),
232
+ user_data: locate_config_value(:user_data)
225
233
  )
226
234
 
227
235
  server = client.droplets.create(droplet)
@@ -0,0 +1,50 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ #
13
+ require 'chef/knife/digital_ocean_base'
14
+
15
+ class Chef
16
+ class Knife
17
+ class DigitalOceanDropletShutdown < Knife
18
+ include Knife::DigitalOceanBase
19
+
20
+ banner 'knife digital_ocean droplet shutdown (options)'
21
+
22
+ option :id,
23
+ short: '-I ID',
24
+ long: '--droplet-id ID',
25
+ description: 'Droplet ID'
26
+
27
+ def run
28
+ $stdout.sync = true
29
+
30
+ validate!
31
+
32
+ unless locate_config_value(:id)
33
+ ui.error('ID cannot be empty. => -I <id>')
34
+ exit 1
35
+ end
36
+
37
+ ui.info "Shutdown droplet with id: #{locate_config_value(:id)}"
38
+
39
+ result = client.droplet_actions.shutdown(droplet_id: locate_config_value(:id))
40
+
41
+ unless result.class == DropletKit::Action
42
+ ui.error JSON.parse(result)['message']
43
+ exit 1
44
+ end
45
+
46
+ wait_for_status(result, status: 'off')
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,5 +1,5 @@
1
1
  module Knife
2
2
  module DigitalOcean
3
- VERSION = '2.5.0'
3
+ VERSION = '2.6.0'
4
4
  end
5
5
  end
@@ -0,0 +1,66 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.digitalocean.com/v2/droplets/4829346/actions
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"type":"shutdown"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Authorization:
13
+ - Bearer FAKE_ACCESS_TOKEN
14
+ User-Agent:
15
+ - Faraday v0.9.1
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 201
23
+ message: Created
24
+ headers:
25
+ Server:
26
+ - cloudflare-nginx
27
+ Date:
28
+ - Sat, 11 Apr 2015 23:27:14 GMT
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Transfer-Encoding:
32
+ - chunked
33
+ Connection:
34
+ - keep-alive
35
+ Set-Cookie: _COOKIE_ID_
36
+ Status:
37
+ - 201 Created
38
+ X-Frame-Options:
39
+ - SAMEORIGIN
40
+ X-Xss-Protection:
41
+ - 1; mode=block
42
+ X-Content-Type-Options:
43
+ - nosniff
44
+ Ratelimit-Limit:
45
+ - '5000'
46
+ Ratelimit-Remaining:
47
+ - '4997'
48
+ Ratelimit-Reset:
49
+ - '1428797844'
50
+ Etag:
51
+ - '"8add870987c9c4e49d74ba6b653690a3"'
52
+ Cache-Control:
53
+ - max-age=0, private, must-revalidate
54
+ X-Request-Id:
55
+ - e2cac9ba-7bc9-444f-939c-02c57920221c
56
+ X-Runtime:
57
+ - '0.166743'
58
+ Cf-Ray:
59
+ - 1d5a76021bd31834-EWR
60
+ body:
61
+ encoding: UTF-8
62
+ string: '{"action":{"id":47949289,"status":"in-progress","type":"shutdown","started_at":"2015-04-11T23:27:14Z","completed_at":null,"resource_id":4829346,"resource_type":"droplet","region":{"name":"New
63
+ York 3","slug":"nyc3","sizes":["512mb","1gb","2gb","4gb","8gb","16gb","32gb","48gb","64gb"],"features":["virtio","private_networking","backups","ipv6","metadata"],"available":true},"region_slug":"nyc3"}}'
64
+ http_version:
65
+ recorded_at: Sat, 11 Apr 2015 23:27:14 GMT
66
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Knife::DigitalOceanDropletShutdown do
4
+ subject { Chef::Knife::DigitalOceanDropletShutdown.new }
5
+
6
+ let(:access_token) { ENV['DIGITALOCEAN_ACCESS_TOKEN'] }
7
+
8
+ before :each do
9
+ Chef::Knife::DigitalOceanDropletShutdown.load_deps
10
+ Chef::Config['knife']['digital_ocean_access_token'] = access_token
11
+ allow(subject).to receive(:puts)
12
+ allow(subject).to receive(:wait_for_status).and_return('OK')
13
+ subject.config[:id] = '4829346'
14
+ subject.config[:action] = 'off'
15
+ end
16
+
17
+ describe '#run' do
18
+ it 'should validate the Digital Ocean config keys exist' do
19
+ VCR.use_cassette('droplet_shutdown') do
20
+ expect(subject).to receive(:validate!)
21
+ subject.run
22
+ end
23
+ end
24
+
25
+ it 'should power the droplet and exit with 0' do
26
+ VCR.use_cassette('droplet_shutdown') do
27
+ allow(subject.client).to receive_message_chain(:droplet_actions, :shutdown)
28
+ expect { subject.run }.not_to raise_error
29
+ end
30
+ end
31
+
32
+ it 'should return OK' do
33
+ VCR.use_cassette('droplet_shutdown') do
34
+ expect(subject.run).to eq 'OK'
35
+ end
36
+ end
37
+ end
38
+ end
@@ -15,6 +15,7 @@ require 'chef/knife/digital_ocean_droplet_reboot'
15
15
  require 'chef/knife/digital_ocean_droplet_power'
16
16
  require 'chef/knife/digital_ocean_droplet_powercycle'
17
17
  require 'chef/knife/digital_ocean_droplet_rename'
18
+ require 'chef/knife/digital_ocean_droplet_shutdown'
18
19
  require 'chef/knife/digital_ocean_droplet_snapshot'
19
20
  require 'chef/knife/digital_ocean_droplet_rebuild'
20
21
  require 'chef/knife/digital_ocean_droplet_resize'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-digital_ocean
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roland Moriz
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-19 00:00:00.000000000 Z
12
+ date: 2017-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -259,6 +259,7 @@ files:
259
259
  - lib/chef/knife/digital_ocean_droplet_rebuild.rb
260
260
  - lib/chef/knife/digital_ocean_droplet_rename.rb
261
261
  - lib/chef/knife/digital_ocean_droplet_resize.rb
262
+ - lib/chef/knife/digital_ocean_droplet_shutdown.rb
262
263
  - lib/chef/knife/digital_ocean_droplet_snapshot.rb
263
264
  - lib/chef/knife/digital_ocean_image_destroy.rb
264
265
  - lib/chef/knife/digital_ocean_image_list.rb
@@ -283,6 +284,7 @@ files:
283
284
  - spec/fixtures/vcr_cassettes/droplet_rebuild.yml
284
285
  - spec/fixtures/vcr_cassettes/droplet_rename.yml
285
286
  - spec/fixtures/vcr_cassettes/droplet_resize.yml
287
+ - spec/fixtures/vcr_cassettes/droplet_shutdown.yml
286
288
  - spec/fixtures/vcr_cassettes/droplet_snapshot.yml
287
289
  - spec/fixtures/vcr_cassettes/image.yml
288
290
  - spec/fixtures/vcr_cassettes/public_images.yml
@@ -306,6 +308,7 @@ files:
306
308
  - spec/lib/chef/knife/digital_ocean_droplet_rebuild_spec.rb
307
309
  - spec/lib/chef/knife/digital_ocean_droplet_rename_spec.rb
308
310
  - spec/lib/chef/knife/digital_ocean_droplet_resize_spec.rb
311
+ - spec/lib/chef/knife/digital_ocean_droplet_shutdown_spec.rb
309
312
  - spec/lib/chef/knife/digital_ocean_droplet_snapshot_spec.rb
310
313
  - spec/lib/chef/knife/digital_ocean_image_list_spec.rb
311
314
  - spec/lib/chef/knife/digital_ocean_region_list_spec.rb
@@ -335,7 +338,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
335
338
  version: '0'
336
339
  requirements: []
337
340
  rubyforge_project:
338
- rubygems_version: 2.5.1
341
+ rubygems_version: 2.6.11
339
342
  signing_key:
340
343
  specification_version: 4
341
344
  summary: A plugin for chef's knife to manage instances of DigitalOcean servers
@@ -353,6 +356,7 @@ test_files:
353
356
  - spec/fixtures/vcr_cassettes/droplet_rebuild.yml
354
357
  - spec/fixtures/vcr_cassettes/droplet_rename.yml
355
358
  - spec/fixtures/vcr_cassettes/droplet_resize.yml
359
+ - spec/fixtures/vcr_cassettes/droplet_shutdown.yml
356
360
  - spec/fixtures/vcr_cassettes/droplet_snapshot.yml
357
361
  - spec/fixtures/vcr_cassettes/image.yml
358
362
  - spec/fixtures/vcr_cassettes/public_images.yml
@@ -376,6 +380,7 @@ test_files:
376
380
  - spec/lib/chef/knife/digital_ocean_droplet_rebuild_spec.rb
377
381
  - spec/lib/chef/knife/digital_ocean_droplet_rename_spec.rb
378
382
  - spec/lib/chef/knife/digital_ocean_droplet_resize_spec.rb
383
+ - spec/lib/chef/knife/digital_ocean_droplet_shutdown_spec.rb
379
384
  - spec/lib/chef/knife/digital_ocean_droplet_snapshot_spec.rb
380
385
  - spec/lib/chef/knife/digital_ocean_image_list_spec.rb
381
386
  - spec/lib/chef/knife/digital_ocean_region_list_spec.rb