foreman_fog_proxmox 0.8.0 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of foreman_fog_proxmox might be problematic. Click here for more details.

Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -1
  3. data/Rakefile +3 -1
  4. data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +2 -2
  5. data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +2 -2
  6. data/app/helpers/node_dashboard_helper.rb +13 -14
  7. data/app/helpers/proxmox_compute_selectors_helper.rb +49 -50
  8. data/app/helpers/proxmox_container_helper.rb +42 -36
  9. data/app/helpers/proxmox_form_helper.rb +38 -40
  10. data/app/helpers/proxmox_server_helper.rb +39 -41
  11. data/app/helpers/proxmox_vm_helper.rb +21 -25
  12. data/app/models/concerns/fog_extensions/proxmox/disk.rb +8 -8
  13. data/app/models/concerns/fog_extensions/proxmox/interface.rb +8 -8
  14. data/app/models/concerns/fog_extensions/proxmox/node.rb +24 -22
  15. data/app/models/concerns/fog_extensions/proxmox/server.rb +71 -59
  16. data/app/models/concerns/fog_extensions/proxmox/server_config.rb +47 -39
  17. data/app/models/concerns/fog_extensions/proxmox/volume.rb +8 -8
  18. data/app/models/concerns/host_ext/proxmox/interfaces.rb +21 -13
  19. data/app/models/concerns/orchestration/proxmox/compute.rb +14 -10
  20. data/app/models/foreman_fog_proxmox/options_select.rb +14 -14
  21. data/app/models/foreman_fog_proxmox/proxmox.rb +30 -466
  22. data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +54 -0
  23. data/app/models/foreman_fog_proxmox/proxmox_connection.rb +67 -0
  24. data/app/models/foreman_fog_proxmox/proxmox_console.rb +41 -0
  25. data/app/models/foreman_fog_proxmox/proxmox_images.rb +53 -0
  26. data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +60 -0
  27. data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +49 -0
  28. data/app/models/foreman_fog_proxmox/proxmox_token_expiration.rb +30 -0
  29. data/app/models/foreman_fog_proxmox/proxmox_version.rb +36 -0
  30. data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +108 -0
  31. data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +162 -0
  32. data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +74 -0
  33. data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +85 -0
  34. data/app/overrides/compute_resources_vms/form/add_clone_to_new_vm_compute_detail.rb +7 -6
  35. data/app/overrides/compute_resources_vms/form/add_from_profile_to_compute_attributes_form.rb +13 -11
  36. data/app/overrides/compute_resources_vms/form/add_vm_type_to_networks_form.rb +13 -11
  37. data/app/overrides/compute_resources_vms/form/add_vm_type_to_nic_provider_specific_form.rb +8 -7
  38. data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_edit.rb +7 -6
  39. data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_new_volume.rb +7 -6
  40. data/app/overrides/compute_resources_vms/form/remove_new_vm_from_removable_layout.rb +7 -6
  41. data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +16 -16
  42. data/app/views/api/v2/compute_resources/proxmox.json.rabl +3 -1
  43. data/app/views/compute_resources/form/_proxmox.html.erb +3 -0
  44. data/app/views/compute_resources/show/_proxmox.html.erb +8 -0
  45. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_attributes_form.html.erb +5 -0
  46. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_form.html.erb +6 -1
  47. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_hosts_compute_detail_form.html.erb +6 -0
  48. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_form.html.erb +6 -2
  49. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_new_childs_form.html.erb +8 -2
  50. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +6 -0
  51. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +15 -1
  52. data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +2 -2
  53. data/app/views/compute_resources_vms/form/proxmox/_general.html.erb +1 -1
  54. data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +6 -1
  55. data/app/views/compute_resources_vms/form/proxmox/container/_extended.html.erb +1 -1
  56. data/app/views/compute_resources_vms/form/proxmox/container/_volume_mp.html.erb +1 -1
  57. data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +1 -1
  58. data/app/views/compute_resources_vms/form/proxmox/server/_volume.html.erb +2 -2
  59. data/config/routes.rb +4 -4
  60. data/lib/foreman_fog_proxmox/engine.rb +14 -14
  61. data/lib/foreman_fog_proxmox/semver.rb +78 -78
  62. data/lib/foreman_fog_proxmox/value.rb +5 -3
  63. data/lib/foreman_fog_proxmox/version.rb +1 -1
  64. data/lib/tasks/foreman_fog_proxmox_tasks.rake +3 -13
  65. data/locale/en/foreman_fog_proxmox.edit.po +472 -0
  66. data/locale/en/foreman_fog_proxmox.po +48 -24
  67. data/locale/en/foreman_fog_proxmox.po.time_stamp +0 -0
  68. data/locale/foreman_fog_proxmox.pot +140 -102
  69. data/locale/fr/foreman_fog_proxmox.edit.po +472 -0
  70. data/locale/fr/foreman_fog_proxmox.po +52 -28
  71. data/locale/fr/foreman_fog_proxmox.po.time_stamp +0 -0
  72. data/locale/gemspec.rb +2 -0
  73. data/test/{unit/foreman_fog_proxmox/proxmox_test_helpers.rb → factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb} +4 -140
  74. data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +61 -0
  75. data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +134 -0
  76. data/test/factories/proxmox_factory.rb +15 -15
  77. data/test/functional/compute_resources_controller_test.rb +12 -10
  78. data/test/test_plugin_helper.rb +2 -0
  79. data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +178 -182
  80. data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +122 -126
  81. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +180 -187
  82. data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +116 -0
  83. data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +71 -0
  84. data/test/unit/foreman_fog_proxmox/proxmox_test.rb +9 -479
  85. data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +82 -0
  86. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +207 -0
  87. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +92 -0
  88. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +324 -0
  89. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_test.rb +43 -0
  90. data/test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb +71 -0
  91. data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +63 -0
  92. data/test/unit/foreman_fog_proxmox/semver_test.rb +67 -53
  93. metadata +52 -14
