foreman_fog_proxmox 0.12.2 → 0.13.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -5
  3. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +36 -2
  4. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +134 -60
  5. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js +2 -50
  6. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume.js +39 -0
  7. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume_cdrom.js +63 -0
  8. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume_cloudinit.js +25 -0
  9. data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +1 -1
  10. data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +23 -25
  11. data/app/helpers/proxmox_compute_controllers_helper.rb +39 -0
  12. data/app/helpers/proxmox_compute_resources_helper.rb +49 -0
  13. data/app/helpers/proxmox_compute_selectors_helper.rb +6 -44
  14. data/app/helpers/proxmox_form_helper.rb +12 -4
  15. data/app/{models/concerns/fog_extensions/proxmox/volume.rb → helpers/proxmox_storages_helper.rb} +5 -8
  16. data/app/helpers/proxmox_vm_cdrom_helper.rb +35 -0
  17. data/app/helpers/proxmox_vm_cloudinit_helper.rb +43 -0
  18. data/app/helpers/proxmox_vm_config_helper.rb +160 -0
  19. data/app/helpers/proxmox_vm_helper.rb +24 -62
  20. data/app/helpers/proxmox_vm_interfaces_helper.rb +85 -0
  21. data/app/helpers/proxmox_vm_os_template_helper.rb +47 -0
  22. data/app/{models/foreman_fog_proxmox/proxmox_token_expiration.rb → helpers/proxmox_vm_uuid_helper.rb} +14 -10
  23. data/app/helpers/proxmox_vm_volumes_helper.rb +105 -0
  24. data/app/models/concerns/fog_extensions/proxmox/disk.rb +17 -2
  25. data/app/models/concerns/fog_extensions/proxmox/interface.rb +19 -4
  26. data/app/models/concerns/fog_extensions/proxmox/server.rb +12 -3
  27. data/app/models/concerns/fog_extensions/proxmox/server_config.rb +8 -30
  28. data/app/models/concerns/host_ext/proxmox/interfaces.rb +7 -2
  29. data/app/models/concerns/orchestration/proxmox/compute.rb +49 -0
  30. data/app/models/foreman_fog_proxmox/proxmox.rb +58 -15
  31. data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +14 -18
  32. data/app/models/foreman_fog_proxmox/proxmox_connection.rb +14 -9
  33. data/app/models/foreman_fog_proxmox/proxmox_images.rb +2 -1
  34. data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +53 -28
  35. data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +1 -1
  36. data/app/models/foreman_fog_proxmox/proxmox_version.rb +7 -2
  37. data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +19 -31
  38. data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +108 -94
  39. data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +9 -6
  40. data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +79 -22
  41. data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +6 -2
  42. data/app/views/api/v2/compute_resources/proxmox.json.rabl +1 -1
  43. data/app/views/compute_resources/form/_proxmox.html.erb +23 -10
  44. data/app/views/compute_resources/show/_proxmox.html.erb +6 -6
  45. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +3 -1
  46. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +46 -29
  47. data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +3 -3
  48. data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +2 -1
  49. data/app/views/compute_resources_vms/form/proxmox/container/_network.html.erb +8 -7
  50. data/app/views/compute_resources_vms/form/proxmox/server/_advanced.html.erb +0 -2
  51. data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +15 -14
  52. data/app/views/compute_resources_vms/form/proxmox/server/_network.html.erb +2 -2
  53. data/app/views/compute_resources_vms/form/proxmox/server/_volume_cdrom.html.erb +34 -0
  54. data/app/views/compute_resources_vms/form/proxmox/server/_volume_cloud_init.html.erb +29 -0
  55. data/app/views/compute_resources_vms/form/proxmox/server/{_volume.html.erb → _volume_hard_disk.html.erb} +7 -3
  56. data/app/views/compute_resources_vms/show/_proxmox.html.erb +2 -0
  57. data/config/routes.rb +7 -7
  58. data/db/migrate/20210312105013_update_proxmox_uuid_host.rb +29 -0
  59. data/lib/foreman_fog_proxmox/engine.rb +15 -10
  60. data/lib/foreman_fog_proxmox/hash_collection.rb +69 -0
  61. data/lib/foreman_fog_proxmox/version.rb +1 -1
  62. data/lib/tasks/foreman_fog_proxmox_tasks.rake +0 -3
  63. data/test/factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb +20 -8
  64. data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +5 -5
  65. data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +17 -7
  66. data/test/factories/proxmox_factory.rb +4 -4
  67. data/test/functional/compute_resources_controller_test.rb +4 -4
  68. data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +53 -32
  69. data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +56 -31
  70. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +22 -20
  71. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_uuid_helper_test.rb +38 -0
  72. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_volumes_helper_test.rb +50 -0
  73. data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +10 -11
  74. data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +38 -10
  75. data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +10 -10
  76. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +34 -24
  77. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +8 -8
  78. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cdrom_test.rb +181 -0
  79. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cloudinit_test.rb +131 -0
  80. data/test/unit/foreman_fog_proxmox/{proxmox_vm_commands_server_update_volumes_test.rb → proxmox_vm_commands_server_update_hard_disk_test.rb} +45 -19
  81. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +21 -21
  82. data/test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb +3 -3
  83. data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +3 -3
  84. metadata +44 -23
  85. data/app/helpers/proxmox_container_helper.rb +0 -163
  86. data/app/helpers/proxmox_server_helper.rb +0 -155
