foreman_fog_proxmox 0.14.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +42 -29
  3. data/app/controllers/concerns/foreman_fog_proxmox/compute_resources_vms_controller.rb +17 -7
  4. data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +1 -1
  5. data/app/controllers/concerns/foreman_fog_proxmox/hosts_controller.rb +8 -3
  6. data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +6 -3
  7. data/app/helpers/proxmox_compute_controllers_helper.rb +2 -1
  8. data/app/helpers/proxmox_compute_resources_helper.rb +3 -3
  9. data/app/helpers/proxmox_compute_resources_vms_helper.rb +16 -7
  10. data/app/helpers/proxmox_form_helper.rb +9 -5
  11. data/app/helpers/proxmox_vm_config_helper.rb +16 -25
  12. data/app/helpers/proxmox_vm_interfaces_helper.rb +19 -6
  13. data/app/helpers/proxmox_vm_os_template_helper.rb +2 -5
  14. data/app/helpers/proxmox_vm_uuid_helper.rb +1 -1
  15. data/app/helpers/proxmox_vm_volumes_helper.rb +22 -25
  16. data/app/models/concerns/fog_extensions/proxmox/node.rb +2 -2
  17. data/app/models/concerns/fog_extensions/proxmox/server.rb +9 -5
  18. data/app/models/concerns/host_ext/proxmox/associator.rb +3 -2
  19. data/app/models/concerns/host_ext/proxmox/for_vm.rb +1 -1
  20. data/app/models/concerns/host_ext/proxmox/interfaces.rb +7 -3
  21. data/app/models/concerns/orchestration/proxmox/compute.rb +11 -4
  22. data/app/models/foreman_fog_proxmox/options_select.rb +1 -3
  23. data/app/models/foreman_fog_proxmox/proxmox.rb +12 -10
  24. data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +15 -3
  25. data/app/models/foreman_fog_proxmox/proxmox_connection.rb +6 -2
  26. data/app/models/foreman_fog_proxmox/proxmox_console.rb +3 -1
  27. data/app/models/foreman_fog_proxmox/proxmox_images.rb +2 -2
  28. data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +28 -6
  29. data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +6 -1
  30. data/app/models/foreman_fog_proxmox/proxmox_pools.rb +4 -4
  31. data/app/models/foreman_fog_proxmox/proxmox_version.rb +7 -3
  32. data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +9 -7
  33. data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +37 -24
  34. data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +4 -5
  35. data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +23 -12
  36. data/app/models/foreman_fog_proxmox/vms.rb +2 -2
  37. data/app/views/compute_resources_vms/form/proxmox/container/_config.html.erb +2 -2
  38. data/app/views/compute_resources_vms/form/proxmox/container/_volume_mp.html.erb +1 -1
  39. data/app/views/compute_resources_vms/form/proxmox/container/_volume_rootfs.html.erb +1 -1
  40. data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +3 -3
  41. data/app/views/compute_resources_vms/form/proxmox/server/_volume_hard_disk.html.erb +1 -1
  42. data/config/routes.rb +8 -4
  43. data/db/migrate/20210312105013_update_proxmox_uuid_host.rb +1 -2
  44. data/lib/foreman_fog_proxmox/engine.rb +4 -3
  45. data/lib/foreman_fog_proxmox/semver.rb +1 -4
  46. data/lib/foreman_fog_proxmox/version.rb +1 -1
  47. data/locale/en/foreman_fog_proxmox.po +140 -47
  48. data/locale/foreman_fog_proxmox.pot +300 -137
  49. data/locale/fr/foreman_fog_proxmox.po +145 -52
  50. data/test/factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb +6 -7
  51. data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +6 -7
  52. data/test/functional/compute_resources_controller_test.rb +4 -2
  53. data/test/test_plugin_helper.rb +12 -7
  54. data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +38 -47
  55. data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +49 -34
  56. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +29 -65
  57. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_volumes_helper_test.rb +3 -3
  58. data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +22 -13
  59. data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +18 -9
  60. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +45 -35
  61. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +0 -4
  62. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cdrom_test.rb +34 -22
  63. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cloudinit_test.rb +20 -14
  64. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_hard_disk_test.rb +76 -54
  65. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +26 -15
  66. data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +1 -1
  67. data/test/unit/foreman_fog_proxmox/semver_test.rb +2 -1
  68. metadata +35 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19b7f2f30af319dbc8881900c660bf9ddc5026eb8762ace34dcd6b4ac7fa85f8
4
- data.tar.gz: 5430f62a1d7db829fddb142c468d5c3741a0090131f0a3d26746bec75f6b943e
3
+ metadata.gz: 70a0629dba4c5afe29ddca15cbe49df9325edb80ca73d076c41c3fc1d283ecff
4
+ data.tar.gz: f680eed4c519701ecdc5bc38117ca62eb846551ab972aa8e5f38869b17fe414e
5
5
  SHA512:
