foreman_fog_proxmox 0.13.0 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -4
  3. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +25 -13
  4. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +3 -1
  5. data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +23 -25
  6. data/app/helpers/proxmox_vm_config_helper.rb +5 -4
  7. data/app/helpers/proxmox_vm_uuid_helper.rb +34 -0
  8. data/app/models/concerns/fog_extensions/proxmox/server.rb +4 -0
  9. data/app/models/concerns/orchestration/proxmox/compute.rb +48 -0
  10. data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +1 -0
  11. data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +1 -1
  12. data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +8 -6
  13. data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +6 -2
  14. data/app/views/api/v2/compute_resources/proxmox.json.rabl +1 -1
  15. data/app/views/compute_resources_vms/form/proxmox/server/_volume_cdrom.html.erb +1 -1
  16. data/config/routes.rb +7 -7
  17. data/db/migrate/20210312105013_update_proxmox_uuid_host.rb +29 -0
  18. data/lib/foreman_fog_proxmox/engine.rb +7 -1
  19. data/lib/foreman_fog_proxmox/version.rb +1 -1
  20. data/test/functional/compute_resources_controller_test.rb +4 -4
  21. data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +4 -3
  22. data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +3 -1
  23. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_uuid_helper_test.rb +38 -0
  24. data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +3 -3
  25. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6101f16731ab275d2adfb1b0abc8fd25690688e34569b7f63c360fb6442da5ec
4
- data.tar.gz: 62bfd05f02a526de1a4decc27d5a8c6ee5539b58316fb0bc29338dc26f4c0a04
3
+ metadata.gz: 6ee2ea48049134a2a429baa88bd6f3299c321f38a5f3532c8c17d1a3012dc277
4
+ data.tar.gz: 246a3ee1a5bb9f7f99e55b7f97f637cae3b49b12e7917667444238ae007e21e6
5
5
  SHA512:
6
- metadata.gz: d46aa0181a540105670a8b4cc988f791cde9ac05d8323c2eec250d53ee44c1b1eaea581619276f21cc7a433931470007019e2e3028ece8f750b4fcef704398ac
7
- data.tar.gz: ce879270338d08b684991184079b8106519de9394c4e85b8cfcc74e5e30620a75d217eefa8ce8301711b30fbcd20ef051925a3190ae5b8b34e4c4157a1a3895c
6
+ metadata.gz: b7ba0a9c31049f222e8cd06fd411356ae1302dcf1b9b0acfe0be8498d514c39e3c54373d8603484183c01318bff6c9ad4b18c8366f28916ffa05976e87b62914
7
+ data.tar.gz: 66d723e3135509e731e663438fa5d5cd3f79464641e4470c7b8f7908d744ba04d069a579c334140acc1b927c408208fa91cac5e30daf27998cb64f91575b9fc8
data/README.md CHANGED
@@ -32,7 +32,8 @@ You can support the plugin development via the following methods:
32
32
  |>=0.10 |>=5.4|>=0.9.4|>=1.22|>=2.5|
33
33
  |>=0.11 |>=5.4|>=0.10|>=1.22|>=2.5|
34
34
  |>=0.12 |>=6.1|>=0.11|>=2.0|>=2.5|
35
- |>=0.14 |>=6.2|>=0.13|>=2.0|>=2.5|
35
+ |>=0.14 |>=6.2|=0.13.0|>=2.4|>=2.7|
36
+ |>=0.14 |>=6.2|>=0.13.1|>=2.3|>=2.5|
36
37
 
37
38
  ## Installation
38
39
 
@@ -136,6 +137,7 @@ gem 'foreman_fog_proxmox', :path => '../../theforeman/foreman_fog_proxmox'
136
137
  gem 'fog-proxmox', :path => '../../fog/fog-proxmox' # optional if you need to modify fog-proxmox code too
137
138
  gem 'ruby-debug-ide' # dev
138
139
  gem 'debase' # dev
140
+ gem 'solargraph' # dev
139
141
  gem 'simplecov' # test
140
142
  ```
141
143
 
@@ -143,8 +145,9 @@ gem 'simplecov' # test
143
145
 
144
146
  ```shell
145
147
  gem install bundler
146
- # prerequisites postgresql-client library on OS
148
+ # prerequisites postgresql-XX-client library on OS (XX=major release installed in OS)
147
149
  bundle config set without 'libvirt ovirt mysql2'
150
+ bundle config build.pg --with-pg-config=/usr/pgsql-XX/bin/pg_config
148
151
  bundle install