@@ -43,13 +43,13 @@ module ForemanFogProxmox
43
43
  end
44
44
 
45
45
  it 'computes next vmid when vmid == 0 and creates server' do
46
- args = { vmid: '0', type: 'qemu', node_id: 'pve', start_after_create: '0' }
46
+ args = { vmid: '0', type: 'qemu', node_id: 'proxmox', start_after_create: '0' }
47
47
  servers = mock('servers')
48
48
  servers.stubs(:id_valid?).returns(true)
49
49
  servers.stubs(:next_id).returns('101')
50
50
  cr = mock_node_servers(ForemanFogProxmox::Proxmox.new, servers)
51
51
  cr.stubs(:convert_sizes).with(args)
52
- cr.stubs(:parse_server_vm).with(args).returns(args)
52
+ cr.stubs(:parse_typed_vm).with(args, 'qemu').returns(args)
53
53
  servers.stubs(:create).with(args)
54
54
  vm = mock('vm')
55
55
  cr.stubs(:find_vm_by_uuid).with((args[:vmid]).to_s).returns(vm)
@@ -57,12 +57,12 @@ module ForemanFogProxmox
57
57
  end
58
58
 
59
59
  it 'creates server without bootstart' do
60
- args = { vmid: '100', type: 'qemu', node_id: 'pve', start_after_create: '0' }
60
+ args = { vmid: '100', type: 'qemu', node_id: 'proxmox', start_after_create: '0' }
61
61
  servers = mock('servers')
62
62
  servers.stubs(:id_valid?).returns(true)
63
63
  cr = mock_node_servers(ForemanFogProxmox::Proxmox.new, servers)
64
64
  cr.stubs(:convert_sizes).with(args)
65
- cr.stubs(:parse_server_vm).with(args).returns(args)
65
+ cr.stubs(:parse_typed_vm).with(args, 'qemu').returns(args)
66
66
  servers.stubs(:create).with(args)
67
67
  vm = mock('vm')
68
68
  cr.stubs(:find_vm_by_uuid).with((args[:vmid]).to_s).returns(vm)
@@ -70,12 +70,12 @@ module ForemanFogProxmox
70
70
  end
71
71
 
72
72
  it 'creates server with bootstart' do
73
- args = { vmid: '100', type: 'qemu', node_id: 'pve', start_after_create: '1' }
73
+ args = { vmid: '100', type: 'qemu', node_id: 'proxmox', start_after_create: '1' }
74
74
  servers = mock('servers')
75
75
  servers.stubs(:id_valid?).returns(true)
76
76
  cr = mock_node_servers(ForemanFogProxmox::Proxmox.new, servers)
77
77
  cr.stubs(:convert_sizes).with(args)
78
- cr.stubs(:parse_server_vm).with(args).returns(args)
78
+ cr.stubs(:parse_typed_vm).with(args, 'qemu').returns(args)
79
79
  vm = mock('vm')
80
80
  servers.stubs(:create).with(args).returns(vm)
81
81
  cr.stubs(:find_vm_by_uuid).with((args[:vmid]).to_s).returns(vm)
@@ -84,12 +84,12 @@ module ForemanFogProxmox
84
84
  end
85
85
 
86
86
  it 'creates server within pool' do
87
- args = { vmid: '100', type: 'qemu', node_id: 'pve', start_after_create: '0', pool: 'pool1' }
87
+ args = { vmid: '100', type: 'qemu', node_id: 'proxmox', start_after_create: '0', pool: 'pool1' }
88
88
  servers = mock('servers')
