knife-ionoscloud 5.0.0.beta.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 (272) hide show
  1. checksums.yaml +7 -0
  2. data/.gitbook.yaml +4 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +54 -0
  4. data/.github/ISSUE_TEMPLATE/config.yml +5 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +51 -0
  6. data/.github/workflows/ci.yml +38 -0
  7. data/.github/workflows/publish.yml +58 -0
  8. data/.gitignore +26 -0
  9. data/.rubocop.yml +148 -0
  10. data/Gemfile +4 -0
  11. data/LICENSE.txt +201 -0
  12. data/Rakefile +7 -0
  13. data/docs/README.md +67 -0
  14. data/docs/changelog.md +1 -0
  15. data/docs/docs_generator.rb +107 -0
  16. data/docs/subcommands/backupunit_create.md +38 -0
  17. data/docs/subcommands/backupunit_delete.md +26 -0
  18. data/docs/subcommands/backupunit_list.md +26 -0
  19. data/docs/subcommands/backupunit_ssourl.md +30 -0
  20. data/docs/subcommands/composite_server_create.md +97 -0
  21. data/docs/subcommands/contract_list.md +26 -0
  22. data/docs/subcommands/datacenter_create.md +41 -0
  23. data/docs/subcommands/datacenter_delete.md +26 -0
  24. data/docs/subcommands/datacenter_list.md +26 -0
  25. data/docs/subcommands/firewall_create.md +65 -0
  26. data/docs/subcommands/firewall_delete.md +38 -0
  27. data/docs/subcommands/firewall_list.md +38 -0
  28. data/docs/subcommands/group_create.md +48 -0
  29. data/docs/subcommands/group_delete.md +26 -0
  30. data/docs/subcommands/group_get.md +30 -0
  31. data/docs/subcommands/group_list.md +29 -0
  32. data/docs/subcommands/group_user_add.md +30 -0
  33. data/docs/subcommands/group_user_remove.md +30 -0
  34. data/docs/subcommands/image_list.md +26 -0
  35. data/docs/subcommands/ipblock_create.md +37 -0
  36. data/docs/subcommands/ipblock_delete.md +26 -0
  37. data/docs/subcommands/ipblock_list.md +26 -0
  38. data/docs/subcommands/ipfailover_add.md +46 -0
  39. data/docs/subcommands/ipfailover_remove.md +42 -0
  40. data/docs/subcommands/k8s_create.md +39 -0
  41. data/docs/subcommands/k8s_delete.md +26 -0
  42. data/docs/subcommands/k8s_list.md +26 -0
  43. data/docs/subcommands/kubeconfig_get.md +30 -0
  44. data/docs/subcommands/label_add.md +45 -0
  45. data/docs/subcommands/label_list.md +35 -0
  46. data/docs/subcommands/label_remove.md +37 -0
  47. data/docs/subcommands/lan_create.md +36 -0
  48. data/docs/subcommands/lan_delete.md +30 -0
  49. data/docs/subcommands/lan_list.md +30 -0
  50. data/docs/subcommands/loadbalancer_create.md +43 -0
  51. data/docs/subcommands/loadbalancer_delete.md +30 -0
  52. data/docs/subcommands/loadbalancer_get.md +34 -0
  53. data/docs/subcommands/loadbalancer_list.md +30 -0
  54. data/docs/subcommands/loadbalancer_nic_add.md +34 -0
  55. data/docs/subcommands/loadbalancer_nic_remove.md +34 -0
  56. data/docs/subcommands/location_list.md +26 -0
  57. data/docs/subcommands/nic_create.md +51 -0
  58. data/docs/subcommands/nic_delete.md +34 -0
  59. data/docs/subcommands/nic_list.md +34 -0
  60. data/docs/subcommands/node_delete.md +34 -0
  61. data/docs/subcommands/node_list.md +34 -0
  62. data/docs/subcommands/node_replace.md +36 -0
  63. data/docs/subcommands/nodepool_create.md +87 -0
  64. data/docs/subcommands/nodepool_delete.md +30 -0
  65. data/docs/subcommands/nodepool_list.md +30 -0
  66. data/docs/subcommands/pcc_create.md +38 -0
  67. data/docs/subcommands/pcc_delete.md +26 -0
  68. data/docs/subcommands/pcc_list.md +26 -0
  69. data/docs/subcommands/request_list.md +32 -0
  70. data/docs/subcommands/request_status.md +30 -0
  71. data/docs/subcommands/request_wait.md +30 -0
  72. data/docs/subcommands/resource_list.md +34 -0
  73. data/docs/subcommands/s3key_create.md +30 -0
  74. data/docs/subcommands/s3key_delete.md +30 -0
  75. data/docs/subcommands/s3key_list.md +30 -0
  76. data/docs/subcommands/server_create.md +55 -0
  77. data/docs/subcommands/server_delete.md +32 -0
  78. data/docs/subcommands/server_list.md +30 -0
  79. data/docs/subcommands/server_reboot.md +30 -0
  80. data/docs/subcommands/server_start.md +30 -0
  81. data/docs/subcommands/server_stop.md +30 -0
  82. data/docs/subcommands/share_create.md +40 -0
  83. data/docs/subcommands/share_delete.md +30 -0
  84. data/docs/subcommands/share_list.md +30 -0
  85. data/docs/subcommands/snapshot_create.md +34 -0
  86. data/docs/subcommands/snapshot_delete.md +26 -0
  87. data/docs/subcommands/snapshot_list.md +26 -0
  88. data/docs/subcommands/snapshot_restore.md +38 -0
  89. data/docs/subcommands/user_create.md +49 -0
  90. data/docs/subcommands/user_delete.md +26 -0
  91. data/docs/subcommands/user_list.md +29 -0
  92. data/docs/subcommands/user_ssourl.md +30 -0
  93. data/docs/subcommands/volume_attach.md +34 -0
  94. data/docs/subcommands/volume_create.md +63 -0
  95. data/docs/subcommands/volume_delete.md +30 -0
  96. data/docs/subcommands/volume_detach.md +36 -0
  97. data/docs/subcommands/volume_list.md +33 -0
  98. data/docs/summary.md +89 -0
  99. data/docs/templates/subcommand_doc.mustache +26 -0
  100. data/docs/templates/summary.mustache +10 -0
  101. data/knife-ionoscloud.gemspec +27 -0
  102. data/lib/chef/knife/ionoscloud_backupunit_create.rb +63 -0
  103. data/lib/chef/knife/ionoscloud_backupunit_delete.rb +55 -0
  104. data/lib/chef/knife/ionoscloud_backupunit_list.rb +41 -0
  105. data/lib/chef/knife/ionoscloud_backupunit_ssourl.rb +39 -0
  106. data/lib/chef/knife/ionoscloud_base.rb +76 -0
  107. data/lib/chef/knife/ionoscloud_composite_server_create.rb +217 -0
  108. data/lib/chef/knife/ionoscloud_contract_list.rb +50 -0
  109. data/lib/chef/knife/ionoscloud_datacenter_create.rb +66 -0
  110. data/lib/chef/knife/ionoscloud_datacenter_delete.rb +56 -0
  111. data/lib/chef/knife/ionoscloud_datacenter_list.rb +50 -0
  112. data/lib/chef/knife/ionoscloud_firewall_create.rb +135 -0
  113. data/lib/chef/knife/ionoscloud_firewall_delete.rb +76 -0
  114. data/lib/chef/knife/ionoscloud_firewall_list.rb +72 -0
  115. data/lib/chef/knife/ionoscloud_group_create.rb +89 -0
  116. data/lib/chef/knife/ionoscloud_group_delete.rb +61 -0
  117. data/lib/chef/knife/ionoscloud_group_get.rb +46 -0
  118. data/lib/chef/knife/ionoscloud_group_list.rb +62 -0
  119. data/lib/chef/knife/ionoscloud_group_user_add.rb +72 -0
  120. data/lib/chef/knife/ionoscloud_group_user_remove.rb +72 -0
  121. data/lib/chef/knife/ionoscloud_image_list.rb +47 -0
  122. data/lib/chef/knife/ionoscloud_ipblock_create.rb +63 -0
  123. data/lib/chef/knife/ionoscloud_ipblock_delete.rb +50 -0
  124. data/lib/chef/knife/ionoscloud_ipblock_list.rb +42 -0
  125. data/lib/chef/knife/ionoscloud_ipfailover_add.rb +76 -0
  126. data/lib/chef/knife/ionoscloud_ipfailover_remove.rb +76 -0
  127. data/lib/chef/knife/ionoscloud_k8s_create.rb +79 -0
  128. data/lib/chef/knife/ionoscloud_k8s_delete.rb +67 -0
  129. data/lib/chef/knife/ionoscloud_k8s_list.rb +45 -0
  130. data/lib/chef/knife/ionoscloud_kubeconfig_get.rb +37 -0
  131. data/lib/chef/knife/ionoscloud_label_add.rb +84 -0
  132. data/lib/chef/knife/ionoscloud_label_list.rb +83 -0
  133. data/lib/chef/knife/ionoscloud_label_remove.rb +77 -0
  134. data/lib/chef/knife/ionoscloud_lan_create.rb +69 -0
  135. data/lib/chef/knife/ionoscloud_lan_delete.rb +54 -0
  136. data/lib/chef/knife/ionoscloud_lan_list.rb +46 -0
  137. data/lib/chef/knife/ionoscloud_loadbalancer_create.rb +87 -0
  138. data/lib/chef/knife/ionoscloud_loadbalancer_delete.rb +68 -0
  139. data/lib/chef/knife/ionoscloud_loadbalancer_get.rb +51 -0
  140. data/lib/chef/knife/ionoscloud_loadbalancer_list.rb +50 -0
  141. data/lib/chef/knife/ionoscloud_loadbalancer_nic_add.rb +75 -0
  142. data/lib/chef/knife/ionoscloud_loadbalancer_nic_remove.rb +76 -0
  143. data/lib/chef/knife/ionoscloud_location_list.rb +38 -0
  144. data/lib/chef/knife/ionoscloud_nic_create.rb +104 -0
  145. data/lib/chef/knife/ionoscloud_nic_delete.rb +62 -0
  146. data/lib/chef/knife/ionoscloud_nic_list.rb +57 -0
  147. data/lib/chef/knife/ionoscloud_node_delete.rb +65 -0
  148. data/lib/chef/knife/ionoscloud_node_list.rb +55 -0
  149. data/lib/chef/knife/ionoscloud_node_replace.rb +54 -0
  150. data/lib/chef/knife/ionoscloud_nodepool_create.rb +163 -0
  151. data/lib/chef/knife/ionoscloud_nodepool_delete.rb +60 -0
  152. data/lib/chef/knife/ionoscloud_nodepool_list.rb +51 -0
  153. data/lib/chef/knife/ionoscloud_pcc_create.rb +68 -0
  154. data/lib/chef/knife/ionoscloud_pcc_delete.rb +57 -0
  155. data/lib/chef/knife/ionoscloud_pcc_list.rb +41 -0
  156. data/lib/chef/knife/ionoscloud_request_list.rb +94 -0
  157. data/lib/chef/knife/ionoscloud_request_status.rb +37 -0
  158. data/lib/chef/knife/ionoscloud_request_wait.rb +41 -0
  159. data/lib/chef/knife/ionoscloud_resource_list.rb +81 -0
  160. data/lib/chef/knife/ionoscloud_s3key_create.rb +45 -0
  161. data/lib/chef/knife/ionoscloud_s3key_delete.rb +57 -0
  162. data/lib/chef/knife/ionoscloud_s3key_list.rb +46 -0
  163. data/lib/chef/knife/ionoscloud_server_create.rb +104 -0
  164. data/lib/chef/knife/ionoscloud_server_delete.rb +62 -0
  165. data/lib/chef/knife/ionoscloud_server_list.rb +58 -0
  166. data/lib/chef/knife/ionoscloud_server_reboot.rb +45 -0
  167. data/lib/chef/knife/ionoscloud_server_start.rb +43 -0
  168. data/lib/chef/knife/ionoscloud_server_stop.rb +44 -0
  169. data/lib/chef/knife/ionoscloud_share_create.rb +71 -0
  170. data/lib/chef/knife/ionoscloud_share_delete.rb +55 -0
  171. data/lib/chef/knife/ionoscloud_share_list.rb +47 -0
  172. data/lib/chef/knife/ionoscloud_snapshot_create.rb +58 -0
  173. data/lib/chef/knife/ionoscloud_snapshot_delete.rb +54 -0
  174. data/lib/chef/knife/ionoscloud_snapshot_list.rb +45 -0
  175. data/lib/chef/knife/ionoscloud_snapshot_restore.rb +69 -0
  176. data/lib/chef/knife/ionoscloud_user_create.rb +83 -0
  177. data/lib/chef/knife/ionoscloud_user_delete.rb +56 -0
  178. data/lib/chef/knife/ionoscloud_user_list.rb +60 -0
  179. data/lib/chef/knife/ionoscloud_user_ssourl.rb +37 -0
  180. data/lib/chef/knife/ionoscloud_volume_attach.rb +52 -0
  181. data/lib/chef/knife/ionoscloud_volume_create.rb +133 -0
  182. data/lib/chef/knife/ionoscloud_volume_delete.rb +67 -0
  183. data/lib/chef/knife/ionoscloud_volume_detach.rb +77 -0
  184. data/lib/chef/knife/ionoscloud_volume_list.rb +70 -0
  185. data/lib/knife-ionoscloud/version.rb +6 -0
  186. data/spec/chef/knife/ionoscloud_backupunit_create_spec.rb +65 -0
  187. data/spec/chef/knife/ionoscloud_backupunit_delete_spec.rb +101 -0
  188. data/spec/chef/knife/ionoscloud_backupunit_list_spec.rb +72 -0
  189. data/spec/chef/knife/ionoscloud_backupunit_ssourl_spec.rb +93 -0
  190. data/spec/chef/knife/ionoscloud_base_spec.rb +157 -0
  191. data/spec/chef/knife/ionoscloud_composite_server_create_spec.rb +111 -0
  192. data/spec/chef/knife/ionoscloud_contract_list_spec.rb +81 -0
  193. data/spec/chef/knife/ionoscloud_datacenter_create_spec.rb +72 -0
  194. data/spec/chef/knife/ionoscloud_datacenter_delete_spec.rb +102 -0
  195. data/spec/chef/knife/ionoscloud_datacenter_list_spec.rb +76 -0
  196. data/spec/chef/knife/ionoscloud_firewall_create_spec.rb +90 -0
  197. data/spec/chef/knife/ionoscloud_firewall_delete_spec.rb +117 -0
  198. data/spec/chef/knife/ionoscloud_firewall_list_spec.rb +90 -0
  199. data/spec/chef/knife/ionoscloud_group_create_spec.rb +76 -0
  200. data/spec/chef/knife/ionoscloud_group_delete_spec.rb +109 -0
  201. data/spec/chef/knife/ionoscloud_group_get_spec.rb +73 -0
  202. data/spec/chef/knife/ionoscloud_group_list_spec.rb +115 -0
  203. data/spec/chef/knife/ionoscloud_group_user_add_spec.rb +134 -0
  204. data/spec/chef/knife/ionoscloud_group_user_remove_spec.rb +130 -0
  205. data/spec/chef/knife/ionoscloud_image_list_spec.rb +75 -0
  206. data/spec/chef/knife/ionoscloud_ipblock_create_spec.rb +72 -0
  207. data/spec/chef/knife/ionoscloud_ipblock_delete_spec.rb +102 -0
  208. data/spec/chef/knife/ionoscloud_ipblock_list_spec.rb +74 -0
  209. data/spec/chef/knife/ionoscloud_ipfailover_add_spec.rb +83 -0
  210. data/spec/chef/knife/ionoscloud_ipfailover_remove_spec.rb +122 -0
  211. data/spec/chef/knife/ionoscloud_k8s_create_spec.rb +83 -0
  212. data/spec/chef/knife/ionoscloud_k8s_delete_spec.rb +172 -0
  213. data/spec/chef/knife/ionoscloud_k8s_list_spec.rb +73 -0
  214. data/spec/chef/knife/ionoscloud_kubeconfig_get_spec.rb +91 -0
  215. data/spec/chef/knife/ionoscloud_label_add_spec.rb +287 -0
  216. data/spec/chef/knife/ionoscloud_label_list_spec.rb +337 -0
  217. data/spec/chef/knife/ionoscloud_label_remove_spec.rb +391 -0
  218. data/spec/chef/knife/ionoscloud_lan_create_spec.rb +77 -0
  219. data/spec/chef/knife/ionoscloud_lan_delete_spec.rb +103 -0
  220. data/spec/chef/knife/ionoscloud_lan_list_spec.rb +73 -0
  221. data/spec/chef/knife/ionoscloud_loadbalancer_create_spec.rb +82 -0
  222. data/spec/chef/knife/ionoscloud_loadbalancer_delete_spec.rb +107 -0
  223. data/spec/chef/knife/ionoscloud_loadbalancer_get_spec.rb +68 -0
  224. data/spec/chef/knife/ionoscloud_loadbalancer_list_spec.rb +74 -0
  225. data/spec/chef/knife/ionoscloud_loadbalancer_nic_add_spec.rb +128 -0
  226. data/spec/chef/knife/ionoscloud_loadbalancer_nic_remove_spec.rb +124 -0
  227. data/spec/chef/knife/ionoscloud_location_list_spec.rb +67 -0
  228. data/spec/chef/knife/ionoscloud_nic_create_spec.rb +85 -0
  229. data/spec/chef/knife/ionoscloud_nic_delete_spec.rb +108 -0
  230. data/spec/chef/knife/ionoscloud_nic_list_spec.rb +83 -0
  231. data/spec/chef/knife/ionoscloud_node_delete_spec.rb +107 -0
  232. data/spec/chef/knife/ionoscloud_node_list_spec.rb +75 -0
  233. data/spec/chef/knife/ionoscloud_node_replace_spec.rb +94 -0
  234. data/spec/chef/knife/ionoscloud_nodepool_create_spec.rb +99 -0
  235. data/spec/chef/knife/ionoscloud_nodepool_delete_spec.rb +106 -0
  236. data/spec/chef/knife/ionoscloud_nodepool_list_spec.rb +76 -0
  237. data/spec/chef/knife/ionoscloud_pcc_create_spec.rb +70 -0
  238. data/spec/chef/knife/ionoscloud_pcc_delete_spec.rb +106 -0
  239. data/spec/chef/knife/ionoscloud_pcc_list_spec.rb +69 -0
  240. data/spec/chef/knife/ionoscloud_request_list_spec.rb +165 -0
  241. data/spec/chef/knife/ionoscloud_request_status_spec.rb +92 -0
  242. data/spec/chef/knife/ionoscloud_request_wait_spec.rb +74 -0
  243. data/spec/chef/knife/ionoscloud_resource_list_spec.rb +155 -0
  244. data/spec/chef/knife/ionoscloud_s3key_create_spec.rb +64 -0
  245. data/spec/chef/knife/ionoscloud_s3key_delete_spec.rb +103 -0
  246. data/spec/chef/knife/ionoscloud_s3key_list_spec.rb +70 -0
  247. data/spec/chef/knife/ionoscloud_server_create_spec.rb +84 -0
  248. data/spec/chef/knife/ionoscloud_server_delete_spec.rb +108 -0
  249. data/spec/chef/knife/ionoscloud_server_list_spec.rb +85 -0
  250. data/spec/chef/knife/ionoscloud_server_reboot_spec.rb +95 -0
  251. data/spec/chef/knife/ionoscloud_server_start_spec.rb +95 -0
  252. data/spec/chef/knife/ionoscloud_server_stop_spec.rb +95 -0
  253. data/spec/chef/knife/ionoscloud_share_create_spec.rb +68 -0
  254. data/spec/chef/knife/ionoscloud_share_delete_spec.rb +103 -0
  255. data/spec/chef/knife/ionoscloud_share_list_spec.rb +70 -0
  256. data/spec/chef/knife/ionoscloud_snapshot_create_spec.rb +74 -0
  257. data/spec/chef/knife/ionoscloud_snapshot_delete_spec.rb +103 -0
  258. data/spec/chef/knife/ionoscloud_snapshot_list_spec.rb +73 -0
  259. data/spec/chef/knife/ionoscloud_snapshot_restore_spec.rb +78 -0
  260. data/spec/chef/knife/ionoscloud_user_create_spec.rb +73 -0
  261. data/spec/chef/knife/ionoscloud_user_delete_spec.rb +104 -0
  262. data/spec/chef/knife/ionoscloud_user_list_spec.rb +103 -0
  263. data/spec/chef/knife/ionoscloud_user_ssourl_spec.rb +93 -0
  264. data/spec/chef/knife/ionoscloud_volume_attach_spec.rb +99 -0
  265. data/spec/chef/knife/ionoscloud_volume_create_spec.rb +143 -0
  266. data/spec/chef/knife/ionoscloud_volume_delete_spec.rb +108 -0
  267. data/spec/chef/knife/ionoscloud_volume_detach_spec.rb +110 -0
  268. data/spec/chef/knife/ionoscloud_volume_list_spec.rb +118 -0
  269. data/spec/spec_helper.rb +702 -0
  270. data/spec/test.sh +3 -0
  271. data/summary.md +0 -0
  272. metadata +460 -0
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+ require 'ionoscloud_volume_delete'
3
+
4
+ Chef::Knife::IonoscloudVolumeDelete.load_deps
5
+
6
+ describe Chef::Knife::IonoscloudVolumeDelete do
7
+ before :each do
8
+ subject { Chef::Knife::IonoscloudVolumeDelete.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 VolumeApi.datacenters_volumes_delete when the ID is valid' do
16
+ volume = volume_mock
17
+ subject_config = {
18
+ ionoscloud_username: 'email',
19
+ ionoscloud_password: 'password',
20
+ datacenter_id: 'datacenter_id',
21
+ yes: true,
22
+ }
23
+
24
+ subject_config.each { |key, value| subject.config[key] = value }
25
+ subject.name_args = [volume.id]
26
+
27
+ expect(subject).to receive(:puts).with("ID: #{volume.id}")
28
+ expect(subject).to receive(:puts).with("Name: #{volume.properties.name}")
29
+ expect(subject).to receive(:puts).with("Size: #{volume.properties.size}")
30
+ expect(subject).to receive(:puts).with("Bus: #{volume.properties.bus}")
31
+ expect(subject).to receive(:puts).with("Image: #{volume.properties.image}")
32
+ expect(subject).to receive(:puts).with("Type: #{volume.properties.type}")
33
+ expect(subject).to receive(:puts).with("Licence Type: #{volume.properties.licence_type}")
34
+ expect(subject).to receive(:puts).with("Zone: #{volume.properties.availability_zone}")
35
+ expect(subject.ui).to receive(:warn).with("Deleted Volume #{volume.id}. Request ID: ")
36
+
37
+ expect(subject).not_to receive(:wait_for)
38
+ expect(subject).to receive(:get_request_id).once
39
+ mock_call_api(
40
+ subject,
41
+ [
42
+ {
43
+ method: 'GET',
44
+ path: "/datacenters/#{subject_config[:datacenter_id]}/volumes/#{volume.id}",
45
+ operation: :'VolumeApi.datacenters_volumes_find_by_id',
46
+ return_type: 'Volume',
47
+ result: volume,
48
+ },
49
+ {
50
+ method: 'DELETE',
51
+ path: "/datacenters/#{subject_config[:datacenter_id]}/volumes/#{volume.id}",
52
+ operation: :'VolumeApi.datacenters_volumes_delete',
53
+ },
54
+ ],
55
+ )
56
+
57
+ expect { subject.run }.not_to raise_error(Exception)
58
+ end
59
+
60
+ it 'should not call VolumeApi.datacenters_volumes_delete when the ID is not valid' do
61
+ volume_id = 'invalid_id'
62
+ subject_config = {
63
+ ionoscloud_username: 'email',
64
+ ionoscloud_password: 'password',
65
+ datacenter_id: 'datacenter_id',
66
+ }
67
+
68
+ subject_config.each { |key, value| subject.config[key] = value }
69
+ subject.name_args = [volume_id]
70
+
71
+ expect(subject.ui).to receive(:error).with("Volume ID #{volume_id} not found. Skipping.")
72
+
73
+ expect(subject.api_client).not_to receive(:wait_for)
74
+ mock_call_api(
75
+ subject,
76
+ [
77
+ {
78
+ method: 'GET',
79
+ path: "/datacenters/#{subject_config[:datacenter_id]}/volumes/#{volume_id}",
80
+ operation: :'VolumeApi.datacenters_volumes_find_by_id',
81
+ return_type: 'Volume',
82
+ exception: Ionoscloud::ApiError.new(code: 404),
83
+ },
84
+ ],
85
+ )
86
+
87
+ expect { subject.run }.not_to raise_error(Exception)
88
+ end
89
+
90
+ it 'should not make any call if any required option is missing' do
91
+ required_options = subject.instance_variable_get(:@required_options)
92
+
93
+ arrays_without_one_element(required_options).each do |test_case|
94
+
95
+ test_case[:array].each { |value| subject.config[value] = 'test' }
96
+
97
+ expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
98
+ expect(subject.api_client).not_to receive(:call_api)
99
+
100
+ expect { subject.run }.to raise_error(SystemExit) do |error|
101
+ expect(error.status).to eq(1)
102
+ end
103
+
104
+ required_options.each { |value| subject.config[value] = nil }
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+ require 'ionoscloud_volume_detach'
3
+
4
+ Chef::Knife::IonoscloudVolumeDetach.load_deps
5
+
6
+ describe Chef::Knife::IonoscloudVolumeDetach do
7
+ before :each do
8
+ subject { Chef::Knife::IonoscloudVolumeDetach.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 ServerApi.datacenters_servers_volumes_delete when the ID is valid' do
16
+ volume = volume_mock
17
+ subject_config = {
18
+ ionoscloud_username: 'email',
19
+ ionoscloud_password: 'password',
20
+ datacenter_id: 'datacenter_id',
21
+ server_id: 'server_id',
22
+ yes: true,
23
+ }
24
+
25
+ subject_config.each { |key, value| subject.config[key] = value }
26
+ subject.name_args = [volume.id]
27
+
28
+ expect(subject).to receive(:puts).with("ID: #{volume.id}")
29
+ expect(subject).to receive(:puts).with("Name: #{volume.properties.name}")
30
+ expect(subject).to receive(:puts).with("Size: #{volume.properties.size}")
31
+ expect(subject).to receive(:puts).with("Bus: #{volume.properties.bus}")
32
+ expect(subject).to receive(:puts).with("Image: #{volume.properties.image}")
33
+ expect(subject).to receive(:puts).with("Type: #{volume.properties.type}")
34
+ expect(subject).to receive(:puts).with("Licence Type: #{volume.properties.licence_type}")
35
+ expect(subject).to receive(:puts).with("Zone: #{volume.properties.availability_zone}")
36
+ expect(subject.ui).to receive(:msg).with("Detaching Volume #{volume.id} from server. Request ID: ")
37
+
38
+ expect(subject).not_to receive(:wait_for)
39
+ expect(subject).to receive(:get_request_id).once
40
+ mock_call_api(
41
+ subject,
42
+ [
43
+ {
44
+ method: 'GET',
45
+ path: "/datacenters/#{subject_config[:datacenter_id]}/servers/#{subject_config[:server_id]}/volumes/#{volume.id}",
46
+ operation: :'ServerApi.datacenters_servers_volumes_find_by_id',
47
+ return_type: 'Volume',
48
+ result: volume,
49
+ },
50
+ {
51
+ method: 'DELETE',
52
+ path: "/datacenters/#{subject_config[:datacenter_id]}/servers/#{subject_config[:server_id]}/volumes/#{volume.id}",
53
+ operation: :'ServerApi.datacenters_servers_volumes_delete',
54
+ },
55
+ ],
56
+ )
57
+
58
+ expect { subject.run }.not_to raise_error(Exception)
59
+ end
60
+
61
+ it 'should not call ServerApi.datacenters_servers_volumes_delete when the ID is not valid' do
62
+ volume_id = 'invalid_id'
63
+ subject_config = {
64
+ ionoscloud_username: 'email',
65
+ ionoscloud_password: 'password',
66
+ datacenter_id: 'datacenter_id',
67
+ server_id: 'server_id',
68
+ }
69
+
70
+ subject_config.each { |key, value| subject.config[key] = value }
71
+ subject.name_args = [volume_id]
72
+
73
+ expect(subject.ui).to receive(:error).with("Volume ID #{volume_id} not found. Skipping.")
74
+
75
+ expect(subject.api_client).not_to receive(:wait_for)
76
+ mock_call_api(
77
+ subject,
78
+ [
79
+ {
80
+ method: 'GET',
81
+ path: "/datacenters/#{subject_config[:datacenter_id]}/servers/#{subject_config[:server_id]}/volumes/#{volume_id}",
82
+ operation: :'ServerApi.datacenters_servers_volumes_find_by_id',
83
+ return_type: 'Volume',
84
+ exception: Ionoscloud::ApiError.new(code: 404),
85
+ },
86
+ ],
87
+ )
88
+
89
+ expect { subject.run }.not_to raise_error(Exception)
90
+ end
91
+
92
+ it 'should not make any call if any required option is missing' do
93
+ required_options = subject.instance_variable_get(:@required_options)
94
+
95
+ arrays_without_one_element(required_options).each do |test_case|
96
+
97
+ test_case[:array].each { |value| subject.config[value] = 'test' }
98
+
99
+ expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
100
+ expect(subject.api_client).not_to receive(:call_api)
101
+
102
+ expect { subject.run }.to raise_error(SystemExit) do |error|
103
+ expect(error.status).to eq(1)
104
+ end
105
+
106
+ required_options.each { |value| subject.config[value] = nil }
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,118 @@
1
+ require 'spec_helper'
2
+ require 'ionoscloud_volume_list'
3
+
4
+ Chef::Knife::IonoscloudVolumeList.load_deps
5
+
6
+ describe Chef::Knife::IonoscloudVolumeList do
7
+ before :each do
8
+ subject { Chef::Knife::IonoscloudVolumeList.new }
9
+
10
+ @volumes = volumes_mock
11
+
12
+ @volume_list = volume_list = [
13
+ subject.ui.color('ID', :bold),
14
+ subject.ui.color('Name', :bold),
15
+ subject.ui.color('Size', :bold),
16
+ subject.ui.color('Bus', :bold),
17
+ subject.ui.color('Image', :bold),
18
+ subject.ui.color('Type', :bold),
19
+ subject.ui.color('Zone', :bold),
20
+ subject.ui.color('Device Number', :bold),
21
+ @volumes.items.first.id,
22
+ @volumes.items.first.properties.name,
23
+ @volumes.items.first.properties.size.to_s,
24
+ @volumes.items.first.properties.bus,
25
+ @volumes.items.first.properties.image,
26
+ @volumes.items.first.properties.type,
27
+ @volumes.items.first.properties.availability_zone,
28
+ @volumes.items.first.properties.device_number.to_s,
29
+ @volumes.items[1].id,
30
+ @volumes.items[1].properties.name,
31
+ @volumes.items[1].properties.size.to_s,
32
+ @volumes.items[1].properties.bus,
33
+ @volumes.items[1].properties.image,
34
+ @volumes.items[1].properties.type,
35
+ @volumes.items[1].properties.availability_zone,
36
+ @volumes.items[1].properties.device_number.to_s,
37
+ ]
38
+
39
+ allow(subject).to receive(:puts)
40
+ allow(subject).to receive(:print)
41
+ end
42
+
43
+ describe '#run' do
44
+ it 'should call VolumeApi.datacenters_volumes_get when no server_id is set' do
45
+ subject_config = {
46
+ ionoscloud_username: 'email',
47
+ ionoscloud_password: 'password',
48
+ datacenter_id: 'datacenter_id',
49
+ }
50
+
51
+ subject_config.each { |key, value| subject.config[key] = value }
52
+
53
+ expect(subject.ui).to receive(:list).with(@volume_list, :uneven_columns_across, 8)
54
+
55
+ mock_call_api(
56
+ subject,
57
+ [
58
+ {
59
+ method: 'GET',
60
+ path: "/datacenters/#{subject_config[:datacenter_id]}/volumes",
61
+ operation: :'VolumeApi.datacenters_volumes_get',
62
+ return_type: 'Volumes',
63
+ result: @volumes,
64
+ },
65
+ ],
66
+ )
67
+
68
+ expect { subject.run }.not_to raise_error(Exception)
69
+ end
70
+
71
+ it 'should call ServerApi.datacenters_servers_volumes_get when server_id is set' do
72
+ subject_config = {
73
+ ionoscloud_username: 'email',
74
+ ionoscloud_password: 'password',
75
+ datacenter_id: 'datacenter_id',
76
+ server_id: 'server_id'
77
+ }
78
+
79
+ subject_config.each { |key, value| subject.config[key] = value }
80
+
81
+ expect(subject.ui).to receive(:list).with(@volume_list, :uneven_columns_across, 8)
82
+
83
+ expect(subject.api_client).not_to receive(:wait_for)
84
+ mock_call_api(
85
+ subject,
86
+ [
87
+ {
88
+ method: 'GET',
89
+ path: "/datacenters/#{subject_config[:datacenter_id]}/servers/#{subject_config[:server_id]}/volumes",
90
+ operation: :'ServerApi.datacenters_servers_volumes_get',
91
+ return_type: 'AttachedVolumes',
92
+ result: @volumes,
93
+ },
94
+ ],
95
+ )
96
+
97
+ expect { subject.run }.not_to raise_error(Exception)
98
+ end
99
+
100
+ it 'should not make any call if any required option is missing' do
101
+ required_options = subject.instance_variable_get(:@required_options)
102
+
103
+ arrays_without_one_element(required_options).each do |test_case|
104
+
105
+ test_case[:array].each { |value| subject.config[value] = 'test' }
106
+
107
+ expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
108
+ expect(subject.api_client).not_to receive(:call_api)
109
+
110
+ expect { subject.run }.to raise_error(SystemExit) do |error|
111
+ expect(error.status).to eq(1)
112
+ end
113
+
114
+ required_options.each { |value| subject.config[value] = nil }
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,702 @@
1
+ $:.unshift File.expand_path('../../lib/chef/knife', __FILE__)
2
+ require 'rspec'
3
+ require 'chef'
4
+ require 'securerandom'
5
+ require 'simplecov'
6
+
7
+ RSpec.configure do |config|
8
+ config.pattern = 'spec/chef/knife/*_spec.rb'
9
+ end
10
+
11
+ SimpleCov.start do
12
+ add_group 'Commands', 'lib/chef/knife/'
13
+ add_group 'Spec files', 'spec/chef/knife/'
14
+ end
15
+ SimpleCov.coverage_dir 'coverage'
16
+
17
+ def contract_mock(opts = {})
18
+ Ionoscloud::Contract.new(
19
+ type: opts[:type] || 'contract',
20
+ properties: Ionoscloud::ContractProperties.new(
21
+ contract_number: opts[:contract_number] || 31884391,
22
+ owner: opts[:owner] || 'user@domain.com',
23
+ reg_domain: opts[:reg_domain] || 'ionos.de',
24
+ status: opts[:status] || 'BILLABLE',
25
+ resource_limits: opts[:resource_limits] || Ionoscloud::ResourceLimits.new(
26
+ cores_per_contract: opts[:cores_per_contract] || 8,
27
+ cores_per_server: opts[:cores_per_server] || 4,
28
+ cores_provisioned: opts[:cores_provisioned] || 2,
29
+ hdd_limit_per_contract: opts[:hdd_limit_per_contract] || 600,
30
+ hdd_limit_per_volume: opts[:hdd_limit_per_volume] || 400,
31
+ hdd_volume_provisioned: opts[:hdd_volume_provisioned] || 100,
32
+ ram_per_contract: opts[:ram_per_contract] || 20480,
33
+ ram_per_server: opts[:ram_per_server] || 20480,
34
+ ram_provisioned: opts[:ram_provisioned] || 4096,
35
+ reservable_ips: opts[:reservable_ips] || 10,
36
+ reserved_ips_in_use: opts[:reserved_ips_in_use] || 12,
37
+ reserved_ips_on_contract: opts[:reserved_ips_on_contract] || 20,
38
+ ssd_limit_per_contract: opts[:ssd_limit_per_contract] || 600,
39
+ ssd_limit_per_volume: opts[:ssd_limit_per_volume] || 300,
40
+ ssd_volume_provisioned: opts[:ssd_volume_provisioned] || 50,
41
+ k8s_cluster_limit_total: opts[:k8s_cluster_limit_total] || 12,
42
+ k8s_clusters_provisioned: opts[:k8s_clusters_provisioned] || 1,
43
+ ),
44
+ ),
45
+ )
46
+ end
47
+
48
+ def ipblock_mock(opts = {})
49
+ Ionoscloud::IpBlock.new(
50
+ id: opts[:id] || SecureRandom.uuid,
51
+ properties: Ionoscloud::IpBlockProperties.new(
52
+ name: opts[:name] || 'Test IpBlock',
53
+ size: opts[:size] || 4,
54
+ location: opts[:location] || 'de/fra',
55
+ ips: opts[:ips] || ['87.106.113.181', '87.106.113.176', '87.106.113.177', '87.106.113.178'],
56
+ ),
57
+ )
58
+ end
59
+
60
+ def ipblocks_mock(opts = {})
61
+ Ionoscloud::IpBlocks.new(
62
+ id: 'IpBlocks',
63
+ type: 'collection',
64
+ items: [ipblock_mock, ipblock_mock],
65
+ )
66
+ end
67
+
68
+ def datacenter_mock(opts = {})
69
+ Ionoscloud::Datacenter.new(
70
+ id: opts[:id] || SecureRandom.uuid,
71
+ properties: Ionoscloud::DatacenterProperties.new(
72
+ name: opts[:name] || 'Test Datacenter',
73
+ description: opts[:description] || 'Test description',
74
+ location: opts[:location] || 'de/fra',
75
+ version: opts[:version] || 12,
76
+ ),
77
+ )
78
+ end
79
+
80
+ def datacenters_mock(opts = {})
81
+ Ionoscloud::Datacenters.new(
82
+ id: 'Datacenters',
83
+ type: 'collection',
84
+ items: [datacenter_mock, datacenter_mock],
85
+ )
86
+ end
87
+
88
+ def server_mock(opts = {})
89
+ Ionoscloud::Server.new(
90
+ id: opts[:id] || SecureRandom.uuid,
91
+ properties: Ionoscloud::ServerProperties.new(
92
+ name: opts[:name] || 'Test Server',
93
+ ram: opts[:ram] || 1024,
94
+ cores: opts[:cores] || 1,
95
+ availability_zone: opts[:availability_zone] || 'ZONE_1',
96
+ cpu_family: opts[:cpu_family] || 'INTEL_SKYLAKE',
97
+ boot_cdrom: opts[:boot_cdrom] || Ionoscloud::ResourceReference.new({ id: SecureRandom.uuid }),
98
+ boot_volume: opts[:boot_volume] || Ionoscloud::ResourceReference.new({ id: SecureRandom.uuid }),
99
+ ),
100
+ entities: Ionoscloud::ServerEntities.new(
101
+ volumes: opts[:volumes] || [],
102
+ nics: opts[:nics] || [],
103
+ )
104
+ )
105
+ end
106
+
107
+ def servers_mock(opts = {})
108
+ Ionoscloud::Servers.new(
109
+ id: 'servers',
110
+ type: 'collection',
111
+ items: [server_mock, server_mock],
112
+ )
113
+ end
114
+
115
+ def volume_mock(opts = {})
116
+ Ionoscloud::Volume.new(
117
+ id: opts[:id] || SecureRandom.uuid,
118
+ properties: Ionoscloud::VolumeProperties.new(
119
+ name: opts[:name] || 'Test Volume',
120
+ size: opts[:size] || 2,
121
+ type: opts[:type] || 'HDD',
122
+ bus: opts[:bus] || 'VIRTIO',
123
+ availability_zone: opts[:availability_zone] || 'AUTO',
124
+ licence_type: opts[:licence_type] || 'LINUX',
125
+ image: opts[:image] || SecureRandom.uuid,
126
+ ),
127
+ )
128
+ end
129
+
130
+ def volumes_mock(opts = {})
131
+ Ionoscloud::Volumes.new(
132
+ id: 'volumes',
133
+ type: 'collection',
134
+ items: [volume_mock, volume_mock],
135
+ )
136
+ end
137
+
138
+ def label_resource_mock(opts = {})
139
+ Ionoscloud::LabelResource.new(
140
+ id: opts[:id] || SecureRandom.uuid,
141
+ properties: Ionoscloud::LabelResourceProperties.new(
142
+ key: opts[:key] || 'key',
143
+ value: opts[:value] || 'value',
144
+ ),
145
+ )
146
+ end
147
+
148
+ def label_resources_mock(opts = {})
149
+ Ionoscloud::LabelResources.new(
150
+ id: 'labelresources',
151
+ type: 'collection',
152
+ items: [label_resource_mock, label_resource_mock],
153
+ )
154
+ end
155
+
156
+ def label_mock(opts = {})
157
+ Ionoscloud::Label.new(
158
+ id: opts[:id] || SecureRandom.uuid,
159
+ properties: Ionoscloud::LabelProperties.new(
160
+ resource_id: opts[:resource_id] || 'resource_id',
161
+ resource_type: opts[:resource_type] || 'resource_type',
162
+ key: opts[:key] || 'key',
163
+ value: opts[:value] || 'value',
164
+ ),
165
+ )
166
+ end
167
+
168
+ def labels_mock(opts = {})
169
+ Ionoscloud::Labels.new(
170
+ id: 'labels',
171
+ type: 'collection',
172
+ items: [label_mock, label_mock],
173
+ )
174
+ end
175
+
176
+ def backupunit_mock(opts = {})
177
+ Ionoscloud::BackupUnit.new(
178
+ id: opts[:id] || SecureRandom.uuid,
179
+ properties: Ionoscloud::BackupUnitProperties.new(
180
+ name: opts[:name] || 'backupunit_name',
181
+ password: opts[:password] || 'password1234',
182
+ email: opts[:email] || 'test@test.com',
183
+ ),
184
+ )
185
+ end
186
+
187
+ def backupunits_mock(opts = {})
188
+ Ionoscloud::BackupUnits.new(
189
+ id: 'backupunits',
190
+ type: 'collection',
191
+ items: [backupunit_mock, backupunit_mock],
192
+ )
193
+ end
194
+
195
+ def lan_mock(opts = {})
196
+ Ionoscloud::Lan.new(
197
+ id: opts[:id] || '1',
198
+ properties: Ionoscloud::LanProperties.new(
199
+ name: opts[:name] || 'lan_name',
200
+ public: opts[:public] || true,
201
+ ip_failover: opts[:ip_failover] || [],
202
+ ),
203
+ )
204
+ end
205
+
206
+ def lans_mock(opts = {})
207
+ Ionoscloud::Lans.new(
208
+ id: 'lans',
209
+ type: 'collection',
210
+ items: [lan_mock],
211
+ )
212
+ end
213
+
214
+ def nic_mock(opts = {})
215
+ Ionoscloud::Nic.new(
216
+ id: opts[:id] || SecureRandom.uuid,
217
+ properties: Ionoscloud::NicProperties.new(
218
+ name: opts[:name] || 'nic_name',
219
+ ips: opts[:ips] || ['1.1.1.1', '1.1.1.2'],
220
+ nat: opts[:nat] || true,
221
+ dhcp: opts[:dhcp] || true,
222
+ firewall_active: opts[:firewall_active] || true,
223
+ mac: opts[:mac] || '00:0a:95:9d:68:16',
224
+ lan: opts[:lan] || 1,
225
+ ),
226
+ entities: Ionoscloud::NicEntities.new(
227
+ firewallrules: opts[:firewallrules] || [],
228
+ )
229
+ )
230
+ end
231
+
232
+ def nics_mock(opts = {})
233
+ Ionoscloud::Nics.new(
234
+ id: 'nics',
235
+ type: 'collection',
236
+ items: [nic_mock, nic_mock],
237
+ )
238
+ end
239
+
240
+ def firewall_mock(opts = {})
241
+ Ionoscloud::FirewallRule.new(
242
+ id: opts[:id] || SecureRandom.uuid,
243
+ properties: Ionoscloud::FirewallruleProperties.new(
244
+ name: opts[:name] || 'firewall_name',
245
+ protocol: opts[:protocol] || 'UDP',
246
+ source_mac: opts[:source_mac] || '01:23:45:67:89:00',
247
+ source_ip: opts[:source_ip] || '10.9.20.11',
248
+ target_ip: opts[:target_ip] || '10.9.20.11',
249
+ port_range_start: opts[:port_range_start] || 22,
250
+ port_range_end: opts[:port_range_end] || 22,
251
+ icmp_type: opts[:icmp_type] || 4,
252
+ icmp_code: opts[:icmp_code] || 7,
253
+ ),
254
+ )
255
+ end
256
+
257
+ def firewalls_mock(opts = {})
258
+ Ionoscloud::FirewallRules.new(
259
+ id: 'firewalls',
260
+ type: 'collection',
261
+ items: [firewall_mock, firewall_mock],
262
+ )
263
+ end
264
+
265
+ def load_balancer_mock(opts = {})
266
+ Ionoscloud::Loadbalancer.new(
267
+ id: opts[:id] || SecureRandom.uuid,
268
+ properties: Ionoscloud::LoadbalancerProperties.new(
269
+ name: opts[:name] || 'load_balancer_name',
270
+ ip: opts[:ip] || '1.1.1.1',
271
+ dhcp: opts[:dhcp] || true,
272
+ ),
273
+ entities: Ionoscloud::LoadbalancerEntities.new(
274
+ balancednics: opts[:nics] || nics_mock,
275
+ )
276
+ )
277
+ end
278
+
279
+ def load_balancers_mock(opts = {})
280
+ Ionoscloud::Loadbalancers.new(
281
+ id: 'loadbalancers',
282
+ type: 'collection',
283
+ items: [load_balancer_mock],
284
+ )
285
+ end
286
+
287
+ def image_mock(opts = {})
288
+ Ionoscloud::Image.new(
289
+ id: opts[:id] || SecureRandom.uuid,
290
+ properties: Ionoscloud::ImageProperties.new(
291
+ name: opts[:name] || 'image_name',
292
+ description: opts[:description] || 'image_description',
293
+ location: opts[:location] || 'image_location',
294
+ size: opts[:size] || 10,
295
+ public: opts[:public] || true,
296
+ ),
297
+ )
298
+ end
299
+
300
+ def images_mock(opts = {})
301
+ Ionoscloud::Images.new(
302
+ id: 'images',
303
+ type: 'collection',
304
+ items: [image_mock],
305
+ )
306
+ end
307
+
308
+ def location_mock(opts = {})
309
+ Ionoscloud::Location.new(
310
+ id: opts[:id] || SecureRandom.uuid,
311
+ properties: Ionoscloud::LocationProperties.new(
312
+ name: opts[:name] || 'location_name',
313
+ ),
314
+ )
315
+ end
316
+
317
+ def locations_mock(opts = {})
318
+ Ionoscloud::Locations.new(
319
+ id: 'locations',
320
+ type: 'collection',
321
+ items: [location_mock],
322
+ )
323
+ end
324
+
325
+ def location_mock(opts = {})
326
+ Ionoscloud::Location.new(
327
+ id: opts[:id] || SecureRandom.uuid,
328
+ properties: Ionoscloud::LocationProperties.new(
329
+ name: opts[:name] || 'location_name',
330
+ ),
331
+ )
332
+ end
333
+
334
+ def locations_mock(opts = {})
335
+ Ionoscloud::Locations.new(
336
+ id: 'locations',
337
+ type: 'collection',
338
+ items: [location_mock],
339
+ )
340
+ end
341
+
342
+ def maintenance_window_mock(opts = {})
343
+ Ionoscloud::KubernetesMaintenanceWindow.new(
344
+ day_of_the_week: opts[:day_of_the_week] || 'Sunday',
345
+ time: opts[:time] || '23:03:19Z',
346
+ )
347
+ end
348
+
349
+ def auto_scaling_mock(opts = {})
350
+ Ionoscloud::KubernetesAutoScaling.new(
351
+ min_node_count: opts[:min_node_count] || 2,
352
+ max_node_count: opts[:max_node_count] || 3,
353
+ )
354
+ end
355
+
356
+ def kubeconfig_mock(opts = {})
357
+ Ionoscloud::KubernetesConfig.new(
358
+ id: opts[:id] || SecureRandom.uuid,
359
+ properties: Ionoscloud::KubernetesConfigProperties.new(
360
+ kubeconfig: opts[:kubeconfig] || 'kubeconfig_file_data',
361
+ ),
362
+ )
363
+ end
364
+
365
+ def k8s_cluster_mock(opts = {})
366
+ Ionoscloud::KubernetesCluster.new(
367
+ id: opts[:id] || SecureRandom.uuid,
368
+ properties: Ionoscloud::KubernetesClusterProperties.new(
369
+ name: opts[:name] || 'k8s_cluster_name',
370
+ k8s_version: opts[:k8s_version] || '1.15.4,',
371
+ maintenance_window: opts[:maintenance_window] || maintenance_window_mock,
372
+ available_upgrade_versions: opts[:available_upgrade_versions] || ['1.16.4', '1.17.7'],
373
+ viable_node_pool_versions: opts[:viable_node_pool_versions] || ['1.17.7', '1.18.2']
374
+ ),
375
+ metadata: Ionoscloud::DatacenterElementMetadata.new(
376
+ state: opts[:state] || 'ACTIVE',
377
+ ),
378
+ entities: opts[:entities] || Ionoscloud::KubernetesClusterEntities.new(
379
+ nodepools: k8s_nodepools_mock,
380
+ ),
381
+ )
382
+ end
383
+
384
+ def k8s_clusters_mock(opts = {})
385
+ Ionoscloud::KubernetesClusters.new(
386
+ id: 'k8s',
387
+ type: 'collection',
388
+ items: [k8s_cluster_mock],
389
+ )
390
+ end
391
+
392
+ def k8s_nodepool_mock(opts = {})
393
+ Ionoscloud::KubernetesNodePool.new(
394
+ id: opts[:id] || SecureRandom.uuid,
395
+ properties: Ionoscloud::KubernetesNodePoolProperties.new(
396
+ name: opts[:name] || 'k8s_nodepool_name',
397
+ datacenter_id: opts[:datacenter_id] || SecureRandom.uuid,
398
+ node_count: opts[:node_count] || 2,
399
+ cores_count: opts[:cores_count] || 2,
400
+ cpu_family: opts[:cpu_family] || 'AMD_OPTERON',
401
+ ram_size: opts[:ram_size] || 2048,
402
+ availability_zone: opts[:availability_zone] || 'AUTO',
403
+ storage_type: opts[:storage_type] || 'SSD',
404
+ storage_size: opts[:storage_size] || 100,
405
+ k8s_version: opts[:k8s_version] || '1.15.4',
406
+ maintenance_window: opts[:maintenance_window] || maintenance_window_mock,
407
+ auto_scaling: opts[:auto_scaling] || auto_scaling_mock,
408
+ lans: opts[:lans] || [lan_mock, lan_mock],
409
+ labels: opts[:labels] || nil,
410
+ annotations: opts[:annotations] || nil,
411
+ public_ips: opts[:public_ips] || ['81.173.1.2', '82.231.2.5', '92.221.2.4'],
412
+ available_upgrade_versions: opts[:available_upgrade_versions] || ['1.16.4', '1.17.7'],
413
+ ),
414
+ metadata: Ionoscloud::KubernetesNodeMetadata.new(
415
+ state: 'READY',
416
+ ),
417
+ )
418
+ end
419
+
420
+ def k8s_nodepools_mock(opts = {})
421
+ Ionoscloud::KubernetesNodePools.new(
422
+ id: "#{SecureRandom.uuid}/nodepools",
423
+ type: 'collection',
424
+ items: opts[:items] || [k8s_nodepool_mock],
425
+ )
426
+ end
427
+
428
+ def k8s_node_mock(opts = {})
429
+ Ionoscloud::KubernetesNode.new(
430
+ id: opts[:id] || SecureRandom.uuid,
431
+ properties: Ionoscloud::KubernetesNodeProperties.new(
432
+ name: opts[:name] || 'k8s_node_name',
433
+ public_ip: opts[:public_ip] || '1.1.1.1',
434
+ k8s_version: opts[:k8s_version] || '1.17.7',
435
+ ),
436
+ metadata: Ionoscloud::KubernetesNodeMetadata.new(
437
+ state: 'READY',
438
+ ),
439
+ )
440
+ end
441
+
442
+ def k8s_nodes_mock(opts = {})
443
+ Ionoscloud::KubernetesNodes.new(
444
+ id: "#{SecureRandom.uuid}/nodes",
445
+ type: 'collection',
446
+ items: [k8s_node_mock],
447
+ )
448
+ end
449
+
450
+ def datacenter_mock(opts = {})
451
+ Ionoscloud::Datacenter.new(
452
+ id: opts[:id] || SecureRandom.uuid,
453
+ properties: Ionoscloud::DatacenterProperties.new(
454
+ name: opts[:name] || 'datacenter_name',
455
+ description: opts[:description] || 'datacenter_description',
456
+ location: opts[:location] || 'de/fra',
457
+ ),
458
+ )
459
+ end
460
+
461
+ def datacenters_mock(opts = {})
462
+ Ionoscloud::Datacenters.new(
463
+ id: 'datacenters',
464
+ type: 'collection',
465
+ items: [datacenter_mock],
466
+ )
467
+ end
468
+
469
+ def pcc_mock(opts = {})
470
+ Ionoscloud::PrivateCrossConnect.new(
471
+ id: opts[:id] || SecureRandom.uuid,
472
+ properties: Ionoscloud::PrivateCrossConnectProperties.new(
473
+ name: opts[:name] || 'pcc_name',
474
+ description: opts[:description] || 'pcc_description',
475
+ peers: opts[:peers] || [lan_mock, lan_mock],
476
+ connectable_datacenters: opts[:connectable_datacenters] || [datacenter_mock, datacenter_mock],
477
+ ),
478
+ )
479
+ end
480
+
481
+ def pccs_mock(opts = {})
482
+ Ionoscloud::PrivateCrossConnects.new(
483
+ id: 'pccs',
484
+ type: 'collection',
485
+ items: [pcc_mock],
486
+ )
487
+ end
488
+
489
+ def backupunit_sso_mock(opts = {})
490
+ Ionoscloud::BackupUnitSSO.new(
491
+ sso_url: opts['sso_url'] || 'www.sso-url.com',
492
+ )
493
+ end
494
+
495
+ def sso_url_mock(opts = {})
496
+ Ionoscloud::S3ObjectStorageSSO.new(
497
+ sso_url: opts['sso_url'] || 'www.sso-url.com',
498
+ )
499
+ end
500
+
501
+ def s3_key_mock(opts = {})
502
+ Ionoscloud::S3Key.new(
503
+ id: opts[:id] || SecureRandom.uuid,
504
+ properties: Ionoscloud::S3KeyProperties.new(
505
+ secret_key: opts[:secret_key] || 'secret_key',
506
+ active: opts[:active] || true,
507
+ ),
508
+ )
509
+ end
510
+
511
+ def s3_keys_mock(opts = {})
512
+ Ionoscloud::S3Keys.new(
513
+ id: 's3keys',
514
+ type: 'collection',
515
+ items: [s3_key_mock],
516
+ )
517
+ end
518
+
519
+ def group_share_mock(opts = {})
520
+ Ionoscloud::GroupShare.new(
521
+ id: opts[:id] || SecureRandom.uuid,
522
+ properties: Ionoscloud::GroupShareProperties.new(
523
+ edit_privilege: opts[:edit_privilege] || true,
524
+ share_privilege: opts[:share_privilege] || true,
525
+ ),
526
+ )
527
+ end
528
+
529
+ def group_shares_mock(opts = {})
530
+ Ionoscloud::GroupShares.new(
531
+ id: 'shares',
532
+ type: 'collection',
533
+ items: [group_share_mock],
534
+ )
535
+ end
536
+
537
+ def resource_mock(opts = {})
538
+ Ionoscloud::Resource.new(
539
+ id: opts[:id] || SecureRandom.uuid,
540
+ type: opts[:type] || 'resource_type',
541
+ properties: Ionoscloud::ResourceProperties.new(
542
+ name: opts[:name] || 'resource_name',
543
+ ),
544
+ )
545
+ end
546
+
547
+ def resources_mock(opts = {})
548
+ Ionoscloud::Resources.new(
549
+ id: 'resources',
550
+ type: 'collection',
551
+ items: [resource_mock],
552
+ )
553
+ end
554
+
555
+ def snapshot_mock(opts = {})
556
+ Ionoscloud::Snapshot.new(
557
+ id: opts[:id] || SecureRandom.uuid,
558
+ properties: Ionoscloud::SnapshotProperties.new(
559
+ name: opts[:name] || 'snapshot_name',
560
+ description: opts[:description] || 'snapshot_description',
561
+ licence_type: opts[:licence_type] || 'LINUX',
562
+ location: opts[:location] || 'de/fra',
563
+ size: opts[:size] || 10.0,
564
+ ),
565
+ )
566
+ end
567
+
568
+ def snapshots_mock(opts = {})
569
+ Ionoscloud::Snapshots.new(
570
+ id: 'snapshots',
571
+ type: 'collection',
572
+ items: [snapshot_mock],
573
+ )
574
+ end
575
+
576
+ def group_mock(opts = {})
577
+ Ionoscloud::Group.new(
578
+ id: opts[:id] || SecureRandom.uuid,
579
+ properties: Ionoscloud::GroupProperties.new(
580
+ name: opts[:name] || 'group_name',
581
+ create_data_center: opts[:create_data_center] || true,
582
+ create_snapshot: opts[:create_snapshot] || true,
583
+ reserve_ip: opts[:reserve_ip] || true,
584
+ access_activity_log: opts[:access_activity_log] || true,
585
+ s3_privilege: opts[:s3_privilege] || true,
586
+ create_backup_unit: opts[:create_backup_unit] || true,
587
+ ),
588
+ entities: Ionoscloud::GroupEntities.new(
589
+ users: group_members_mock,
590
+ ),
591
+ )
592
+ end
593
+
594
+ def groups_mock(opts = {})
595
+ Ionoscloud::Groups.new(
596
+ id: 'groups',
597
+ type: 'collection',
598
+ items: [group_mock, group_mock],
599
+ )
600
+ end
601
+
602
+ def group_members_mock(opts = {})
603
+ Ionoscloud::GroupMembers.new(
604
+ id: 'groupmembers',
605
+ type: 'collection',
606
+ items: [user_mock, user_mock],
607
+ )
608
+ end
609
+
610
+ def user_mock(opts = {})
611
+ Ionoscloud::User.new(
612
+ id: opts[:id] || SecureRandom.uuid,
613
+ properties: Ionoscloud::UserProperties.new(
614
+ firstname: opts[:firstname] || 'Firstname',
615
+ lastname: opts[:lastname] || 'Lastname',
616
+ email: opts[:email] || 'a@a.a',
617
+ password: opts[:password] || 'parola1234',
618
+ administrator: opts[:administrator] || false,
619
+ force_sec_auth: opts[:force_sec_auth] || false,
620
+ ),
621
+ )
622
+ end
623
+
624
+ def users_mock(opts = {})
625
+ Ionoscloud::Users.new(
626
+ id: 'users',
627
+ type: 'collection',
628
+ items: [user_mock],
629
+ )
630
+ end
631
+
632
+ def request_status_mock(opts = {})
633
+ Ionoscloud::RequestStatus.new(
634
+ id: opts[:id] || SecureRandom.uuid,
635
+ metadata: Ionoscloud::RequestStatusMetadata.new(
636
+ status: opts[:status] || 'DONE',
637
+ message: opts[:message] || 'Message',
638
+ targets: opts[:targets] || []
639
+ ),
640
+ )
641
+ end
642
+
643
+ def request_target_mock(opts = {})
644
+ Ionoscloud::RequestTarget.new(
645
+ status: opts[:status] || 'DONE',
646
+ target: opts[:target] || resource_mock,
647
+ )
648
+ end
649
+
650
+ def request_mock(opts = {})
651
+ Ionoscloud::Request.new(
652
+ id: opts[:id] || SecureRandom.uuid,
653
+ properties: Ionoscloud::RequestProperties.new(
654
+ method: opts[:method] || 'POST',
655
+ ),
656
+ metadata: Ionoscloud::RequestMetadata.new(
657
+ request_status: request_status_mock(opts)
658
+ )
659
+ )
660
+ end
661
+
662
+ def requests_mock(opts = {})
663
+ Ionoscloud::Requests.new(
664
+ id: 'requests',
665
+ type: 'collection',
666
+ items: [request_mock, request_mock({ targets: [request_target_mock] })],
667
+ )
668
+ end
669
+
670
+ def arrays_without_one_element(arr)
671
+ result = [{ array: arr[1..], removed: [arr[0]]}]
672
+ (1..arr.length - 1).each { |i| result.append({ array: arr[0..i-1] + arr[i+1..], removed: [arr[i]]}) }
673
+ result
674
+ end
675
+
676
+ def mock_wait_for(subject)
677
+ expect(subject.api_client).to receive(:wait_for).once { true }
678
+ end
679
+
680
+ def mock_call_api(subject, rules)
681
+ rules.each do |rule|
682
+ expect(subject.api_client).to receive(:call_api).once do |method, path, opts|
683
+ result = nil
684
+ received_body = opts[:body].nil? ? opts[:body] : JSON.parse(opts[:body], symbolize_names: true)
685
+
686
+ expect(method.to_s).to eq(rule[:method])
687
+ expect(path).to eq(rule[:path])
688
+ expect(opts[:operation]).to eq(rule[:operation])
689
+ expect(opts[:form_params]).to eq(rule[:form_params] || {})
690
+ expect(opts[:return_type]).to eq(rule[:return_type] || 'Object')
691
+ expect(received_body).to eq(rule[:body] || nil)
692
+ expect(opts.slice(*(rule[:options] || {}).keys)).to eql((rule[:options] || {}))
693
+
694
+ if rule[:exception]
695
+ raise rule[:exception]
696
+ end
697
+
698
+ rule[:result]
699
+ end
700
+ end
701
+ expect(subject.api_client).not_to receive(:call_api)
702
+ end