knife-digital_ocean 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/README.md +112 -20
  4. data/Rakefile +6 -0
  5. data/knife-digital_ocean.gemspec +4 -0
  6. data/lib/chef/knife/digital_ocean_base.rb +15 -0
  7. data/lib/chef/knife/digital_ocean_domain_create.rb +9 -10
  8. data/lib/chef/knife/digital_ocean_domain_destroy.rb +5 -5
  9. data/lib/chef/knife/digital_ocean_domain_list.rb +1 -2
  10. data/lib/chef/knife/digital_ocean_domain_record_create.rb +18 -18
  11. data/lib/chef/knife/digital_ocean_domain_record_destroy.rb +9 -10
  12. data/lib/chef/knife/digital_ocean_domain_record_edit.rb +21 -21
  13. data/lib/chef/knife/digital_ocean_domain_record_list.rb +4 -5
  14. data/lib/chef/knife/digital_ocean_droplet_create.rb +4 -5
  15. data/lib/chef/knife/digital_ocean_droplet_destroy.rb +3 -6
  16. data/lib/chef/knife/digital_ocean_droplet_power.rb +66 -0
  17. data/lib/chef/knife/digital_ocean_droplet_powercycle.rb +48 -0
  18. data/lib/chef/knife/digital_ocean_droplet_reboot.rb +48 -0
  19. data/lib/chef/knife/digital_ocean_droplet_rebuild.rb +58 -0
  20. data/lib/chef/knife/digital_ocean_droplet_rename.rb +58 -0
  21. data/lib/chef/knife/digital_ocean_droplet_resize.rb +58 -0
  22. data/lib/chef/knife/digital_ocean_droplet_snapshot.rb +58 -0
  23. data/lib/chef/knife/digital_ocean_image_destroy.rb +42 -0
  24. data/lib/chef/knife/digital_ocean_image_list.rb +1 -1
  25. data/lib/chef/knife/digital_ocean_image_transfer.rb +66 -0
  26. data/lib/chef/knife/digital_ocean_region_list.rb +1 -1
  27. data/lib/chef/knife/digital_ocean_sshkey_create.rb +11 -11
  28. data/lib/chef/knife/digital_ocean_sshkey_destroy.rb +6 -6
  29. data/lib/chef/knife/digital_ocean_sshkey_list.rb +1 -1
  30. data/lib/knife-digital_ocean/version.rb +1 -1
  31. data/spec/fixtures/keys/id_rsa.pub +1 -0
  32. data/spec/fixtures/vcr_cassettes/accountinfo.yml +7 -9
  33. data/spec/fixtures/vcr_cassettes/domain_create.yml +65 -0
  34. data/spec/fixtures/vcr_cassettes/{domainlist.yml → domain_list.yml} +15 -12
  35. data/spec/fixtures/vcr_cassettes/domain_record_create.yml +65 -0
  36. data/spec/fixtures/vcr_cassettes/domain_record_list.yml +63 -0
  37. data/spec/fixtures/vcr_cassettes/droplet.yml +12 -17
  38. data/spec/fixtures/vcr_cassettes/droplet_power.yml +65 -0
  39. data/spec/fixtures/vcr_cassettes/droplet_powercycle.yml +127 -0
  40. data/spec/fixtures/vcr_cassettes/droplet_reboot.yml +127 -0
  41. data/spec/fixtures/vcr_cassettes/droplet_rebuild.yml +65 -0
  42. data/spec/fixtures/vcr_cassettes/droplet_rename.yml +127 -0
  43. data/spec/fixtures/vcr_cassettes/droplet_resize.yml +65 -0
  44. data/spec/fixtures/vcr_cassettes/droplet_snapshot.yml +1057 -0
  45. data/spec/fixtures/vcr_cassettes/image.yml +55 -59
  46. data/spec/fixtures/vcr_cassettes/public_images.yml +54 -59
  47. data/spec/fixtures/vcr_cassettes/region.yml +8 -10
  48. data/spec/fixtures/vcr_cassettes/sizes.yml +8 -10
  49. data/spec/fixtures/vcr_cassettes/sshkey.yml +8 -10
  50. data/spec/fixtures/vcr_cassettes/sshkey_create.yml +68 -0
  51. data/spec/lib/chef/knife/digital_ocean_account_info_spec.rb +4 -4
  52. data/spec/lib/chef/knife/digital_ocean_domain_create_spec.rb +35 -1
  53. data/spec/lib/chef/knife/digital_ocean_domain_list_spec.rb +8 -9
  54. data/spec/lib/chef/knife/digital_ocean_domain_record_create_spec.rb +37 -1
  55. data/spec/lib/chef/knife/digital_ocean_domain_record_list_spec.rb +34 -1
  56. data/spec/lib/chef/knife/digital_ocean_droplet_create_spec.rb +5 -1
  57. data/spec/lib/chef/knife/digital_ocean_droplet_list_spec.rb +4 -4
  58. data/spec/lib/chef/knife/digital_ocean_droplet_power_spec.rb +39 -0
  59. data/spec/lib/chef/knife/digital_ocean_droplet_powercycle_spec.rb +38 -0
  60. data/spec/lib/chef/knife/digital_ocean_droplet_reboot_spec.rb +38 -0
  61. data/spec/lib/chef/knife/digital_ocean_droplet_rebuild_spec.rb +39 -0
  62. data/spec/lib/chef/knife/digital_ocean_droplet_rename_spec.rb +39 -0
  63. data/spec/lib/chef/knife/digital_ocean_droplet_resize_spec.rb +39 -0
  64. data/spec/lib/chef/knife/digital_ocean_droplet_snapshot_spec.rb +39 -0
  65. data/spec/lib/chef/knife/digital_ocean_image_list_spec.rb +8 -10
  66. data/spec/lib/chef/knife/digital_ocean_region_list_spec.rb +4 -4
  67. data/spec/lib/chef/knife/digital_ocean_size_list_spec.rb +4 -4
  68. data/spec/lib/chef/knife/digital_ocean_sshkey_create_spec.rb +35 -1
  69. data/spec/lib/chef/knife/digital_ocean_sshkey_list_spec.rb +4 -4
  70. data/spec/spec_helper.rb +29 -2
  71. metadata +93 -6
  72. data/spec/lib/chef/knife/digital_ocean_domain_record_edit_spec.rb +0 -5