89
89
  servers.stubs(:id_valid?).returns(true)
90
90
  cr = mock_node_servers(ForemanFogProxmox::Proxmox.new, servers)
91
91
  cr.stubs(:convert_sizes).with(args)
92
- cr.stubs(:parse_server_vm).with(args).returns(args)
92
+ cr.stubs(:parse_typed_vm).with(args, 'qemu').returns(args)
93
93
  vm = mock('vm')
94
94
  servers.stubs(:create).with(args).returns(vm)
95
95
  cr.stubs(:find_vm_by_uuid).with((args[:vmid]).to_s).returns(vm)
@@ -0,0 +1,181 @@
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
+ require 'test_plugin_helper'
21
+ require 'models/compute_resources/compute_resource_test_helpers'
22
+ require 'factories/foreman_fog_proxmox/proxmox_node_mock_factory'
23
+ require 'factories/foreman_fog_proxmox/proxmox_server_mock_factory'
24
+ require 'active_support/core_ext/hash/indifferent_access'
25
+
26
+ module ForemanFogProxmox
27
+ class ProxmoxVmCommandsServerUpdateTest < ActiveSupport::TestCase
28
+ include ComputeResourceTestHelpers
29
+ include ProxmoxNodeMockFactory
30
+ include ProxmoxServerMockFactory
31
+ include ProxmoxVmHelper
32
+
33
+ describe 'save_vm' do
34
+ before do
35
+ @cr = FactoryBot.build_stubbed(:proxmox_cr)
36
+ end
37
+
38
+ it 'saves modified server config with added cdrom' do
39
+ uuid = '100'
40
+ config = mock('config')
41
+ disks = mock('disks')
42
+ disk = mock('disk')
43
+ disk.stubs(:storage).returns('local-lvm')
44
+ disk.stubs(:id).returns('ide2')
45
+ disks.stubs(:get).returns
46
+ config.stubs(:disks).returns(disks)
47
+ config.stubs(:attributes).returns(:cores => '')
48
+ vm = mock('vm')
49
+ vm.stubs(:identity).returns(uuid)
50
+ vm.stubs(:attributes).returns('' => '')
51
+ vm.stubs(:config).returns(config)
52
+ vm.stubs(:container?).returns(false)
53
+ vm.stubs(:type).returns('qemu')
54
+ vm.stubs(:node_id).returns('proxmox')
55
+ @cr.stubs(:find_vm_by_uuid).returns(vm)
56
+ new_attributes = {
57
+ 'templated' => '0',
58
+ 'node_id' => 'proxmox',
59
+ 'config_attributes' => {
60
+ 'cores' => '1',
61
+ 'cpulimit' => '1'
62
+ },
63
+ 'volumes_attributes' => {
64
+ '0' => {
65
+ 'id' => 'ide2',
66
+ '_delete' => '',
67
+ 'device' => '2',
68
+ 'controller' => 'ide',
69
+ 'storage_type' => 'cdrom',
70
+ 'storage' => 'local-lvm',
71
+ 'cdrom' => 'image',
72
+ 'volid' => 'local-lvm:iso/ubuntu-20_4.iso'
73
+ }
74
+ }
75
+ }.with_indifferent_access
76
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0')
77
+ expected_config_attr = { :cores => '1', :cpulimit => '1' }
78
+ expected_volume_attr = { id: 'ide2', storage: 'local:lvm', volid: 'local-lvm:iso/ubuntu-20_4.iso', media: 'cdrom' }
79
+ vm.expects(:attach, expected_volume_attr)
80
+ vm.expects(:update, expected_config_attr)
81
+ @cr.save_vm(uuid, new_attributes)
82
+ end
83
+
84
+ it 'saves modified server config with removed cdrom' do
85
+ uuid = '100'
86
+ config = mock('config')
87
+ disks = mock('disks')
88
+ disk = mock('disk')
89
+ disk.stubs(:size).returns(1_073_741_824)
90
+ disk.stubs(:storage).returns('local-lvm')
91
+ disk.stubs(:volid).returns('local-lvm:iso/ubuntu-20_4.iso')
92
+ disk.stubs(:media).returns('cdrom')
93
+ disk.stubs(:id).returns('ide2')
94
+ disks.stubs(:get).returns(disk)
95
+ config.stubs(:disks).returns(disks)
96
+ config.stubs(:attributes).returns(:cores => '')
97
+ vm = mock('vm')
98
+ vm.stubs(:identity).returns(uuid)
99
+ vm.stubs(:attributes).returns('ide2' => '')
100
+ vm.stubs(:config).returns(config)
101
+ vm.stubs(:container?).returns(false)
102
+ vm.stubs(:templated?).returns(false)
103
+ vm.stubs(:type).returns('qemu')
104
+ vm.stubs(:node_id).returns('proxmox')
105
+ @cr.stubs(:find_vm_by_uuid).returns(vm)
106
+ new_attributes = {
107
+ 'templated' => '0',
108
+ 'node_id' => 'proxmox',
109
+ 'config_attributes' => {
110
+ 'cores' => '1',
111
+ 'cpulimit' => '1'
112
+ },
113
+ 'volumes_attributes' => {
114
+ '0' => {
115
+ 'id' => 'ide2',
116
+ '_delete' => '1',
117
+ 'device' => '2',
118
+ 'controller' => 'ide',
119
+ 'storage_type' => 'cdrom',
120
+ 'cdrom' => 'none'
121
+ }
122
+ }
123
+ }.with_indifferent_access
124
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'config_attributes' => { 'onboot' => '0' })
125
+ expected_config_attr = { :cores => '1', :cpulimit => '1' }
126
+ expected_volume_attr = 'ide2'
127
+ vm.expects(:detach, expected_volume_attr)
128
+ vm.expects(:update, expected_config_attr)
129
+ @cr.save_vm(uuid, new_attributes)
130
+ end
131
+
132
+ it 'saves modified server config with modified cdrom from image into physical' do
133
+ uuid = '100'
134
+ config = mock('config')
135
+ disks = mock('disks')
136
+ disk = mock('disk')
137
+ disk.stubs(:size).returns(1_073_741_824)
138
+ disk.stubs(:storage).returns('local-lvm')
139
+ disk.stubs(:volid).returns('local-lvm:iso/ubuntu-20_4.iso')
140
+ disk.stubs(:media).returns('cdrom')
141
+ disk.stubs(:id).returns('ide2')
142
+ disk.stubs(:attributes).returns(id: 'ide2', storage: 'local-lvm', volid: 'local-lvm:vm-100-disk-0', size: 1_073_741_824)
143
+ disks.stubs(:get).returns(disk)
144
+ config.stubs(:disks).returns(disks)
145
+ config.stubs(:attributes).returns(:cores => '')
146
+ vm = mock('vm')
147
+ vm.stubs(:identity).returns(uuid)
148
+ vm.stubs(:attributes).returns('ide2' => '')
149
+ vm.stubs(:config).returns(config)
150
+ vm.stubs(:container?).returns(false)
151
+ vm.stubs(:type).returns('qemu')
152
+ vm.stubs(:node_id).returns('proxmox')
153
+ @cr.stubs(:find_vm_by_uuid).returns(vm)
154
+ new_attributes = {
155
+ 'templated' => '0',
156
+ 'node_id' => 'proxmox',
157
+ 'config_attributes' => {
158
+ 'cores' => '1',
159
+ 'cpulimit' => '1'
160
+ },
161
+ 'volumes_attributes' => {
162
+ '0' => {
163
+ 'id' => 'ide2',
164
+ '_delete' => '',
165
+ 'device' => '2',
166
+ 'controller' => 'ide',
167
+ 'storage_type' => 'cdrom',
168
+ 'cdrom' => 'cdrom'
169
+ }
170
+ }
171
+ }.with_indifferent_access
172
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
173
+ expected_config_attr = { :cores => '1', :cpulimit => '1' }
174
+ expected_volume_attr = { :id => 'ide2', :cdrom => 'cdrom' }
175
+ vm.expects(:attach, expected_volume_attr)
176
+ vm.expects(:update, expected_config_attr)
177
+ @cr.save_vm(uuid, new_attributes)
178
+ end
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,131 @@
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
+ require 'test_plugin_helper'
21
+ require 'models/compute_resources/compute_resource_test_helpers'
22
+ require 'factories/foreman_fog_proxmox/proxmox_node_mock_factory'
23
+ require 'factories/foreman_fog_proxmox/proxmox_server_mock_factory'
24
+ require 'active_support/core_ext/hash/indifferent_access'
25
+
26
+ module ForemanFogProxmox
27
+ class ProxmoxVmCommandsServerUpdateTest < ActiveSupport::TestCase
28
+ include ComputeResourceTestHelpers
29
+ include ProxmoxNodeMockFactory
30
+ include ProxmoxServerMockFactory
31
+ include ProxmoxVmHelper
32
+
33
+ describe 'save_vm' do
34
+ before do
35
+ @cr = FactoryBot.build_stubbed(:proxmox_cr)
36
+ end
37
+
38
+ it 'saves modified server config with added cloudinit' do
39
+ uuid = '100'
40
+ config = mock('config')
41
+ disks = mock('disks')
42
+ disk = mock('disk')
43
+ disk.stubs(:storage).returns('local-lvm')
44
+ disk.stubs(:id).returns('ide0')
45
+ disks.stubs(:get).returns
46
+ config.stubs(:disks).returns(disks)
47
+ config.stubs(:attributes).returns(:cores => '')
48
+ vm = mock('vm')
49
+ vm.stubs(:identity).returns(uuid)
50
+ vm.stubs(:attributes).returns('' => '')
51
+ vm.stubs(:config).returns(config)
52
+ vm.stubs(:container?).returns(false)
53
+ vm.stubs(:type).returns('qemu')
54
+ vm.stubs(:node_id).returns('proxmox')
55
+ @cr.stubs(:find_vm_by_uuid).returns(vm)
56
+ new_attributes = {
57
+ 'templated' => '0',
58
+ 'node_id' => 'proxmox',
59
+ 'config_attributes' => {
60
+ 'cores' => '1',
61
+ 'cpulimit' => '1'
62
+ },
63
+ 'volumes_attributes' => {
64
+ '0' => {
65
+ 'id' => 'ide2',
66
+ '_delete' => '',
67
+ 'device' => '0',
68
+ 'controller' => 'ide',
69
+ 'storage_type' => 'cloud_init',
70
+ 'storage' => 'local-lvm',
71
+ 'volid' => 'local-lvm:cloudinit'
72
+ }
73
+ }
74
+ }.with_indifferent_access
75
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0')
76
+ expected_config_attr = { :cores => '1', :cpulimit => '1' }
77
+ expected_volume_attr = { id: 'ide0', storage: 'local:lvm', volid: 'local-lvm:cloudinit', media: 'cdrom' }
78
+ vm.expects(:attach, expected_volume_attr)
79
+ vm.expects(:update, expected_config_attr)
80
+ @cr.save_vm(uuid, new_attributes)
81
+ end
82
+
83
+ it 'saves modified server config with removed cdrom' do
84
+ uuid = '100'
85
+ config = mock('config')
86
+ disks = mock('disks')
87
+ disk = mock('disk')
88
+ disk.stubs(:size).returns(1_073_741_824)
89
+ disk.stubs(:storage).returns('local-lvm')
90
+ disk.stubs(:volid).returns('local-lvm:vm-100-cloudinit')
91
+ disk.stubs(:media).returns('cdrom')
92
+ disk.stubs(:id).returns('ide0')
93
+ disks.stubs(:get).returns(disk)
94
+ config.stubs(:disks).returns(disks)
95
+ config.stubs(:attributes).returns(:cores => '')
96
+ vm = mock('vm')
97
+ vm.stubs(:identity).returns(uuid)
98
+ vm.stubs(:attributes).returns('ide0' => '')
99
+ vm.stubs(:config).returns(config)
100
+ vm.stubs(:container?).returns(false)
101
+ vm.stubs(:templated?).returns(false)
102
+ vm.stubs(:type).returns('qemu')
103
+ vm.stubs(:node_id).returns('proxmox')
104
+ @cr.stubs(:find_vm_by_uuid).returns(vm)
105
+ new_attributes = {
106
+ 'templated' => '0',
107
+ 'node_id' => 'proxmox',
108
+ 'config_attributes' => {
109
+ 'cores' => '1',
110
+ 'cpulimit' => '1'
111
+ },
112
+ 'volumes_attributes' => {
113
+ '0' => {
114
+ 'id' => 'ide0',
115
+ '_delete' => '1',
116
+ 'device' => '0',
117
+ 'controller' => 'ide',
118
+ 'storage_type' => 'cloud_init'
119
+ }
120
+ }
121
+ }.with_indifferent_access
122
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'config_attributes' => { 'onboot' => '0' })
123
+ expected_config_attr = { :cores => '1', :cpulimit => '1' }
124
+ expected_volume_attr = 'ide0'
125
+ vm.expects(:detach, expected_volume_attr)
126
+ vm.expects(:update, expected_config_attr)
127
+ @cr.save_vm(uuid, new_attributes)
128
+ end
129
+ end
130
+ end
131
+ end
@@ -43,18 +43,21 @@ module ForemanFogProxmox
43
43
  disk.stubs(:size).returns(1_073_741_824)
