knife-ionoscloud 5.1.0 → 6.0.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/knife-ionoscloud.gemspec +1 -1
- data/lib/chef/knife/ionoscloud_backupunit_create.rb +1 -1
- data/lib/chef/knife/ionoscloud_backupunit_delete.rb +1 -1
- data/lib/chef/knife/ionoscloud_backupunit_list.rb +1 -1
- data/lib/chef/knife/ionoscloud_backupunit_ssourl.rb +1 -1
- data/lib/chef/knife/ionoscloud_base.rb +1 -1
- data/lib/chef/knife/ionoscloud_composite_server_create.rb +25 -23
- data/lib/chef/knife/ionoscloud_contract_list.rb +32 -23
- data/lib/chef/knife/ionoscloud_cube_server_create.rb +215 -0
- data/lib/chef/knife/ionoscloud_datacenter_create.rb +1 -1
- data/lib/chef/knife/ionoscloud_datacenter_delete.rb +1 -1
- data/lib/chef/knife/ionoscloud_datacenter_list.rb +4 -2
- data/lib/chef/knife/ionoscloud_firewall_create.rb +11 -4
- data/lib/chef/knife/ionoscloud_firewall_delete.rb +4 -3
- data/lib/chef/knife/ionoscloud_firewall_list.rb +5 -3
- data/lib/chef/knife/ionoscloud_flowlog_create.rb +121 -0
- data/lib/chef/knife/ionoscloud_flowlog_delete.rb +106 -0
- data/lib/chef/knife/ionoscloud_flowlog_list.rb +100 -0
- data/lib/chef/knife/ionoscloud_group_create.rb +35 -14
- data/lib/chef/knife/ionoscloud_group_delete.rb +7 -0
- data/lib/chef/knife/ionoscloud_group_get.rb +6 -0
- data/lib/chef/knife/ionoscloud_group_list.rb +19 -7
- data/lib/chef/knife/ionoscloud_image_list.rb +1 -1
- data/lib/chef/knife/ionoscloud_ipfailover_add.rb +1 -1
- data/lib/chef/knife/ionoscloud_ipfailover_remove.rb +1 -1
- data/lib/chef/knife/ionoscloud_k8s_delete.rb +5 -2
- data/lib/chef/knife/ionoscloud_label_add.rb +1 -1
- data/lib/chef/knife/ionoscloud_label_list.rb +1 -1
- data/lib/chef/knife/ionoscloud_label_remove.rb +1 -1
- data/lib/chef/knife/ionoscloud_lan_create.rb +1 -1
- data/lib/chef/knife/ionoscloud_lan_delete.rb +1 -1
- data/lib/chef/knife/ionoscloud_lan_list.rb +1 -1
- data/lib/chef/knife/ionoscloud_loadbalancer_create.rb +1 -1
- data/lib/chef/knife/ionoscloud_loadbalancer_delete.rb +1 -1
- data/lib/chef/knife/ionoscloud_loadbalancer_get.rb +1 -1
- data/lib/chef/knife/ionoscloud_loadbalancer_list.rb +1 -1
- data/lib/chef/knife/ionoscloud_loadbalancer_nic_add.rb +1 -1
- data/lib/chef/knife/ionoscloud_loadbalancer_nic_remove.rb +1 -1
- data/lib/chef/knife/ionoscloud_location_list.rb +5 -3
- data/lib/chef/knife/ionoscloud_natgateway_create.rb +71 -0
- data/lib/chef/knife/ionoscloud_natgateway_delete.rb +69 -0
- data/lib/chef/knife/ionoscloud_natgateway_lan_add.rb +82 -0
- data/lib/chef/knife/ionoscloud_natgateway_lan_remove.rb +58 -0
- data/lib/chef/knife/ionoscloud_natgateway_list.rb +49 -0
- data/lib/chef/knife/ionoscloud_natgateway_rule_add.rb +124 -0
- data/lib/chef/knife/ionoscloud_natgateway_rule_list.rb +63 -0
- data/lib/chef/knife/ionoscloud_natgateway_rule_remove.rb +72 -0
- data/lib/chef/knife/ionoscloud_networkloadbalancer_create.rb +95 -0
- data/lib/chef/knife/ionoscloud_networkloadbalancer_delete.rb +81 -0
- data/lib/chef/knife/ionoscloud_networkloadbalancer_list.rb +56 -0
- data/lib/chef/knife/ionoscloud_networkloadbalancer_rule_add.rb +150 -0
- data/lib/chef/knife/ionoscloud_networkloadbalancer_rule_list.rb +63 -0
- data/lib/chef/knife/ionoscloud_networkloadbalancer_rule_remove.rb +78 -0
- data/lib/chef/knife/ionoscloud_networkloadbalancer_rule_target_add.rb +141 -0
- data/lib/chef/knife/ionoscloud_networkloadbalancer_rule_target_list.rb +68 -0
- data/lib/chef/knife/ionoscloud_networkloadbalancer_rule_target_remove.rb +105 -0
- data/lib/chef/knife/ionoscloud_nic_create.rb +14 -9
- data/lib/chef/knife/ionoscloud_nic_delete.rb +4 -2
- data/lib/chef/knife/ionoscloud_nic_list.rb +9 -5
- data/lib/chef/knife/ionoscloud_node_list.rb +0 -1
- data/lib/chef/knife/ionoscloud_nodepool_create.rb +42 -16
- data/lib/chef/knife/ionoscloud_nodepool_delete.rb +25 -0
- data/lib/chef/knife/ionoscloud_nodepool_lan_add.rb +130 -0
- data/lib/chef/knife/ionoscloud_nodepool_lan_remove.rb +96 -0
- data/lib/chef/knife/ionoscloud_nodepool_list.rb +3 -1
- data/lib/chef/knife/ionoscloud_pcc_create.rb +2 -2
- data/lib/chef/knife/ionoscloud_pcc_delete.rb +1 -1
- data/lib/chef/knife/ionoscloud_pcc_list.rb +1 -1
- data/lib/chef/knife/ionoscloud_request_list.rb +1 -1
- data/lib/chef/knife/ionoscloud_request_status.rb +1 -1
- data/lib/chef/knife/ionoscloud_s3key_create.rb +2 -2
- data/lib/chef/knife/ionoscloud_s3key_delete.rb +3 -3
- data/lib/chef/knife/ionoscloud_s3key_list.rb +2 -2
- data/lib/chef/knife/ionoscloud_server_console.rb +42 -0
- data/lib/chef/knife/ionoscloud_server_create.rb +8 -8
- data/lib/chef/knife/ionoscloud_server_delete.rb +1 -1
- data/lib/chef/knife/ionoscloud_server_list.rb +16 -5
- data/lib/chef/knife/ionoscloud_server_reboot.rb +1 -1
- data/lib/chef/knife/ionoscloud_server_resume.rb +43 -0
- data/lib/chef/knife/ionoscloud_server_start.rb +1 -1
- data/lib/chef/knife/ionoscloud_server_stop.rb +1 -1
- data/lib/chef/knife/ionoscloud_server_suspend.rb +44 -0
- data/lib/chef/knife/ionoscloud_server_token.rb +42 -0
- data/lib/chef/knife/ionoscloud_server_upgrade.rb +44 -0
- data/lib/chef/knife/ionoscloud_snapshot_create.rb +2 -2
- data/lib/chef/knife/ionoscloud_snapshot_delete.rb +1 -1
- data/lib/chef/knife/ionoscloud_snapshot_list.rb +1 -1
- data/lib/chef/knife/ionoscloud_snapshot_restore.rb +2 -2
- data/lib/chef/knife/ionoscloud_template_list.rb +46 -0
- data/lib/chef/knife/ionoscloud_user_ssourl.rb +1 -1
- data/lib/chef/knife/ionoscloud_volume_attach.rb +1 -1
- data/lib/chef/knife/ionoscloud_volume_create.rb +33 -35
- data/lib/chef/knife/ionoscloud_volume_delete.rb +1 -1
- data/lib/chef/knife/ionoscloud_volume_detach.rb +1 -1
- data/lib/chef/knife/ionoscloud_volume_list.rb +2 -2
- data/lib/knife-ionoscloud/version.rb +1 -1
- data/spec/chef/knife/ionoscloud_backupunit_create_spec.rb +2 -2
- data/spec/chef/knife/ionoscloud_backupunit_delete_spec.rb +5 -5
- data/spec/chef/knife/ionoscloud_backupunit_list_spec.rb +1 -1
- data/spec/chef/knife/ionoscloud_backupunit_ssourl_spec.rb +3 -3
- data/spec/chef/knife/ionoscloud_base_spec.rb +4 -4
- data/spec/chef/knife/ionoscloud_composite_server_create_spec.rb +11 -8
- data/spec/chef/knife/ionoscloud_contract_list_spec.rb +32 -27
- data/spec/chef/knife/ionoscloud_cube_server_create_spec.rb +249 -0
- data/spec/chef/knife/ionoscloud_datacenter_create_spec.rb +3 -2
- data/spec/chef/knife/ionoscloud_datacenter_delete_spec.rb +5 -5
- data/spec/chef/knife/ionoscloud_datacenter_list_spec.rb +5 -3
- data/spec/chef/knife/ionoscloud_firewall_create_spec.rb +5 -3
- data/spec/chef/knife/ionoscloud_firewall_delete_spec.rb +6 -5
- data/spec/chef/knife/ionoscloud_firewall_list_spec.rb +5 -3
- data/spec/chef/knife/ionoscloud_flowlog_create_spec.rb +254 -0
- data/spec/chef/knife/ionoscloud_flowlog_delete_spec.rb +360 -0
- data/spec/chef/knife/ionoscloud_flowlog_list_spec.rb +264 -0
- data/spec/chef/knife/ionoscloud_group_create_spec.rb +6 -0
- data/spec/chef/knife/ionoscloud_group_delete_spec.rb +6 -0
- data/spec/chef/knife/ionoscloud_group_get_spec.rb +6 -0
- data/spec/chef/knife/ionoscloud_group_list_spec.rb +26 -8
- data/spec/chef/knife/ionoscloud_image_list_spec.rb +2 -2
- data/spec/chef/knife/ionoscloud_ipfailover_add_spec.rb +3 -3
- data/spec/chef/knife/ionoscloud_ipfailover_remove_spec.rb +4 -4
- data/spec/chef/knife/ionoscloud_k8s_delete_spec.rb +5 -2
- data/spec/chef/knife/ionoscloud_kubeconfig_get_spec.rb +2 -2
- data/spec/chef/knife/ionoscloud_label_add_spec.rb +10 -10
- data/spec/chef/knife/ionoscloud_label_list_spec.rb +14 -14
- data/spec/chef/knife/ionoscloud_label_remove_spec.rb +20 -20
- data/spec/chef/knife/ionoscloud_lan_create_spec.rb +3 -3
- data/spec/chef/knife/ionoscloud_lan_delete_spec.rb +5 -5
- data/spec/chef/knife/ionoscloud_lan_list_spec.rb +2 -2
- data/spec/chef/knife/ionoscloud_loadbalancer_create_spec.rb +3 -3
- data/spec/chef/knife/ionoscloud_loadbalancer_delete_spec.rb +5 -5
- data/spec/chef/knife/ionoscloud_loadbalancer_get_spec.rb +2 -2
- data/spec/chef/knife/ionoscloud_loadbalancer_list_spec.rb +2 -2
- data/spec/chef/knife/ionoscloud_loadbalancer_nic_add_spec.rb +6 -6
- data/spec/chef/knife/ionoscloud_loadbalancer_nic_remove_spec.rb +6 -6
- data/spec/chef/knife/ionoscloud_location_list_spec.rb +5 -3
- data/spec/chef/knife/ionoscloud_natgateway_create_spec.rb +77 -0
- data/spec/chef/knife/ionoscloud_natgateway_delete_spec.rb +118 -0
- data/spec/chef/knife/ionoscloud_natgateway_lan_add_spec.rb +143 -0
- data/spec/chef/knife/ionoscloud_natgateway_lan_remove_spec.rb +194 -0
- data/spec/chef/knife/ionoscloud_natgateway_list_spec.rb +79 -0
- data/spec/chef/knife/ionoscloud_natgateway_rule_add_spec.rb +98 -0
- data/spec/chef/knife/ionoscloud_natgateway_rule_list_spec.rb +92 -0
- data/spec/chef/knife/ionoscloud_natgateway_rule_remove_spec.rb +77 -0
- data/spec/chef/knife/ionoscloud_networkloadbalancer_create_spec.rb +80 -0
- data/spec/chef/knife/ionoscloud_networkloadbalancer_delete_spec.rb +119 -0
- data/spec/chef/knife/ionoscloud_networkloadbalancer_list_spec.rb +88 -0
- data/spec/chef/knife/ionoscloud_networkloadbalancer_rule_add_spec.rb +104 -0
- data/spec/chef/knife/ionoscloud_networkloadbalancer_rule_list_spec.rb +89 -0
- data/spec/chef/knife/ionoscloud_networkloadbalancer_rule_remove_spec.rb +124 -0
- data/spec/chef/knife/ionoscloud_networkloadbalancer_rule_target_add_spec.rb +109 -0
- data/spec/chef/knife/ionoscloud_networkloadbalancer_rule_target_list_spec.rb +85 -0
- data/spec/chef/knife/ionoscloud_networkloadbalancer_rule_target_remove_spec.rb +263 -0
- data/spec/chef/knife/ionoscloud_nic_create_spec.rb +9 -5
- data/spec/chef/knife/ionoscloud_nic_delete_spec.rb +8 -6
- data/spec/chef/knife/ionoscloud_nic_list_spec.rb +12 -6
- data/spec/chef/knife/ionoscloud_nodepool_create_spec.rb +15 -1
- data/spec/chef/knife/ionoscloud_nodepool_lan_add_spec.rb +226 -0
- data/spec/chef/knife/ionoscloud_nodepool_lan_remove.rb +199 -0
- data/spec/chef/knife/ionoscloud_nodepool_list_spec.rb +3 -1
- data/spec/chef/knife/ionoscloud_pcc_create_spec.rb +6 -6
- data/spec/chef/knife/ionoscloud_pcc_delete_spec.rb +5 -5
- data/spec/chef/knife/ionoscloud_pcc_list_spec.rb +2 -2
- data/spec/chef/knife/ionoscloud_request_list_spec.rb +16 -16
- data/spec/chef/knife/ionoscloud_request_status_spec.rb +3 -3
- data/spec/chef/knife/ionoscloud_s3key_create_spec.rb +2 -2
- data/spec/chef/knife/ionoscloud_s3key_delete_spec.rb +5 -5
- data/spec/chef/knife/ionoscloud_s3key_list_spec.rb +2 -2
- data/spec/chef/knife/ionoscloud_server_console_spec.rb +97 -0
- data/spec/chef/knife/ionoscloud_server_create_spec.rb +3 -3
- data/spec/chef/knife/ionoscloud_server_delete_spec.rb +5 -5
- data/spec/chef/knife/ionoscloud_server_list_spec.rb +63 -5
- data/spec/chef/knife/ionoscloud_server_reboot_spec.rb +3 -5
- data/spec/chef/knife/ionoscloud_server_resume_spec.rb +93 -0
- data/spec/chef/knife/ionoscloud_server_start_spec.rb +3 -5
- data/spec/chef/knife/ionoscloud_server_stop_spec.rb +3 -5
- data/spec/chef/knife/ionoscloud_server_suspend_spec.rb +93 -0
- data/spec/chef/knife/ionoscloud_server_token_spec.rb +97 -0
- data/spec/chef/knife/ionoscloud_server_upgrade_spec.rb +96 -0
- data/spec/chef/knife/ionoscloud_snapshot_create_spec.rb +3 -3
- data/spec/chef/knife/ionoscloud_snapshot_delete_spec.rb +5 -5
- data/spec/chef/knife/ionoscloud_snapshot_list_spec.rb +2 -2
- data/spec/chef/knife/ionoscloud_snapshot_restore_spec.rb +3 -3
- data/spec/chef/knife/ionoscloud_template_list_spec.rb +78 -0
- data/spec/chef/knife/ionoscloud_user_ssourl_spec.rb +3 -3
- data/spec/chef/knife/ionoscloud_volume_attach_spec.rb +4 -4
- data/spec/chef/knife/ionoscloud_volume_create_spec.rb +6 -58
- data/spec/chef/knife/ionoscloud_volume_delete_spec.rb +5 -5
- data/spec/chef/knife/ionoscloud_volume_detach_spec.rb +5 -5
- data/spec/chef/knife/ionoscloud_volume_list_spec.rb +4 -4
- data/spec/spec_helper.rb +223 -29
- metadata +93 -6
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_natgateway_lan_add'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudNatgatewayLanAdd.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudNatgatewayLanAdd do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudNatgatewayLanAdd.new }
|
9
|
+
|
10
|
+
allow(subject).to receive(:puts)
|
11
|
+
allow(subject).to receive(:print)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#run' do
|
15
|
+
it 'should call NATGatewaysApi.datacenters_natgateways_patch and add a new lan when need' do
|
16
|
+
natgateway = natgateway_mock
|
17
|
+
lan = natgateway_lan_mock(lan_id: 2, gateway_ips: ['0.8.152.237/24'])
|
18
|
+
subject_config = {
|
19
|
+
ionoscloud_username: 'email',
|
20
|
+
ionoscloud_password: 'password',
|
21
|
+
datacenter_id: 'datacenter_id',
|
22
|
+
natgateway_id: natgateway.id,
|
23
|
+
lan_id: lan.id,
|
24
|
+
gateway_ips: lan.gateway_ips.join(','),
|
25
|
+
yes: true,
|
26
|
+
}
|
27
|
+
|
28
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
29
|
+
|
30
|
+
expect(subject).to receive(:puts).with("ID: #{natgateway.id}")
|
31
|
+
expect(subject).to receive(:puts).with("Name: #{natgateway.properties.name}")
|
32
|
+
expect(subject).to receive(:puts).with("IPS: #{natgateway.properties.public_ips}")
|
33
|
+
expect(subject).to receive(:puts).with("LANS: #{(natgateway.properties.lans + [lan]).map { |el| { id: el.id, gateway_ips: el.gateway_ips } }}")
|
34
|
+
|
35
|
+
expected_properties = natgateway.properties.to_hash
|
36
|
+
expected_properties[:lans] << lan.to_hash
|
37
|
+
|
38
|
+
mock_wait_for(subject)
|
39
|
+
mock_call_api(
|
40
|
+
subject,
|
41
|
+
[
|
42
|
+
{
|
43
|
+
method: 'GET',
|
44
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways/#{natgateway.id}",
|
45
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_find_by_nat_gateway_id',
|
46
|
+
return_type: 'NatGateway',
|
47
|
+
result: natgateway,
|
48
|
+
},
|
49
|
+
{
|
50
|
+
method: 'PATCH',
|
51
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways/#{natgateway.id}",
|
52
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_patch',
|
53
|
+
body: expected_properties,
|
54
|
+
return_type: 'NatGateway',
|
55
|
+
result: natgateway,
|
56
|
+
},
|
57
|
+
{
|
58
|
+
method: 'GET',
|
59
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways/#{natgateway.id}",
|
60
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_find_by_nat_gateway_id',
|
61
|
+
return_type: 'NatGateway',
|
62
|
+
result: natgateway,
|
63
|
+
},
|
64
|
+
],
|
65
|
+
)
|
66
|
+
|
67
|
+
expect { subject.run }.not_to raise_error(Exception)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should call NATGatewaysApi.datacenters_natgateways_patch and update an existing lan when need' do
|
71
|
+
natgateway = natgateway_mock
|
72
|
+
lan = natgateway_lan_mock(lan_id: 1, gateway_ips: ['0.8.152.237/24'])
|
73
|
+
subject_config = {
|
74
|
+
ionoscloud_username: 'email',
|
75
|
+
ionoscloud_password: 'password',
|
76
|
+
datacenter_id: 'datacenter_id',
|
77
|
+
natgateway_id: natgateway.id,
|
78
|
+
lan_id: lan.id,
|
79
|
+
gateway_ips: lan.gateway_ips.join(','),
|
80
|
+
yes: true,
|
81
|
+
}
|
82
|
+
|
83
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
84
|
+
|
85
|
+
expect(subject).to receive(:puts).with("ID: #{natgateway.id}")
|
86
|
+
expect(subject).to receive(:puts).with("Name: #{natgateway.properties.name}")
|
87
|
+
expect(subject).to receive(:puts).with("IPS: #{natgateway.properties.public_ips}")
|
88
|
+
expect(subject).to receive(:puts).with("LANS: #{[{ id: lan.id, gateway_ips: lan.gateway_ips }]}")
|
89
|
+
|
90
|
+
expected_properties = natgateway.properties.to_hash
|
91
|
+
expected_properties[:lans] = [lan.to_hash]
|
92
|
+
|
93
|
+
mock_wait_for(subject)
|
94
|
+
mock_call_api(
|
95
|
+
subject,
|
96
|
+
[
|
97
|
+
{
|
98
|
+
method: 'GET',
|
99
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways/#{natgateway.id}",
|
100
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_find_by_nat_gateway_id',
|
101
|
+
return_type: 'NatGateway',
|
102
|
+
result: natgateway,
|
103
|
+
},
|
104
|
+
{
|
105
|
+
method: 'PATCH',
|
106
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways/#{natgateway.id}",
|
107
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_patch',
|
108
|
+
body: expected_properties,
|
109
|
+
return_type: 'NatGateway',
|
110
|
+
result: natgateway,
|
111
|
+
},
|
112
|
+
{
|
113
|
+
method: 'GET',
|
114
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways/#{natgateway.id}",
|
115
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_find_by_nat_gateway_id',
|
116
|
+
return_type: 'NatGateway',
|
117
|
+
result: natgateway,
|
118
|
+
},
|
119
|
+
],
|
120
|
+
)
|
121
|
+
|
122
|
+
expect { subject.run }.not_to raise_error(Exception)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should not make any call if any required option is missing' do
|
126
|
+
required_options = subject.instance_variable_get(:@required_options)
|
127
|
+
|
128
|
+
arrays_without_one_element(required_options).each do |test_case|
|
129
|
+
|
130
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
131
|
+
|
132
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
133
|
+
expect(subject.api_client).not_to receive(:call_api)
|
134
|
+
|
135
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
136
|
+
expect(error.status).to eq(1)
|
137
|
+
end
|
138
|
+
|
139
|
+
required_options.each { |value| subject.config[value] = nil }
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_natgateway_lan_remove'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudNatgatewayLanRemove.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudNatgatewayLanRemove do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudNatgatewayLanRemove.new }
|
9
|
+
|
10
|
+
allow(subject).to receive(:puts)
|
11
|
+
allow(subject).to receive(:print)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#run' do
|
15
|
+
it 'should call NATGatewaysApi.datacenters_natgateways_patch and remove lans' do
|
16
|
+
natgateway = natgateway_mock
|
17
|
+
subject_config = {
|
18
|
+
ionoscloud_username: 'email',
|
19
|
+
ionoscloud_password: 'password',
|
20
|
+
datacenter_id: 'datacenter_id',
|
21
|
+
natgateway_id: natgateway.id,
|
22
|
+
yes: true,
|
23
|
+
}
|
24
|
+
|
25
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
26
|
+
subject.name_args = natgateway.properties.lans.map { |el| el.id }
|
27
|
+
|
28
|
+
expect(subject).to receive(:puts).with("ID: #{natgateway.id}")
|
29
|
+
expect(subject).to receive(:puts).with("Name: #{natgateway.properties.name}")
|
30
|
+
expect(subject).to receive(:puts).with("IPS: #{natgateway.properties.public_ips}")
|
31
|
+
expect(subject).to receive(:puts).with("LANS: #{[]}")
|
32
|
+
|
33
|
+
expected_properties = natgateway.properties.to_hash
|
34
|
+
expected_properties[:lans] = []
|
35
|
+
|
36
|
+
mock_wait_for(subject)
|
37
|
+
mock_call_api(
|
38
|
+
subject,
|
39
|
+
[
|
40
|
+
{
|
41
|
+
method: 'GET',
|
42
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways/#{natgateway.id}",
|
43
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_find_by_nat_gateway_id',
|
44
|
+
return_type: 'NatGateway',
|
45
|
+
result: natgateway,
|
46
|
+
},
|
47
|
+
{
|
48
|
+
method: 'PATCH',
|
49
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways/#{natgateway.id}",
|
50
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_patch',
|
51
|
+
body: expected_properties,
|
52
|
+
return_type: 'NatGateway',
|
53
|
+
result: natgateway,
|
54
|
+
},
|
55
|
+
{
|
56
|
+
method: 'GET',
|
57
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways/#{natgateway.id}",
|
58
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_find_by_nat_gateway_id',
|
59
|
+
return_type: 'NatGateway',
|
60
|
+
result: natgateway,
|
61
|
+
},
|
62
|
+
],
|
63
|
+
)
|
64
|
+
|
65
|
+
expect { subject.run }.not_to raise_error(Exception)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should call NATGatewaysApi.datacenters_natgateways_patch and remove only wanted lans' do
|
69
|
+
lan1 = natgateway_lan_mock(lan_id: 1)
|
70
|
+
lan2 = natgateway_lan_mock(lan_id: 4)
|
71
|
+
lan3 = natgateway_lan_mock(lan_id: 3)
|
72
|
+
natgateway = natgateway_mock(lans: [lan1, lan2])
|
73
|
+
subject_config = {
|
74
|
+
ionoscloud_username: 'email',
|
75
|
+
ionoscloud_password: 'password',
|
76
|
+
datacenter_id: 'datacenter_id',
|
77
|
+
natgateway_id: natgateway.id,
|
78
|
+
yes: true,
|
79
|
+
}
|
80
|
+
|
81
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
82
|
+
subject.name_args = [lan3.id]
|
83
|
+
|
84
|
+
expect(subject).to receive(:puts).with("ID: #{natgateway.id}")
|
85
|
+
expect(subject).to receive(:puts).with("Name: #{natgateway.properties.name}")
|
86
|
+
expect(subject).to receive(:puts).with("IPS: #{natgateway.properties.public_ips}")
|
87
|
+
expect(subject).to receive(:puts).with("LANS: #{natgateway.properties.lans.map { |el| { id: el.id, gateway_ips: el.gateway_ips } }}")
|
88
|
+
|
89
|
+
expected_properties = natgateway.properties.to_hash
|
90
|
+
|
91
|
+
mock_wait_for(subject)
|
92
|
+
mock_call_api(
|
93
|
+
subject,
|
94
|
+
[
|
95
|
+
{
|
96
|
+
method: 'GET',
|
97
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways/#{natgateway.id}",
|
98
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_find_by_nat_gateway_id',
|
99
|
+
return_type: 'NatGateway',
|
100
|
+
result: natgateway,
|
101
|
+
},
|
102
|
+
{
|
103
|
+
method: 'PATCH',
|
104
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways/#{natgateway.id}",
|
105
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_patch',
|
106
|
+
body: expected_properties,
|
107
|
+
return_type: 'NatGateway',
|
108
|
+
result: natgateway,
|
109
|
+
},
|
110
|
+
{
|
111
|
+
method: 'GET',
|
112
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways/#{natgateway.id}",
|
113
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_find_by_nat_gateway_id',
|
114
|
+
return_type: 'NatGateway',
|
115
|
+
result: natgateway,
|
116
|
+
},
|
117
|
+
],
|
118
|
+
)
|
119
|
+
expect { subject.run }.not_to raise_error(Exception)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should call NATGatewaysApi.datacenters_natgateways_patch and remove only wanted lans 2' do
|
123
|
+
lan1 = natgateway_lan_mock(lan_id: 1)
|
124
|
+
lan2 = natgateway_lan_mock(lan_id: 4)
|
125
|
+
natgateway = natgateway_mock(lans: [lan1, lan2])
|
126
|
+
subject_config = {
|
127
|
+
ionoscloud_username: 'email',
|
128
|
+
ionoscloud_password: 'password',
|
129
|
+
datacenter_id: 'datacenter_id',
|
130
|
+
natgateway_id: natgateway.id,
|
131
|
+
yes: true,
|
132
|
+
}
|
133
|
+
|
134
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
135
|
+
subject.name_args = [lan2.id]
|
136
|
+
|
137
|
+
expect(subject).to receive(:puts).with("ID: #{natgateway.id}")
|
138
|
+
expect(subject).to receive(:puts).with("Name: #{natgateway.properties.name}")
|
139
|
+
expect(subject).to receive(:puts).with("IPS: #{natgateway.properties.public_ips}")
|
140
|
+
expect(subject).to receive(:puts).with("LANS: #{[{ id: lan1.id, gateway_ips: lan1.gateway_ips }]}")
|
141
|
+
|
142
|
+
expected_properties = natgateway.properties.to_hash
|
143
|
+
expected_properties[:lans] = [lan1.to_hash]
|
144
|
+
|
145
|
+
mock_wait_for(subject)
|
146
|
+
mock_call_api(
|
147
|
+
subject,
|
148
|
+
[
|
149
|
+
{
|
150
|
+
method: 'GET',
|
151
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways/#{natgateway.id}",
|
152
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_find_by_nat_gateway_id',
|
153
|
+
return_type: 'NatGateway',
|
154
|
+
result: natgateway,
|
155
|
+
},
|
156
|
+
{
|
157
|
+
method: 'PATCH',
|
158
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways/#{natgateway.id}",
|
159
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_patch',
|
160
|
+
body: expected_properties,
|
161
|
+
return_type: 'NatGateway',
|
162
|
+
result: natgateway,
|
163
|
+
},
|
164
|
+
{
|
165
|
+
method: 'GET',
|
166
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways/#{natgateway.id}",
|
167
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_find_by_nat_gateway_id',
|
168
|
+
return_type: 'NatGateway',
|
169
|
+
result: natgateway,
|
170
|
+
},
|
171
|
+
],
|
172
|
+
)
|
173
|
+
expect { subject.run }.not_to raise_error(Exception)
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should not make any call if any required option is missing' do
|
177
|
+
required_options = subject.instance_variable_get(:@required_options)
|
178
|
+
|
179
|
+
arrays_without_one_element(required_options).each do |test_case|
|
180
|
+
|
181
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
182
|
+
|
183
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
184
|
+
expect(subject.api_client).not_to receive(:call_api)
|
185
|
+
|
186
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
187
|
+
expect(error.status).to eq(1)
|
188
|
+
end
|
189
|
+
|
190
|
+
required_options.each { |value| subject.config[value] = nil }
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_natgateway_list'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudNatgatewayList.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudNatgatewayList do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudNatgatewayList.new }
|
9
|
+
|
10
|
+
allow(subject).to receive(:puts)
|
11
|
+
allow(subject).to receive(:print)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#run' do
|
15
|
+
it 'should call NATGatewayApi.datacenters_natgateways_get' do
|
16
|
+
natgateways = natgateways_mock
|
17
|
+
subject_config = {
|
18
|
+
ionoscloud_username: 'email',
|
19
|
+
ionoscloud_password: 'password',
|
20
|
+
datacenter_id: 'datacenter_id',
|
21
|
+
}
|
22
|
+
|
23
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
24
|
+
|
25
|
+
natgateway_list = [
|
26
|
+
subject.ui.color('ID', :bold),
|
27
|
+
subject.ui.color('Name', :bold),
|
28
|
+
subject.ui.color('IPS', :bold),
|
29
|
+
subject.ui.color('LANS', :bold),
|
30
|
+
subject.ui.color('Rules Count', :bold),
|
31
|
+
natgateways.items.first.id,
|
32
|
+
natgateways.items.first.properties.name,
|
33
|
+
natgateways.items.first.properties.public_ips,
|
34
|
+
natgateways.items.first.properties.lans.map { |el| { id: el.id, gateway_ips: el.gateway_ips } },
|
35
|
+
natgateways.items.first.entities.rules.items.length,
|
36
|
+
natgateways.items[1].id,
|
37
|
+
natgateways.items[1].properties.name,
|
38
|
+
natgateways.items[1].properties.public_ips,
|
39
|
+
natgateways.items[1].properties.lans.map { |el| { id: el.id, gateway_ips: el.gateway_ips } },
|
40
|
+
natgateways.items[1].entities.rules.items.length,
|
41
|
+
]
|
42
|
+
|
43
|
+
expect(subject.ui).to receive(:list).with(natgateway_list, :uneven_columns_across, 5)
|
44
|
+
|
45
|
+
mock_call_api(
|
46
|
+
subject,
|
47
|
+
[
|
48
|
+
{
|
49
|
+
method: 'GET',
|
50
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways",
|
51
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_get',
|
52
|
+
return_type: 'NatGateways',
|
53
|
+
result: natgateways,
|
54
|
+
},
|
55
|
+
],
|
56
|
+
)
|
57
|
+
|
58
|
+
expect { subject.run }.not_to raise_error(Exception)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should not make any call if any required option is missing' do
|
62
|
+
required_options = subject.instance_variable_get(:@required_options)
|
63
|
+
|
64
|
+
arrays_without_one_element(required_options).each do |test_case|
|
65
|
+
|
66
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
67
|
+
|
68
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
69
|
+
expect(subject.api_client).not_to receive(:call_api)
|
70
|
+
|
71
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
72
|
+
expect(error.status).to eq(1)
|
73
|
+
end
|
74
|
+
|
75
|
+
required_options.each { |value| subject.config[value] = nil }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_natgateway_rule_add'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudNatgatewayRuleAdd.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudNatgatewayRuleAdd do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudNatgatewayRuleAdd.new }
|
9
|
+
|
10
|
+
allow(subject).to receive(:puts)
|
11
|
+
allow(subject).to receive(:print)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#run' do
|
15
|
+
it 'should call NATGatewaysApi.datacenters_natgateways_rules_post when the ID is valid' do
|
16
|
+
natgateway = natgateway_mock
|
17
|
+
rule = natgateway_rule_mock
|
18
|
+
subject_config = {
|
19
|
+
ionoscloud_username: 'email',
|
20
|
+
ionoscloud_password: 'password',
|
21
|
+
datacenter_id: 'datacenter_id',
|
22
|
+
natgateway_id: natgateway.id,
|
23
|
+
name: rule.properties.name,
|
24
|
+
type: rule.properties.type,
|
25
|
+
protocol: rule.properties.protocol,
|
26
|
+
public_ip: rule.properties.public_ip,
|
27
|
+
source_subnet: rule.properties.source_subnet,
|
28
|
+
target_subnet: rule.properties.target_subnet,
|
29
|
+
target_port_range_start: rule.properties.target_port_range.start,
|
30
|
+
target_port_range_end: rule.properties.target_port_range._end,
|
31
|
+
yes: true,
|
32
|
+
}
|
33
|
+
|
34
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
35
|
+
|
36
|
+
expect(subject).to receive(:puts).with("ID: #{natgateway.id}")
|
37
|
+
expect(subject).to receive(:puts).with("Name: #{natgateway.properties.name}")
|
38
|
+
expect(subject).to receive(:puts).with("IPS: #{natgateway.properties.public_ips}")
|
39
|
+
expect(subject).to receive(:puts).with("LANS: #{natgateway.properties.lans.map { |el| { id: el.id, gateway_ips: el.gateway_ips } }}")
|
40
|
+
expect(subject).to receive(:puts).with("Rules: #{(natgateway.entities.rules.items + [rule]).map do |el|
|
41
|
+
{
|
42
|
+
id: el.id,
|
43
|
+
name: el.properties.name,
|
44
|
+
type: el.properties.type,
|
45
|
+
protocol: el.properties.protocol,
|
46
|
+
public_ip: el.properties.public_ip,
|
47
|
+
source_subnet: el.properties.source_subnet,
|
48
|
+
target_subnet: el.properties.target_subnet,
|
49
|
+
target_port_range_start: el.properties.target_port_range ? el.properties.target_port_range.start : '',
|
50
|
+
target_port_range_end: el.properties.target_port_range ? el.properties.target_port_range._end : '',
|
51
|
+
}
|
52
|
+
end}")
|
53
|
+
|
54
|
+
mock_wait_for(subject)
|
55
|
+
mock_call_api(
|
56
|
+
subject,
|
57
|
+
[
|
58
|
+
{
|
59
|
+
method: 'POST',
|
60
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways/#{natgateway.id}/rules",
|
61
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_rules_post',
|
62
|
+
body: { properties: rule.properties.to_hash },
|
63
|
+
return_type: 'NatGatewayRule',
|
64
|
+
},
|
65
|
+
{
|
66
|
+
method: 'GET',
|
67
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/natgateways/#{natgateway.id}",
|
68
|
+
operation: :'NATGatewaysApi.datacenters_natgateways_find_by_nat_gateway_id',
|
69
|
+
return_type: 'NatGateway',
|
70
|
+
result: natgateway,
|
71
|
+
},
|
72
|
+
],
|
73
|
+
)
|
74
|
+
|
75
|
+
natgateway.entities.rules.items << rule
|
76
|
+
|
77
|
+
expect { subject.run }.not_to raise_error(Exception)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should not make any call if any required option is missing' do
|
81
|
+
required_options = subject.instance_variable_get(:@required_options)
|
82
|
+
|
83
|
+
arrays_without_one_element(required_options).each do |test_case|
|
84
|
+
|
85
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
86
|
+
|
87
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
88
|
+
expect(subject.api_client).not_to receive(:call_api)
|
89
|
+
|
90
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
91
|
+
expect(error.status).to eq(1)
|
92
|
+
end
|
93
|
+
|
94
|
+
required_options.each { |value| subject.config[value] = nil }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|