knife-profitbricks 1.2.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +303 -96
  4. data/knife-profitbricks.gemspec +1 -1
  5. data/lib/chef/knife/profitbricks_base.rb +24 -0
  6. data/lib/chef/knife/profitbricks_composite_server_create.rb +59 -45
  7. data/lib/chef/knife/profitbricks_contract_list.rb +37 -0
  8. data/lib/chef/knife/profitbricks_datacenter_create.rb +8 -7
  9. data/lib/chef/knife/profitbricks_firewall_create.rb +15 -15
  10. data/lib/chef/knife/profitbricks_firewall_delete.rb +6 -8
  11. data/lib/chef/knife/profitbricks_firewall_list.rb +6 -5
  12. data/lib/chef/knife/profitbricks_ipblock_create.rb +6 -7
  13. data/lib/chef/knife/profitbricks_ipfailover_add.rb +60 -0
  14. data/lib/chef/knife/profitbricks_ipfailover_remove.rb +60 -0
  15. data/lib/chef/knife/profitbricks_lan_create.rb +5 -3
  16. data/lib/chef/knife/profitbricks_lan_list.rb +1 -1
  17. data/lib/chef/knife/profitbricks_nic_create.rb +12 -14
  18. data/lib/chef/knife/profitbricks_nic_delete.rb +4 -3
  19. data/lib/chef/knife/profitbricks_nic_list.rb +4 -3
  20. data/lib/chef/knife/profitbricks_server_create.rb +14 -16
  21. data/lib/chef/knife/profitbricks_server_delete.rb +1 -1
  22. data/lib/chef/knife/profitbricks_server_list.rb +1 -1
  23. data/lib/chef/knife/profitbricks_server_reboot.rb +1 -1
  24. data/lib/chef/knife/profitbricks_server_start.rb +1 -1
  25. data/lib/chef/knife/profitbricks_server_stop.rb +1 -1
  26. data/lib/chef/knife/profitbricks_volume_attach.rb +5 -5
  27. data/lib/chef/knife/profitbricks_volume_create.rb +38 -18
  28. data/lib/chef/knife/profitbricks_volume_delete.rb +1 -1
  29. data/lib/chef/knife/profitbricks_volume_detach.rb +4 -4
  30. data/lib/chef/knife/profitbricks_volume_list.rb +5 -6
  31. data/lib/knife-profitbricks/version.rb +1 -1
  32. data/spec/chef/knife/profitbricks_composite_server_create_spec.rb +64 -0
  33. data/spec/chef/knife/profitbricks_contract_list_spec.rb +20 -0
  34. data/spec/chef/knife/profitbricks_datacenter_create_spec.rb +44 -0
  35. data/spec/chef/knife/profitbricks_datacenter_delete_spec.rb +39 -0
  36. data/spec/chef/knife/profitbricks_datacenter_list_spec.rb +7 -6
  37. data/spec/chef/knife/profitbricks_firewall_create_spec.rb +74 -0
  38. data/spec/chef/knife/profitbricks_firewall_delete_spec.rb +86 -0
  39. data/spec/chef/knife/profitbricks_firewall_list_spec.rb +61 -0
  40. data/spec/chef/knife/profitbricks_image_list_spec.rb +19 -0
  41. data/spec/chef/knife/profitbricks_ipblock_create_spec.rb +39 -0
  42. data/spec/chef/knife/profitbricks_ipblock_delete_spec.rb +37 -0
  43. data/spec/chef/knife/profitbricks_ipfailover_add_spec.rb +80 -0
  44. data/spec/chef/knife/profitbricks_ipfailover_remove_spec.rb +85 -0
  45. data/spec/chef/knife/profitbricks_lan_create_spec.rb +59 -0
  46. data/spec/chef/knife/profitbricks_lan_delete_spec.rb +58 -0
  47. data/spec/chef/knife/profitbricks_lan_list_spec.rb +37 -0
  48. data/spec/chef/knife/profitbricks_location_list_spec.rb +24 -0
  49. data/spec/chef/knife/profitbricks_nic_create_spec.rb +71 -0
  50. data/spec/chef/knife/profitbricks_nic_delete_spec.rb +69 -0
  51. data/spec/chef/knife/profitbricks_nic_list_spec.rb +69 -0
  52. data/spec/chef/knife/profitbricks_server_create_spec.rb +63 -0
  53. data/spec/chef/knife/profitbricks_server_delete_spec.rb +63 -0
  54. data/spec/chef/knife/profitbricks_server_list_spec.rb +65 -0
  55. data/spec/chef/knife/profitbricks_server_reboot_spec.rb +65 -0
  56. data/spec/chef/knife/profitbricks_server_start_spec.rb +68 -0
  57. data/spec/chef/knife/profitbricks_server_stop_spec.rb +65 -0
  58. data/spec/chef/knife/profitbricks_volume_attach_spec.rb +70 -0
  59. data/spec/chef/knife/profitbricks_volume_create_spec.rb +63 -0
  60. data/spec/chef/knife/profitbricks_volume_delete_spec.rb +70 -0
  61. data/spec/chef/knife/profitbricks_volume_detach_spec.rb +81 -0
  62. data/spec/chef/knife/profitbricks_volume_list_spec.rb +80 -0
  63. data/spec/spec_helper.rb +22 -3
  64. data/spec/test.sh +1 -1
  65. metadata +81 -18
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'profitbricks_image_list'
3
+
4
+ Chef::Knife::ProfitbricksImageList.load_deps
5
+
6
+ describe Chef::Knife::ProfitbricksImageList do
7
+ let(:image_list) { Chef::Knife::ProfitbricksImageList.new }
8
+
9
+ before :each do
10
+ allow(image_list).to receive(:puts)
11
+ end
12
+
13
+ describe '#run' do
14
+ it 'should output the column headers' do
15
+ expect(image_list).to receive(:puts).with(/^ID\s+Name\s+Description\s+Location\s+Size\s+Public\s*$/)
16
+ image_list.run
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'profitbricks_ipblock_create'
3
+
4
+ Chef::Knife::ProfitbricksIpblockCreate.load_deps
5
+
6
+ describe Chef::Knife::ProfitbricksIpblockCreate do
7
+ subject { Chef::Knife::ProfitbricksIpblockCreate.new }
8
+
9
+ before :each do
10
+ {
11
+ location: 'us/las',
12
+ size: 1
13
+ }.each do |key, value|
14
+ Chef::Config[:knife][key] = value
15
+ end
16
+ allow(subject).to receive(:puts)
17
+ end
18
+
19
+ after :each do
20
+ ProfitBricks.configure do |config|
21
+ config.username = Chef::Config[:knife][:profitbricks_username]
22
+ config.password = Chef::Config[:knife][:profitbricks_password]
23
+ config.url = Chef::Config[:knife][:profitbricks_url]
24
+ config.debug = Chef::Config[:knife][:profitbricks_debug] || false
25
+ config.global_classes = false
26
+ end
27
+
28
+ ipid = subject.instance_variable_get :@ipid
29
+ ip = ProfitBricks::IPBlock.get(ipid)
30
+ ip.release
31
+ end
32
+
33
+ describe '#run' do
34
+ it 'should reserve a IP block' do
35
+ expect(subject).to receive(:puts).with('done')
36
+ subject.run
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+ require 'profitbricks_ipblock_delete'
3
+
4
+ Chef::Knife::ProfitbricksIpblockDelete.load_deps
5
+
6
+ describe Chef::Knife::ProfitbricksIpblockDelete do
7
+ subject { Chef::Knife::ProfitbricksIpblockDelete.new }
8
+
9
+ before :each do
10
+ allow(subject).to receive(:puts)
11
+ allow(subject.ui).to receive(:confirm)
12
+
13
+ subject.config[:yes] = true
14
+
15
+ ProfitBricks.configure do |config|
16
+ config.username = Chef::Config[:knife][:profitbricks_username]
17
+ config.password = Chef::Config[:knife][:profitbricks_password]
18
+ config.url = Chef::Config[:knife][:profitbricks_url]
19
+ config.debug = Chef::Config[:knife][:profitbricks_debug] || false
20
+ config.global_classes = false
21
+ end
22
+
23
+ @ip = ProfitBricks::IPBlock.reserve(name: 'Ruby SDK Test',
24
+ location: 'us/las',
25
+ size: 2)
26
+
27
+ @ip.wait_for { ready? }
28
+ subject.name_args = [@ip.id]
29
+ end
30
+
31
+ describe '#run' do
32
+ it 'should delete a data center' do
33
+ expect(subject).to receive(:puts).with('ID: ' + @ip.id)
34
+ subject.run
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+ require 'profitbricks_ipfailover_add'
3
+
4
+ Chef::Knife::ProfitbricksFailoverAdd.load_deps
5
+
6
+ describe Chef::Knife::ProfitbricksFailoverAdd do
7
+ subject { Chef::Knife::ProfitbricksFailoverAdd.new }
8
+
9
+ before :each do
10
+ {
11
+ name: 'Chef Test',
12
+ public: 'true'
13
+ }.each do |key, value|
14
+ Chef::Config[:knife][key] = value
15
+ end
16
+
17
+ ProfitBricks.configure do |config|
18
+ config.username = Chef::Config[:knife][:profitbricks_username]
19
+ config.password = Chef::Config[:knife][:profitbricks_password]
20
+ config.url = Chef::Config[:knife][:profitbricks_url]
21
+ config.debug = Chef::Config[:knife][:profitbricks_debug] || false
22
+ config.global_classes = false
23
+ end
24
+
25
+ @datacenter = ProfitBricks::Datacenter.create(name: 'Chef test',
26
+ description: 'Chef test datacenter',
27
+ location: 'us/las')
28
+ @datacenter.wait_for { ready? }
29
+
30
+ @server = ProfitBricks::Server.create(@datacenter.id, name: 'Chef Test',
31
+ ram: 1024,
32
+ cores: 1,
33
+ availabilityZone: 'ZONE_1',
34
+ cpuFamily: 'INTEL_XEON')
35
+ @server.wait_for { ready? }
36
+
37
+ @lan = ProfitBricks::LAN.create(@datacenter.id, name: 'Chef Test',
38
+ public: 'true')
39
+ @lan.wait_for { ready? }
40
+
41
+ @nic = ProfitBricks::NIC.create(@datacenter.id, @server.id, lan: @lan.id)
42
+ @nic.wait_for { ready? }
43
+
44
+ @ip_block = ProfitBricks::IPBlock.reserve(location: 'us/las',
45
+ size: 1)
46
+ @ip_block.wait_for { ready? }
47
+ @nic.update(ips: [@ip_block.properties['ips'][0]])
48
+ @nic.wait_for { ready? }
49
+
50
+ Chef::Config[:knife][:datacenter_id] = @datacenter.id
51
+ Chef::Config[:knife][:lan_id] = @lan.id
52
+ Chef::Config[:knife][:ip] = @ip_block.properties['ips'][0]
53
+ Chef::Config[:knife][:nic_id] = @nic.id
54
+
55
+ allow(subject).to receive(:puts)
56
+ end
57
+
58
+ after :each do
59
+ ProfitBricks.configure do |config|
60
+ config.username = Chef::Config[:knife][:profitbricks_username]
61
+ config.password = Chef::Config[:knife][:profitbricks_password]
62
+ config.url = Chef::Config[:knife][:profitbricks_url]
63
+ config.debug = Chef::Config[:knife][:profitbricks_debug] || false
64
+ config.global_classes = false
65
+ end
66
+
67
+ @datacenter.delete
68
+ @datacenter.wait_for { ready? }
69
+ @ip_block.release
70
+ @ip_block.wait_for { ready? }
71
+ end
72
+
73
+ describe '#run' do
74
+ it 'should add ip failover' do
75
+ expect(subject).to receive(:puts).with('Name: Chef Test')
76
+ expect(subject).to receive(:puts).with('Public: true')
77
+ subject.run
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+ require 'profitbricks_ipfailover_remove'
3
+
4
+ Chef::Knife::ProfitbricksFailoverRemove.load_deps
5
+
6
+ describe Chef::Knife::ProfitbricksFailoverRemove do
7
+ subject { Chef::Knife::ProfitbricksFailoverRemove.new }
8
+
9
+ before :each do
10
+ {
11
+ name: 'Chef Test',
12
+ public: 'true'
13
+ }.each do |key, value|
14
+ Chef::Config[:knife][key] = value
15
+ end
16
+
17
+ ProfitBricks.configure do |config|
18
+ config.username = Chef::Config[:knife][:profitbricks_username]
19
+ config.password = Chef::Config[:knife][:profitbricks_password]
20
+ config.url = Chef::Config[:knife][:profitbricks_url]
21
+ config.debug = Chef::Config[:knife][:profitbricks_debug] || false
22
+ config.global_classes = false
23
+ end
24
+
25
+ @datacenter = ProfitBricks::Datacenter.create(name: 'Chef test',
26
+ description: 'Chef test datacenter',
27
+ location: 'us/las')
28
+ @datacenter.wait_for { ready? }
29
+
30
+ @server = ProfitBricks::Server.create(@datacenter.id, name: 'Chef Test',
31
+ ram: 1024,
32
+ cores: 1,
33
+ availabilityZone: 'ZONE_1',
34
+ cpuFamily: 'INTEL_XEON')
35
+ @server.wait_for { ready? }
36
+
37
+ @lan = ProfitBricks::LAN.create(@datacenter.id, name: 'Chef Test',
38
+ public: 'true')
39
+ @lan.wait_for { ready? }
40
+
41
+ @nic = ProfitBricks::NIC.create(@datacenter.id, @server.id, lan: @lan.id)
42
+ @nic.wait_for { ready? }
43
+
44
+ @ip_block = ProfitBricks::IPBlock.reserve(location: 'us/las',
45
+ size: 1)
46
+ @ip_block.wait_for { ready? }
47
+ @nic.update(ips: [@ip_block.properties['ips'][0]])
48
+ @nic.wait_for { ready? }
49
+ ip_failover = {}
50
+ ip_failover['ip'] = @ip_block.properties['ips'][0]
51
+ ip_failover['nicUuid'] = @nic.id
52
+
53
+ @lan.update(ipFailover: [ip_failover])
54
+ @lan.wait_for { ready? }
55
+ Chef::Config[:knife][:datacenter_id] = @datacenter.id
56
+ Chef::Config[:knife][:lan_id] = @lan.id
57
+ Chef::Config[:knife][:ip] = @ip_block.properties['ips'][0]
58
+ Chef::Config[:knife][:nic_id] = @nic.id
59
+
60
+ allow(subject).to receive(:puts)
61
+ end
62
+
63
+ after :each do
64
+ ProfitBricks.configure do |config|
65
+ config.username = Chef::Config[:knife][:profitbricks_username]
66
+ config.password = Chef::Config[:knife][:profitbricks_password]
67
+ config.url = Chef::Config[:knife][:profitbricks_url]
68
+ config.debug = Chef::Config[:knife][:profitbricks_debug] || false
69
+ config.global_classes = false
70
+ end
71
+
72
+ @datacenter.delete
73
+ @datacenter.wait_for { ready? }
74
+ @ip_block.release
75
+ @ip_block.wait_for { ready? }
76
+ end
77
+
78
+ describe '#run' do
79
+ it 'should renive ip failover' do
80
+ expect(subject).to receive(:puts).with('Name: Chef Test')
81
+ expect(subject).to receive(:puts).with('Public: true')
82
+ subject.run
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+ require 'profitbricks_lan_create'
3
+
4
+ Chef::Knife::ProfitbricksLanCreate.load_deps
5
+
6
+ describe Chef::Knife::ProfitbricksLanCreate do
7
+ subject { Chef::Knife::ProfitbricksLanCreate.new }
8
+
9
+ before :each do
10
+ {
11
+ name: 'Chef Test',
12
+ public: 'true'
13
+ }.each do |key, value|
14
+ Chef::Config[:knife][key] = value
15
+ end
16
+
17
+ ProfitBricks.configure do |config|
18
+ config.username = Chef::Config[:knife][:profitbricks_username]
19
+ config.password = Chef::Config[:knife][:profitbricks_password]
20
+ config.url = Chef::Config[:knife][:profitbricks_url]
21
+ config.debug = Chef::Config[:knife][:profitbricks_debug] || false
22
+ config.global_classes = false
23
+ end
24
+
25
+ @datacenter = ProfitBricks::Datacenter.create(name: 'Chef test',
26
+ description: 'Chef test datacenter',
27
+ location: 'us/las')
28
+ @datacenter.wait_for { ready? }
29
+
30
+ @lan = ProfitBricks::LAN.create(@datacenter.id, name: 'Chef Test',
31
+ public: 'true')
32
+ @lan.wait_for { ready? }
33
+
34
+ Chef::Config[:knife][:datacenter_id] = @datacenter.id
35
+
36
+ allow(subject).to receive(:puts)
37
+ end
38
+
39
+ after :each do
40
+ ProfitBricks.configure do |config|
41
+ config.username = Chef::Config[:knife][:profitbricks_username]
42
+ config.password = Chef::Config[:knife][:profitbricks_password]
43
+ config.url = Chef::Config[:knife][:profitbricks_url]
44
+ config.debug = Chef::Config[:knife][:profitbricks_debug] || false
45
+ config.global_classes = false
46
+ end
47
+
48
+ @datacenter.delete
49
+ @datacenter.wait_for { ready? }
50
+ end
51
+
52
+ describe '#run' do
53
+ it 'should create a lan' do
54
+ expect(subject).to receive(:puts).with('Name: Chef Test')
55
+ expect(subject).to receive(:puts).with('Public: true')
56
+ subject.run
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ require 'profitbricks_lan_delete'
3
+
4
+ Chef::Knife::ProfitbricksLanDelete.load_deps
5
+
6
+ describe Chef::Knife::ProfitbricksLanDelete do
7
+ subject { Chef::Knife::ProfitbricksLanDelete.new }
8
+
9
+ before :each do
10
+ {
11
+ name: 'Chef Test',
12
+ public: 'true'
13
+ }.each do |key, value|
14
+ Chef::Config[:knife][key] = value
15
+ end
16
+
17
+ ProfitBricks.configure do |config|
18
+ config.username = Chef::Config[:knife][:profitbricks_username]
19
+ config.password = Chef::Config[:knife][:profitbricks_password]
20
+ config.url = Chef::Config[:knife][:profitbricks_url]
21
+ config.debug = Chef::Config[:knife][:profitbricks_debug] || false
22
+ config.global_classes = false
23
+ end
24
+
25
+ @datacenter = ProfitBricks::Datacenter.create(name: 'Chef test',
26
+ description: 'Chef test datacenter',
27
+ location: 'us/las')
28
+ @datacenter.wait_for { ready? }
29
+
30
+ @lan = ProfitBricks::LAN.create(@datacenter.id, name: 'Chef Test',
31
+ public: 'true')
32
+ @lan.wait_for { ready? }
33
+
34
+ Chef::Config[:knife][:datacenter_id] = @datacenter.id
35
+ subject.config[:yes] = true
36
+
37
+ allow(subject).to receive(:puts)
38
+ end
39
+
40
+ after :each do
41
+ ProfitBricks.configure do |config|
42
+ config.username = Chef::Config[:knife][:profitbricks_username]
43
+ config.password = Chef::Config[:knife][:profitbricks_password]
44
+ config.url = Chef::Config[:knife][:profitbricks_url]
45
+ config.debug = Chef::Config[:knife][:profitbricks_debug] || false
46
+ config.global_classes = false
47
+ end
48
+
49
+ @datacenter.delete
50
+ @datacenter.wait_for { ready? }
51
+ end
52
+
53
+ describe '#run' do
54
+ it 'should delete a lan' do
55
+ subject.run
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+ require 'profitbricks_lan_list'
3
+
4
+ Chef::Knife::ProfitbricksLanList.load_deps
5
+
6
+ describe Chef::Knife::ProfitbricksLanList do
7
+ let(:lan_list) { Chef::Knife::ProfitbricksLanList.new }
8
+
9
+ before :each do
10
+ ProfitBricks.configure do |config|
11
+ config.username = Chef::Config[:knife][:profitbricks_username]
12
+ config.password = Chef::Config[:knife][:profitbricks_password]
13
+ config.url = Chef::Config[:knife][:profitbricks_url]
14
+ config.debug = Chef::Config[:knife][:profitbricks_debug] || false
15
+ config.global_classes = false
16
+ end
17
+
18
+ @datacenter = ProfitBricks::Datacenter.create(name: 'Chef test',
19
+ description: 'Chef test datacenter',
20
+ location: 'us/las')
21
+ @datacenter.wait_for { ready? }
22
+
23
+ @lan = ProfitBricks::LAN.create(@datacenter.id, name: 'Chef Test',
24
+ public: 'true')
25
+ @lan.wait_for { ready? }
26
+
27
+ Chef::Config[:knife][:datacenter_id] = @datacenter.id
28
+ allow(lan_list).to receive(:puts)
29
+ end
30
+
31
+ describe '#run' do
32
+ it 'should output the column headers' do
33
+ expect(lan_list).to receive(:puts).with(/^ID\s+Name\s+Public\s*$/)
34
+ lan_list.run
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'profitbricks_location_list'
3
+
4
+ Chef::Knife::ProfitbricksLocationList.load_deps
5
+
6
+ describe Chef::Knife::ProfitbricksLocationList do
7
+ before :each do
8
+ subject { Chef::Knife::ProfitbricksLocationList.new }
9
+
10
+ allow(subject).to receive(:puts)
11
+ end
12
+
13
+ describe '#run' do
14
+ it 'should output the column headers' do
15
+ expect(subject).to receive(:puts).with("ID Name \nde/fkb karlsruhe\nde/fra frankfurt\nus/las lasvegas \nus/ewr newark \n")
16
+ subject.run
17
+ end
18
+
19
+ it 'should output the data center locations' do
20
+ expect(subject).to receive(:puts).with(/(?:us\/las)/)
21
+ subject.run
22
+ end
23
+ end
24
+ end