@@ -21,14 +21,14 @@ class Chef
21
21
  banner 'knife digital_ocean domain record destroy (options)'
22
22
 
23
23
  option :domain,
24
- :short => '-D NAME',
25
- :long => '--domain-id NAME',
26
- :description => 'The domain name'
24
+ short: '-D NAME',
25
+ long: '--domain-id NAME',
26
+ description: 'The domain name'
27
27
 
28
28
  option :record,
29
- :short => '-R ID',
30
- :long => '--record-id ID',
31
- :description => 'The record id'
29
+ short: '-R ID',
30
+ long: '--record-id ID',
31
+ description: 'The record id'
32
32
 
33
33
  def run
34
34
  $stdout.sync = true
@@ -36,19 +36,18 @@ class Chef
36
36
  validate!
37
37
 
38
38
  unless locate_config_value(:domain)
39
- ui.error("Domain cannot be empty. => -D <domain-name>")
39
+ ui.error('Domain cannot be empty. => -D <domain-name>')
40
40
  exit 1
41
41
  end
42
42
 
43
43
  unless locate_config_value(:record)
44
- ui.error("Record cannot be empty. => -R <record-id>")
44
+ ui.error('Record cannot be empty. => -R <record-id>')
45
45
  exit 1
46
46
  end
47
47
 
48
48
  result = client.domain_records.delete for_domain: locate_config_value(:domain), id: locate_config_value(:record)
49
- ui.error JSON.parse(result)['message'] rescue 'OK'
49
+ ui.info 'OK' if result == true or ui.error JSON.parse(result)['message']
50
50
  end
51
-
52
51
  end
53
52
  end
54
53
  end
@@ -21,29 +21,29 @@ class Chef
21
21
  banner 'knife digital_ocean domain record edit (options)'
22
22
 
23
23
  option :domain,
24
- :short => '-D NAME',
25
- :long => '--domain-id NAME',
26
- :description => 'The domain name'
24
+ short: '-D NAME',
25
+ long: '--domain-id NAME',
26
+ description: 'The domain name'
27
27
 
28
28
  option :record,
29
- :short => '-R ID',
30
- :long => '--record-id ID',
31
- :description => 'The record id'
29
+ short: '-R ID',
30
+ long: '--record-id ID',
31
+ description: 'The record id'
32
32
 
33
33
  option :type,
34
- :short => '-T RECORD TYPE',
35
- :long => '--type RECORD TYPE',
36
- :description => 'The type of record'
34
+ short: '-T RECORD TYPE',
35
+ long: '--type RECORD TYPE',
36
+ description: 'The type of record'
37
37
 
38
38
  option :name,
39
- :short => '-N RECORD NAME',
40
- :long => '--name RECORD NAME',
41
- :description => 'The record name'
39
+ short: '-N RECORD NAME',
40
+ long: '--name RECORD NAME',
41
+ description: 'The record name'
42
42
 
43
43
  option :data,
44
- :short => '-a DATA',
45
- :long => '--data DATA',
46
- :description => 'The record data'
44
+ short: '-a DATA',
45
+ long: '--data DATA',
46
+ description: 'The record data'
47
47
 
48
48
  def run
49
49
  $stdout.sync = true