@@ -35,6 +35,9 @@ msgstr "Charge moyenne du serveur (x100)"
35
35
  msgid "Ballooning Device"
36
36
  msgstr "Périphérique à gonflement"
37
37
 
38
+ msgid "Boot device order"
39
+ msgstr ""
40
+
38
41
  msgid "Bridge"
39
42
  msgstr "Pont"
40
43
 
@@ -107,12 +110,21 @@ msgstr "Activer/désactiver la virtualisation matérielle de KVM"
107
110
  msgid "Extended"
108
111
  msgstr "Etendu"
109
112
 
110
- msgid "Failed retrieving proxmox vm by vmid=%{vmid} and type=%{type}"
111
- msgstr "Echec de récupération de la vm proxmox avec vmid=%{vmid} et type=%{type}"
113
+ msgid "Failed retrieving proxmox server vm by vmid=%<vmid>s"
114
+ msgstr ""
115
+
116
+ msgid "Failed to undo update compute %<compute_resource>s instance %<name>s: %<e>s"
117
+ msgstr ""
118
+
119
+ msgid "Failed to update a compute %<compute_resource>s instance %<name>s: %<e>s"
120
+ msgstr ""
112
121
 
113
122
  msgid "Firewall"
114
123
  msgstr "Pare-feu"
115
124
 
125
+ msgid "Floppy disk (a), hard disk (c), cdrom (d), network (n). Default cdn"
126
+ msgstr ""
127
+
116
128
  msgid "Foreman Fog Proxmox widget"
117
129
  msgstr ""
118
130
 
@@ -125,9 +137,6 @@ msgstr "Général"
125
137
  msgid "Hostname"
126
138
  msgstr "Nom d'hôte"
127
139
 
128
- msgid "Identifier interface[%{index}] required."
129
- msgstr "L'identifiant de interface[%{index}] est obligatoire."
130
-
131
140
  msgid "Image"
132
141
  msgstr ""
133
142
 
@@ -137,12 +146,6 @@ msgstr ""
137
146
  msgid "Image VMID"
138
147
  msgstr ""
139
148
 
140
- msgid "Invalid identifier interface[%{index}]. Must be net[n] with n integer >= 0"
141
- msgstr "L'identifiant de interface[%{index}] est incorrect. La syntaxe correcte est net[n] avec n un entier naturel positif"
142
-
143
- msgid "Invalid uuid=[%{uuid}]."
144
- msgstr ""
145
-
146
149
  msgid "KVM"
147
150
  msgstr ""
148
151
 
