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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +303 -96
- data/knife-profitbricks.gemspec +1 -1
- data/lib/chef/knife/profitbricks_base.rb +24 -0
- data/lib/chef/knife/profitbricks_composite_server_create.rb +59 -45
- data/lib/chef/knife/profitbricks_contract_list.rb +37 -0
- data/lib/chef/knife/profitbricks_datacenter_create.rb +8 -7
- data/lib/chef/knife/profitbricks_firewall_create.rb +15 -15
- data/lib/chef/knife/profitbricks_firewall_delete.rb +6 -8
- data/lib/chef/knife/profitbricks_firewall_list.rb +6 -5
- data/lib/chef/knife/profitbricks_ipblock_create.rb +6 -7
- data/lib/chef/knife/profitbricks_ipfailover_add.rb +60 -0
- data/lib/chef/knife/profitbricks_ipfailover_remove.rb +60 -0
- data/lib/chef/knife/profitbricks_lan_create.rb +5 -3
- data/lib/chef/knife/profitbricks_lan_list.rb +1 -1
- data/lib/chef/knife/profitbricks_nic_create.rb +12 -14
- data/lib/chef/knife/profitbricks_nic_delete.rb +4 -3
- data/lib/chef/knife/profitbricks_nic_list.rb +4 -3
- data/lib/chef/knife/profitbricks_server_create.rb +14 -16
- data/lib/chef/knife/profitbricks_server_delete.rb +1 -1
- data/lib/chef/knife/profitbricks_server_list.rb +1 -1
- data/lib/chef/knife/profitbricks_server_reboot.rb +1 -1
- data/lib/chef/knife/profitbricks_server_start.rb +1 -1
- data/lib/chef/knife/profitbricks_server_stop.rb +1 -1
- data/lib/chef/knife/profitbricks_volume_attach.rb +5 -5
- data/lib/chef/knife/profitbricks_volume_create.rb +38 -18
- data/lib/chef/knife/profitbricks_volume_delete.rb +1 -1
- data/lib/chef/knife/profitbricks_volume_detach.rb +4 -4
- data/lib/chef/knife/profitbricks_volume_list.rb +5 -6
- data/lib/knife-profitbricks/version.rb +1 -1
- data/spec/chef/knife/profitbricks_composite_server_create_spec.rb +64 -0
- data/spec/chef/knife/profitbricks_contract_list_spec.rb +20 -0
- data/spec/chef/knife/profitbricks_datacenter_create_spec.rb +44 -0
- data/spec/chef/knife/profitbricks_datacenter_delete_spec.rb +39 -0
- data/spec/chef/knife/profitbricks_datacenter_list_spec.rb +7 -6
- data/spec/chef/knife/profitbricks_firewall_create_spec.rb +74 -0
- data/spec/chef/knife/profitbricks_firewall_delete_spec.rb +86 -0
- data/spec/chef/knife/profitbricks_firewall_list_spec.rb +61 -0
- data/spec/chef/knife/profitbricks_image_list_spec.rb +19 -0
- data/spec/chef/knife/profitbricks_ipblock_create_spec.rb +39 -0
- data/spec/chef/knife/profitbricks_ipblock_delete_spec.rb +37 -0
- data/spec/chef/knife/profitbricks_ipfailover_add_spec.rb +80 -0
- data/spec/chef/knife/profitbricks_ipfailover_remove_spec.rb +85 -0
- data/spec/chef/knife/profitbricks_lan_create_spec.rb +59 -0
- data/spec/chef/knife/profitbricks_lan_delete_spec.rb +58 -0
- data/spec/chef/knife/profitbricks_lan_list_spec.rb +37 -0
- data/spec/chef/knife/profitbricks_location_list_spec.rb +24 -0
- data/spec/chef/knife/profitbricks_nic_create_spec.rb +71 -0
- data/spec/chef/knife/profitbricks_nic_delete_spec.rb +69 -0
- data/spec/chef/knife/profitbricks_nic_list_spec.rb +69 -0
- data/spec/chef/knife/profitbricks_server_create_spec.rb +63 -0
- data/spec/chef/knife/profitbricks_server_delete_spec.rb +63 -0
- data/spec/chef/knife/profitbricks_server_list_spec.rb +65 -0
- data/spec/chef/knife/profitbricks_server_reboot_spec.rb +65 -0
- data/spec/chef/knife/profitbricks_server_start_spec.rb +68 -0
- data/spec/chef/knife/profitbricks_server_stop_spec.rb +65 -0
- data/spec/chef/knife/profitbricks_volume_attach_spec.rb +70 -0
- data/spec/chef/knife/profitbricks_volume_create_spec.rb +63 -0
- data/spec/chef/knife/profitbricks_volume_delete_spec.rb +70 -0
- data/spec/chef/knife/profitbricks_volume_detach_spec.rb +81 -0
- data/spec/chef/knife/profitbricks_volume_list_spec.rb +80 -0
- data/spec/spec_helper.rb +22 -3
- data/spec/test.sh +1 -1
- metadata +81 -18
@@ -17,7 +17,7 @@ class Chef
|
|
17
17
|
connection
|
18
18
|
@name_args.each do |volume_id|
|
19
19
|
begin
|
20
|
-
volume = ProfitBricks::Volume.get(
|
20
|
+
volume = ProfitBricks::Volume.get(Chef::Config[:knife][:datacenter_id], volume_id)
|
21
21
|
rescue Excon::Errors::NotFound
|
22
22
|
ui.error("Volume ID #{volume_id} not found. Skipping.")
|
23
23
|
next
|
@@ -16,14 +16,14 @@ class Chef
|
|
16
16
|
option :server_id,
|
17
17
|
short: '-S SERVER_ID',
|
18
18
|
long: '--server-id SERVER_ID',
|
19
|
-
description: 'The ID of the server'
|
20
|
-
required: true
|
19
|
+
description: 'The ID of the server'
|
21
20
|
|
22
21
|
def run
|
23
22
|
connection
|
23
|
+
validate_required_params(%i(datacenter_id server_id), Chef::Config[:knife])
|
24
24
|
@name_args.each do |volume_id|
|
25
25
|
begin
|
26
|
-
volume = ProfitBricks::Volume.get(
|
26
|
+
volume = ProfitBricks::Volume.get(Chef::Config[:knife][:datacenter_id], nil, volume_id)
|
27
27
|
rescue Excon::Errors::NotFound
|
28
28
|
ui.error("Volume ID #{volume_id} not found. Skipping.")
|
29
29
|
next
|
@@ -37,7 +37,7 @@ class Chef
|
|
37
37
|
|
38
38
|
confirm('Do you really want to detach this volume')
|
39
39
|
|
40
|
-
volume.detach(
|
40
|
+
volume.detach(Chef::Config[:knife][:server_id])
|
41
41
|
ui.msg("Detaching volume #{volume_id} from server")
|
42
42
|
end
|
43
43
|
end
|
@@ -16,8 +16,7 @@ class Chef
|
|
16
16
|
option :server_id,
|
17
17
|
short: '-S SERVER_ID',
|
18
18
|
long: '--server-id SERVER_ID',
|
19
|
-
description: 'The ID of the server'
|
20
|
-
required: false
|
19
|
+
description: 'The ID of the server'
|
21
20
|
|
22
21
|
def run
|
23
22
|
$stdout.sync = true
|
@@ -33,8 +32,8 @@ class Chef
|
|
33
32
|
]
|
34
33
|
|
35
34
|
connection
|
36
|
-
if defined?(
|
37
|
-
server = ProfitBricks::Server.get(
|
35
|
+
if defined?(Chef::Config[:knife][:server_id])
|
36
|
+
server = ProfitBricks::Server.get(Chef::Config[:knife][:datacenter_id], Chef::Config[:knife][:server_id])
|
38
37
|
server.list_volumes.each do |volume|
|
39
38
|
volume_list << volume.id
|
40
39
|
volume_list << volume.properties['name']
|
@@ -44,9 +43,9 @@ class Chef
|
|
44
43
|
volume_list << volume.properties['type']
|
45
44
|
volume_list << volume.properties['availabilityZone']
|
46
45
|
volume_list << volume.properties['deviceNumber'].to_s
|
47
|
-
end
|
46
|
+
end
|
48
47
|
else
|
49
|
-
ProfitBricks::Volume.list(
|
48
|
+
ProfitBricks::Volume.list(Chef::Config[:knife][:datacenter_id]).each do |volume|
|
50
49
|
volume_list << volume.id
|
51
50
|
volume_list << volume.properties['name']
|
52
51
|
volume_list << volume.properties['size'].to_s
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'profitbricks_composite_server_create'
|
3
|
+
|
4
|
+
Chef::Knife::ProfitbricksCompositeServerCreate.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::ProfitbricksCompositeServerCreate do
|
7
|
+
subject { Chef::Knife::ProfitbricksCompositeServerCreate.new }
|
8
|
+
|
9
|
+
ProfitBricks.configure do |config|
|
10
|
+
config.username = ENV['PROFITBRICKS_USERNAME']
|
11
|
+
config.password = ENV['PROFITBRICKS_PASSWORD']
|
12
|
+
config.url = ENV['PROFITBRICKS_API_URL']
|
13
|
+
config.debug = false
|
14
|
+
config.global_classes = false
|
15
|
+
end
|
16
|
+
|
17
|
+
before :each do
|
18
|
+
@dcid = ''
|
19
|
+
allow(subject).to receive(:puts)
|
20
|
+
end
|
21
|
+
|
22
|
+
after :each do
|
23
|
+
datacenter = ProfitBricks::Datacenter.get(@dcid)
|
24
|
+
datacenter.delete
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#run' do
|
28
|
+
it 'should create a composite server' do
|
29
|
+
|
30
|
+
datacenter = ProfitBricks::Datacenter.create(name: 'Chef test',
|
31
|
+
description: 'Chef test datacenter',
|
32
|
+
location: 'us/las')
|
33
|
+
|
34
|
+
datacenter.wait_for { ready? }
|
35
|
+
|
36
|
+
@dcid = datacenter.id
|
37
|
+
|
38
|
+
{
|
39
|
+
profitbricks_username: ENV['PROFITBRICKS_USERNAME'],
|
40
|
+
profitbricks_password: ENV['PROFITBRICKS_PASSWORD'],
|
41
|
+
profitbricks_url: ENV['PROFITBRICKS_API_URL'],
|
42
|
+
name: 'Chef test',
|
43
|
+
cores: '2',
|
44
|
+
ram: '2048',
|
45
|
+
size: 4,
|
46
|
+
dhcp: true,
|
47
|
+
lan: 1,
|
48
|
+
datacenter_id: @dcid,
|
49
|
+
imagealias: 'ubuntu:latest',
|
50
|
+
type: 'HDD',
|
51
|
+
imagepassword: 'K3tTj8G14a3EgKyNeeiY'
|
52
|
+
}.each do |key, value|
|
53
|
+
Chef::Config[:knife][key] = value
|
54
|
+
end
|
55
|
+
|
56
|
+
expect(subject).to receive(:puts).with('Name: Chef test')
|
57
|
+
expect(subject).to receive(:puts).with('Cores: 2')
|
58
|
+
expect(subject).to receive(:puts).with('CPU Family: ')
|
59
|
+
expect(subject).to receive(:puts).with('Ram: 2048')
|
60
|
+
expect(subject).to receive(:puts).with('Availability Zone: ')
|
61
|
+
subject.run
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'profitbricks_contract_list'
|
3
|
+
|
4
|
+
Chef::Knife::ProfitbricksContractList.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::ProfitbricksContractList do
|
7
|
+
let(:contract_list) { Chef::Knife::ProfitbricksContractList.new }
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
allow(contract_list).to receive(:puts)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#run' do
|
14
|
+
it 'should output the column headers' do
|
15
|
+
expect(contract_list).to receive(:puts).with('Contract Type: contract')
|
16
|
+
expect(contract_list).to receive(:puts).with('Status: BILLABLE')
|
17
|
+
contract_list.run
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'profitbricks_datacenter_create'
|
3
|
+
|
4
|
+
Chef::Knife::ProfitbricksDatacenterCreate.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::ProfitbricksDatacenterCreate do
|
7
|
+
subject { Chef::Knife::ProfitbricksDatacenterCreate.new }
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
{
|
11
|
+
name: 'Chef test',
|
12
|
+
description: 'Chef test datacenter',
|
13
|
+
location: 'us/las'
|
14
|
+
}.each do |key, value|
|
15
|
+
Chef::Config[:knife][key] = value
|
16
|
+
end
|
17
|
+
|
18
|
+
allow(subject).to receive(:puts)
|
19
|
+
end
|
20
|
+
|
21
|
+
after :each do
|
22
|
+
ProfitBricks.configure do |config|
|
23
|
+
config.username = Chef::Config[:knife][:profitbricks_username]
|
24
|
+
config.password = Chef::Config[:knife][:profitbricks_password]
|
25
|
+
config.url = Chef::Config[:knife][:profitbricks_url]
|
26
|
+
config.debug = Chef::Config[:knife][:profitbricks_debug] || false
|
27
|
+
config.global_classes = false
|
28
|
+
end
|
29
|
+
|
30
|
+
dcid = subject.instance_variable_get :@dcid
|
31
|
+
datacenter = ProfitBricks::Datacenter.get(dcid)
|
32
|
+
datacenter.delete
|
33
|
+
datacenter.wait_for { ready? }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#run' do
|
37
|
+
it 'should create a data center' do
|
38
|
+
expect(subject).to receive(:puts).with('Name: Chef test')
|
39
|
+
expect(subject).to receive(:puts).with('Description: Chef test datacenter')
|
40
|
+
expect(subject).to receive(:puts).with('Location: us/las')
|
41
|
+
subject.run
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'profitbricks_datacenter_delete'
|
3
|
+
|
4
|
+
Chef::Knife::ProfitbricksDatacenterDelete.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::ProfitbricksDatacenterDelete do
|
7
|
+
subject { Chef::Knife::ProfitbricksDatacenterDelete.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
|
+
@datacenter = ProfitBricks::Datacenter.create(name: 'Chef test',
|
24
|
+
description: 'Chef test datacenter',
|
25
|
+
location: 'us/las')
|
26
|
+
|
27
|
+
@datacenter.wait_for { ready? }
|
28
|
+
subject.name_args = [@datacenter.id]
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#run' do
|
32
|
+
it 'should delete a data center' do
|
33
|
+
expect(subject).to receive(:puts).with('Name: Chef test')
|
34
|
+
expect(subject).to receive(:puts).with('Description: Chef test datacenter')
|
35
|
+
expect(subject).to receive(:puts).with('Location: us/las')
|
36
|
+
subject.run
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -4,20 +4,21 @@ require 'profitbricks_datacenter_list'
|
|
4
4
|
Chef::Knife::ProfitbricksDatacenterList.load_deps
|
5
5
|
|
6
6
|
describe Chef::Knife::ProfitbricksDatacenterList do
|
7
|
+
let(:datacenter_list) { Chef::Knife::ProfitbricksDatacenterList.new }
|
8
|
+
|
7
9
|
before :each do
|
8
|
-
|
9
|
-
allow(subject).to receive(:puts)
|
10
|
+
allow(datacenter_list).to receive(:puts)
|
10
11
|
end
|
11
12
|
|
12
13
|
describe '#run' do
|
13
14
|
it 'should output the column headers' do
|
14
|
-
expect(
|
15
|
-
|
15
|
+
expect(datacenter_list).to receive(:puts).with(/^ID\s+Name\s+Description\s+Location\s+Version\s*$/)
|
16
|
+
datacenter_list.run
|
16
17
|
end
|
17
18
|
|
18
19
|
it 'should output the data center locations' do
|
19
|
-
expect(
|
20
|
-
|
20
|
+
expect(datacenter_list).to receive(:puts).with(/^ID\s+Name\s+Description\s+Location\s+Version\s*$/)
|
21
|
+
datacenter_list.run
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'profitbricks_firewall_create'
|
3
|
+
|
4
|
+
Chef::Knife::ProfitbricksFirewallCreate.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::ProfitbricksFirewallCreate do
|
7
|
+
before :each do
|
8
|
+
ProfitBricks.configure do |config|
|
9
|
+
config.username = Chef::Config[:knife][:profitbricks_username]
|
10
|
+
config.password = Chef::Config[:knife][:profitbricks_password]
|
11
|
+
config.url = Chef::Config[:knife][:profitbricks_url]
|
12
|
+
config.debug = Chef::Config[:knife][:profitbricks_debug] || false
|
13
|
+
config.global_classes = false
|
14
|
+
end
|
15
|
+
@dcid = ''
|
16
|
+
|
17
|
+
datacenter = ProfitBricks::Datacenter.create(name: 'Chef test',
|
18
|
+
description: 'Chef test datacenter',
|
19
|
+
location: 'us/las')
|
20
|
+
|
21
|
+
datacenter.wait_for { ready? }
|
22
|
+
@dcid = datacenter.id
|
23
|
+
|
24
|
+
@server = ProfitBricks::Server.create(datacenter.id, name: 'Chef Test',
|
25
|
+
ram: 1024,
|
26
|
+
cores: 1,
|
27
|
+
availabilityZone: 'ZONE_1',
|
28
|
+
cpuFamily: 'INTEL_XEON')
|
29
|
+
@server.wait_for { ready? }
|
30
|
+
|
31
|
+
@nic = ProfitBricks::NIC.create(datacenter.id, @server.id, name: 'Chef Test',
|
32
|
+
dhcp: true,
|
33
|
+
lan: 1,
|
34
|
+
firewallActive: true,
|
35
|
+
nat: false)
|
36
|
+
@nic.wait_for { ready? }
|
37
|
+
|
38
|
+
allow(subject).to receive(:puts)
|
39
|
+
end
|
40
|
+
|
41
|
+
after :each do
|
42
|
+
datacenter = ProfitBricks::Datacenter.get(@dcid)
|
43
|
+
datacenter.delete
|
44
|
+
datacenter.wait_for { ready? }
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#run' do
|
48
|
+
it 'should output the column headers' do
|
49
|
+
{
|
50
|
+
datacenter_id: @dcid,
|
51
|
+
server_id: @server.id,
|
52
|
+
nic_id: @nic.id,
|
53
|
+
name: 'Chef test',
|
54
|
+
protocol: 'TCP',
|
55
|
+
portrangestart: '22',
|
56
|
+
portrangeend: 22
|
57
|
+
}.each do |key, value|
|
58
|
+
Chef::Config[:knife][key] = value
|
59
|
+
end
|
60
|
+
|
61
|
+
expect(subject).to receive(:puts).with('Name: Chef test')
|
62
|
+
expect(subject).to receive(:puts).with('Protocol: TCP')
|
63
|
+
expect(subject).to receive(:puts).with('Source MAC: ')
|
64
|
+
expect(subject).to receive(:puts).with('Source IP: ')
|
65
|
+
expect(subject).to receive(:puts).with('Target IP: ')
|
66
|
+
expect(subject).to receive(:puts).with('Port Range Start: 22')
|
67
|
+
expect(subject).to receive(:puts).with('Port Range End: 22')
|
68
|
+
expect(subject).to receive(:puts).with('ICMP Type: ')
|
69
|
+
expect(subject).to receive(:puts).with('ICMP Code: ')
|
70
|
+
|
71
|
+
subject.run
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'profitbricks_firewall_delete'
|
3
|
+
|
4
|
+
Chef::Knife::ProfitbricksFirewallDelete.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::ProfitbricksFirewallDelete do
|
7
|
+
subject { Chef::Knife::ProfitbricksFirewallDelete.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
|
+
@dcid = ''
|
24
|
+
|
25
|
+
datacenter = ProfitBricks::Datacenter.create(name: 'Chef test',
|
26
|
+
description: 'Chef test datacenter',
|
27
|
+
location: 'us/las')
|
28
|
+
|
29
|
+
datacenter.wait_for { ready? }
|
30
|
+
@dcid = datacenter.id
|
31
|
+
|
32
|
+
@server = ProfitBricks::Server.create(datacenter.id, name: 'Chef Test',
|
33
|
+
ram: 1024,
|
34
|
+
cores: 1,
|
35
|
+
availabilityZone: 'ZONE_1',
|
36
|
+
cpuFamily: 'INTEL_XEON')
|
37
|
+
@server.wait_for { ready? }
|
38
|
+
|
39
|
+
@nic = ProfitBricks::NIC.create(datacenter.id, @server.id, name: 'Chef Test',
|
40
|
+
dhcp: true,
|
41
|
+
lan: 1,
|
42
|
+
firewallActive: true,
|
43
|
+
nat: false)
|
44
|
+
@nic.wait_for { ready? }
|
45
|
+
|
46
|
+
@fw = ProfitBricks::Firewall.create(datacenter.id, @server.id, @nic.id,
|
47
|
+
name: 'SSH',
|
48
|
+
protocol: 'TCP',
|
49
|
+
sourceMac: '01:23:45:67:89:00',
|
50
|
+
sourceIp: nil,
|
51
|
+
targetIp: nil,
|
52
|
+
portRangeStart: 22,
|
53
|
+
portRangeEnd: 22,
|
54
|
+
icmpType: nil,
|
55
|
+
icmpCode: nil)
|
56
|
+
|
57
|
+
@fw.wait_for { ready? }
|
58
|
+
end
|
59
|
+
|
60
|
+
after :each do
|
61
|
+
datacenter = ProfitBricks::Datacenter.get(@dcid)
|
62
|
+
datacenter.delete
|
63
|
+
datacenter.wait_for { ready? }
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#run' do
|
67
|
+
it 'should delete a firewall rule' do
|
68
|
+
subject.name_args = [@fw.id]
|
69
|
+
|
70
|
+
{
|
71
|
+
datacenter_id: @dcid,
|
72
|
+
server_id: @server.id,
|
73
|
+
nic_id: @nic.id
|
74
|
+
}.each do |key, value|
|
75
|
+
Chef::Config[:knife][key] = value
|
76
|
+
end
|
77
|
+
|
78
|
+
expect(subject).to receive(:puts).with('Name: SSH')
|
79
|
+
expect(subject).to receive(:puts).with('Protocol: TCP')
|
80
|
+
expect(subject).to receive(:puts).with('Source MAC: 01:23:45:67:89:00')
|
81
|
+
expect(subject).to receive(:puts).with('Port Range Start: 22')
|
82
|
+
expect(subject).to receive(:puts).with('Port Range End: 22')
|
83
|
+
subject.run
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'profitbricks_firewall_list'
|
3
|
+
|
4
|
+
Chef::Knife::ProfitbricksFirewallList.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::ProfitbricksFirewallList do
|
7
|
+
before :each do
|
8
|
+
ProfitBricks.configure do |config|
|
9
|
+
config.username = Chef::Config[:knife][:profitbricks_username]
|
10
|
+
config.password = Chef::Config[:knife][:profitbricks_password]
|
11
|
+
config.url = Chef::Config[:knife][:profitbricks_url]
|
12
|
+
config.debug = Chef::Config[:knife][:profitbricks_debug] || false
|
13
|
+
config.global_classes = false
|
14
|
+
end
|
15
|
+
@dcid = ''
|
16
|
+
|
17
|
+
datacenter = ProfitBricks::Datacenter.create(name: 'Chef test',
|
18
|
+
description: 'Chef test datacenter',
|
19
|
+
location: 'us/las')
|
20
|
+
|
21
|
+
datacenter.wait_for { ready? }
|
22
|
+
@dcid = datacenter.id
|
23
|
+
|
24
|
+
@server = ProfitBricks::Server.create(datacenter.id, name: 'Chef Test',
|
25
|
+
ram: 1024,
|
26
|
+
cores: 1,
|
27
|
+
availabilityZone: 'ZONE_1',
|
28
|
+
cpuFamily: 'INTEL_XEON')
|
29
|
+
@server.wait_for { ready? }
|
30
|
+
|
31
|
+
@nic = ProfitBricks::NIC.create(datacenter.id, @server.id, name: 'Chef Test',
|
32
|
+
dhcp: true,
|
33
|
+
lan: 1,
|
34
|
+
firewallActive: true,
|
35
|
+
nat: false)
|
36
|
+
@nic.wait_for { ready? }
|
37
|
+
|
38
|
+
allow(subject).to receive(:puts)
|
39
|
+
end
|
40
|
+
|
41
|
+
after :each do
|
42
|
+
datacenter = ProfitBricks::Datacenter.get(@dcid)
|
43
|
+
datacenter.delete
|
44
|
+
datacenter.wait_for { ready? }
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#run' do
|
48
|
+
it 'should output the column headers' do
|
49
|
+
{
|
50
|
+
datacenter_id: @dcid,
|
51
|
+
server_id: @server.id,
|
52
|
+
nic_id: @nic.id
|
53
|
+
}.each do |key, value|
|
54
|
+
Chef::Config[:knife][key] = value
|
55
|
+
end
|
56
|
+
|
57
|
+
expect(subject).to receive(:puts).with("ID Name Protocol Source MAC Source IP Target IP Port Range Start Port Range End ICMP Type ICMP CODE\n")
|
58
|
+
subject.run
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|