44
44
  disk.stubs(:storage).returns('local-lvm')
45
45
  disk.stubs(:id).returns('scsi0')
46
+ disk.stubs(:attributes).returns(id: 'scsi0', storage: 'local-lvm', size: 1_073_741_824)
46
47
  disks.stubs(:get).returns
47
48
  config.stubs(:disks).returns(disks)
48
49
  config.stubs(:attributes).returns(:cores => '')
49
50
  vm = mock('vm')
51
+ vm.stubs(:identity).returns(uuid)
52
+ vm.stubs(:attributes).returns('' => '')
50
53
  vm.stubs(:config).returns(config)
51
54
  vm.stubs(:container?).returns(false)
52
55
  vm.stubs(:type).returns('qemu')
53
- vm.stubs(:node_id).returns('pve')
56
+ vm.stubs(:node_id).returns('proxmox')
54
57
  @cr.stubs(:find_vm_by_uuid).returns(vm)
55
58
  new_attributes = {
56
59
  'templated' => '0',
57
- 'node_id' => 'pve',
60
+ 'node_id' => 'proxmox',
58
61
  'config_attributes' => {
59
62
  'cores' => '1',
60
63
  'cpulimit' => '1'
@@ -65,13 +68,14 @@ module ForemanFogProxmox
65
68
  '_delete' => '',
66
69
  'device' => '0',
67
70
  'controller' => 'scsi',
71
+ 'storage_type' => 'hard_disk',
68
72
  'storage' => 'local-lvm',
69
73
  'size' => '2147483648',
70
74
  'cache' => 'none'
71
75
  }
72
76
  }