@@ -51,27 +51,27 @@ class Chef
51
51
  validate!
52
52
 
53
53
  unless locate_config_value(:domain)
54
- ui.error("Domain cannot be empty. => -D <domain-name>")
54
+ ui.error('Domain cannot be empty. => -D <domain-name>')
55
55
  exit 1
56
56
  end
57
57
 
58
58
  unless locate_config_value(:record)
59
- ui.error("Record cannot be empty. => -R <record-id>")
59
+ ui.error('Record cannot be empty. => -R <record-id>')
60
60
  exit 1
61
61
  end
62
62
 
63
63
  unless locate_config_value(:type)
64
- ui.error("Record type cannot be empty. => -T <record-type>")
64
+ ui.error('Record type cannot be empty. => -T <record-type>')
65
65
  exit 1
66
66
  end
67
67
 
68
68
  unless locate_config_value(:name)
69
- ui.error("Record name cannot be empty. => -N <record-name>")
69
+ ui.error('Record name cannot be empty. => -N <record-name>')
70
70
  exit 1
71
71
  end
72
72
 
73
73
  unless locate_config_value(:data)
74
- ui.error("Record data cannot be empty. => -d <data>")
74
+ ui.error('Record data cannot be empty. => -d <data>')
75
75
  exit 1
76
76
  end
77
77
 
@@ -81,7 +81,7 @@ class Chef
81
81
  data: locate_config_value(:data)
82
82
  )
83
83
  result = client.domain_records.update domain_record, for_domain: locate_config_value(:domain), id: locate_config_value(:record)
84
- ui.error JSON.parse(result)['message'] rescue 'OK'
84
+ ui.info 'OK' if result == true or ui.error JSON.parse(result)['message']
85
85
  end
86
86
  end
87
87
  end
@@ -19,9 +19,9 @@ class Chef
19
19
  banner 'knife digital_ocean domain record list (options)'
20
20
 
21
21
  option :name,
22
- :short => '-D NAME',
23
- :long => '--domain-name NAME',
24
- :description => 'The domain name'
22
+ short: '-D NAME',
23
+ long: '--domain-name NAME',
24
+ description: 'The domain name'
25
25
 
26
26
  def run
27
27
  $stdout.sync = true
@@ -29,7 +29,7 @@ class Chef
29
29
  validate!
30
30
 
31
31
  unless locate_config_value(:name)
32
- ui.error("Domain Name cannot be empty. => -D <domain-name>")
32
+ ui.error('Domain Name cannot be empty. => -D <domain-name>')
33
33
  exit 1
34
34
  end
35
35
 
@@ -48,7 +48,6 @@ class Chef
48
48
  domains_list << domain.data.to_s
49
49
  end
50
50
 
51
-
52
51
  puts ui.list(domains_list, :uneven_columns_across, 4)
53
52
  end
54
53
  end
@@ -206,13 +206,12 @@ class Chef
206
206
  ipv6: locate_config_value(:ipv6)
207
207
  )
208
208
 
209
-
210
209
  server = client.droplets.create(droplet)
211
210
 
212
- # if client.droplets.find(id: server.id).status != 'in-progress'
213
- # ui.error("Droplet could not be started #{server.inspect}")
214
- # exit 1
215
- # end
211
+ if client.droplets.find(id: server.id).status != 'new'
212
+ ui.error("Droplet could not be started #{server.inspect}")
213
+ exit 1
214
+ end
216
215
 
217
216
  puts "Droplet creation for #{locate_config_value(:server_name)} started. Droplet-ID is #{server.id}"
218
217
 
@@ -29,7 +29,6 @@ class Chef
29
29
  long: '--all',
30
30
  description: '!WARNING! UNRECOVERABLE Destroy all droplets.'
31
31
 
32
-
33
32
  def run
34
33
  $stdout.sync = true
35
34
 
@@ -52,15 +51,13 @@ class Chef
52
51
  end
53
52
 
54
53
  if locate_config_value(:all)
55
- droplets_ids = client.droplets.all.map do |droplet|
56
- droplet.id
57
- end
54
+ droplets_ids = client.droplets.all.map(&:id)
58
55
  end
59
56
 
60
57
  droplets_ids.each do |id|
61
- puts "Delete droplet with id: #{id}"
58
+ ui.info "Delete droplet with id: #{id}"
62
59
  result = client.droplets.delete(id: id)
63
- puts JSON.parse(result)['message'] rescue 'OK'
60
+ ui.info 'OK' if result == true or ui.error JSON.parse(result)['message']
64
61
  end
65
62
  end
66
63
  end