149
152
  ```
150
153
 
@@ -177,7 +180,7 @@ cp config/model.mappings.example config/model.mappings
177
180
  cp config/database.yml.example config/database.yml
178
181
  ```
179
182
 
180
- add these lines to config/database.yml:
183
+ add these lines to each environment in config/database.yml:
181
184
 
182
185
  ```yaml
183
186
  username: foreman
@@ -188,6 +191,7 @@ add these lines to config/database.yml:
188
191
  cp config/ignored_environments.yml.sample config/ignored_environments.yml
189
192
  docker run --name foreman-db -e POSTGRES_DB=foreman -e POSTGRES_USER=foreman -e POSTGRES_PASSWORD=foreman -p 5432:5432 -d postgres
190
193
  bundle exec bin/rake db:migrate
194
+ # reboot if settings.NAME error in schema
191
195
  bundle exec bin/rake db:seed assets:precompile locale:pack webpack:compile
192
196
  ```
193
197
 
@@ -206,7 +210,15 @@ docker exec -it foreman-db psql -U foreman
206
210
  foreman=# create database "foreman-test";
207
211
  ```
208
212
 
209
- all:
213
+ then add test schema and seeds:
214
+
215
+ ```shell
216
+ RAILS_ENV=test bundle exec bin/rake db:migrate
217
+ # reboot if error: "ActiveRecord::RecordNotFound: Couldn't find Setting with [WHERE "settings"."name" = $1]"
218
+ RAILS_ENV=test bundle exec bin/rake db:seed
219
+ ```
220
+
221
+ Finally you can test all:
210
222
 
211
223
  ```shell
212
224
  export DISABLE_SPRING=true
@@ -274,6 +286,12 @@ bundle exec bin/rails server
274
286
  bundle exec foreman start
