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.
Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/knife-ionoscloud.gemspec +1 -1
  3. data/lib/chef/knife/ionoscloud_backupunit_create.rb +1 -1
  4. data/lib/chef/knife/ionoscloud_backupunit_delete.rb +1 -1
  5. data/lib/chef/knife/ionoscloud_backupunit_list.rb +1 -1
  6. data/lib/chef/knife/ionoscloud_backupunit_ssourl.rb +1 -1
  7. data/lib/chef/knife/ionoscloud_base.rb +1 -1
  8. data/lib/chef/knife/ionoscloud_composite_server_create.rb +25 -23
  9. data/lib/chef/knife/ionoscloud_contract_list.rb +32 -23
  10. data/lib/chef/knife/ionoscloud_cube_server_create.rb +215 -0
  11. data/lib/chef/knife/ionoscloud_datacenter_create.rb +1 -1
  12. data/lib/chef/knife/ionoscloud_datacenter_delete.rb +1 -1
  13. data/lib/chef/knife/ionoscloud_datacenter_list.rb +4 -2
  14. data/lib/chef/knife/ionoscloud_firewall_create.rb +11 -4
  15. data/lib/chef/knife/ionoscloud_firewall_delete.rb +4 -3
  16. data/lib/chef/knife/ionoscloud_firewall_list.rb +5 -3
  17. data/lib/chef/knife/ionoscloud_flowlog_create.rb +121 -0
  18. data/lib/chef/knife/ionoscloud_flowlog_delete.rb +106 -0
  19. data/lib/chef/knife/ionoscloud_flowlog_list.rb +100 -0
  20. data/lib/chef/knife/ionoscloud_group_create.rb +35 -14
  21. data/lib/chef/knife/ionoscloud_group_delete.rb +7 -0
  22. data/lib/chef/knife/ionoscloud_group_get.rb +6 -0
  23. data/lib/chef/knife/ionoscloud_group_list.rb +19 -7
  24. data/lib/chef/knife/ionoscloud_image_list.rb +1 -1
  25. data/lib/chef/knife/ionoscloud_ipfailover_add.rb +1 -1
  26. data/lib/chef/knife/ionoscloud_ipfailover_remove.rb +1 -1
  27. data/lib/chef/knife/ionoscloud_k8s_delete.rb +5 -2
  28. data/lib/chef/knife/ionoscloud_label_add.rb +1 -1
  29. data/lib/chef/knife/ionoscloud_label_list.rb +1 -1
  30. data/lib/chef/knife/ionoscloud_label_remove.rb +1 -1
  31. data/lib/chef/knife/ionoscloud_lan_create.rb +1 -1
  32. data/lib/chef/knife/ionoscloud_lan_delete.rb +1 -1
  33. data/lib/chef/knife/ionoscloud_lan_list.rb +1 -1
  34. data/lib/chef/knife/ionoscloud_loadbalancer_create.rb +1 -1
  35. data/lib/chef/knife/ionoscloud_loadbalancer_delete.rb +1 -1
  36. data/lib/chef/knife/ionoscloud_loadbalancer_get.rb +1 -1
  37. data/lib/chef/knife/ionoscloud_loadbalancer_list.rb +1 -1
  38. data/lib/chef/knife/ionoscloud_loadbalancer_nic_add.rb +1 -1
  39. data/lib/chef/knife/ionoscloud_loadbalancer_nic_remove.rb +1 -1
  40. data/lib/chef/knife/ionoscloud_location_list.rb +5 -3
  41. data/lib/chef/knife/ionoscloud_natgateway_create.rb +71 -0
  42. data/lib/chef/knife/ionoscloud_natgateway_delete.rb +69 -0
  43. data/lib/chef/knife/ionoscloud_natgateway_lan_add.rb +82 -0
  44. data/lib/chef/knife/ionoscloud_natgateway_lan_remove.rb +58 -0
  45. data/lib/chef/knife/ionoscloud_natgateway_list.rb +49 -0
  46. data/lib/chef/knife/ionoscloud_natgateway_rule_add.rb +124 -0
  47. data/lib/chef/knife/ionoscloud_natgateway_rule_list.rb +63 -0
  48. data/lib/chef/knife/ionoscloud_natgateway_rule_remove.rb +72 -0
  49. data/lib/chef/knife/ionoscloud_networkloadbalancer_create.rb +95 -0
  50. data/lib/chef/knife/ionoscloud_networkloadbalancer_delete.rb +81 -0
  51. data/lib/chef/knife/ionoscloud_networkloadbalancer_list.rb +56 -0
  52. data/lib/chef/knife/ionoscloud_networkloadbalancer_rule_add.rb +150 -0
  53. data/lib/chef/knife/ionoscloud_networkloadbalancer_rule_list.rb +63 -0
  54. data/lib/chef/knife/ionoscloud_networkloadbalancer_rule_remove.rb +78 -0
  55. data/lib/chef/knife/ionoscloud_networkloadbalancer_rule_target_add.rb +141 -0
  56. data/lib/chef/knife/ionoscloud_networkloadbalancer_rule_target_list.rb +68 -0
  57. data/lib/chef/knife/ionoscloud_networkloadbalancer_rule_target_remove.rb +105 -0
  58. data/lib/chef/knife/ionoscloud_nic_create.rb +14 -9
  59. data/lib/chef/knife/ionoscloud_nic_delete.rb +4 -2
  60. data/lib/chef/knife/ionoscloud_nic_list.rb +9 -5
  61. data/lib/chef/knife/ionoscloud_node_list.rb +0 -1
  62. data/lib/chef/knife/ionoscloud_nodepool_create.rb +42 -16
  63. data/lib/chef/knife/ionoscloud_nodepool_delete.rb +25 -0
  64. data/lib/chef/knife/ionoscloud_nodepool_lan_add.rb +130 -0
  65. data/lib/chef/knife/ionoscloud_nodepool_lan_remove.rb +96 -0
  66. data/lib/chef/knife/ionoscloud_nodepool_list.rb +3 -1
  67. data/lib/chef/knife/ionoscloud_pcc_create.rb +2 -2
  68. data/lib/chef/knife/ionoscloud_pcc_delete.rb +1 -1
  69. data/lib/chef/knife/ionoscloud_pcc_list.rb +1 -1
  70. data/lib/chef/knife/ionoscloud_request_list.rb +1 -1
  71. data/lib/chef/knife/ionoscloud_request_status.rb +1 -1
  72. data/lib/chef/knife/ionoscloud_s3key_create.rb +2 -2
  73. data/lib/chef/knife/ionoscloud_s3key_delete.rb +3 -3
  74. data/lib/chef/knife/ionoscloud_s3key_list.rb +2 -2
  75. data/lib/chef/knife/ionoscloud_server_console.rb +42 -0
  76. data/lib/chef/knife/ionoscloud_server_create.rb +8 -8
  77. data/lib/chef/knife/ionoscloud_server_delete.rb +1 -1
  78. data/lib/chef/knife/ionoscloud_server_list.rb +16 -5
  79. data/lib/chef/knife/ionoscloud_server_reboot.rb +1 -1
  80. data/lib/chef/knife/ionoscloud_server_resume.rb +43 -0
  81. data/lib/chef/knife/ionoscloud_server_start.rb +1 -1
  82. data/lib/chef/knife/ionoscloud_server_stop.rb +1 -1
  83. data/lib/chef/knife/ionoscloud_server_suspend.rb +44 -0
  84. data/lib/chef/knife/ionoscloud_server_token.rb +42 -0
  85. data/lib/chef/knife/ionoscloud_server_upgrade.rb +44 -0
  86. data/lib/chef/knife/ionoscloud_snapshot_create.rb +2 -2
  87. data/lib/chef/knife/ionoscloud_snapshot_delete.rb +1 -1
  88. data/lib/chef/knife/ionoscloud_snapshot_list.rb +1 -1
  89. data/lib/chef/knife/ionoscloud_snapshot_restore.rb +2 -2
  90. data/lib/chef/knife/ionoscloud_template_list.rb +46 -0
  91. data/lib/chef/knife/ionoscloud_user_ssourl.rb +1 -1
  92. data/lib/chef/knife/ionoscloud_volume_attach.rb +1 -1
  93. data/lib/chef/knife/ionoscloud_volume_create.rb +33 -35
  94. data/lib/chef/knife/ionoscloud_volume_delete.rb +1 -1
  95. data/lib/chef/knife/ionoscloud_volume_detach.rb +1 -1
  96. data/lib/chef/knife/ionoscloud_volume_list.rb +2 -2
  97. data/lib/knife-ionoscloud/version.rb +1 -1
  98. data/spec/chef/knife/ionoscloud_backupunit_create_spec.rb +2 -2
  99. data/spec/chef/knife/ionoscloud_backupunit_delete_spec.rb +5 -5
  100. data/spec/chef/knife/ionoscloud_backupunit_list_spec.rb +1 -1
  101. data/spec/chef/knife/ionoscloud_backupunit_ssourl_spec.rb +3 -3
  102. data/spec/chef/knife/ionoscloud_base_spec.rb +4 -4
  103. data/spec/chef/knife/ionoscloud_composite_server_create_spec.rb +11 -8
  104. data/spec/chef/knife/ionoscloud_contract_list_spec.rb +32 -27
  105. data/spec/chef/knife/ionoscloud_cube_server_create_spec.rb +249 -0
  106. data/spec/chef/knife/ionoscloud_datacenter_create_spec.rb +3 -2
  107. data/spec/chef/knife/ionoscloud_datacenter_delete_spec.rb +5 -5
  108. data/spec/chef/knife/ionoscloud_datacenter_list_spec.rb +5 -3
  109. data/spec/chef/knife/ionoscloud_firewall_create_spec.rb +5 -3
  110. data/spec/chef/knife/ionoscloud_firewall_delete_spec.rb +6 -5
  111. data/spec/chef/knife/ionoscloud_firewall_list_spec.rb +5 -3
  112. data/spec/chef/knife/ionoscloud_flowlog_create_spec.rb +254 -0
  113. data/spec/chef/knife/ionoscloud_flowlog_delete_spec.rb +360 -0
  114. data/spec/chef/knife/ionoscloud_flowlog_list_spec.rb +264 -0
  115. data/spec/chef/knife/ionoscloud_group_create_spec.rb +6 -0
  116. data/spec/chef/knife/ionoscloud_group_delete_spec.rb +6 -0
  117. data/spec/chef/knife/ionoscloud_group_get_spec.rb +6 -0
  118. data/spec/chef/knife/ionoscloud_group_list_spec.rb +26 -8
  119. data/spec/chef/knife/ionoscloud_image_list_spec.rb +2 -2
  120. data/spec/chef/knife/ionoscloud_ipfailover_add_spec.rb +3 -3
  121. data/spec/chef/knife/ionoscloud_ipfailover_remove_spec.rb +4 -4
  122. data/spec/chef/knife/ionoscloud_k8s_delete_spec.rb +5 -2
  123. data/spec/chef/knife/ionoscloud_kubeconfig_get_spec.rb +2 -2
  124. data/spec/chef/knife/ionoscloud_label_add_spec.rb +10 -10
  125. data/spec/chef/knife/ionoscloud_label_list_spec.rb +14 -14
  126. data/spec/chef/knife/ionoscloud_label_remove_spec.rb +20 -20
  127. data/spec/chef/knife/ionoscloud_lan_create_spec.rb +3 -3
  128. data/spec/chef/knife/ionoscloud_lan_delete_spec.rb +5 -5
  129. data/spec/chef/knife/ionoscloud_lan_list_spec.rb +2 -2
  130. data/spec/chef/knife/ionoscloud_loadbalancer_create_spec.rb +3 -3
  131. data/spec/chef/knife/ionoscloud_loadbalancer_delete_spec.rb +5 -5
  132. data/spec/chef/knife/ionoscloud_loadbalancer_get_spec.rb +2 -2
  133. data/spec/chef/knife/ionoscloud_loadbalancer_list_spec.rb +2 -2
  134. data/spec/chef/knife/ionoscloud_loadbalancer_nic_add_spec.rb +6 -6
  135. data/spec/chef/knife/ionoscloud_loadbalancer_nic_remove_spec.rb +6 -6
  136. data/spec/chef/knife/ionoscloud_location_list_spec.rb +5 -3
  137. data/spec/chef/knife/ionoscloud_natgateway_create_spec.rb +77 -0
  138. data/spec/chef/knife/ionoscloud_natgateway_delete_spec.rb +118 -0
  139. data/spec/chef/knife/ionoscloud_natgateway_lan_add_spec.rb +143 -0
  140. data/spec/chef/knife/ionoscloud_natgateway_lan_remove_spec.rb +194 -0
  141. data/spec/chef/knife/ionoscloud_natgateway_list_spec.rb +79 -0
  142. data/spec/chef/knife/ionoscloud_natgateway_rule_add_spec.rb +98 -0
  143. data/spec/chef/knife/ionoscloud_natgateway_rule_list_spec.rb +92 -0
  144. data/spec/chef/knife/ionoscloud_natgateway_rule_remove_spec.rb +77 -0
  145. data/spec/chef/knife/ionoscloud_networkloadbalancer_create_spec.rb +80 -0
  146. data/spec/chef/knife/ionoscloud_networkloadbalancer_delete_spec.rb +119 -0
  147. data/spec/chef/knife/ionoscloud_networkloadbalancer_list_spec.rb +88 -0
  148. data/spec/chef/knife/ionoscloud_networkloadbalancer_rule_add_spec.rb +104 -0
  149. data/spec/chef/knife/ionoscloud_networkloadbalancer_rule_list_spec.rb +89 -0
  150. data/spec/chef/knife/ionoscloud_networkloadbalancer_rule_remove_spec.rb +124 -0
  151. data/spec/chef/knife/ionoscloud_networkloadbalancer_rule_target_add_spec.rb +109 -0
  152. data/spec/chef/knife/ionoscloud_networkloadbalancer_rule_target_list_spec.rb +85 -0
  153. data/spec/chef/knife/ionoscloud_networkloadbalancer_rule_target_remove_spec.rb +263 -0
  154. data/spec/chef/knife/ionoscloud_nic_create_spec.rb +9 -5
  155. data/spec/chef/knife/ionoscloud_nic_delete_spec.rb +8 -6
  156. data/spec/chef/knife/ionoscloud_nic_list_spec.rb +12 -6
  157. data/spec/chef/knife/ionoscloud_nodepool_create_spec.rb +15 -1
  158. data/spec/chef/knife/ionoscloud_nodepool_lan_add_spec.rb +226 -0
  159. data/spec/chef/knife/ionoscloud_nodepool_lan_remove.rb +199 -0
  160. data/spec/chef/knife/ionoscloud_nodepool_list_spec.rb +3 -1
  161. data/spec/chef/knife/ionoscloud_pcc_create_spec.rb +6 -6
  162. data/spec/chef/knife/ionoscloud_pcc_delete_spec.rb +5 -5
  163. data/spec/chef/knife/ionoscloud_pcc_list_spec.rb +2 -2
  164. data/spec/chef/knife/ionoscloud_request_list_spec.rb +16 -16
  165. data/spec/chef/knife/ionoscloud_request_status_spec.rb +3 -3
  166. data/spec/chef/knife/ionoscloud_s3key_create_spec.rb +2 -2
  167. data/spec/chef/knife/ionoscloud_s3key_delete_spec.rb +5 -5
  168. data/spec/chef/knife/ionoscloud_s3key_list_spec.rb +2 -2
  169. data/spec/chef/knife/ionoscloud_server_console_spec.rb +97 -0
  170. data/spec/chef/knife/ionoscloud_server_create_spec.rb +3 -3
  171. data/spec/chef/knife/ionoscloud_server_delete_spec.rb +5 -5
  172. data/spec/chef/knife/ionoscloud_server_list_spec.rb +63 -5
  173. data/spec/chef/knife/ionoscloud_server_reboot_spec.rb +3 -5
  174. data/spec/chef/knife/ionoscloud_server_resume_spec.rb +93 -0
  175. data/spec/chef/knife/ionoscloud_server_start_spec.rb +3 -5
  176. data/spec/chef/knife/ionoscloud_server_stop_spec.rb +3 -5
  177. data/spec/chef/knife/ionoscloud_server_suspend_spec.rb +93 -0
  178. data/spec/chef/knife/ionoscloud_server_token_spec.rb +97 -0
  179. data/spec/chef/knife/ionoscloud_server_upgrade_spec.rb +96 -0
  180. data/spec/chef/knife/ionoscloud_snapshot_create_spec.rb +3 -3
  181. data/spec/chef/knife/ionoscloud_snapshot_delete_spec.rb +5 -5
  182. data/spec/chef/knife/ionoscloud_snapshot_list_spec.rb +2 -2
  183. data/spec/chef/knife/ionoscloud_snapshot_restore_spec.rb +3 -3
  184. data/spec/chef/knife/ionoscloud_template_list_spec.rb +78 -0
  185. data/spec/chef/knife/ionoscloud_user_ssourl_spec.rb +3 -3
  186. data/spec/chef/knife/ionoscloud_volume_attach_spec.rb +4 -4
  187. data/spec/chef/knife/ionoscloud_volume_create_spec.rb +6 -58
  188. data/spec/chef/knife/ionoscloud_volume_delete_spec.rb +5 -5
  189. data/spec/chef/knife/ionoscloud_volume_detach_spec.rb +5 -5
  190. data/spec/chef/knife/ionoscloud_volume_list_spec.rb +4 -4
  191. data/spec/spec_helper.rb +223 -29
  192. 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