@@ -0,0 +1,66 @@
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 DigitalOceanDropletPower < Knife
18
+ include Knife::DigitalOceanBase
19
+
20
+ banner 'knife digital_ocean droplet power (options)'
21
+
22
+ option :action,
23
+ short: '-a ACTION',
24
+ long: '--action ACTION',
25
+ description: 'Power Action On/Off'
26
+
27
+ option :id,
28
+ short: '-I ID',
29
+ long: '--droplet-id ID',
30
+ description: 'Droplet ID'
31
+
32
+ def run
33
+ $stdout.sync = true
34
+
35
+ validate!
36
+
37
+ unless locate_config_value(:action)
38
+ ui.error('Action cannot be empty. => -a <action>')
39
+ exit 1
40
+ end
41
+
42
+ unless locate_config_value(:id)
43
+ ui.error('ID cannot be empty. => -I <id>')
44
+ exit 1
45
+ end
46
+
47
+ case locate_config_value(:action)
48
+ when /(on)/i
49
+ result = client.droplet_actions.power_on(droplet_id: locate_config_value(:id))
50
+ when /(off)/i
51
+ result = client.droplet_actions.power_off(droplet_id: locate_config_value(:id))
52
+ else
53
+ ui.error 'Bad Action: Use on/off.'
54
+ exit 1
55
+ end
56
+
57
+ unless result.class == DropletKit::Action
58
+ ui.error JSON.parse(result)['message']
59
+ exit 1
60
+ end
61
+
62
+ wait_for_status(result)
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,48 @@
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 DigitalOceanDropletPowercycle < Knife
18
+ include Knife::DigitalOceanBase
19
+
20
+ banner 'knife digital_ocean droplet powercycle (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
+ result = client.droplet_actions.power_cycle(droplet_id: locate_config_value(:id))
38
+
39
+ unless result.class == DropletKit::Action
40
+ ui.error JSON.parse(result)['message']
41
+ exit 1
42
+ end
43
+
44
+ wait_for_status(result, status: 'active')
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,48 @@
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 DigitalOceanDropletReboot < Knife
18
+ include Knife::DigitalOceanBase
19
+
20
+ banner 'knife digital_ocean droplet reboot (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
+ result = client.droplet_actions.reboot(droplet_id: locate_config_value(:id))
38
+
39
+ unless result.class == DropletKit::Action
40
+ ui.error JSON.parse(result)['message']
41
+ exit 1
42
+ end
43
+
44
+ wait_for_status(result)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,58 @@
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 DigitalOceanDropletRebuild < Knife
18
+ include Knife::DigitalOceanBase
19
+
20
+ banner 'knife digital_ocean droplet rebuild (options)'
21
+
22
+ option :image,
23
+ short: '-i IMAGE',
24
+ long: '--image-id IMAGE',
25
+ description: 'Image ID'
26
+
27
+ option :id,
28
+ short: '-I ID',
29
+ long: '--droplet-id ID',
30
+ description: 'Droplet ID'
31
+
32
+ def run
33
+ $stdout.sync = true
34
+
35
+ validate!
36
+
37
+ unless locate_config_value(:image)
38
+ ui.error('Image ID cannot be empty. => -i <image-id>')
39
+ exit 1
40
+ end
41
+
42
+ unless locate_config_value(:id)
43
+ ui.error('ID cannot be empty. => -I <id>')
44
+ exit 1
45
+ end
46
+
47
+ result = client.droplet_actions.rebuild(droplet_id: locate_config_value(:id), image: locate_config_value(:image))
48
+
49
+ unless result.class == DropletKit::Action
50
+ ui.error JSON.parse(result)['message']
51
+ exit 1
52
+ end
53
+
54
+ wait_for_status(result, status: 'active')
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,58 @@
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 DigitalOceanDropletRename < Knife
18
+ include Knife::DigitalOceanBase
19
+
20
+ banner 'knife digital_ocean droplet rename (options)'
21
+
22
+ option :name,
23
+ short: '-N NAME',
24
+ long: '--droplet-name NAME',
25
+ description: 'Name of droplet'
26
+
27
+ option :id,
28
+ short: '-I ID',
29
+ long: '--droplet-id ID',
30
+ description: 'Droplet ID'
31
+
32
+ def run
33
+ $stdout.sync = true
34
+
35
+ validate!
36
+
37
+ unless locate_config_value(:name)
38
+ ui.error('Name cannot be empty. => -N <name>')
39
+ exit 1
40
+ end
41
+
42
+ unless locate_config_value(:id)
43
+ ui.error('ID cannot be empty. => -I <id>')
44
+ exit 1
45
+ end
46
+
47
+ result = client.droplet_actions.rename(droplet_id: locate_config_value(:id), name: locate_config_value(:name))
48
+
49
+ unless result.class == DropletKit::Action
50
+ ui.error JSON.parse(result)['message']
51
+ exit 1
52
+ end
53
+
54
+ wait_for_status(result)
55
+ end
56
+ end
57
+ end
58
+ end