275
287
  ```
276
288
 
289
+ If you want to delete vm on host destroy, add this line in config/settings.yml:
290
+
291
+ ```yml
292
+ :destroy_vm_on_host_delete: false
293
+ ```
294
+
277
295
  See details in [foreman plugin development](https://projects.theforeman.org/projects/foreman/wiki/How_to_Create_a_Plugin)
278
296
 
279
297
  ## Contributing
@@ -36,20 +36,32 @@ function sslVerifyPeerSelected() {
36
36
  }
37
37
  }
38
38
 
39
+ function enableField(id) {
40
+ $(id).show();
41
+ $(id).removeAttr('disabled');
42
+ }
43
+
44
+ function disableField(id) {
45
+ $(id).hide();
46
+ $(id).attr('disabled','disabled');
47
+ }
48
+
49
+ function toggleFieldset(method, selected){
50
+ return method === selected ? enableField(authMethodFieldsetId(method)) : disableField(authMethodFieldsetId(method));
51
+ }
52
+
53
+ function authMethods(){
54
+ return ['user_token', 'access_ticket'];
55
+ }
56
+
57
+ function authMethodFieldsetId(method){
58
+ return '#compute_ressource_' + method + '_field_set';
59
+ }
60
+
39
61
  function authMethodSelected() {
40
62
  var selected = $("#compute_resource_auth_method").val();
41
63
  console.log("auth_method="+selected);
42
- var compute_ressource_user_token_field_set = $('#compute_ressource_user_token_field_set');
43
- var compute_ressource_access_ticket_field_set = $('#compute_ressource_access_ticket_field_set');
44
- if (selected == 'user_token') {
45
- compute_ressource_user_token_field_set.show();
46
- compute_ressource_user_token_field_set.removeAttr('disabled');
47
- compute_ressource_access_ticket_field_set.hide();
48
- compute_ressource_access_ticket_field_set.attr('disabled','disabled');
49
- } else {
50
- compute_ressource_access_ticket_field_set.show();
51
- compute_ressource_access_ticket_field_set.removeAttr('disabled');
52
- compute_ressource_user_token_field_set.hide();
53
- compute_ressource_user_token_field_set.attr('disabled','disabled');
54
- }
64
+ authMethods().forEach(function(method){
65
+ toggleFieldset(method, selected);
66
+ });
55
67
  }
@@ -228,7 +228,9 @@ function updateOptions(options_path, start_options_id, end_options_id, start_sec
228
228
  if ( start_second_options_id != undefined && end_second_options_id != undefined) {
229
229
  select_second_ids = selectIds(start_second_options_id, end_second_options_id);
230
230
  }
231
- var url = '/foreman_fog_proxmox/' + options_path + '/' + node_id;
231
+ var compute_resource_id = $("#host_compute_resource_id").val();
232
+ if (compute_resource_id == undefined) compute_resource_id = $("#compute_attribute_compute_resource_id").val(); // profil
233
+ var url = '/foreman_fog_proxmox/' + options_path + '/' + compute_resource_id + '/' + node_id;
232
234
  if (second_id != undefined) url += '/' + second_id;
233
235
  tfm.tools.showSpinner();
234
236
  $.getJSON({
@@ -19,59 +19,57 @@
19
19
 
20
20
  module ForemanFogProxmox
21
21
  class ComputeResourcesController < ::ApplicationController
22
- before_action :load_compute_resource
23
-
24
- # GET foreman_fog_proxmox/isos/:node_id/:storage
25
- def isos_by_node_and_storage
26
- volumes = @compute_resource.images_by_storage(params[:node_id], params[:storage], 'iso')
22
+ # GET foreman_fog_proxmox/isos/:compute_resource_id/:node_id/:storage
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')
27
25
  respond_to do |format|
28
26
  format.json { render :json => volumes }
29
27
  end
30
28
  end
31
29
 
32
- # GET foreman_fog_proxmox/ostemplates/:node_id/:storage
33
- def ostemplates_by_node_and_storage
34
- volumes = @compute_resource.images_by_storage(params[:node_id], params[:storage], 'vztmpl')
30
+ # GET foreman_fog_proxmox/ostemplates/:compute_resource_id/:node_id/:storage
31
+ 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')
35
33
  respond_to do |format|
36
34
  format.json { render :json => volumes }
37
35
  end
38
36
  end
39
37
 
40
- # GET foreman_fog_proxmox/isos/:node_id
41
- def isos_by_node
42
- volumes = @compute_resource.images_by_storage(params[:node_id], params[:storage], 'iso')
38
+ # GET foreman_fog_proxmox/isos/:compute_resource_id/:node_id
39
+ def isos_by_id_and_node
40
+ volumes = load_compute_resource(params[:compute_resource_id]).images_by_storage(params[:node_id], params[:storage], 'iso')
43
41
  respond_to do |format|
44
42
  format.json { render :json => volumes }
45
43
  end
46
44
  end
47
45
 
48
- # GET foreman_fog_proxmox/ostemplates/:node_id
49
- def ostemplates_by_node
50
- storages = @compute_resource.storages(params[:node_id], 'vztmpl')
46
+ # GET foreman_fog_proxmox/ostemplates/:compute_resource_id/:node_id
47
+ def ostemplates_by_id_and_node
48
+ storages = load_compute_resource(params[:compute_resource_id]).storages(params[:node_id], 'vztmpl')
51
49
  respond_to do |format|
52
50
  format.json { render :json => storages }
53
51
  end
54
52
  end
55
53
 
56
- # GET foreman_fog_proxmox/storages/:node_id
57
- def storages_by_node
58
- storages = @compute_resource.storages(params[:node_id])
54
+ # GET foreman_fog_proxmox/storages/:compute_resource_id/:node_id
55
+ def storages_by_id_and_node
56
+ storages = load_compute_resource(params[:compute_resource_id]).storages(params[:node_id])
59
57
  respond_to do |format|
60
58
  format.json { render :json => storages }
61
59
  end
62
60
  end
63
61
 
64
- # GET foreman_fog_proxmox/isostorages/:node_id
65
- def iso_storages_by_node
66
- storages = @compute_resource.storages(params[:node_id], 'iso')
62
+ # GET foreman_fog_proxmox/isostorages/:compute_resource_id/:node_id
63
+ def iso_storages_by_id_and_node
64
+ storages = load_compute_resource(params[:compute_resource_id]).storages(params[:node_id], 'iso')
67
65
  respond_to do |format|
68
66
  format.json { render :json => storages }
69
67
  end
70
68
  end
71
69
 
72
- # GET foreman_fog_proxmox/bridges/:node_id
73
- def bridges_by_node
74
- bridges = @compute_resource.bridges(params[:node_id])
70
+ # GET foreman_fog_proxmox/bridges/:compute_resource_id/:node_id
71
+ def bridges_by_id_and_node
72
+ bridges = load_compute_resource(params[:compute_resource_id]).bridges(params[:node_id])
75
73
  respond_to do |format|
76
74
  format.json { render :json => bridges }
77
75
  end
@@ -79,8 +77,8 @@ module ForemanFogProxmox
79
77
 
80
78
  private
81
79
 
82
- def load_compute_resource
83
- @compute_resource = ComputeResource.find_by(type: 'ForemanFogProxmox::Proxmox')
80
+ def load_compute_resource(compute_resource_id)
81
+ ComputeResource.find(compute_resource_id)
84
82
  end
85
83
  end
86
84
  end
@@ -31,7 +31,7 @@ module ProxmoxVmConfigHelper
31
31
 
32
32
  def object_to_config_hash(vm, type)
33
33
  vm_h = ActiveSupport::HashWithIndifferentAccess.new
34
- main_a = ['hostname', 'name', 'vmid']
34
+ main_a = ['vmid']
35
35
  main = vm.attributes.select { |key, _value| main_a.include? key }
36
36
  main_a += ['templated']
37
37
  config = vm.config.attributes.reject { |key, _value| main_a.include?(key) || Fog::Proxmox::DiskHelper.disk?(key) || Fog::Proxmox::NicHelper.nic?(key) }
@@ -47,14 +47,15 @@ module ProxmoxVmConfigHelper
47
47
  config_hash.store(key, memory)
48
48
  end
49
49
 
50
- def general_a
51
- general_a = ['name', 'node_id', 'type', 'config_attributes', 'volumes_attributes', 'interfaces_attributes']
50
+ def general_a(type)
51
+ general_a = ['node_id', 'type', 'config_attributes', 'volumes_attributes', 'interfaces_attributes']
52
52
  general_a += ['firmware_type', 'provision_method', 'container_volumes', 'server_volumes', 'start_after_create']
53
+ general_a += ['name'] if type == 'lxc'
53
54
  general_a
54
55
  end
55
56
 
56
57
  def config_typed_keys(type)
57
- keys = { general: general_a }
58
+ keys = { general: general_a(type) }
58
59
  main_a = ['name', 'type', 'node_id', 'vmid', 'interfaces', 'mount_points', 'disks']
59
60
  case type
60
61
  when 'lxc'
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+
12
+ # ForemanFogProxmox is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ module ProxmoxVmUuidHelper
21
+ UUID_REGEXP = /(?<cluster_id>\d+)[_](?<vmid>\d+)/.freeze
22
+ def extract(uuid, name)
23
+ captures_h = uuid ? UUID_REGEXP.match(uuid.to_s) : { cluster_id: '', vmid: '' }
24
+ captures_h ? captures_h[name] : ''
25
+ end
26
+
27
+ def match_uuid?(uuid)
28
+ extract(uuid, :cluster_id) != ''
29
+ end
30
+
31
+ def extract_vmid(uuid)
32
+ extract(uuid, :vmid)
33
+ end
34
+ end
@@ -23,6 +23,10 @@ module FogExtensions
23
23
  extend ActiveSupport::Concern
24
24
  attr_accessor :image_id, :templated, :ostemplate_storage, :ostemplate_file, :password, :start_after_create
25
25
 
26
+ def unique_cluster_identity
27
+ compute_resource.name + '_' + identity
28
+ end
29
+
26
30
  def start
27
31
  action('start')
28
32
  end
@@ -38,6 +38,54 @@ module Orchestration
38
38
  rescue StandardError => e
39
39
  failure format(_('Failed to undo update compute %<compute_resource>s instance %<name>s: %<e>s'), :compute_resource => compute_resource, :name => name, :e => e), e
40
40
  end
41
+
42
+ def empty_provided_ips?(ip, ip6)
43
+ ip.blank? && ip6.blank? && (compute_provides?(:ip) || compute_provides?(:ip6))
44
+ end
45
+
46
+ def ips_keys
47
+ [:ip, :ip6]
48
+ end
49
+
50
+ def computeIp(foreman_attr, fog_attr)
51
+ vm.send(fog_attr) || find_address(foreman_attr)
52
+ end
53
+
54
+ def computeValue(foreman_attr, fog_attr)
55
+ value = ''
56
+ value += compute_resource.id.to_s + '_' if foreman_attr == :uuid
57
+ value += vm.send(fog_attr)
58
+ value
59
+ end
60
+
61
+ def setVmDetails
62
+ attrs = compute_resource.provided_attributes
63
+ result = true
64
+ attrs.each do |foreman_attr, fog_attr|
65
+ if foreman_attr == :mac
66
+ result = false unless match_macs_to_nics(fog_attr)
67
+ elsif ips_keys.include?(foreman_attr)
68
+ value = computeIp(foreman_attr, fog_attr)
69
+ send("#{foreman_attr}=", value)
70
+ result = false if send(foreman_attr).present? && !validate_foreman_attr(value, ::Nic::Base, foreman_attr)
71
+ else
72
+ value = computeValue(foreman_attr, fog_attr)
73
+ send("#{foreman_attr}=", value)
74
+ result = false unless validate_required_foreman_attr(value, Host, foreman_attr)
75
+ end
76
+ end
77
+ return failure(format(_('Failed to acquire IP addresses from compute resource for %<name>s'), name: name)) if empty_provided_ips?(ip, ip6)
78
+
79
+ result
80
+ end
81
+
82
+ def setComputeDetails
83
+ if vm
84
+ setVmDetails
85
+ else
86
+ failure format(_('failed to save %<name>s'), name: name)
87
+ end
88
+ end
41
89
  end
42
90
  end
43
91
  end
@@ -26,6 +26,7 @@ module ForemanFogProxmox
26
26
  when 'lxc'
27
27
  host.compute_attributes['config_attributes'].store('hostname', host.name)
28
28
  when 'qemu'
29
+ host.compute_attributes['config_attributes'].store('name', host.name)
29
30
  unless compute_os_types(host).include?(ostype)
30
31
  raise ::Foreman::Exception, format(_('Operating system family %<type>s is not consistent with %<ostype>s'), type: host.operatingsystem.type, ostype: ostype)
31
32
  end
@@ -50,7 +50,7 @@ module ForemanFogProxmox
50
50
  end
51
51
  rescue StandardError => e
52
52
  logger.warn(format(_('failed to create vm: %<e>s'), e: e))
53
- destroy_vm vm.id if vm
53
+ destroy_vm client.identity + '_' + vm.id if vm
54
54
  raise e
55
55
  end
56
56
 
@@ -20,6 +20,7 @@
20
20
  module ForemanFogProxmox
21
21
  module ProxmoxVmQueries
22
22
  include ProxmoxPools
23
+ include ProxmoxVmUuidHelper
23
24
 
24
25
  def nodes
25
26
  nodes = client.nodes.all if client
@@ -51,25 +52,26 @@ module ForemanFogProxmox
51
52
  def find_vm_by_uuid(uuid)
52
53
  # look for the uuid on all known nodes
53
54
  vm = nil
55
+ vmid = extract_vmid(uuid)
54
56
  nodes.each do |node|
55
- vm = find_vm_in_servers_by_uuid(node.servers, uuid)
56
- vm ||= find_vm_in_servers_by_uuid(node.containers, uuid)
57
+ vm = find_vm_in_servers_by_vmid(node.servers, vmid)
58
+ vm ||= find_vm_in_servers_by_vmid(node.containers, vmid)
57
59
  unless vm.nil?
58
- logger.debug("found vm #{uuid} on node #{node.node}")
60
+ logger.debug("found vm #{vmid} on node #{node.node}")
59
61
  break
60
62
  end
61
63
  end
62
64
  vm
63
65
  end
64
66
 
65
- def find_vm_in_servers_by_uuid(servers, uuid)
66
- vm = servers.get(uuid) unless ForemanFogProxmox::Value.empty?(uuid)
67
+ def find_vm_in_servers_by_vmid(servers, vmid)
68
+ vm = servers.get(vmid) unless ForemanFogProxmox::Value.empty?(vmid)
67
69
  pool_owner(vm) if vm
68
70
  vm
69
71
  rescue Fog::Errors::NotFound
70
72
  nil
71
73
  rescue StandardError => e
72
- Foreman::Logging.exception(format(_('Failed retrieving proxmox server vm by vmid=%<vmid>s'), vmid: uuid), e)
74
+ Foreman::Logging.exception(format(_('Failed retrieving proxmox server vm by vmid=%<vmid>s'), vmid: vmid), e)
73
75
  raise(ActiveRecord::RecordNotFound, e)
74
76
  end
75
77
  end
@@ -24,9 +24,13 @@ module ForemanFogProxmox
24
24
  @filter = filter
25
25
  end
26
26
 
27
+ def node
28
+ @compute_resource = ComputeResource.where(type: 'ForemanFogProxmox::Proxmox').first
29
+ @compute_resource.nodes.first
30
+ end
31
+
27
32
  def node_id
28
- @compute_resource = ComputeResource.find_by(type: 'ForemanFogProxmox::Proxmox')
29
- @compute_resource&.node_id
33
+ node&.identity
30
34
  end
31
35
 
32
36
  def statistics
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- attributes :url, :user, :password, :ssl_verify_peer, :ssl_certs, :renew
3
+ attributes :url, :user, :ssl_verify_peer, :ssl_certs, :renew
@@ -27,7 +27,7 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
27
27
  <%= radio_button_f f, :cdrom, :value => 'cdrom' , :text => _('Physical'), :onclick => 'cdromSelected(this)' %>
28
28
  <%= radio_button_f f, :cdrom, :value => 'image' , :text => _('Image'), :onclick => 'cdromSelected(this)' %>
29
29
  <% end %>
30
- <%= field_set_tag _("Image"), :id => "cdrom_image_form_#{f.index}", :class => ('hide' unless %[image].include? f.object.cdrom), :disabled => (%[cdrom none].include? f.object.cdrom) do %>
30
+ <%= field_set_tag(_("Image"), :id => "cdrom_image_form_#{f.index}", :class => ('hide' unless %[image].include? f.object.cdrom), :disabled => (%[cdrom none].include? f.object.cdrom)) do %>
31
31
  <%= select_f f, :storage, compute_resource.storages(node_id,'iso'), :storage, :storage, { :include_blank => true }, :label => _('Storage'), :label_size => "col-md-2", :onchange => 'storageIsoSelected(this)' %>
32
32
  <%= select_f f, :volid, compute_resource.images_by_storage(node_id, f.object.storage, 'iso'), :volid, :volid, { :include_blank => true }, :label => _('Image ISO'), :label_size => "col-md-2" %>
33
33
  <% end %>
data/config/routes.rb CHANGED
@@ -19,12 +19,12 @@
19
19
 
20
20
  Rails.application.routes.draw do
21
21
  namespace :foreman_fog_proxmox do
22
- match 'isos/:node_id/:storage', :to => 'compute_resources#isos_by_node_and_storage', :via => 'get'
23
- match 'ostemplates/:node_id/:storage', :to => 'compute_resources#ostemplates_by_node_and_storage', :via => 'get'
24
- match 'isos/:node_id', :to => 'compute_resources#isos_by_node', :via => 'get'
25
- match 'ostemplates/:node_id', :to => 'compute_resources#ostemplates_by_node', :via => 'get'
26
- match 'storages/:node_id', :to => 'compute_resources#storages_by_node', :via => 'get'
27
- match 'isostorages/:node_id', :to => 'compute_resources#iso_storages_by_node', :via => 'get'
28
- match 'bridges/:node_id', :to => 'compute_resources#bridges_by_node', :via => 'get'
22
+ match 'isos/:compute_resource_id/:node_id/:storage', :to => 'compute_resources#isos_by_id_and_node_and_storage', :via => 'get'
23
+ match 'ostemplates/:compute_resource_id/:node_id/:storage', :to => 'compute_resources#ostemplates_by_id_and_node_and_storage', :via => 'get'
24
+ match 'isos/:compute_resource_id/:node_id', :to => 'compute_resources#isos_by_id_and_node', :via => 'get'
25
+ match 'ostemplates/:compute_resource_id/:node_id', :to => 'compute_resources#ostemplates_by_id_and_node', :via => 'get'
26
+ match 'storages/:compute_resource_id/:node_id', :to => 'compute_resources#storages_by_id_and_node', :via => 'get'
27
+ match 'isostorages/:compute_resource_id/:node_id', :to => 'compute_resources#iso_storages_by_id_and_node', :via => 'get'
28
+ match 'bridges/:compute_resource_id/:node_id', :to => 'compute_resources#bridges_by_id_and_node', :via => 'get'
29
29
  end
30
30
  end
@@ -0,0 +1,29 @@
1
+ include ProxmoxVmUuidHelper
2
+ class UpdateProxmoxUuidHost < ActiveRecord::Migration[6.0]
3
+
4
+ def up
5
+ execute(sql(:concat))
6
+ end
7
+
8
+ def down
9
+ execute(sql(:substring))
10
+ end
11
+
12
+ private
13
+
14
+ def concat
15
+ "concat(h.compute_resource_id, '_', h.uuid) "
16
+ end
17
+
18
+ def substring
19
+ "substring(h.uuid, position('_' in h.uuid) + 1, length(h.uuid)) "
20
+ end
21
+
22
+ def sql(func_type)
23
+ sql = 'update hosts h set uuid = '
24
+ sql += send(func_type)
25
+ sql += 'from compute_resources cr '
26
+ sql += "where cr.id = h.compute_resource_id and cr.type = 'ForemanFogProxmox::Proxmox';"
27
+ sql
28
+ end
29
+ end
@@ -46,7 +46,13 @@ module ForemanFogProxmox
46
46
  widget 'foreman_fog_proxmox_widget', name: N_('Foreman Fog Proxmox widget'), sizex: 8, sizey: 1
47
47
  security_block :foreman_fog_proxmox do
48
48
  permission :view_compute_resource, { :compute_resources =>
49
- [:ostemplates_by_node_and_storage, :isos_by_node_and_storage, :ostemplates_by_node, :isos_by_node, :storages_by_node, :iso_storages_by_node, :bridges_by_node] }
49
+ [:ostemplates_by_id_and_node_and_storage,
50
+ :isos_by_id_and_node_and_storage,
51
+ :ostemplates_by_id_and_node,
52
+ :isos_by_id_and_node,
53
+ :storages_by_id_and_node,
54
+ :iso_storages_by_id_and_node,
55
+ :bridges_by_id_and_node] }
50
56
  end
51
57
  end
52
58
  end
@@ -18,5 +18,5 @@
18
18
  # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module ForemanFogProxmox
21
- VERSION = '0.13.0'
21
+ VERSION = '0.13.1'
22
22
  end
@@ -21,25 +21,25 @@ require 'test_plugin_helper'
21
21
  module ForemanFogProxmox
22
22
  class ComputeResourcesControllerTest < ActionController::TestCase
23
23
  test 'should get isos by node and storage' do
24
- get :isos_by_node_and_storage, params: { :node_id => 'proxmox', :storage => 'local' }
24
+ get :isos_by_id_and_node_and_storage, params: { :compute_resource_id => 1, :node_id => 'proxmox', :storage => 'local' }
25
25
  assert_response :found
26
26
  show_response = @response.body
27
27
  assert_not show_response.empty?
28
28
  end
29
29
  test 'should get ostemplates by node and storage' do
30
- get :ostemplates_by_node_and_storage, params: { :node_id => 'proxmox', :storage => 'local' }
30
+ get :ostemplates_by_id_and_node_and_storage, params: { :compute_resource_id => 1, :node_id => 'proxmox', :storage => 'local' }
31
31
  assert_response :found
32
32
  show_response = @response.body
33
33
  assert_not show_response.empty?
34
34
  end
35
35
  test 'should get isos by node' do
36
- get :isos_by_node, params: { :node_id => 'proxmox' }
36
+ get :isos_by_id_and_node, params: { :compute_resource_id => 1, :node_id => 'proxmox' }
37
37
  assert_response :found
38
38
  show_response = @response.body
39
39
  assert_not show_response.empty?
40
40
  end
41
41
  test 'should get ostemplates by node' do
42
- get :ostemplates_by_node, params: { :node_id => 'proxmox' }
42
+ get :ostemplates_by_id_and_node, params: { :compute_resource_id => 1, :node_id => 'proxmox' }
43
43
  assert_response :found
44
44
  show_response = @response.body
45
45
  assert_not show_response.empty?
@@ -33,7 +33,6 @@ module ForemanFogProxmox
33
33
 
34
34
  let(:host_form) do
35
35
  { 'vmid' => '100',
36
- 'name' => 'test',
37
36
  'type' => 'lxc',
38
37
  'node_id' => 'proxmox',
39
38
  'ostemplate_storage' => 'local',
@@ -49,7 +48,7 @@ module ForemanFogProxmox
49
48
  'cpuunits' => '',
50
49
  'arch' => 'amd64',
51
50
  'ostype' => 'debian',
52
- 'hostname' => '',
51
+ 'hostname' => 'toto-tata.pve',
53
52
  'nameserver' => '',
54
53
  'searchdomain' => ''
55
54
 
@@ -88,7 +87,7 @@ module ForemanFogProxmox
88
87
  let(:container) do
89
88
  { 'vmid' => '100',
90
89
  :vmid => '100',
91
- 'name' => 'test',
90
+ 'hostname' => 'toto-tata.pve',
92
91
  'type' => 'lxc',
93
92
  :type => 'lxc',
94
93
  'node_id' => 'proxmox',
@@ -148,6 +147,7 @@ module ForemanFogProxmox
148
147
  assert_equal 536_870_912, vm[:memory]
149
148
  assert_equal 'local-lvm:1073741824', vm[:rootfs]
150
149
  assert_equal 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876', vm[:net0]
150
+ assert_equal 'toto-tata.pve', vm[:hostname]
151
151
  assert_not vm.key?(:config)
152
152
  assert_not vm.key?(:node)
153
153
  assert_not vm.key?(:type)
@@ -165,6 +165,7 @@ module ForemanFogProxmox
165
165
  :cores => '1',
166
166
  :arch => 'amd64',
167
167
  :ostype => 'debian',
168
+ :hostname => 'toto-tata.pve',
168
169
  :net0 => 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876',
169
170
  :net1 => 'name=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876',
170
171
  :rootfs => 'local-lvm:1073741824',
@@ -33,10 +33,11 @@ module ForemanFogProxmox
33
33
 
34
34
  let(:host_form) do
35
35
  { 'vmid' => '100',
36
- 'name' => 'test',
36
+ 'name' => 'toto-tata.pve',
37
37
  'node_id' => 'proxmox',
38
38
  'type' => 'qemu',
39
39
  'config_attributes' => {
40
+ 'name' => 'toto-tata.pve',
40
41
  'memory' => '536870912',
41
42
  'balloon' => '268435456',
42
43
  'shares' => '5',
@@ -111,6 +112,7 @@ module ForemanFogProxmox
111
112
  assert_equal 5, vm[:shares]
112
113
  assert_equal 'local-lvm:1073741824,cache=none', vm[:scsi0]
113
114
  assert_equal 'model=virtio,bridge=vmbr0,firewall=0,link_down=0', vm[:net0]
115
+ assert_equal 'toto-tata.pve', vm[:name]
114
116
  assert_not vm.key?(:config)
115
117
  assert_not vm.key?(:node)
116
118
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+
12
+ # ForemanFogProxmox is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'test_plugin_helper'
21
+
22
+ module ForemanFogProxmox
23
+ class ProxmoxVmUuidHelperTest < ActiveSupport::TestCase
24
+ include ProxmoxVmUuidHelper
25
+
26
+ describe 'extract_vmid' do
27
+ setup { Fog.mock! }
28
+ teardown { Fog.unmock! }
29
+
30
+ it '#uuid=1_100 returns 100' do
31
+ assert_equal '100', extract_vmid('1_100')
32
+ end
33
+ it '#uuid=pve_100 returns ' do
34
+ assert_equal '', extract_vmid('pve_100')
35
+ end
36
+ end
37
+ end
38
+ 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.13.0
4
+ version: 0.13.1
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: 2021-02-23 00:00:00.000000000 Z
12
+ date: 2021-03-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: deface
@@ -114,6 +114,7 @@ files:
114
114
  - app/helpers/proxmox_vm_helper.rb
115
115
  - app/helpers/proxmox_vm_interfaces_helper.rb
116
116
  - app/helpers/proxmox_vm_os_template_helper.rb
117
+ - app/helpers/proxmox_vm_uuid_helper.rb
117
118
  - app/helpers/proxmox_vm_volumes_helper.rb
118
119
  - app/models/concerns/fog_extensions/proxmox/disk.rb
119
120
  - app/models/concerns/fog_extensions/proxmox/interface.rb
@@ -178,6 +179,7 @@ files:
178
179
  - app/views/dashboard/_foreman_fog_proxmox_widget.erb
179
180
  - app/views/images/form/_proxmox.html.erb
180
181
  - config/routes.rb
182
+ - db/migrate/20210312105013_update_proxmox_uuid_host.rb
181
183
  - lib/foreman_fog_proxmox.rb
182
184
  - lib/foreman_fog_proxmox/engine.rb
183
185
  - lib/foreman_fog_proxmox/hash_collection.rb
@@ -199,6 +201,7 @@ files:
199
201
  - test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb
200
202
  - test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb
201
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
202
205
  - test/unit/foreman_fog_proxmox/helpers/proxmox_vm_volumes_helper_test.rb
203
206
  - test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb
204
207
  - test/unit/foreman_fog_proxmox/proxmox_images_test.rb
@@ -248,6 +251,7 @@ test_files:
248
251
  - test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb
249
252
  - test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb
250
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
251
255
  - test/unit/foreman_fog_proxmox/helpers/proxmox_vm_volumes_helper_test.rb
252
256
  - test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb
253
257
  - test/unit/foreman_fog_proxmox/proxmox_images_test.rb