73
77
  }.with_indifferent_access
74
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'pve', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0')
78
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0')
75
79
  expected_config_attr = { :cores => '1', :cpulimit => '1' }
76
80
  expected_volume_attr = { id: 'scsi0', storage: 'local:lvm', size: (2_147_483_648 / GIGA).to_s }
77
81
  vm.expects(:attach, expected_volume_attr)
@@ -91,15 +95,17 @@ module ForemanFogProxmox
91
95
  config.stubs(:disks).returns(disks)
92
96
  config.stubs(:attributes).returns(:cores => '')
93
97
  vm = mock('vm')
98
+ vm.stubs(:identity).returns(uuid)
99
+ vm.stubs(:attributes).returns('scsi0' => '')
94
100
  vm.stubs(:config).returns(config)
95
101
  vm.stubs(:container?).returns(false)
96
102
  vm.stubs(:templated?).returns(false)
97
103
  vm.stubs(:type).returns('qemu')
98
- vm.stubs(:node_id).returns('pve')
104
+ vm.stubs(:node_id).returns('proxmox')
99
105
  @cr.stubs(:find_vm_by_uuid).returns(vm)
100
106
  new_attributes = {
101
107
  'templated' => '0',
102
- 'node_id' => 'pve',
108
+ 'node_id' => 'proxmox',
103
109
  'config_attributes' => {
104
110
  'cores' => '1',
105
111
  'cpulimit' => '1'
@@ -108,6 +114,7 @@ module ForemanFogProxmox
108
114
  '0' => {
109
115
  '_delete' => '1',
110
116
  'id' => 'scsi0',
117
+ 'storage_type' => 'hard_disk',
111
118
  'volid' => 'local-lvm:vm-100-disk-0',
112
119
  'device' => '0',
113
120
  'controller' => 'scsi',
@@ -117,7 +124,7 @@ module ForemanFogProxmox
117
124
  }
118
125
  }
119
126
  }.with_indifferent_access
