foreman_fog_proxmox 0.12.1 → 0.13.2

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 +25 -6
  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 +47 -26
  85. data/app/helpers/proxmox_container_helper.rb +0 -163
  86. data/app/helpers/proxmox_server_helper.rb +0 -155
@@ -44,9 +44,9 @@ module ForemanFogProxmox
44
44
  vm.stubs(:container?).returns(false)
45
45
  vm.stubs(:templated?).returns(false)
46
46
  vm.stubs(:type).returns('qemu')
47
- vm.stubs(:node_id).returns('pve')
47
+ vm.stubs(:node_id).returns('proxmox')
48
48
  @cr.stubs(:find_vm_by_uuid).returns(vm)
49
- attr = { 'templated' => '0', 'node_id' => 'pve2' }
49
+ attr = { 'templated' => '0', 'node_id' => 'proxmox2' }
50
50
  vm.expects(:migrate)
51
51
  @cr.save_vm(uuid, attr)
52
52
  end
@@ -60,10 +60,10 @@ module ForemanFogProxmox
60
60
  vm.stubs(:container?).returns(false)
61
61
  vm.stubs(:templated?).returns(false)
62
62
  vm.stubs(:type).returns('qemu')
63
- vm.stubs(:node_id).returns('pve')
63
+ vm.stubs(:node_id).returns('proxmox')
64
64
  @cr.stubs(:find_vm_by_uuid).returns(vm)
