foreman_fog_proxmox 0.10.2 → 0.12.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 (40) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +61 -13
  3. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js +0 -22
  4. data/app/helpers/proxmox_compute_selectors_helper.rb +14 -0
  5. data/app/helpers/proxmox_server_helper.rb +2 -6
  6. data/app/helpers/proxmox_vm_helper.rb +2 -10
  7. data/app/models/concerns/fog_extensions/proxmox/server.rb +1 -0
  8. data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +14 -1
  9. data/app/models/foreman_fog_proxmox/proxmox_connection.rb +1 -1
  10. data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +1 -1
  11. data/app/models/foreman_fog_proxmox/proxmox_pools.rb +56 -0
  12. data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +5 -1
  13. data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +4 -4
  14. data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +6 -7
  15. data/app/views/api/v2/compute_resources/proxmox.json.rabl +1 -1
  16. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +2 -2
  17. data/app/views/compute_resources_vms/form/proxmox/_general.html.erb +1 -0
  18. data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +4 -4
  19. data/app/views/compute_resources_vms/show/_proxmox.html.erb +1 -0
  20. data/lib/foreman_fog_proxmox/engine.rb +2 -2
  21. data/lib/foreman_fog_proxmox/version.rb +1 -1
  22. data/locale/en/foreman_fog_proxmox.po +18 -3
  23. data/locale/foreman_fog_proxmox.pot +48 -28
  24. data/locale/fr/foreman_fog_proxmox.po +18 -3
  25. data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +6 -0
  26. data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +4 -4
  27. data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +10 -9
  28. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +1 -1
  29. data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +10 -2
  30. data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +4 -4
  31. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +14 -0
  32. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +29 -1
  33. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +91 -0
  34. data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +7 -2
  35. data/test/unit/foreman_fog_proxmox/semver_test.rb +3 -5
  36. metadata +21 -24
  37. data/locale/en/foreman_fog_proxmox.edit.po +0 -508
  38. data/locale/en/foreman_fog_proxmox.po.time_stamp +0 -0
  39. data/locale/fr/foreman_fog_proxmox.edit.po +0 -508
  40. data/locale/fr/foreman_fog_proxmox.po.time_stamp +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a2aa0eb531e4580fc08dd5645fb2db4a4f1f2cbe22e9f8facee9428e1ca2d75
4
- data.tar.gz: fcc524d8576edc27619cae0f08049e429bca3a936d5970e094dbd55ea28df8d7
3
+ metadata.gz: 4a8a1a5346987d31022f1711c5181ed80fe9d4a5e23a1ec44cb3d65f81c98e4d
4
+ data.tar.gz: ead9626148eee34158047668bc15c2a97b83bb6f6779d4478b932af059b808fb
5
5
  SHA512:
6
- metadata.gz: b2faa03134097bbcf3923d768469b73b37c3fb0230cf75090306ed2dd40529282fab6518cc9558693b513310ea875d947ab1f8403cb9045b09a94b03b1f4a072
7
- data.tar.gz: d9480dfad771621a8debce4575689a60ddb3328da49e3133e73005e28522514c538aecc592b1aa97b5b2a1734fe62f954ebedd8306fca4fda0af46448e07ab48
6
+ metadata.gz: acb1466f50ee8c3ec8e6f6b8844ce88e05a1d732960073bd3e8d7b88c61f55a9d69ddde052882f6ded98930128b52a16d909c5d63db3aada9520a51d0fcd907e
7
+ data.tar.gz: d69dd9aaf71ee9e21c5cdf8dc6dc25ced882ab98f8e8064084e3f533dcddb362c9ee85784744dcc4e0ddefe66c7109263f85bf477622e62848bb42bf7a43a65f
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  ![ForemanFogProxmox](.github/images/foremanproxmox.png)
2
2
 