120
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'pve', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'config_attributes' => { 'onboot' => '0' })
127
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'config_attributes' => { 'onboot' => '0' })
121
128
  expected_config_attr = { :cores => '1', :cpulimit => '1' }
122
129
  expected_volume_attr = 'scsi0'
123
130
  vm.expects(:detach, expected_volume_attr)
@@ -132,20 +139,24 @@ module ForemanFogProxmox
132
139
  disks = mock('disks')
133
140
  disk = mock('disk')
134
141
  disk.stubs(:size).returns(1_073_741_824)
135
- disk.stubs(:storage).returns('local-lvm')
142
+ disk.stubs(:storage).returns('scsi0')
143
+ disk.stubs(:id).returns('local-lvm')
144
+ disk.stubs(:attributes).returns(id: 'scsi0', storage: 'local-lvm', size: 1_073_741_824)
136
145
  disks.stubs(:get).returns(disk)
137
146
  config.stubs(:disks).returns(disks)
138
147
  config.stubs(:attributes).returns(:cores => '')
139
148
  vm = mock('vm')
149
+ vm.stubs(:identity).returns(uuid)
150
+ vm.stubs(:attributes).returns('scsi0' => '')
140
151
  vm.stubs(:config).returns(config)
141
152
  vm.stubs(:container?).returns(false)