65
- attr = { 'templated' => '0', 'node_id' => 'pve', 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' } }.with_indifferent_access
66
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'pve', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0')
65
+ attr = { 'templated' => '0', 'node_id' => 'proxmox', 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' } }.with_indifferent_access
66
+ @cr.stubs(:parse_typed_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0')
67
67
  expected_attr = { :cores => '1', :cpulimit => '1' }.with_indifferent_access
68
68
  vm.expects(:update, expected_attr)
69
69
  @cr.save_vm(uuid, attr)
@@ -97,11 +97,11 @@ module ForemanFogProxmox
97
97
  vm.stubs(:config).returns(config)
98
98
  vm.stubs(:container?).returns(false)
99
99
  vm.stubs(:type).returns('qemu')
100
- vm.stubs(:node_id).returns('pve')
100
+ vm.stubs(:node_id).returns('proxmox')
101
101
  @cr.stubs(:find_vm_by_uuid).returns(vm)
102
102
  new_attributes = {
103
103
  'templated' => '0',
104
- 'node_id' => 'pve',
104
+ 'node_id' => 'proxmox',
105
105
  'config_attributes' => {
106
106
  'cores' => '1',
107
107
  'cpulimit' => '1'
@@ -113,9 +113,9 @@ module ForemanFogProxmox
113
113
  }
114
114
  }
115
115
  }.with_indifferent_access
116
- @cr.stubs(:parse_server_vm).returns(
116
+ @cr.stubs(:parse_typed_vm).returns(
117
117
  'vmid' => '100',
118
- 'node_id' => 'pve',
118
+ 'node_id' => 'proxmox',
119
119
  'type' => 'qemu',
120
120
  'cores' => '1',
121
121
  'cpulimit' => '1',
@@ -136,7 +136,7 @@ module ForemanFogProxmox
136
136
  vm.stubs(:config).returns(config)
137
137
  vm.stubs(:container?).returns(false)
138
138
  vm.stubs(:type).returns('qemu')
139
- vm.stubs(:node_id).returns('pve')
139
+ vm.stubs(:node_id).returns('proxmox')
140
140
  vm.stubs(:vmid).returns(uuid)
141
141
  @cr.stubs(:find_vm_by_uuid).returns(vm)
142
142
  identity_client = mock('identity_client')
@@ -154,9 +154,9 @@ module ForemanFogProxmox
154
154
  pools.expects(:get).with('pool2').returns(pool2)
155
155
  identity_client.stubs(:pools).returns(pools)
156
156
  @cr.stubs(:identity_client).returns(identity_client)
157
- attr = { 'templated' => '0', 'node_id' => 'pve', 'pool' => 'pool2', 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' } }.with_indifferent_access
158
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'pve', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0', 'pool' => 'pool2')
159
- vm.expects(:update).with({ 'node_id' => 'pve', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' }.with_indifferent_access)
157
+ attr = { 'templated' => '0', 'node_id' => 'proxmox', 'pool' => 'pool2', 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' } }.with_indifferent_access
158
+ @cr.stubs(:parse_typed_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0', 'pool' => 'pool2')
159
+ vm.expects(:update).with({ 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' }.with_indifferent_access)
160
160
  @cr.save_vm(uuid, attr)
161
161
  end
162
162
 
@@ -169,7 +169,7 @@ module ForemanFogProxmox
169
169
  vm.stubs(:config).returns(config)
170
170
  vm.stubs(:container?).returns(false)
171
171
  vm.stubs(:type).returns('qemu')
172
- vm.stubs(:node_id).returns('pve')
172
+ vm.stubs(:node_id).returns('proxmox')
173
173
  vm.stubs(:vmid).returns(uuid)
174
174
  @cr.stubs(:find_vm_by_uuid).returns(vm)
175
175
  identity_client = mock('identity_client')
@@ -183,9 +183,9 @@ module ForemanFogProxmox
183
183
  pools.expects(:get).with('').returns(nil)
184
184
  identity_client.stubs(:pools).returns(pools)
185
185
  @cr.stubs(:identity_client).returns(identity_client)
186
- attr = { 'templated' => '0', 'node_id' => 'pve', 'pool' => '', 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' } }.with_indifferent_access
187
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'pve', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0', 'pool' => '')
188
- vm.expects(:update).with({ 'node_id' => 'pve', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' }.with_indifferent_access)
186
+ attr = { 'templated' => '0', 'node_id' => 'proxmox', 'pool' => '', 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' } }.with_indifferent_access
187
+ @cr.stubs(:parse_typed_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0', 'pool' => '')
188
+ vm.expects(:update).with({ 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' }.with_indifferent_access)
189
189
  @cr.save_vm(uuid, attr)
190
190
  end
191
191
 
@@ -198,7 +198,7 @@ module ForemanFogProxmox
198
198
  vm.stubs(:config).returns(config)
199
199
  vm.stubs(:container?).returns(false)
200
200
  vm.stubs(:type).returns('qemu')
201
- vm.stubs(:node_id).returns('pve')
201
+ vm.stubs(:node_id).returns('proxmox')
202
202
  vm.stubs(:vmid).returns(uuid)
203
203
  @cr.stubs(:find_vm_by_uuid).returns(vm)
204
204
  identity_client = mock('identity_client')
@@ -212,9 +212,9 @@ module ForemanFogProxmox
212
212
  pools.expects(:get).with('').returns(nil)
213
213
  identity_client.stubs(:pools).returns(pools)
214
214
  @cr.stubs(:identity_client).returns(identity_client)
215
- attr = { 'templated' => '0', 'node_id' => 'pve', 'pool' => 'pool2', 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' } }.with_indifferent_access
216
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'pve', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0', 'pool' => 'pool2')
217
- vm.expects(:update).with({ 'node_id' => 'pve', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' }.with_indifferent_access)
215
+ attr = { 'templated' => '0', 'node_id' => 'proxmox', 'pool' => 'pool2', 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' } }.with_indifferent_access
216
+ @cr.stubs(:parse_typed_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0', 'pool' => 'pool2')
217
+ vm.expects(:update).with({ 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' }.with_indifferent_access)
218
218
  @cr.save_vm(uuid, attr)
219
219
  end
220
220
  end
@@ -43,7 +43,7 @@ module ForemanFogProxmox
43
43
  config = mock('config')
44
44
  config.stubs(:inspect).returns('config')
45
45
  vm.stubs(:config).returns(config)
46
- @cr.stubs(:new_server_vm).with(attr).returns(vm)
46
+ @cr.stubs(:new_typed_vm).with(attr, 'qemu').returns(vm)
47
47
  assert_equal vm, @cr.new_vm(attr)
48
48
  end
49
49
 
@@ -53,7 +53,7 @@ module ForemanFogProxmox
53
53
  config = mock('config')
54
54
  config.stubs(:inspect).returns('config')
55
55
  vm.stubs(:config).returns(config)
56
- @cr.stubs(:new_server_vm).with(attr).returns(vm)
56
+ @cr.stubs(:new_typed_vm).with(attr, 'qemu').returns(vm)
57
57
  assert_equal vm, @cr.new_vm(attr)
58
58
  end
59
59
 
@@ -63,7 +63,7 @@ module ForemanFogProxmox
63
63
  config = mock('config')
64
64
  config.stubs(:inspect).returns('config')
65
65
  vm.stubs(:config).returns(config)
66
- @cr.stubs(:new_container_vm).with(attr).returns(vm)
66
+ @cr.stubs(:new_typed_vm).with(attr, 'lxc').returns(vm)
67
67
  assert_equal vm, @cr.new_vm(attr)
68
68
  end
69
69
  end
@@ -35,14 +35,14 @@ module ForemanFogProxmox
35
35
  describe 'find_vm_by_uuid' do
36
36
  it 'returns nil when the uuid does not match' do
37
37
  cr = mock_node_servers_containers(ForemanFogProxmox::Proxmox.new, empty_servers, empty_servers)
38
- assert cr.find_vm_by_uuid('100').nil?
38
+ assert cr.find_vm_by_uuid('1_100').nil?
39
39
  end
40
40
 
41
41
  it 'raises RecordNotFound when the compute raises error' do
42
42
  exception = Fog::Errors::Error.new
43
43
  cr = mock_node_servers(ForemanFogProxmox::Proxmox.new, servers_raising_exception(exception))
44
44
  assert_raises ActiveRecord::RecordNotFound do
45
- cr.find_vm_by_uuid('100')
45
+ cr.find_vm_by_uuid('1_100')
46
46
  end
47
47
  end
48
48
 
@@ -61,7 +61,7 @@ module ForemanFogProxmox
61
61
  empty_servers, empty_servers, # node1
62
62
  servers, empty_servers # node2
63
63
  )
64
- assert_equal vm, cr.find_vm_by_uuid(args[:vmid])
64
+ assert_equal vm, cr.find_vm_by_uuid('1_' + args[:vmid])
65
65
  end
66
66
  end
67
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_fog_proxmox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Robert
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-07-22 00:00:00.000000000 Z
12
+ date: 2021-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: deface
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '0.13'
34
+ version: '0.14'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '0.13'
41
+ version: '0.14'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rdoc
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -97,20 +97,30 @@ files:
97
97
  - app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js
98
98
  - app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_container.js
99
99
  - app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js
100
+ - app/assets/javascripts/foreman_fog_proxmox/proxmox_volume.js
101
+ - app/assets/javascripts/foreman_fog_proxmox/proxmox_volume_cdrom.js
102
+ - app/assets/javascripts/foreman_fog_proxmox/proxmox_volume_cloudinit.js
100
103
  - app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb
101
104
  - app/controllers/foreman_fog_proxmox/compute_resources_controller.rb
102
105
  - app/helpers/node_dashboard_helper.rb
106
+ - app/helpers/proxmox_compute_controllers_helper.rb
107
+ - app/helpers/proxmox_compute_resources_helper.rb
103
108
  - app/helpers/proxmox_compute_selectors_helper.rb
104
- - app/helpers/proxmox_container_helper.rb
105
109
  - app/helpers/proxmox_form_helper.rb
106
- - app/helpers/proxmox_server_helper.rb
110
+ - app/helpers/proxmox_storages_helper.rb
111
+ - app/helpers/proxmox_vm_cdrom_helper.rb
112
+ - app/helpers/proxmox_vm_cloudinit_helper.rb
113
+ - app/helpers/proxmox_vm_config_helper.rb
107
114
  - app/helpers/proxmox_vm_helper.rb
115
+ - app/helpers/proxmox_vm_interfaces_helper.rb
116
+ - app/helpers/proxmox_vm_os_template_helper.rb
117
+ - app/helpers/proxmox_vm_uuid_helper.rb
118
+ - app/helpers/proxmox_vm_volumes_helper.rb
108
119
  - app/models/concerns/fog_extensions/proxmox/disk.rb
109
120
  - app/models/concerns/fog_extensions/proxmox/interface.rb
110
121
  - app/models/concerns/fog_extensions/proxmox/node.rb
111
122
  - app/models/concerns/fog_extensions/proxmox/server.rb
112
123
  - app/models/concerns/fog_extensions/proxmox/server_config.rb
113
- - app/models/concerns/fog_extensions/proxmox/volume.rb
114
124
  - app/models/concerns/host_ext/proxmox/interfaces.rb
115
125
  - app/models/concerns/orchestration/proxmox/compute.rb
116
126
  - app/models/foreman_fog_proxmox/options_select.rb
@@ -122,7 +132,6 @@ files:
122
132
  - app/models/foreman_fog_proxmox/proxmox_interfaces.rb
123
133
  - app/models/foreman_fog_proxmox/proxmox_operating_systems.rb
124
134
  - app/models/foreman_fog_proxmox/proxmox_pools.rb
125
- - app/models/foreman_fog_proxmox/proxmox_token_expiration.rb
126
135
  - app/models/foreman_fog_proxmox/proxmox_version.rb
127
136
  - app/models/foreman_fog_proxmox/proxmox_vm_commands.rb
128
137
  - app/models/foreman_fog_proxmox/proxmox_vm_new.rb
@@ -162,14 +171,18 @@ files:
162
171
  - app/views/compute_resources_vms/form/proxmox/server/_advanced.html.erb
163
172
  - app/views/compute_resources_vms/form/proxmox/server/_config.html.erb
164
173
  - app/views/compute_resources_vms/form/proxmox/server/_network.html.erb
165
- - app/views/compute_resources_vms/form/proxmox/server/_volume.html.erb
174
+ - app/views/compute_resources_vms/form/proxmox/server/_volume_cdrom.html.erb
175
+ - app/views/compute_resources_vms/form/proxmox/server/_volume_cloud_init.html.erb
176
+ - app/views/compute_resources_vms/form/proxmox/server/_volume_hard_disk.html.erb
166
177
  - app/views/compute_resources_vms/index/_proxmox.html.erb
167
178
  - app/views/compute_resources_vms/show/_proxmox.html.erb
168
179
  - app/views/dashboard/_foreman_fog_proxmox_widget.erb
169
180
  - app/views/images/form/_proxmox.html.erb
170
181
  - config/routes.rb
182
+ - db/migrate/20210312105013_update_proxmox_uuid_host.rb
171
183
  - lib/foreman_fog_proxmox.rb
172
184
  - lib/foreman_fog_proxmox/engine.rb
185
+ - lib/foreman_fog_proxmox/hash_collection.rb
173
186
  - lib/foreman_fog_proxmox/semver.rb
174
187
  - lib/foreman_fog_proxmox/value.rb
175
188
  - lib/foreman_fog_proxmox/version.rb
@@ -188,6 +201,8 @@ files:
188
201
  - test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb
189
202
  - test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb
190
203
  - test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb
204
+ - test/unit/foreman_fog_proxmox/helpers/proxmox_vm_uuid_helper_test.rb
205
+ - test/unit/foreman_fog_proxmox/helpers/proxmox_vm_volumes_helper_test.rb
191
206
  - test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb
192
207
  - test/unit/foreman_fog_proxmox/proxmox_images_test.rb
193
208
  - test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb
@@ -195,8 +210,10 @@ files:
195
210
  - test/unit/foreman_fog_proxmox/proxmox_version_test.rb
196
211
  - test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb
197
212
  - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb
213
+ - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cdrom_test.rb
214
+ - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cloudinit_test.rb
215
+ - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_hard_disk_test.rb
198
216
  - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb
199
- - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_volumes_test.rb
200
217
  - test/unit/foreman_fog_proxmox/proxmox_vm_commands_test.rb
201
218
  - test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb
202
219
  - test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb
@@ -220,30 +237,34 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
237
  - !ruby/object:Gem::Version
221
238
  version: '0'
222
239
  requirements: []
223
- rubygems_version: 3.0.3
240
+ rubygems_version: 3.2.3
224
241
  signing_key:
225
242
  specification_version: 4
226
243
  summary: Foreman plugin that adds Proxmox VE compute resource using fog-proxmox
227
244
  test_files:
245
+ - test/factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb
228
246
  - test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb
229
247
  - test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb
230
- - test/factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb
231
248
  - test/factories/proxmox_factory.rb
232
- - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_volumes_test.rb
233
- - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb
234
- - test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb
235
- - test/unit/foreman_fog_proxmox/proxmox_version_test.rb
236
- - test/unit/foreman_fog_proxmox/proxmox_vm_commands_test.rb
237
- - test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb
238
- - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb
239
- - test/unit/foreman_fog_proxmox/proxmox_images_test.rb
240
- - test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb
249
+ - test/functional/compute_resources_controller_test.rb
250
+ - test/test_plugin_helper.rb
251
+ - test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb
252
+ - test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb
253
+ - test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb
254
+ - test/unit/foreman_fog_proxmox/helpers/proxmox_vm_uuid_helper_test.rb
255
+ - test/unit/foreman_fog_proxmox/helpers/proxmox_vm_volumes_helper_test.rb
241
256
  - test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb
257
+ - test/unit/foreman_fog_proxmox/proxmox_images_test.rb
242
258
  - test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb
243
259
  - test/unit/foreman_fog_proxmox/proxmox_test.rb
260
+ - test/unit/foreman_fog_proxmox/proxmox_version_test.rb
261
+ - test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb
262
+ - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb
263
+ - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cdrom_test.rb
264
+ - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cloudinit_test.rb
265
+ - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_hard_disk_test.rb
266
+ - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb
267
+ - test/unit/foreman_fog_proxmox/proxmox_vm_commands_test.rb
268
+ - test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb
269
+ - test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb
244
270
  - test/unit/foreman_fog_proxmox/semver_test.rb
245
- - test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb
246
- - test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb
247
- - test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb
248
- - test/test_plugin_helper.rb
249
- - test/functional/compute_resources_controller_test.rb
@@ -1,163 +0,0 @@
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 'fog/proxmox/helpers/disk_helper'
21
- require 'fog/proxmox/helpers/nic_helper'
22
- require 'foreman_fog_proxmox/value'
23
-
24
- module ProxmoxContainerHelper
25
- def config_keys
26
- general_a = ['node_id', 'name', 'type', 'config_attributes', 'volumes_attributes', 'interfaces_attributes']
27
- general_a += ['firmware_type', 'provision_method', 'container_volumes', 'server_volumes', 'start_after_create']
28
- keys = { general: general_a }
29
- keys.store(:main, ['name', 'type', 'node_id', 'vmid', 'interfaces', 'mount_points', 'disks'])
30
- keys.store(:cpu, ['arch', 'cpulimit', 'cpuunits', 'cores'])
31
- keys.store(:memory, ['memory', 'swap'])
32
- keys
33
- end
34
-
35
- def ostemplate_keys
36
- ['ostemplate', 'ostemplate_storage', 'ostemplate_file']
37
- end
38
-
39
- def parse_ostemplate_without_keys(args)
40
- parse_container_ostemplate(args.select { |key, _value| ostemplate_keys.include? key })
41
- end
42
-
43
- def config_general_or_ostemplate_key?(key)
44
- config_keys[:general].include?(key) || ostemplate_keys.include?(key)
45
- end
46
-
47
- def parse_container_vm(args)
48
- logger.debug("parse_container_vm args=#{args}")
49
- args = ActiveSupport::HashWithIndifferentAccess.new(args)
50
- return {} unless args
51
- return {} if args.empty?
52
- return {} unless args['type'] == 'lxc'
53
-
54
- config = args['config_attributes']
55
- config ||= args.reject { |key, _value| config_keys[:main].include? key }
56
- ostemplate = parse_ostemplate_without_keys(args)
57
- ostemplate = parse_ostemplate_without_keys(config) unless ostemplate[:ostemplate]
58
- volumes = parse_container_volumes(args['volumes_attributes'])
59
- cpu = parse_container_cpu(config.select { |key, _value| config_keys[:cpu].include? key })
60
- memory = parse_container_memory(config.select { |key, _value| config_keys[:memory].include? key })
61
- interfaces_attributes = args['interfaces_attributes']
62
- interfaces_to_add, interfaces_to_delete = parse_container_interfaces(interfaces_attributes)
63
- logger.debug("config_keys[:general]: #{config_keys[:general]}")
64
- parsed_vm = args.reject { |key, value| config_general_or_ostemplate_key?(key) || ForemanFogProxmox::Value.empty?(value) }
65
- parsed_config = config.reject { |key, value| config_keys.include?(key) || ForemanFogProxmox::Value.empty?(value) }
66
- logger.debug("parse_container_config(): #{parsed_config}")
67
- parsed_vm = parsed_vm.merge(parsed_config).merge(cpu).merge(memory).merge(ostemplate)
68
- interfaces_to_add.each { |interface| parsed_vm = parsed_vm.merge(interface) }
69
- parsed_vm = parsed_vm.merge(delete: interfaces_to_delete.join(',')) unless interfaces_to_delete.empty?
70
- volumes.each { |volume| parsed_vm = parsed_vm.merge(volume) }
71
- logger.debug("parse_container_vm(): #{parsed_vm}")
72
- parsed_vm
73
- end
74
-
75
- def parse_container_memory(args)
76
- memory = {}
77
- args.delete_if { |_key, value| ForemanFogProxmox::Value.empty?(value) }
78
- memory.store(:memory, args['memory'].to_i) if args['memory']
79
- memory.store(:swap, args['swap'].to_i) if args['swap']
80
- logger.debug("parse_container_memory(): #{memory}")
81
- memory
82
- end
83
-
84
- def parse_container_cpu(args)
85
- cpu = {}
86
- args.delete_if { |_key, value| ForemanFogProxmox::Value.empty?(value) }
87
- cpu.store(:arch, args['arch'].to_s) if args['arch']
88
- cpu.store(:cpulimit, args['cpulimit'].to_i) if args['cpulimit']
89
- cpu.store(:cpuunits, args['cpuunits'].to_i) if args['cpuunits']
90
- cpu.store(:cores, args['cores'].to_i) if args['cores']
91
- logger.debug("parse_container_cpu(): #{cpu}")
92
- cpu
93
- end
94
-
95
- def parse_container_ostemplate(args)
96
- ostemplate = args['ostemplate']
97
- ostemplate_file = args['ostemplate_file']
98
- ostemplate ||= ostemplate_file
99
- ostemplate_storage = args['ostemplate_storage']
100
- ostemplate_storage, ostemplate_file, _size = Fog::Proxmox::DiskHelper.extract_storage_volid_size(ostemplate) unless ForemanFogProxmox::Value.empty?(ostemplate)
101
- parsed_ostemplate = { ostemplate: ostemplate, ostemplate_file: ostemplate_file, ostemplate_storage: ostemplate_storage }
102
- logger.debug("parse_container_ostemplate(): #{parsed_ostemplate}")
103
- parsed_ostemplate
104
- end
105
-
106
- def parse_container_volume(args)
107
- disk = {}
108
- id = args['id']
109
- id = "mp#{args['device']}" if args.key?('device')
110
- logger.debug("parse_container_volume() args=#{args}")
111
- return args if ForemanFogProxmox::Value.empty?(id) || Fog::Proxmox::DiskHelper.server_disk?(id)
112
-
113
- args.delete_if { |_key, value| ForemanFogProxmox::Value.empty?(value) }
114
- disk.store(:id, id)
115
- disk.store(:volid, args['volid'])
116
- disk.store(:storage, args['storage'].to_s)
117
- disk.store(:size, args['size'].to_i)
118
- options = args.reject { |key, _value| ['id', 'volid', 'device', 'storage', 'size', '_delete'].include? key }
119
- disk.store(:options, options)
120
- logger.debug("parse_container_volume(): disk=#{disk}")
121
- Fog::Proxmox::DiskHelper.flatten(disk)
122
- end
123
-
124
- def parse_container_volumes(args)
125
- logger.debug("parse_container_volumes() args=#{args}")
126
- volumes = []
127
- args&.each_value { |value| volumes.push(parse_container_volume(value)) }
128
- logger.debug("parse_container_volumes(): volumes=#{volumes}")
129
- volumes
130
- end
131
-
132
- def parse_container_interfaces(interfaces_attributes)
133
- interfaces_to_add = []
134
- interfaces_to_delete = []
135
- interfaces_attributes&.each_value { |value| add_container_interface(value, interfaces_to_delete, interfaces_to_add) }
136
- logger.debug("parse_container_interfaces(): interfaces_to_add=#{interfaces_to_add}, interfaces_to_delete=#{interfaces_to_delete}")
137
- [interfaces_to_add, interfaces_to_delete]
138
- end
139
-
140
- def add_container_interface(interface_attributes, interfaces_to_delete, interfaces_to_add)
141
- interface_attributes.delete_if { |_key, value| ForemanFogProxmox::Value.empty?(value) }
142
- nic = {}
143
- id = interface_attributes['id']
144
- logger.debug("parse_container_interface(): id=#{id}")
145
- delete = interface_attributes['_delete'].to_i == 1
146
- if delete
147
- interfaces_to_delete.push(id.to_s)
148
- else
149
- nic.store(:id, id)
150
- nic.store(:hwaddr, interface_attributes['macaddr']) if interface_attributes['macaddr']
151
- nic.store(:name, interface_attributes['name'].to_s)
152
- nic.store(:bridge, interface_attributes['bridge'].to_s) if interface_attributes['bridge']
153
- nic.store(:ip, interface_attributes['ip'].to_s) if interface_attributes['ip']
154
- nic.store(:ip6, interface_attributes['ip6'].to_s) if interface_attributes['ip6']
155
- nic.store(:gw, interface_attributes['gw'].to_s) if interface_attributes['gw']
156
- nic.store(:gw6, interface_attributes['gw6'].to_s) if interface_attributes['gw6']
157
- nic.store(:rate, interface_attributes['rate'].to_i) if interface_attributes['rate']
158
- nic.store(:tag, interface_attributes['tag'].to_i) if interface_attributes['tag']
159
- logger.debug("parse_container_interface(): add nic=#{nic}")
160
- interfaces_to_add.push(Fog::Proxmox::NicHelper.flatten(nic))
161
- end
162
- end
163
- end