@@ -190,8 +193,8 @@ msgstr "Type de système d'exploitation"
190
193
  msgid "Operating System"
191
194
  msgstr "Système d'exploitation"
192
195
 
193
- msgid "Operating system family %{type} is not consistent with %{ostype}"
194
- msgstr "La famille %{type} du système d'exploitation n'est pas cohérente avec %{ostype}"
196
+ msgid "Operating system family %<type>s is not consistent with %<ostype>s"
197
+ msgstr ""
195
198
 
196
199
  msgid "Optionally provide a CA, or a correctly ordered CA chain. If left blank, disable ssl_verify_peer."
197
200
  msgstr "Vous pouvez éventuellement fournir un certificat ou une chaîne de certificats. Si non renseigné, alors désactivez ssl_verify_peer."
@@ -202,6 +205,9 @@ msgstr ""
202
205
  msgid "Password to authenticate with - used for SSH finish step."
203
206
  msgstr "Mot de passe d'authentification - utilisé dans la dernière phase avec SSH."
204
207
 
208
+ msgid "Path"
209
+ msgstr ""
210
+
205
211
  msgid "Physical"
206
212
  msgstr "Physique"
207
213
 
@@ -211,12 +217,21 @@ msgstr "Alimentation"
211
217
  msgid "Proxmox Node Statistics: %s"
212
218
  msgstr "Statistiques du noeud Proxmox: %s"
213
219
 
220
+ msgid "Proxmox compute resource version is %<version>s"
221
+ msgstr ""
222
+
223
+ msgid "Proxmox version %<version>s is not semver suitable"
224
+ msgstr ""
225
+
214
226
  msgid "Qemu Agent"
215
227
  msgstr "Agent Qemu"
216
228
 
217
229
  msgid "Rate limit"
218
230
  msgstr "Taux limite"
219
231
 
232
+ msgid "Renew expired token ?"
233
+ msgstr ""
234
+
220
235
  msgid "Root password"
221
236
  msgstr "Mot de passe root"
222
237
 
@@ -244,9 +259,6 @@ msgstr ""
244
259
  msgid "Start at boot"
245
260
  msgstr "Démarrer au boot"
246
261
 
247
- msgid "Start/Shutdown order"
248
- msgstr "Ordre au démarrage/arrêt"
249
-
250
262
  msgid "Storage"
251
263
  msgstr "Stockage"
252
264
 
@@ -265,12 +277,24 @@ msgstr "Le compte utilisé pour SSH, en général compte cloud, ubuntu ou root,
265
277
  msgid "Time"
266
278
  msgstr "Temps"
267
279
 
280
+ msgid "Token expires on"
281
+ msgstr ""
282
+
283
+ msgid "Token expires on #{token_deadline}"
284
+ msgstr ""
285
+
286
+ msgid "Token has expired?"
287
+ msgstr ""
288
+
268
289
  msgid "Type"
269
290
  msgstr ""
270
291
 
271
292
  msgid "URL"
272
293
  msgstr ""
273
294
 
295
+ msgid "Unable to shrink %<id>s size. Proxmox allows only increasing size."
296
+ msgstr ""
297
+
274
298
  msgid "Unable to store X509 certificates"
275
299
  msgstr "Impossible d'enregistrer les certificats X509"
276
300
 
@@ -289,16 +313,19 @@ msgstr "Etiquette VLAN"
289
313
  msgid "VM ID"
290
314
  msgstr ""
291
315
 
316
+ msgid "Version"
317
+ msgstr ""
318
+
292
319
  msgid "X509 Certification Authorities"
293
320
  msgstr "Autorités de certification X509"
294
321
 
295
322
  msgid "add new storage volume"
296
323
  msgstr "ajouter un nouveau volume de stockage"
297
324
 
298
- msgid "create_vm(): %{args}"
325
+ msgid "create_vm(): clone %<image_id>s in %<vmid>s"
299
326
  msgstr ""
300
327
 
301
- msgid "create_vm(): clone %{image_id} in %{vmid}"
328
+ msgid "e.g. /path/to/"
302
329
  msgstr ""
303
330
 
304
331
  msgid "e.g. https://127.0.0.1:8006/api2/json"
@@ -307,19 +334,19 @@ msgstr "par exemple https://127.0.0.1:8006/api2/json"
307
334
  msgid "e.g. root@pam"