142
153
  vm.stubs(:templated?).returns(false)
143
154
  vm.stubs(:type).returns('qemu')
144
- vm.stubs(:node_id).returns('pve')
155
+ vm.stubs(:node_id).returns('proxmox')
145
156
  @cr.stubs(:find_vm_by_uuid).returns(vm)
146
157
  new_attributes = {
147
158
  'templated' => '0',
148
- 'node_id' => 'pve',
159
+ 'node_id' => 'proxmox',
149
160
  'config_attributes' => {
150
161
  'cores' => '1',
151
162
  'cpulimit' => '1'
@@ -154,6 +165,7 @@ module ForemanFogProxmox
154
165
  '0' => {
155
166
  'id' => 'scsi0',
156
167
  '_delete' => '',
168
+ 'storage_type' => 'hard_disk',
157
169
  'volid' => 'local-lvm:vm-100-disk-0',
158
170
  'device' => '0',
159
171
  'controller' => 'scsi',
@@ -163,7 +175,7 @@ module ForemanFogProxmox
163
175
  }
164
176
  }
165
177
  }.with_indifferent_access
166
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'pve', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
178
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
167
179
  expected_config_attr = { :cores => '1', :cpulimit => '1' }
168
180
  expected_volume_attr = ['scsi0', '+1G']
169
181
  vm.expects(:extend, expected_volume_attr)
@@ -176,20 +188,24 @@ module ForemanFogProxmox
176
188
  config = mock('config')
177
189
  disks = mock('disks')
178
190
  disk = mock('disk')
191
+ disk.stubs(:id).returns('scsi0')
179
192
  disk.stubs(:size).returns(1_073_741_824)
180
193
  disk.stubs(:storage).returns('local-lvm')
194
+ disk.stubs(:attributes).returns(id: 'scsi0', storage: 'local-lvm', size: 1_073_741_824)
181
195
  disks.stubs(:get).returns(disk)
182
196
  config.stubs(:disks).returns(disks)
183
197
  config.stubs(:attributes).returns(:cores => '')
184
198
  vm = mock('vm')
199
+ vm.stubs(:identity).returns(uuid)
200
+ vm.stubs(:attributes).returns('scsi0' => '')
185
201
  vm.stubs(:config).returns(config)
186
202
  vm.stubs(:container?).returns(false)
187
203
  vm.stubs(:type).returns('qemu')
188
- vm.stubs(:node_id).returns('pve')
204
+ vm.stubs(:node_id).returns('proxmox')
189
205
  @cr.stubs(:find_vm_by_uuid).returns(vm)
190
206
  new_attributes = {
191
207
  'templated' => '0',
192
- 'node_id' => 'pve',
208
+ 'node_id' => 'proxmox',
193
209
  'config_attributes' => {
194
210
  'cores' => '1',
195
211
  'cpulimit' => '1'
@@ -198,6 +214,7 @@ module ForemanFogProxmox
198
214
  '0' => {
199
215
  'id' => 'scsi0',
200
216
  '_delete' => '',
217
+ 'storage_type' => 'hard_disk',
201
218
  'volid' => 'local-lvm:vm-100-disk-0',
202
219
  'device' => '0',
203
220
  'controller' => 'scsi',
@@ -207,7 +224,7 @@ module ForemanFogProxmox
207
224
  }
208
225
  }
209
226
  }.with_indifferent_access
210
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'pve', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
227
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
211
228
  err = assert_raises Foreman::Exception do
212
229
  @cr.save_vm(uuid, new_attributes)
213
230
  end
@@ -219,20 +236,24 @@ module ForemanFogProxmox
219
236
  config = mock('config')
220
237
  disks = mock('disks')