6
- metadata.gz: ceac1a672eb780a7c7e8e05d8024f70d74d129a3ff48ad5d65f9947c78d60778a3697c7a70e030eff53346f3f56587a726fa71b5a719bb448bbea573d7970e47
7
- data.tar.gz: cd477463a37e43ce80db0986f08d8203b225cfc5abae4f31b5c165cfc149197c99be2b2d8687b6e217246609c77d781658d93c119b37c41bfebc6049be852b4a
6
+ metadata.gz: 6c8d56b7e0a4e02ac2195fdd248aa12f5934b8a9746763d1aff59d0df1316f09abb3dbfe212f99e7a39307132065550871bb84a7fcab04787e3e8ca9bd70e50d
7
+ data.tar.gz: 883ee296ceea79f15e220c8fe9cad273aed8201862be59b41b79761ae01d8cc837adcbe3dae54e9e24d1f30f34dee3d85e7eb8c83ccaa94d0522f27bc28925b3
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
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
- [![Test Coverage](https://api.codeclimate.com/v1/badges/922162c278e0fa9207ba/test_coverage)](https://codeclimate.com/github/theforeman/foreman_fog_proxmox/test_coverage)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/a6446cf7b1cf09b83de6/test_coverage)](https://codeclimate.com/github/theforeman/foreman_fog_proxmox/test_coverage)
6
6
  [![Gem Version](https://badge.fury.io/rb/foreman_fog_proxmox.svg)](https://badge.fury.io/rb/foreman_fog_proxmox)
7
7
 
8
8
  # ForemanFogProxmox
@@ -38,7 +38,7 @@ You can support the plugin development via the following methods:
38
38
 
39
39
  ## Installation
40
40
 
41
- ### From OS packages
41
+ ### From OS packages (required)
42
42
 
43
43
  Please see the Foreman manual for complete instructions:
44
44
 
@@ -128,15 +128,17 @@ Then you can check plugin installation after login into your new foreman server
128
128
 
129
129
  ### Dev prerequisites
130
130
 
131
- * You need a Proxmox VE 5.4+ server running.
132
- * You need ruby >= 2.5. You can install it with [asdf-vm](https://asdf-vm.com).
133
- * You also need nodejs in your dev machine to run webpack-dev-server. You can install it with [asdf-vm](https://asdf-vm.com).
131
+ > See [Foreman dev setup](https://github.com/theforeman/foreman/blob/develop/developer_docs/foreman_dev_setup.asciidoc)
132
+
133
+ * You need a Proxmox VE 6.2+ server running.
134
+ * You need ruby 2.7. You can install it with [asdf-vm](https://asdf-vm.com).
135
+ * You also need nodejs 14 in your dev machine to run webpack-dev-server. You can install it with [asdf-vm](https://asdf-vm.com).
134
136
 
135
137
  ### Platform
136
138
 
137
139
  * Fork this github repo.
138
140
  * Clone it on your local machine
139
- * Install foreman v1.22+ on your machine:
141
+ * Install foreman v2.5+ on your machine:
140
142
 
141
143
  ```shell
142
144
  git clone https://github.com/theforeman/foreman -b develop
@@ -158,9 +160,9 @@ gem 'simplecov' # test
158
160
 
159
161
  ```shell
160
162
  gem install bundler
161
- # prerequisites postgresql-XX-client library on OS (XX=major release installed in OS)
162
- bundle config set without 'libvirt ovirt mysql2'
163
- bundle config build.pg --with-pg-config=/usr/pgsql-XX/bin/pg_config
163
+ # prerequisites libraries on Ubuntu OS:
164
+ # sudo apt install postgresql-client-13 libpq-dev libsystemd-dev
165
+ bundle config set without 'libvirt ovirt'
164
166
  bundle install
165
167
  ```
166
168
 
@@ -178,6 +180,12 @@ add these lines to config/settings.yml:
178
180
 
179
181
  ```yaml
180
182
  :webpack_dev_server: true
183
+ :destroy_vm_on_host_delete: true # optional, could be set on UI
184
+ :logging:
185
+ :level: debug
186
+ :loggers:
187
+ :sql:
188
+ :enabled: false
181
189
  ```
182
190
 
183
191
  * SQLite is no more default rails dev or test database, instead add:
@@ -189,45 +197,42 @@ DATABASE_URL=nulldb://nohost
189
197
  * (Optional) test and dev with postgresql database:
190
198
 
191
199
  ```shell
192
- cp config/model.mappings.example config/model.mappings
193
200
  cp config/database.yml.example config/database.yml
194
201
  ```
195
202
 
196
203
  add these lines to each environment in config/database.yml:
197
204
 
198
205
  ```yaml
206
+ host: localhost
199
207
  username: foreman
200
208
  password: foreman
201
209
  ```
202
210
 
203
211
  ```shell
204
212
  cp config/ignored_environments.yml.sample config/ignored_environments.yml
205
- docker run --name foreman-db -v foreman_data:/var/lib/postgresql/data -e POSTGRES_DB=foreman -e POSTGRES_USER=foreman -e POSTGRES_PASSWORD=foreman -p 5432:5432 -d postgres
213
+ docker run --name foreman-db -v foreman_data:/var/lib/postgresql/data -e POSTGRES_DB=foreman -e POSTGRES_USER=foreman -e POSTGRES_PASSWORD=foreman -p 5432:5432 -d postgres:13
206
214
  bundle exec bin/rake db:migrate
207
- # reboot if settings.NAME error in schema
208
- bundle exec bin/rake db:seed assets:precompile locale:pack webpack:compile
215
+ RAILS_ENV=development bundle exec bin/rake db:seed assets:precompile locale:pack webpack:compile
209
216
  ```
210
217
 
211
- * You can reset admin password if needed:
218
+ * You can reset and change your admin password if needed:
212
219
 
213
220
  ```shell
214
- bundle exec bin/rake permissions:reset
221
+ RAILS_ENV=development bundle exec bin/rake permissions:reset password=changeme
215
222
  ```
216
223
 
217
224
  * You should write tests and you can execute those specific to this plugin:
218
225
 
219
- first, create database `foreman-test` with psql commands:
226
+ first, create database `foreman-test`:
220
227
 
221
228
  ```shell
222
- docker exec -it foreman-db psql -U foreman
223
- foreman=# create database "foreman-test";
229
+ RAILS_ENV=test bundle exec rake db:create
224
230
  ```
225
231
 
226
232
  then add test schema and seeds:
227
233
 
228
234
  ```shell
229
235
  RAILS_ENV=test bundle exec bin/rake db:migrate
230
- # reboot if error: "ActiveRecord::RecordNotFound: Couldn't find Setting with [WHERE "settings"."name" = $1]"
231
236
  RAILS_ENV=test bundle exec bin/rake db:seed
232
237
  ```
233
238
 
@@ -245,10 +250,22 @@ export DISABLE_SPRING=true
245
250
  bundle exec bin/rake test TEST=../foreman_fog_proxmox/test/functional/compute_resources_controller_test.rb DATABASE_URL=nulldb://nohost
246
251
  ```
247
252
 
248
- * Check code syntax with rubocop and foreman rules:
253
+ * In foreman_fog_proxmox source directory, check code syntax with rubocop and foreman rules:
254
+
255
+ ```shell
256
+ bundle exec rubocop
257
+ ```
258
+
259
+ safe autocorrect:
260
+
261
+ ```shell
262
+ bundle exec rubocop -a
263
+ ```
264
+
265
+ Temporary ignore offenses:
249
266
 
250
267
  ```shell
251
- bundle exec bin/rake foreman_fog_proxmox:rubocop
268
+ bundle exec rubocop --auto-gen-config
252
269
  ```
253
270
 
254
271
  * See deface overrides result:
@@ -265,14 +282,16 @@ bundle exec bin/rake plugin:assets:precompile[foreman_fog_proxmox]
265
282
 
266
283
  * In foreman directory, after you modify foreman_fog_proxmox translations (language, texts in new files, etc) you have to compile it:
267
284
 
285
+ Prerequisites: [Transifex CLI](https://github.com/transifex/cli)
286
+
268
287
  ```shell
269
- bundle exec bin/rake plugin:gettext[foreman_fog_proxmox]
288
+ bundle exec bin/rake plugin:gettext\[foreman_fog_proxmox\]
270
289
  ```
271
290
 
272
291
  * In foreman directory, run in a new terminal the webpack-dev-server:
273
292
 
274
293
  ```shell
275
- ./node_modules/.bin/webpack-dev-server --config config/webpack.config.js
294
+ ./node_modules/.bin/webpack-dev-server-without-h2 --config config/webpack.config.js
276
295
  ```
277
296
 
278
297
  * Or without webpack-dev-server, add this line in config/settings.yml:
@@ -299,12 +318,6 @@ bundle exec bin/rails server
299
318
  bundle exec foreman start
300
319
  ```
301
320
 
302
- If you want to delete vm on host destroy, add this line in config/settings.yml:
303
-
304
- ```yml
305
- :destroy_vm_on_host_delete: false
306
- ```
307
-
308
321
  See details in [foreman plugin development](https://projects.theforeman.org/projects/foreman/wiki/How_to_Create_a_Plugin)
309
322
 
310
323
  ## Contributing
@@ -26,15 +26,20 @@ module ForemanFogProxmox
26
26
  module Overrides
27
27
  def associate
28
28
  if Host.for_vm_uuid(@compute_resource, @vm).any?
29
- process_error(:error_msg => _("VM already associated with a host"), :redirect => compute_resource_vm_path(:compute_resource_id => params[:compute_resource_id], :id => proxmox_vm_id(@compute_resource, @vm)))
29
+ process_error(:error_msg => _("VM already associated with a host"),
30
+ :redirect => compute_resource_vm_path(:compute_resource_id => params[:compute_resource_id],
31
+ :id => proxmox_vm_id(@compute_resource, @vm)))
30
32
  return
31
33
  end
32
34
  host = @compute_resource.associated_host(@vm) if @compute_resource.respond_to?(:associated_host)
33
35
  if host.present?
34
36
  host.associate!(@compute_resource, @vm)
35
- process_success(:success_msg => _("VM associated to host %s") % host.name, :success_redirect => host_path(host))
37
+ process_success(:success_msg => _("VM associated to host %s") % host.name,
38
+ :success_redirect => host_path(host))
36
39
  else
37
- process_error(:error_msg => _("No host found to associate this VM with"), :redirect => compute_resource_vm_path(:compute_resource_id => params[:compute_resource_id], :id => proxmox_vm_id(@compute_resource, @vm)))
40
+ process_error(:error_msg => _("No host found to associate this VM with"),
41
+ :redirect => compute_resource_vm_path(:compute_resource_id => params[:compute_resource_id],
42
+ :id => proxmox_vm_id(@compute_resource, @vm)))
38
43
  end
39
44
  end
40
45
 
@@ -51,14 +56,15 @@ module ForemanFogProxmox
51
56
  'hosts/console/log'
52
57
  end
53
58
  rescue StandardError => e
54
- process_error :redirect => compute_resource_vm_path(@compute_resource, proxmox_vm_id(@compute_resource, @vm)), :error_msg => (_("Failed to set console: %s") % e), :object => @vm
59
+ process_error :redirect => compute_resource_vm_path(@compute_resource, proxmox_vm_id(@compute_resource, @vm)),
60
+ :error_msg => (_("Failed to set console: %s") % e), :object => @vm
55
61
  end
56
62
 
57
63
  private
58
64
 
59
65
  def proxmox_vm_id(compute_resource, vm)
60
66
  id = vm.identity
61
- id = vm.unique_cluster_identity(compute_resource) if compute_resource.class == ForemanFogProxmox::Proxmox
67
+ id = vm.unique_cluster_identity(compute_resource) if compute_resource.instance_of?(ForemanFogProxmox::Proxmox)
62
68
  id
63
69
  end
64
70
 
@@ -69,11 +75,15 @@ module ForemanFogProxmox
69
75
  else
70
76
  error format(_("failed to %<action>s %<vm>s"), { :action => _(action), :vm => @vm })
71
77
  end
72
- redirect_back(:fallback_location => compute_resource_vm_path(:compute_resource_id => params[:compute_resource_id], :id => proxmox_vm_id(@compute_resource, @vm)))
78
+ redirect_back(:fallback_location => compute_resource_vm_path(
79
+ :compute_resource_id => params[:compute_resource_id], :id => proxmox_vm_id(@compute_resource, @vm)
80
+ ))
73
81
  # This should only rescue Fog::Errors, but Fog returns all kinds of errors...
74
82
  rescue StandardError => e
75
83
  error format(_("Error - %<message>s"), { :message => _(e.message) })
76
- redirect_back(:fallback_location => compute_resource_vm_path(:compute_resource_id => params[:compute_resource_id], :id => proxmox_vm_id(@compute_resource, @vm)))
84
+ redirect_back(:fallback_location => compute_resource_vm_path(
85
+ :compute_resource_id => params[:compute_resource_id], :id => proxmox_vm_id(@compute_resource, @vm)
86
+ ))
77
87
  end
78
88
  end
79
89
  end
@@ -27,7 +27,7 @@ module ForemanFogProxmox
27
27
  def compute_resource_params_filter
28
28
  super.tap do |filter|
29
29
  filter.permit :ssl_verify_peer,
30
- :ssl_certs, :disable_proxy, :auth_method, :token_id, :token
30
+ :ssl_certs, :disable_proxy, :auth_method, :token_id, :token
31
31
  end
32
32
  end
33
33
 
@@ -28,11 +28,16 @@ module ForemanFogProxmox
28
28
  # Clone the host
29
29
  def clone
30
30
  super
31
- return true unless @host.compute_resource.class == ForemanFogProxmox::Proxmox
31
+ return true unless @host.compute_resource.instance_of?(ForemanFogProxmox::Proxmox)
32
32
 
33
33
  @host.compute_attributes[:vmid] = next_vmid
34
- @host.compute_attributes[:interfaces_attributes].each { |index, interface_attributes| @host.compute_attributes[:interfaces_attributes][index] = interface_attributes.merge(macaddr: nil).merge(hwaddr: nil).merge(ip: nil).merge(ip6: nil) }
35
- @host.compute_attributes[:volumes_attributes].each { |index, volume_attributes| @host.compute_attributes[:volumes_attributes][index] = volume_attributes.merge(volid: nil) }
34
+ @host.compute_attributes[:interfaces_attributes].each do |index, interface_attributes|
35
+ @host.compute_attributes[:interfaces_attributes][index] =
36
+ interface_attributes.merge(macaddr: nil).merge(hwaddr: nil).merge(ip: nil).merge(ip6: nil)
37
+ end
38
+ @host.compute_attributes[:volumes_attributes].each do |index, volume_attributes|
39
+ @host.compute_attributes[:volumes_attributes][index] = volume_attributes.merge(volid: nil)
40
+ end
36
41
  end
37
42
 
38
43
  private
@@ -21,7 +21,8 @@ module ForemanFogProxmox
21
21
  class ComputeResourcesController < ::ApplicationController
22
22
  # GET foreman_fog_proxmox/isos/:compute_resource_id/:node_id/:storage
23
23
  def isos_by_id_and_node_and_storage
24
- volumes = load_compute_resource(params[:compute_resource_id]).images_by_storage(params[:node_id], params[:storage], 'iso')
24
+ volumes = load_compute_resource(params[:compute_resource_id]).images_by_storage(params[:node_id],
25
+ params[:storage], 'iso')
25
26
  respond_to do |format|
26
27
  format.json { render :json => volumes }
27
28
  end
@@ -29,7 +30,8 @@ module ForemanFogProxmox
29
30
 
30
31
  # GET foreman_fog_proxmox/ostemplates/:compute_resource_id/:node_id/:storage
31
32
  def ostemplates_by_id_and_node_and_storage
32
- volumes = load_compute_resource(params[:compute_resource_id]).images_by_storage(params[:node_id], params[:storage], 'vztmpl')
33
+ volumes = load_compute_resource(params[:compute_resource_id]).images_by_storage(params[:node_id],
34
+ params[:storage], 'vztmpl')
33
35
  respond_to do |format|
34
36
  format.json { render :json => volumes }
35
37
  end
@@ -37,7 +39,8 @@ module ForemanFogProxmox
37
39
 
38
40
  # GET foreman_fog_proxmox/isos/:compute_resource_id/:node_id
39
41
  def isos_by_id_and_node
40
- volumes = load_compute_resource(params[:compute_resource_id]).images_by_storage(params[:node_id], params[:storage], 'iso')
42
+ volumes = load_compute_resource(params[:compute_resource_id]).images_by_storage(params[:node_id],
43
+ params[:storage], 'iso')
41
44
  respond_to do |format|
42
45
  format.json { render :json => volumes }
43
46
  end
@@ -19,7 +19,8 @@
19
19
 
20
20
  module ProxmoxComputeControllersHelper
21
21
  def proxmox_controllers_map
22
- proxmox_controllers_cloudinit_map << ForemanFogProxmox::OptionsSelect.new(name: 'VirtIO Block', id: 'virtio', range: 15)
22
+ proxmox_controllers_cloudinit_map << ForemanFogProxmox::OptionsSelect.new(name: 'VirtIO Block', id: 'virtio',
23
+ range: 15)
23
24
  end
24
25
 
25
26
  def proxmox_controllers_cloudinit_map
@@ -21,9 +21,9 @@ module ProxmoxComputeResourcesHelper
21
21
  def user_token_expiration_date(compute_resource)
22
22
  expire = compute_resource.current_user_token_expire
23
23
  rescue ::Foreman::Exception => e
24
- return 'Has already expired. Please edit the compute resource to set a new valid one.' if e.message == 'User token expired'
24
+ 'Has already expired. Please edit the compute resource to set a new valid one.' if e.message == 'User token expired'
25
25
  rescue StandardError => e
26
- logger.warn(format(_('failed to get identity client version: %<e>s'), e: e))
26
+ logger.warn("failed to get identity client version: #{e}")
27
27
  raise e
28
28
  else
29
29
  return 'Never' if expire == 0
@@ -36,7 +36,7 @@ module ProxmoxComputeResourcesHelper
36
36
  rescue ::Foreman::Exception => e
37
37
  return [] if e.message == 'User token expired'
38
38
  rescue StandardError => e
39
- logger.warn(format(_('failed to get cluster nodes: %<e>s'), e: e))
39
+ logger.warn("failed to get cluster nodes: #{e}")
40
40
  raise e
41
41
  else
42
42
  nodes
@@ -20,7 +20,7 @@
20
20
  module ProxmoxComputeResourcesVmsHelper
21
21
  def proxmox_vm_id(compute_resource, vm)
22
22
  id = vm.identity
23
- id = vm.unique_cluster_identity(compute_resource) if compute_resource.class == ForemanFogProxmox::Proxmox
23
+ id = vm.unique_cluster_identity(compute_resource) if compute_resource.instance_of?(ForemanFogProxmox::Proxmox)
24
24
  id
25
25
  end
26
26
 
@@ -32,7 +32,9 @@ module ProxmoxComputeResourcesVmsHelper
32
32
  end
33
33
 
34
34
  def vm_power_action(vm, authorizer = nil)
35
- opts = hash_for_power_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => proxmox_vm_id(@compute_resource, vm)).merge(:auth_object => @compute_resource, :permission => 'power_compute_resources_vms', :authorizer => authorizer)
35
+ opts = hash_for_power_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => proxmox_vm_id(@compute_resource, vm)).merge(
36
+ :auth_object => @compute_resource, :permission => 'power_compute_resources_vms', :authorizer => authorizer
37
+ )
36
38
  html = power_action_html(vm)
37
39
 
38
40
  display_link_if_authorized "Power #{action_string(vm)}", opts, html.merge(:method => :put)
@@ -46,7 +48,8 @@ module ProxmoxComputeResourcesVmsHelper
46
48
  :id => proxmox_vm_id(@compute_resource, vm)
47
49
  ).merge(
48
50
  :auth_object => @compute_resource,
49
- :permission => 'edit_compute_resources'),
51
+ :permission => 'edit_compute_resources'
52
+ ),
50
53
  :title => _('Associate VM to a Foreman host'),
51
54
  :method => :put,
52
55
  :class => 'btn btn-default'
@@ -62,7 +65,8 @@ module ProxmoxComputeResourcesVmsHelper
62
65
  hash_for_import_compute_resource_vm_path(
63
66
  :compute_resource_id => @compute_resource,
64
67
  :id => proxmox_vm_id(@compute_resource, vm),
65
- :type => 'managed'),
68
+ :type => 'managed'
69
+ ),
66
70
  html_options
67
71
  )
68
72
  import_unmanaged_link = display_link_if_authorized(
@@ -70,7 +74,8 @@ module ProxmoxComputeResourcesVmsHelper
70
74
  hash_for_import_compute_resource_vm_path(
71
75
  :compute_resource_id => @compute_resource,
72
76
  :id => proxmox_vm_id(@compute_resource, vm),
73
- :type => 'unmanaged'),
77
+ :type => 'unmanaged'
78
+ ),
74
79
  html_options
75
80
  )
76
81
 
@@ -88,12 +93,16 @@ module ProxmoxComputeResourcesVmsHelper
88
93
  ),
89
94
  {
90
95
  :id => 'console-button',
91
- :class => 'btn btn-info'
96
+ :class => 'btn btn-info',
92
97
  }
93
98
  )
94
99
  end
95
100
 
96
101
  def vm_delete_action(vm, authorizer = nil)
97
- display_delete_if_authorized(hash_for_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => proxmox_vm_id(@compute_resource, vm)).merge(:auth_object => @compute_resource, :authorizer => authorizer), :class => 'btn btn-danger')
102
+ display_delete_if_authorized(
103
+ hash_for_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => proxmox_vm_id(@compute_resource, vm)).merge(
104
+ :auth_object => @compute_resource, :authorizer => authorizer
105
+ ), :class => 'btn btn-danger'
106
+ )
98
107
  end
99
108
  end
@@ -29,9 +29,11 @@ module ProxmoxFormHelper
29
29
  options[:value] = value if value.present?
30
30
  addClass options, 'form-control'
31
31
  pass = f.password_field(attr, options) +
32
- tag(:span, '', class: 'glyphicon glyphicon-warning-sign input-addon', title: 'Caps lock ON', style: 'display:none')
32
+ tag(:span, '', class: 'glyphicon glyphicon-warning-sign input-addon', title: 'Caps lock ON',
33
+ style: 'display:none')
33
34
  if unset_button
34
- button = link_to_function(icon_text('edit', '', :kind => 'pficon'), 'toggle_input_group(this)', :id => 'disable-pass-btn', :class => 'btn btn-default', :title => _('Change the password'))
35
+ button = link_to_function(icon_text('edit', '', :kind => 'pficon'), 'toggle_input_group(this)',
36
+ :id => 'disable-pass-btn', :class => 'btn btn-default', :title => _('Change the password'))
35
37
  input_group(pass, input_group_btn(button))
36
38
  else
37
39
  pass
@@ -53,10 +55,12 @@ module ProxmoxFormHelper
53
55
  options[:form_builder_local] ||= :f
54
56
  options[:form_builder_attrs] ||= {}
55
57
 
56
- content_tag(:div, :class => "#{options[:type]}_#{association}_fields_template form_template", :style => 'display: none;') do
57
- form_builder.fields_for(association, options[:object], :child_index => "new_#{options[:type]}_#{association}") do |f|
58
+ content_tag(:div, :class => "#{options[:type]}_#{association}_fields_template form_template",
59
+ :style => 'display: none;') do
60
+ form_builder.fields_for(association, options[:object],
61
+ :child_index => "new_#{options[:type]}_#{association}") do |f|
58
62
  render(:partial => options[:partial], :layout => options[:layout],
59
- :locals => { options[:form_builder_local] => f }.merge(options[:form_builder_attrs]))
63
+ :locals => { options[:form_builder_local] => f }.merge(options[:form_builder_attrs]))
60
64
  end
61
65
  end
62
66
  end
@@ -25,28 +25,20 @@ require 'foreman_fog_proxmox/hash_collection'
25
25
 
26
26
  # Convert a foreman form server hash into a fog-proxmox server attributes hash
27
27
  module ProxmoxVmConfigHelper
28
- KILO = 1024
29
- MEGA = KILO * KILO
30
- GIGA = KILO * MEGA
31
-
32
28
  def object_to_config_hash(vm, type)
33
29
  vm_h = ActiveSupport::HashWithIndifferentAccess.new
34
30
  main_a = ['vmid']
35
31
  main = vm.attributes.select { |key, _value| main_a.include? key }
36
32
  main_a += ['templated']
37
- config = vm.config.attributes.reject { |key, _value| main_a.include?(key) || Fog::Proxmox::DiskHelper.disk?(key) || Fog::Proxmox::NicHelper.nic?(key) }
33
+ config = vm.config.attributes.reject do |key, _value|
34
+ main_a.include?(key) || Fog::Proxmox::DiskHelper.disk?(key) || Fog::Proxmox::NicHelper.nic?(key)
35
+ end
38
36
  vm_h = vm_h.merge(main)
39
37
  vm_h = vm_h.merge('config_attributes': config)
40
- logger.debug(format(_('object_to_config_hash(%<type>s): vm_h=%<vm_h>s'), type: type, vm_h: vm_h))
38
+ logger.debug("object_to_config_hash(#{type}): vm_h=#{vm_h}")
41
39
  vm_h
42
40
  end
43
41
 
44
- def convert_memory_size(config_hash, key)
45
- # default unit memory size is Mb
46
- memory = (config_hash[key].to_i / MEGA).to_s == '0' ? config_hash[key] : (config_hash[key].to_i / MEGA).to_s
47
- config_hash.store(key, memory)
48
- end
49
-
50
42
  def general_a(type)
51
43
  general_a = ['node_id', 'type', 'config_attributes', 'volumes_attributes', 'interfaces_attributes']
52
44
  general_a += ['firmware_type', 'provision_method', 'container_volumes', 'server_volumes', 'start_after_create']
@@ -59,7 +51,7 @@ module ProxmoxVmConfigHelper
59
51
  main_a = ['name', 'type', 'node_id', 'vmid', 'interfaces', 'mount_points', 'disks']
60
52
  case type
61
53
  when 'lxc'
62
- cpu_a = ['arch', 'cpulimit', 'cpuunits', 'cores', 'sockets']
54
+ cpu_a = ['arch', 'cpulimit', 'cpuunits']
63
55
  memory_a = ['memory', 'swap']
64
56
  ostemplate_a = ['ostemplate', 'ostemplate_storage', 'ostemplate_file']
65
57
  keys.store(:ostemplate, ostemplate_a)
@@ -76,10 +68,6 @@ module ProxmoxVmConfigHelper
76
68
  keys
77
69
  end
78
70
 
79
- def convert_memory_sizes(args)
80
- ['memory', 'balloon', 'shares', 'swap'].each { |key| convert_memory_size(args['config_attributes'], key) }
81
- end
82
-
83
71
  def config_general_or_ostemplate_key?(key)
84
72
  config_typed_keys('lxc')[:general].include?(key) || config_typed_keys(type)[:ostemplate].include?(key)
85
73
  end
@@ -125,7 +113,9 @@ module ProxmoxVmConfigHelper
125
113
  logger.debug("parsed_typed_config(#{type}): config_cpu=#{config_cpu}")
126
114
  cpu = parse_typed_cpu(config_cpu, type)
127
115
  memory = parse_typed_memory(config.select { |key, _value| config_typed_keys(type)[:memory].include? key }, type)
128
- parsed_config = config.reject { |key, value| config_a(type).include?(key) || ForemanFogProxmox::Value.empty?(value) }
116
+ parsed_config = config.reject do |key, value|
117
+ config_a(type).include?(key) || ForemanFogProxmox::Value.empty?(value)
118
+ end
129
119
  parsed_vm = args.reject { |key, value| args_a(type).include?(key) || ForemanFogProxmox::Value.empty?(value) }
130
120
  parsed_vm = parsed_vm.merge(config_options(config, args, type))
131
121
  parsed_vm = parsed_vm.merge(parsed_config).merge(cpu).merge(memory)
@@ -134,26 +124,27 @@ module ProxmoxVmConfigHelper
134
124
  end
135
125
 
136
126
  def parse_typed_memory(args, type)
137
- memory = {}
138
127
  ForemanFogProxmox::HashCollection.remove_empty_values(args)
139
- config_typed_keys(type)[:memory].each { |key| ForemanFogProxmox::HashCollection.add_and_format_element(memory, key.to_sym, args, key, :to_i) }
140
- memory
128
+ logger.debug("parse_typed_memory(#{type}): args=#{args}")
129
+ args
141
130
  end
142
131
 
143
132
  def parse_typed_cpu(args, type)
144
133
  cpu = {}
145
134
  ForemanFogProxmox::HashCollection.remove_empty_values(args)
146
- if type == 'qemu'
135
+ case type
136
+ when 'qemu'
147
137
  logger.debug("parse_typed_cpu(#{type}): args=#{args}")
148
138
  cpu_flattened = Fog::Proxmox::CpuHelper.flatten(args)
149
139
  cpu_flattened = args[:cpu] if cpu_flattened.empty?
150
140
  logger.debug("parse_typed_cpu(#{type}): cpu_flattened=#{cpu_flattened}")
151
- ForemanFogProxmox::HashCollection.remove_empty_values(args)
152
- ForemanFogProxmox::HashCollection.remove_keys(args, config_typed_keys('qemu')[:cpu])
153
141
  args.each_value(&:to_i)
154
142
  cpu = { cpu: cpu_flattened }
143
+ when 'lxc'
144
+ config_typed_keys('lxc')[:cpu].each do |key|
145
+ ForemanFogProxmox::HashCollection.add_and_format_element(cpu, key.to_sym, args, key)
146
+ end
155
147
  end
156
- config_typed_keys('lxc')[:cpu].each { |key| ForemanFogProxmox::HashCollection.add_and_format_element(cpu, key.to_sym, args, key) } if type == 'lxc'
157
148
  logger.debug("parse_typed_cpu(#{type}): cpu=#{cpu}")
158
149
  cpu
159
150
  end
@@ -35,8 +35,12 @@ module ProxmoxVmInterfacesHelper
35
35
  interfaces_to_add = []
36
36
  interfaces_to_delete = []
37
37
  interfaces_attributes = args['interfaces_attributes']
38
- interfaces_attributes ||= args['config_attributes']['interfaces_attributes'] unless ForemanFogProxmox::Value.empty?(args['config_attributes'])
39
- interfaces_attributes&.each_value { |value| add_or_delete_typed_interface(value, interfaces_to_delete, interfaces_to_add, type) }
38
+ unless ForemanFogProxmox::Value.empty?(args['config_attributes'])
39
+ interfaces_attributes ||= args['config_attributes']['interfaces_attributes']
40
+ end
41
+ interfaces_attributes&.each_value do |value|
42
+ add_or_delete_typed_interface(value, interfaces_to_delete, interfaces_to_add, type)
43
+ end
40
44
  [interfaces_to_add, interfaces_to_delete]
41
45
  end
42
46
 
@@ -65,7 +69,9 @@ module ProxmoxVmInterfacesHelper
65
69
  def add_or_delete_typed_interface(interface_attributes, interfaces_to_delete, interfaces_to_add, type)
66
70
  logger.debug("add_or_delete_typed_interface(#{type}): interface_attributes=#{interface_attributes}")
67
71
  ForemanFogProxmox::HashCollection.remove_empty_values(interface_attributes)
68
- ForemanFogProxmox::HashCollection.remove_empty_values(interface_attributes['compute_attributes']) if interface_attributes['compute_attributes']
72
+ if interface_attributes['compute_attributes']
73
+ ForemanFogProxmox::HashCollection.remove_empty_values(interface_attributes['compute_attributes'])
74
+ end
69
75
  nic = {}
70
76
  id = interface_attributes['id']
71
77
  delete = interface_attributes['_delete'].to_i == 1
@@ -73,10 +79,17 @@ module ProxmoxVmInterfacesHelper
73
79
  logger.debug("add_or_delete_typed_interface(#{type}): delete id=#{id}")
74
80
  interfaces_to_delete.push(id.to_s)
75
81
  else
76
- interface_common_typed_keys(type).each { |key| ForemanFogProxmox::HashCollection.add_and_format_element(nic, key[:dest].to_sym, interface_attributes, key[:origin]) }
82
+ interface_common_typed_keys(type).each do |key|
83
+ ForemanFogProxmox::HashCollection.add_and_format_element(nic, key[:dest].to_sym, interface_attributes,
84
+ key[:origin])
85
+ end
77
86
  interface_attributes_h = interface_attributes['compute_attributes']
78
- interface_attributes_h ||= interface_attributes if ForemanFogProxmox::Value.empty?(interface_attributes['compute_attributes'])
79
- interface_compute_attributes_typed_keys(type).each { |key| ForemanFogProxmox::HashCollection.add_and_format_element(nic, key.to_sym, interface_attributes_h, key) }
87
+ if ForemanFogProxmox::Value.empty?(interface_attributes['compute_attributes'])
88
+ interface_attributes_h ||= interface_attributes
89
+ end
90
+ interface_compute_attributes_typed_keys(type).each do |key|
91
+ ForemanFogProxmox::HashCollection.add_and_format_element(nic, key.to_sym, interface_attributes_h, key)
92
+ end
80
93
  compute_dhcps(interface_attributes_h)
81
94
  logger.debug("add_or_delete_typed_interface(#{type}): add nic=#{nic}")
82
95
  interfaces_to_add.push(Fog::Proxmox::NicHelper.flatten(nic))
@@ -38,10 +38,7 @@ module ProxmoxVmOsTemplateHelper
38
38
  end
39
39
 
40
40
  def parse_container_ostemplate(args)
41
- ostemplate = args['ostemplate']
42
- ostemplate_file = args['ostemplate_file']
43
- ostemplate ||= ostemplate_file
44
- parsed_ostemplate = { ostemplate: ostemplate }
45
- parsed_ostemplate
41
+ ostemplate = args['ostemplate'] || args['ostemplate_file']
42
+ { ostemplate: ostemplate }
46
43
  end
47
44
  end
@@ -18,7 +18,7 @@
18
18
  # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module ProxmoxVmUuidHelper
21
- UUID_REGEXP = /(?<cluster_id>\d+)[_](?<vmid>\d+)/.freeze
21
+ UUID_REGEXP = /(?<cluster_id>\d+)_(?<vmid>\d+)/.freeze
22
22
  def extract(uuid, name)
23
23
  captures_h = uuid ? UUID_REGEXP.match(uuid.to_s) : { cluster_id: '', vmid: '' }
24
24
  captures_h ? captures_h[name] : ''