308
335
  msgstr "par exemple root@pam"
309
336
 
310
- msgid "failed to create vm: %{e}"
311
- msgstr "échec à la création de la VM: %{e}"
337
+ msgid "failed to create vm: %<e>s"
338
+ msgstr "échec à la création de la VM: %<e>s"
312
339
 
313
- msgid "invalid vmid=%{vmid}"
314
- msgstr "vmid=%{vmid} incorrect"
340
+ msgid "invalid vmid=%<vmid>s"
341
+ msgstr "vmid=%<vmid>s incorrect"
315
342
 
316
- msgid "new_container_vm() vm.config=%{config}"
343
+ msgid "new_container_vm() vm.config=%<config>s"
317
344
  msgstr ""
318
345
 
319
- msgid "new_server_vm() vm.config=%{config}"
346
+ msgid "new_server_vm() vm.config=%<config>s"
320
347
  msgstr ""
321
348
 
322
- msgid "new_vm() vm.config=%{config}"
349
+ msgid "new_vm() vm.config=%<config>s"
323
350
  msgstr ""
324
351
 
325
352
  msgid "remove network interface"
@@ -328,8 +355,5 @@ msgstr "retirer l'interface réseau"
328
355
  msgid "remove storage volume"
329
356
  msgstr "retirer le stockage de volume"
330
357
 
331
- msgid "save_vm(): %{attr}"
332
- msgstr ""
333
-
334
358
  msgid "vmid of template vm."
335
359
  msgstr "vmid de la VM modèle."
File without changes
data/locale/gemspec.rb CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Matches foreman_fog_proxmox.gemspec
2
4
  _('ForemanFogProxmox plugin adds Proxmox VE compute resource to Foreman using fog-proxmox gem.')
@@ -18,142 +18,7 @@
18
18
  # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module ForemanFogProxmox
21
- module ProxmoxTestHelpers
22
-
23
- def mock_node_servers(cr, servers)
24
- node = mock('node')
25
- node.stubs(:servers).returns(servers)
26
- cr.stubs(:node).returns(node)
27
- cr
28
- end
29
-
30
- def mock_node_containers(cr, containers)
31
- node = mock('node')
32
- node.stubs(:containers).returns(containers)
33
- cr.stubs(:node).returns(node)
34
- cr
35
- end
36
-
37
- def mock_node_servers_containers(cr, servers, containers)
38
- node = mock('node')
39
- node.stubs(:containers).returns(containers)
40
- node.stubs(:servers).returns(servers)
41
- cr.stubs(:node).returns(node)
42
- cr
43
- end
44
-
45
- def mock_server_vm
46
- interface_attributes = {
47
- id: 'net0',
48
- macaddr: '36:25:8C:53:0C:50',
49
- model: 'virtio',
50
- name: nil,
51
- ip: nil,
52
- ip6: nil,
53
- bridge: 'vmbr0',
54
- firewall: nil,
55
- link_down: nil,
56
- rate: nil,
57
- queues: nil,
58
- tag: nil
59
- }
60
- interface = mock('interface')
61
- interface.stubs(:attributes).returns(interface_attributes)
62
- interfaces = [interface]
63
- volume_attributes = {
64
- id: 'scsi0',
65
- volid: 'local-lvm:vm-100-disk-1',
66
- size: 8,
67
- storage: 'local-lvm',
68
- cache: 'none',
69
- replicate: nil,
70
- media: nil,
71
- format: nil,
72
- model: 'scsi',
73
- shared: nil,
74
- snapshot: nil,
75
- backup: nil,
76
- aio: nil
77
- }
78
- volume = mock('volume')
79
- volume.stubs(:attributes).returns(volume_attributes)
80
- volumes = [volume]
81
- config = mock('config')
82
- config_attributes = {
83
- vmid: 100,
84
- digest: '0',
85
- description: '',
86
- ostype: 'l26',
87
- smbios1: '0',
88
- numa: 0,
89
- kvm: 0,
90
- vcpus: 1,
91
- cores: 1,
92
- bootdisk: 'scsi0',
93
- onboot: 0,
94
- boot: 'scsi0',
95
- agent: 0,
96
- scsihw: 'scsi',
97
- sockets: 1,
98
- memory: 512,
99
- min_memory: 0,
100
- shares: 0,
101
- balloon: 0,
102
- name: 'test',
103
- cpu: 1,
104
- cpulimit: nil,
105
- cpuunits: nil,
106
- keyboard: 'fr',
107
- vga: 'std',
108
- interfaces: interfaces,
109
- disks: volumes
110
- }
111
- config.stubs(:attributes).returns(config_attributes)
112
- config.stubs(:disks).returns(volumes)
113
- config.stubs(:interfaces).returns(interfaces)
114
- config.stubs(:respond_to?).returns(true)
115
- vm = mock('vm')
116
- vm.stubs(:respond_to?).returns(true)
117
- vm.stubs(:config).returns(config)
118
- vm.stubs(:type).returns('qemu')
119
- vm.stubs(:identity).returns(100)
120
- vm.stubs(:node_id).returns('pve')
121
- service = mock('service')
122
- vm_attributes = {
123
- vmid: 100,
124
- id: 'qemu/100',
125
- node_id: 'pve',
126
- config: config,
127
- service: service,
128
- name: 'test',
129
- type: 'qemu',
130
- maxdisk: 0,
131
- disk: 0,
132
- diskwrite: 0,
133
- diskread: 0,
134
- uptime: 0,
135
- netout: 0,
136
- netin: 0,
137
- cpu: 1,
138
- cpus: 1,
139
- template: 0,
140
- status: 'stopped',
141
- maxcpu: 0,
142
- mem: 0,
143
- maxmem: 512,
144
- qmpstatus: 'stopped',
145
- ha: {},
146
- pid: 0,
147
- blockstat: 0,
148
- balloon: 0,
149
- ballooninfo: 0,
150
- snapshots: []
151
- }
152
- vm.stubs(:attributes).returns(vm_attributes)
153
- vm.stubs(:container?).returns(false)
154
- return vm, config_attributes, volume_attributes, interface_attributes
155
- end
156
-
21
+ module ProxmoxContainerMockFactory
157
22
  def mock_container_vm