221
238
  disk = mock('disk')
239
+ disk.stubs(:id).returns('scsi0')
222
240
  disk.stubs(:size).returns(1_073_741_824)
223
241
  disk.stubs(:storage).returns('local-lvm')
242
+ disk.stubs(:attributes).returns(id: 'scsi0', storage: 'local-lvm', size: 1_073_741_824)
224
243
  disks.stubs(:get).returns(disk)
225
244
  config.stubs(:disks).returns(disks)
226
245
  config.stubs(:attributes).returns(:cores => '')
227
246
  vm = mock('vm')
247
+ vm.stubs(:identity).returns(uuid)
248
+ vm.stubs(:attributes).returns('scsi0' => '')
228
249
  vm.stubs(:config).returns(config)
229
250
  vm.stubs(:container?).returns(false)
230
251
  vm.stubs(:type).returns('qemu')
231
- vm.stubs(:node_id).returns('pve')
252
+ vm.stubs(:node_id).returns('proxmox')
232
253
  @cr.stubs(:find_vm_by_uuid).returns(vm)
233
254
  new_attributes = {
234
255
  'templated' => '0',
235
- 'node_id' => 'pve',
256
+ 'node_id' => 'proxmox',
236
257
  'config_attributes' => {
237
258
  'cores' => '1',
238
259
  'cpulimit' => '1'
@@ -241,6 +262,7 @@ module ForemanFogProxmox
241
262
  '0' => {
242
263
  'id' => 'scsi0',
243
264
  '_delete' => '',
265
+ 'storage_type' => 'hard_disk',
244
266
  'volid' => 'local-lvm:vm-100-disk-0',
245
267
  'device' => '0',
246
268
  'controller' => 'scsi',
@@ -250,7 +272,7 @@ module ForemanFogProxmox
250
272
  }
251
273
  }
252
274
  }.with_indifferent_access
253
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'pve', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
275
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
254
276
  expected_config_attr = { :cores => '1', :cpulimit => '1' }
255
277
  expected_volume_attr = ['scsi0', 'local-lvm2']
256
278
  vm.expects(:move, expected_volume_attr)
@@ -267,18 +289,21 @@ module ForemanFogProxmox
267
289
  disk.stubs(:storage).returns('local-lvm')
268
290
  disk.stubs(:volid).returns('local-lvm:vm-100-disk-0')
269
291
  disk.stubs(:id).returns('scsi0')
292
+ disk.stubs(:attributes).returns(id: 'scsi0', storage: 'local-lvm', volid: 'local-lvm:vm-100-disk-0', size: 1_073_741_824)
270
293
  disks.stubs(:get).returns(disk)
271
294
  config.stubs(:disks).returns(disks)
272
295
  config.stubs(:attributes).returns(:cores => '')
273
296
  vm = mock('vm')
297
+ vm.stubs(:identity).returns(uuid)
298
+ vm.stubs(:attributes).returns('scsi0' => '')
274
299
  vm.stubs(:config).returns(config)
275
300
  vm.stubs(:container?).returns(false)
276
301
  vm.stubs(:type).returns('qemu')
277
- vm.stubs(:node_id).returns('pve')
302
+ vm.stubs(:node_id).returns('proxmox')
278
303
  @cr.stubs(:find_vm_by_uuid).returns(vm)
279
304
  new_attributes = {
280
305
  'templated' => '0',
281
- 'node_id' => 'pve',
306
+ 'node_id' => 'proxmox',
282
307
  'config_attributes' => {
283
308
  'cores' => '1',
284
309
  'cpulimit' => '1'
@@ -287,6 +312,7 @@ module ForemanFogProxmox
287
312
  '0' => {
288
313
  'id' => 'scsi0',
289
314
  '_delete' => '',
315
+ 'storage_type' => 'hard_disk',
290
316
  'volid' => 'local-lvm:vm-100-disk-0',
291
317
  'device' => '0',
292
318
  'controller' => 'scsi',
@@ -296,7 +322,7 @@ module ForemanFogProxmox
296
322
  }
297
323
  }
298
324
  }.with_indifferent_access
299
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'pve', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
325
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
300
326
  expected_config_attr = { :cores => '1', :cpulimit => '1' }
301
327
  expected_volume_attr = { :id => 'scsi0', :volid => 'local-lvm:vm-100-disk-0', :size => 1_073_741_824 }, { :cache => 'directsync' }
302
328
  vm.expects(:attach, expected_volume_attr)