3
- [![Build Status](https://travis-ci.com/theforeman/foreman_fog_proxmox.svg?branch=master)](https://travis-ci.com/theforeman/foreman_fog_proxmox)
3
+ ![CI](https://github.com/theforeman/foreman_fog_proxmox/workflows/CI/badge.svg)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/922162c278e0fa9207ba/maintainability)](https://codeclimate.com/github/theforeman/foreman_fog_proxmox/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/922162c278e0fa9207ba/test_coverage)](https://codeclimate.com/github/theforeman/foreman_fog_proxmox/test_coverage)
6
+ [![Gem Version](https://badge.fury.io/rb/foreman_fog_proxmox.svg)](https://badge.fury.io/rb/foreman_fog_proxmox)
6
7
 
7
8
  # ForemanFogProxmox
8
9
 
@@ -30,6 +31,7 @@ You can support the plugin development via the following methods:
30
31
  |>=0.9 |>=5.4|>=0.9.1|>=1.22|>=2.3|
31
32
  |>=0.10 |>=5.4|>=0.9.4|>=1.22|>=2.5|
32
33
  |>=0.11 |>=5.4|>=0.10|>=1.22|>=2.5|
34
+ |>=0.12 |>=6.1|>=0.11|>=2.0|>=2.5|
33
35
 
34
36
  ## Installation
35
37
 
@@ -129,8 +131,8 @@ git clone https://github.com/theforeman/foreman -b develop
129
131
  * Add this line:
130
132
 
131
133
  ```ruby
132
- gem 'foreman_fog_proxmox', :path => '/your_path_to/foreman_fog_proxmox'
133
- gem 'fog-proxmox', :path => '/your_path_to/fog-proxmox' # optional if you need to modify fog-proxmox code too
134
+ gem 'foreman_fog_proxmox', :path => '../../theforeman/foreman_fog_proxmox'
135
+ gem 'fog-proxmox', :path => '../../fog/fog-proxmox' # optional if you need to modify fog-proxmox code too
134
136
  gem 'ruby-debug-ide' # dev
135
137
  gem 'debase' # dev
136
138
  gem 'simplecov' # test
@@ -139,7 +141,10 @@ gem 'simplecov' # test
139
141
  * In foreman directory, install dependencies:
140
142
 
141
143
  ```shell
142
- bundle install --without libvirt postgresql mysql2
144
+ gem install bundler
145
+ # prerequisites postgresql-client library on OS
146
+ bundle config set without 'libvirt ovirt mysql2'
147
+ bundle install
143
148
  ```
144
149
 
145
150
  ```shell
@@ -152,14 +157,37 @@ npm install
152
157
  cp config/settings.yaml.test config/settings.yaml
153
158
  ```
154
159
 
155
- * Install foreman database (sqlite is default in rails development):
160
+ add these lines to config/settings.yml:
161
+
162
+ ```yaml
163
+ :webpack_dev_server: true
164
+ ```
165
+
166
+ * SQLite is no more default rails dev or test database, instead add:
167
+
168
+ ```shell
169
+ DATABASE_URL=nulldb://nohost
170
+ ```
171
+
172
+ * (Optional) test and dev with postgresql database:
156
173
 
157
174
  ```shell
158
175
  cp config/model.mappings.example config/model.mappings
159
176
  cp config/database.yml.example config/database.yml
177
+ ```
178
+
179
+ add these lines to config/database.yml:
180
+
181
+ ```yaml
182
+ username: foreman
183
+ password: foreman
184
+ ```
185
+
186
+ ```shell
160
187
  cp config/ignored_environments.yml.sample config/ignored_environments.yml
188
+ docker run --name foreman-db -e POSTGRES_DB=foreman -e POSTGRES_USER=foreman -e POSTGRES_PASSWORD=foreman -p 5432:5432 -d postgres
161
189
  bundle exec bin/rake db:migrate
162
- bundle exec bin/rake db:seed
190
+ bundle exec bin/rake db:seed assets:precompile locale:pack webpack:compile
163
191
  ```
164
192
 
165
193
  * You can reset admin password if needed:
@@ -170,6 +198,13 @@ bundle exec bin/rake permissions:reset
170
198
 
171
199
  * You should write tests and you can execute those specific to this plugin:
172
200
 
201
+ first, create database `foreman-test` with psql commands:
202
+
203
+ ```shell
204
+ docker exec -it foreman-db psql -U foreman
205
+ foreman=# create database "foreman-test";
206
+ ```
207
+
173
208
  all:
174
209
 
175
210
  ```shell
@@ -181,7 +216,7 @@ or just one:
181
216
 
182
217
  ```shell
183
218
  export DISABLE_SPRING=true
184
- bundle exec bin/rake test TEST=test/functional/compute_resources_controller_test.rb
219
+ bundle exec bin/rake test TEST=../foreman_fog_proxmox/test/functional/compute_resources_controller_test.rb DATABASE_URL=nulldb://nohost
185
220
  ```
186
221
 
187
222
  * Check code syntax with rubocop and foreman rules:
@@ -208,16 +243,28 @@ bundle exec bin/rake plugin:assets:precompile[foreman_fog_proxmox]
208
243
  bundle exec bin/rake plugin:gettext[foreman_fog_proxmox]
209
244
  ```
210
245
 
211
- * In foreman directory, run rails server:
246
+ * In foreman directory, run in a new terminal the webpack-dev-server:
212
247
 
213
248
  ```shell
214
- bundle exec bin/rails server
249
+ ./node_modules/.bin/webpack-dev-server --config config/webpack.config.js
215
250
  ```
216
251
 
217
- * In foreman directory, run in a new terminal the webpack-dev-server:
252
+ * Or without webpack-dev-server, add this line in config/settings.yml:
253
+
254
+ ```yml
255
+ :webpack_dev_server: false
256
+ ```
257
+
258
+ then compile webpack assets:
218
259
 
219
260
  ```shell
220
- ./node_modules/.bin/webpack-dev-server --config config/webpack.config.js
261
+ bundle exec bin/rake webpack:compile
262
+ ```
263
+
264
+ * In foreman directory, run rails server:
265
+
266
+ ```shell
267
+ bundle exec bin/rails server
221
268
  ```
222
269
 
223
270
  * Or you can launch all together:
@@ -232,8 +279,9 @@ See details in [foreman plugin development](https://projects.theforeman.org/proj
232
279
 
233
280
  If you like it and still want to improve it, [sponsor me](https://github.com/sponsors/tristanrobert)!
234
281
 
235
- You can reach the [contributors](.github/CONTRIBUTORS.md).
236
- Bug reports and pull requests are welcome on GitHub at [ForemanFogProxmox](https://github.com/theforeman/foreman_fog_proxmox).
282
+ * You can reach the [contributors](.github/CONTRIBUTORS.md).
283
+ * [Translate it in your favorite language](https://www.transifex.com/foreman/foreman/foreman_fog_proxmox/)
284
+ * Bug reports and pull requests are welcome on GitHub at [ForemanFogProxmox](https://github.com/theforeman/foreman_fog_proxmox).
237
285
 
238
286
  Please read more information about [how to contribute](.github/CONTRIBUTING.md).
239
287
 
@@ -122,26 +122,4 @@ function computeControllerMaxDevice(controller) {
122
122
  default:
123
123
  return 1;
124
124
  }
125
- }
126
-
127
- function balloonSelected(item) {
128
- var ballooned = $(item).is(':checked');
129
- var memory_f = $("input[name$='[config_attributes][memory]']:hidden");
130
- var min_memory_f = $("input[id$='config_attributes_min_memory']");
131
- var min_memory_hidden_f = $("input[name$='[config_attributes][min_memory]']:hidden");
132
- var shares_f = $("input[id$='config_attributes_shares']");
133
- var shares_hidden_f = $("input[name$='[config_attributes][shares]']:hidden");
134
- if (ballooned) {
135
- min_memory_f.removeAttr('disabled');
136
- shares_f.removeAttr('disabled');
137
- var max = memory_f.val();
138
- console.log("max=" + max);
139
- min_memory_f.attr('data-soft-max', max);
140
- } else {
141
- min_memory_f.attr('disabled', 'disabled');
142
- min_memory_hidden_f.attr('value', '');
143
- shares_f.attr('disabled', 'disabled');
144
- shares_hidden_f.attr('value', '');
145
- }
146
- tfm.numFields.initAll();
147
125
  }
@@ -47,6 +47,15 @@ module ProxmoxComputeSelectorsHelper
47
47
  ForemanFogProxmox::OptionsSelect.new(name: 'VirtIO Block', id: 'virtio', range: 15)]
48
48
  end
49
49
 
50
+ def proxmox_scsi_controllers_map
51
+ [OpenStruct.new(id: 'lsi', name: 'LSI 53C895A (Default)'),
52
+ OpenStruct.new(id: 'lsi53c810', name: 'LSI 53C810'),
53
+ OpenStruct.new(id: 'virtio-scsi-pci', name: 'VirtIO SCSI'),
54
+ OpenStruct.new(id: 'virtio-scsi-single', name: 'VirtIO SCSI Single'),
55
+ OpenStruct.new(id: 'megasas', name: 'MegaRAID SAS 8708EM2'),
56
+ OpenStruct.new(id: 'pvscsi', name: 'VMware PVSCSI')]
57
+ end
58
+
50
59
  def proxmox_operating_systems_map
51
60
  [OpenStruct.new(id: 'other', name: 'Unspecified OS'),
52
61
  OpenStruct.new(id: 'wxp', name: 'Microsoft Windows XP'),
@@ -167,4 +176,9 @@ module ProxmoxComputeSelectorsHelper
167
176
  OpenStruct.new(id: 'rtl8139', name: 'Realtek RTL8139'),
168
177
  OpenStruct.new(id: 'vmxnet3', name: 'VMware vmxnet3')]
169
178
  end
179
+
180
+ def proxmox_bios_map
181
+ [OpenStruct.new(id: 'seabios', name: '(Default) Seabios'),
182
+ OpenStruct.new(id: 'ovmf', name: 'OVMF (UEFI)')]
183
+ end
170
184
  end
@@ -38,7 +38,7 @@ module ProxmoxServerHelper
38
38
  volumes = parse_server_volumes(vols)
39
39
  cpu_a = ['cpu_type', 'spectre', 'pcid']
40
40
  cpu = parse_server_cpu(config.select { |key, _value| cpu_a.include? key })
41
- memory_a = ['memory', 'min_memory', 'balloon', 'shares']
41
+ memory_a = ['memory', 'balloon', 'shares']
42
42
  memory = parse_server_memory(config.select { |key, _value| memory_a.include? key })
43
43
  interfaces_attributes = args['interfaces_attributes']
44
44
  interfaces_to_add, interfaces_to_delete = parse_server_interfaces(interfaces_attributes)
@@ -64,11 +64,7 @@ module ProxmoxServerHelper
64
64
  def parse_server_memory(args)
65
65
  memory = {}
66
66
  memory.store(:memory, args['memory'].to_i) if args['memory']
67
- ballooned = args['balloon'].to_i == 1
68
- if ballooned
69
- memory.store(:shares, args['shares'].to_i) if args['shares']
70
- memory.store(:min_memory, args['min_memory'].to_i) if args['min_memory']
71
- end
67
+ memory.store(:shares, args['shares'].to_i) if args['shares']
72
68
  memory.store(:balloon, args['balloon'].to_i) if args['balloon']
73
69
  logger.debug("parse_server_memory(): #{memory}")
74
70
  memory
@@ -59,7 +59,7 @@ module ProxmoxVmHelper
59
59
 
60
60
  def convert_memory_sizes(args)
61
61
  convert_memory_size(args['config_attributes'], 'memory')
62
- convert_memory_size(args['config_attributes'], 'min_memory')
62
+ convert_memory_size(args['config_attributes'], 'balloon')
63
63
  convert_memory_size(args['config_attributes'], 'shares')
64
64
  convert_memory_size(args['config_attributes'], 'swap')
65
65
  end
@@ -70,7 +70,7 @@ module ProxmoxVmHelper
70
70
 
71
71
  def convert_sizes(args)
72
72
  convert_memory_size(args['config_attributes'], 'memory')
73
- convert_memory_size(args['config_attributes'], 'min_memory')
73
+ convert_memory_size(args['config_attributes'], 'balloon')
74
74
  convert_memory_size(args['config_attributes'], 'shares')
75
75
  convert_memory_size(args['config_attributes'], 'swap')
76
76
  args['volumes_attributes'].each_value { |value| value['size'] = (value['size'].to_i / GIGA).to_s unless ForemanFogProxmox::Value.empty?(value['size']) }
@@ -85,12 +85,4 @@ module ProxmoxVmHelper
85
85
  memory = (config_hash[key].to_i / MEGA).to_s == '0' ? config_hash[key] : (config_hash[key].to_i / MEGA).to_s
86
86
  config_hash.store(key, memory)
87
87
  end
88
-
89
- def vm_type(host)
90
- host.compute_object.type
91
- end
92
-
93
- def node_id(host)
94
- host.compute_object.node_id
95
- end
96
88
  end
@@ -77,6 +77,7 @@ module FogExtensions
77
77
  end
78
78
 
79
79
  delegate :vga, to: :config
80
+ delegate :pool, to: :config
80
81
 
81
82
  def interfaces_attributes=(attrs); end
82
83
 
@@ -38,12 +38,25 @@ module ForemanFogProxmox
38
38
  [:disks, :interfaces, :vmid, :node_id, :node, :type].include?(key) || !vm.config.respond_to?(key)
39
39
  end
40
40
 
41
+ def interface_compute_attributes(interface_attributes)
42
+ vm_attrs = {}
43
+ vm_attrs.store(:mac, interface_attributes[:macaddr])
44
+ vm_attrs.store(:id, interface_attributes[:id])
45
+ vm_attrs.store(:identifier, interface_attributes[:id])
46
+ vm_attrs.store(:ip, interface_attributes[:ip])
47
+ vm_attrs.store(:ip6, interface_attributes[:ip6])
48
+ vm_attrs[:compute_attributes] = interface_attributes.reject { |k, _v| [:macaddr, :id].include?(k) }
49
+ vm_attrs
50
+ end
51
+
41
52
  def vm_compute_attributes(vm)
42
53
  vm_attrs = {}
43
54
  if vm.respond_to?(:config)
44
55
  vm_attrs = vm_attrs.merge(vmid: vm.identity, node_id: vm.node_id, type: vm.type)
45
56
  vm_attrs[:volumes_attributes] = Hash[vm.config.disks.each_with_index.map { |disk, idx| [idx.to_s, disk.attributes] }] if vm.config.respond_to?(:disks)
46
- vm_attrs[:interfaces_attributes] = Hash[vm.config.interfaces.each_with_index.map { |interface, idx| [idx.to_s, interface.attributes] }] if vm.config.respond_to?(:interfaces)
57
+ if vm.config.respond_to?(:interfaces)
58
+ vm_attrs[:interfaces_attributes] = Hash[vm.config.interfaces.each_with_index.map { |interface, idx| [idx.to_s, interface_compute_attributes(interface.attributes)] }]
59
+ end
47
60
  vm_attrs[:config_attributes] = vm.config.attributes.reject do |key, value|
48
61
  not_config_key?(vm, key) || ForemanFogProxmox::Value.empty?(value.to_s) || Fog::Proxmox::DiskHelper.disk?(key.to_s) || Fog::Proxmox::NicHelper.nic?(key.to_s)
49
62
  end
@@ -22,7 +22,7 @@ require 'fog/proxmox'
22
22
  module ForemanFogProxmox
23
23
  module ProxmoxConnection
24
24
  def connection_options
25
- opts = http_proxy ? { proxy: http_proxy.full_url } : { disable_proxy: 1 }
25
+ opts = super
26
26
  opts.store(:ssl_verify_peer, ssl_verify_peer)
27
27
  opts.store(:ssl_cert_store, certs_to_store) if Foreman::Cast.to_bool(ssl_verify_peer)
28
28
  opts
@@ -39,7 +39,7 @@ module ForemanFogProxmox
39
39
  end
40
40
 
41
41
  def os_linux_types_mapping(host)
42
- ['Debian', 'Redhat', 'Suse', 'Altlinux', 'Archlinux', 'CoreOs', 'Gentoo'].include?(host.operatingsystem.type) ? available_linux_operating_systems : []
42
+ ['Debian', 'Redhat', 'Suse', 'Altlinux', 'Archlinux', 'Coreos', 'Gentoo'].include?(host.operatingsystem.type) ? available_linux_operating_systems : []
43
43
  end
44
44
 
45
45
  def os_windows_types_mapping(host)
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2019 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 ProxmoxPools
22
+ def pools
23
+ pools = identity_client.pools.all
24
+ pools.sort_by(&:poolid)
25
+ end
26
+
27
+ def pool_owner(vm)
28
+ logger.debug(format(_('pool_owner(%<vmid>s)'), vmid: vm&.vmid))
29
+ pools_owners = pools.select { |pool| pool.has_server?(vm&.vmid) }
30
+ pool = pools_owners.first
31
+ logger.debug(format(_('found vm: %<vmid>s member of pool: %<poolid>s'), vmid: vm&.vmid, poolid: pool&.poolid))
32
+ vm&.config&.pool = pool&.poolid
33
+ end
34
+
35
+ def add_vm_to_pool(poolid, vmid)
36
+ logger.debug(format(_('add_vm_to_pool(%<poolid>s, %<vmid>s)'), poolid: poolid, vmid: vmid))
37
+ pool = identity_client.pools.get poolid
38
+ pool&.add_server vmid
39
+ end
40
+
41
+ def remove_vm_from_pool(poolid, vmid)
42
+ logger.debug(format(_('remove_vm_from_pool(%<poolid>s, %<vmid>s)'), poolid: poolid, vmid: vmid))
43
+ pool = identity_client.pools.get poolid
44
+ pool&.remove_server vmid
45
+ end
46
+
47
+ def update_pool(vm, poolid)
48
+ pool_owner(vm)
49
+ vm_pool = vm.config.pool || ''
50
+ return if vm_pool.eql?(poolid)
51
+
52
+ remove_vm_from_pool(vm_pool, vm.vmid)
53
+ add_vm_to_pool(poolid, vm.vmid)
54
+ end
55
+ end
56
+ end
@@ -20,6 +20,7 @@
20
20
  module ForemanFogProxmox
21
21
  module ProxmoxVmCommands
22
22
  include ProxmoxVolumes
23
+ include ProxmoxPools
23
24
 
24
25
  def start_on_boot(vm, args)
25
26
  startonboot = args[:start_after_create].blank? ? false : Foreman::Cast.to_bool(args[:start_after_create])
@@ -31,6 +32,7 @@ module ForemanFogProxmox
31
32
  vmid = args[:vmid].to_i
32
33
  type = args[:type]
33
34
  node = client.nodes.get(args[:node_id])
35
+ vmid = node.servers.next_id.to_i if vmid < 1
34
36
  raise ::Foreman::Exception, format(N_('invalid vmid=%<vmid>s'), vmid: vmid) unless node.servers.id_valid?(vmid)
35
37
 
36
38
  image_id = args[:image_id]
@@ -100,11 +102,13 @@ module ForemanFogProxmox
100
102
  volumes_attributes&.each_value { |volume_attributes| save_volume(vm, volume_attributes) }
101
103
  parsed_attr = vm.container? ? parse_container_vm(new_attributes.merge(type: vm.type)) : parse_server_vm(new_attributes.merge(type: vm.type))
102
104
  logger.debug("parsed_attr=#{parsed_attr}")
103
- config_attributes = parsed_attr.reject { |key, _value| [:vmid, :templated, :ostemplate, :ostemplate_file, :ostemplate_storage, :volumes_attributes].include? key.to_sym }
105
+ config_attributes = parsed_attr.reject { |key, _value| [:vmid, :templated, :ostemplate, :ostemplate_file, :ostemplate_storage, :volumes_attributes, :pool].include? key.to_sym }
104
106
  config_attributes = config_attributes.reject { |_key, value| ForemanFogProxmox::Value.empty?(value) }
105
107
  cdrom_attributes = parsed_attr.select { |_key, value| Fog::Proxmox::DiskHelper.cdrom?(value.to_s) }
106
108
  config_attributes = config_attributes.reject { |key, _value| Fog::Proxmox::DiskHelper.disk?(key) }
107
109
  vm.update(config_attributes.merge(cdrom_attributes))
110
+ poolid = new_attributes['pool'] if new_attributes.key?('pool')
111
+ update_pool(vm, poolid) if poolid
108
112
  end
109
113
  find_vm_by_uuid(uuid)
110
114
  end
@@ -39,9 +39,9 @@ module ForemanFogProxmox
39
39
  type ||= 'qemu'
40
40
  case type
41
41
  when 'lxc'
42
- return new_volume_server(attr)
42
+ new_volume_server(attr)
43
43
  when 'qemu'
44
- return new_volume_container(attr)
44
+ new_volume_container(attr)
45
45
  end
46
46
  end
47
47
 
@@ -74,9 +74,9 @@ module ForemanFogProxmox
74
74
  type ||= 'qemu'
75
75
  case type
76
76
  when 'lxc'
77
- return new_container_interface(attr)
77
+ new_container_interface(attr)
78
78
  when 'qemu'
79
- return new_server_interface(attr)
79
+ new_server_interface(attr)
80
80
  end
81
81
  end
82
82
 
@@ -19,16 +19,13 @@
19
19
 
20
20
  module ForemanFogProxmox
21
21
  module ProxmoxVmQueries
22
+ include ProxmoxPools
23
+
22
24
  def nodes
23
25
  nodes = client.nodes.all if client
24
26
  nodes&.sort_by(&:node)
25
27
  end
26
28
 
27
- def pools
28
- pools = identity_client.pools.all
29
- pools.sort_by(&:poolid)
30
- end
31
-
32
29
  def storages(node_id = default_node_id, type = 'images')
33
30
  node = client.nodes.get node_id
34
31
  node ||= default_node
@@ -65,12 +62,14 @@ module ForemanFogProxmox
65
62
  end
66
63
 
67
64
  def find_vm_in_servers_by_uuid(servers, uuid)
68
- servers.get(uuid) if !uuid.nil? && !uuid.to_s.empty?
65
+ vm = servers.get(uuid) if !uuid.nil? && !uuid.to_s.empty?
66
+ pool_owner(vm) if vm
67
+ vm
69
68
  rescue Fog::Errors::NotFound
70
69
  nil
71
70
  rescue StandardError => e
72
71
  Foreman::Logging.exception(format(_('Failed retrieving proxmox server vm by vmid=%<vmid>s'), vmid: uuid), e)
73
- raise(ActiveRecord::RecordNotFound)
72
+ raise(ActiveRecord::RecordNotFound, e)
74
73
  end
75
74
  end
76
75
  end