158
23
  interface_attributes = {
159
24
  id: 'net0',
@@ -196,7 +61,7 @@ module ForemanFogProxmox
196
61
  digest: '0',
197
62
  ostype: 'alpine',
198
63
  storage: 'local-lvm',
199
- template: 0,
64
+ template: 0,
200
65
  arch: 'amd64',
201
66
  memory: 512,
202
67
  swap: nil,
@@ -266,8 +131,7 @@ module ForemanFogProxmox
266
131
  }
267
132
  vm.stubs(:attributes).returns(vm_attributes)
268
133
  vm.stubs(:container?).returns(true)
269
- return vm, config_attributes, volume_attributes, interface_attributes
134
+ [vm, config_attributes, volume_attributes, interface_attributes]
270
135
  end
271
-
272
- end
136
+ end
273
137
  end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+
12
+ # ForemanFogProxmox is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ module ForemanFogProxmox
21
+ module ProxmoxNodeMockFactory
22
+ def mock_node_servers(cr, servers)
23
+ node = mock('node')
24
+ node.stubs(:servers).returns(servers)
25
+ cr.stubs(:nodes).returns([node])
26
+ cr.stubs(:node).returns(node)
27
+ cr
28
+ end
29
+
30
+ def mock_node_containers(cr, containers)
31
+ node = mock('node')
32
+ node.stubs(:containers).returns(containers)
33
+ cr.stubs(:node).returns(node)
34
+ cr.stubs(:nodes).returns([node])
35
+ cr
36
+ end
37
+
38
+ def mock_node_servers_containers(cr, servers, containers)
39
+ node = mock('node')
40
+ node.stubs(:containers).returns(containers)
41
+ node.stubs(:servers).returns(servers)
42
+ cr.stubs(:node).returns(node)
43
+ cr.stubs(:nodes).returns([node])
44
+ cr
45
+ end
46
+
47
+ def mock_cluster_nodes_servers_containers(cr, n1s, n1c, n2s, n2c)
48
+ node1 = mock('node')
49
+ node1.stubs(:node).returns('node1')
50
+ node1.stubs(:servers).returns(n1s)
51
+ node1.stubs(:containers).returns(n1c)
52
+ node2 = mock('node')
53
+ node2.stubs(:node).returns('node2')
54
+ node2.stubs(:servers).returns(n2s)
55
+ node2.stubs(:containers).returns(n2c)
56
+ cr.stubs(:node).returns(node1)
57
+ cr.stubs(:nodes).returns([node1, node2])
58
+ cr
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+
12
+ # ForemanFogProxmox is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ module ForemanFogProxmox
21
+ module ProxmoxServerMockFactory
22
+ def mock_server_vm
23
+ interface_attributes = {
24
+ id: 'net0',
25
+ macaddr: '36:25:8C:53:0C:50',
26
+ model: 'virtio',
27
+ name: nil,
28
+ ip: nil,
29
+ ip6: nil,
30
+ bridge: 'vmbr0',
31
+ firewall: nil,
32
+ link_down: nil,
33
+ rate: nil,
34
+ queues: nil,
35
+ tag: nil
36
+ }
37
+ interface = mock('interface')
38
+ interface.stubs(:attributes).returns(interface_attributes)
39
+ interfaces = [interface]
40
+ volume_attributes = {
41
+ id: 'scsi0',
42
+ volid: 'local-lvm:vm-100-disk-1',
43
+ size: 8,
44
+ storage: 'local-lvm',
45
+ cache: 'none',
46
+ replicate: nil,
47
+ media: nil,
48
+ format: nil,
49
+ model: 'scsi',
50
+ shared: nil,
51
+ snapshot: nil,
52
+ backup: nil,
53
+ aio: nil
54
+ }
55
+ volume = mock('volume')
56
+ volume.stubs(:attributes).returns(volume_attributes)
57
+ volumes = [volume]
58
+ config = mock('config')
59
+ config_attributes = {
60
+ vmid: 100,
61
+ digest: '0',
62
+ description: '',
63
+ ostype: 'l26',
64
+ smbios1: '0',
65
+ numa: 0,
66
+ kvm: 0,
67
+ vcpus: 1,
68
+ cores: 1,
69
+ bootdisk: 'scsi0',
70
+ onboot: 0,
71
+ boot: 'scsi0',
72
+ agent: 0,
73
+ scsihw: 'scsi',
74
+ sockets: 1,
75
+ memory: 512,
76
+ min_memory: 0,
77
+ shares: 0,
78
+ balloon: 0,
79
+ name: 'test',
80
+ cpu: 1,
81
+ cpulimit: nil,
82
+ cpuunits: nil,
83
+ keyboard: 'fr',
84
+ vga: 'std',
85
+ interfaces: interfaces,
86
+ disks: volumes
87
+ }
88
+ config.stubs(:attributes).returns(config_attributes)
89
+ config.stubs(:disks).returns(volumes)
90
+ config.stubs(:interfaces).returns(interfaces)
91
+ config.stubs(:respond_to?).returns(true)
92
+ vm = mock('vm')
93
+ vm.stubs(:respond_to?).returns(true)
94
+ vm.stubs(:config).returns(config)
95
+ vm.stubs(:type).returns('qemu')
96
+ vm.stubs(:identity).returns(100)
97
+ vm.stubs(:node_id).returns('pve')
98
+ service = mock('service')
99
+ vm_attributes = {
100
+ vmid: 100,
101
+ id: 'qemu/100',
102
+ node_id: 'pve',
103
+ config: config,
104
+ service: service,
105
+ name: 'test',
106
+ type: 'qemu',
107
+ maxdisk: 0,
108
+ disk: 0,
109
+ diskwrite: 0,
110
+ diskread: 0,
111
+ uptime: 0,
112
+ netout: 0,
113
+ netin: 0,
114
+ cpu: 1,
115
+ cpus: 1,
116
+ template: 0,
117
+ status: 'stopped',
118
+ maxcpu: 0,
119
+ mem: 0,
120
+ maxmem: 512,
121
+ qmpstatus: 'stopped',
122
+ ha: {},
123
+ pid: 0,
124
+ blockstat: 0,
125
+ balloon: 0,
126
+ ballooninfo: 0,
127
+ snapshots: []
128
+ }
129
+ vm.stubs(:attributes).returns(vm_attributes)
130
+ vm.stubs(:container?).returns(false)
131
+ [vm, config_attributes, volume_attributes, interface_attributes]
132
+ end
133
+ end
134
+ end