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.
- checksums.yaml +4 -4
- data/README.md +22 -4
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +25 -13
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +3 -1
- data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +23 -25
- data/app/helpers/proxmox_vm_config_helper.rb +5 -4
- data/app/helpers/proxmox_vm_uuid_helper.rb +34 -0
- data/app/models/concerns/fog_extensions/proxmox/server.rb +4 -0
- data/app/models/concerns/orchestration/proxmox/compute.rb +48 -0
- data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +1 -0
- data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +1 -1
- data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +8 -6
- data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +6 -2
- data/app/views/api/v2/compute_resources/proxmox.json.rabl +1 -1
- data/app/views/compute_resources_vms/form/proxmox/server/_volume_cdrom.html.erb +1 -1
- data/config/routes.rb +7 -7
- data/db/migrate/20210312105013_update_proxmox_uuid_host.rb +29 -0
- data/lib/foreman_fog_proxmox/engine.rb +7 -1
- data/lib/foreman_fog_proxmox/version.rb +1 -1
- data/test/functional/compute_resources_controller_test.rb +4 -4
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +4 -3
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +3 -1
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_uuid_helper_test.rb +38 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +3 -3
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ee2ea48049134a2a429baa88bd6f3299c321f38a5f3532c8c17d1a3012dc277
|
4
|
+
data.tar.gz: 246a3ee1a5bb9f7f99e55b7f97f637cae3b49b12e7917667444238ae007e21e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
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
|
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
|
-
|
23
|
-
|
24
|
-
|
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
|
34
|
-
volumes =
|
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
|
42
|
-
volumes =
|
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
|
50
|
-
storages =
|
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
|
58
|
-
storages =
|
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
|
66
|
-
storages =
|
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
|
74
|
-
bridges =
|
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
|
-
|
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 = ['
|
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 = ['
|
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
|
@@ -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 =
|
56
|
-
vm ||=
|
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 #{
|
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
|
66
|
-
vm = servers.get(
|
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:
|
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
|
-
|
29
|
-
@compute_resource&.node_id
|
33
|
+
node&.identity
|
30
34
|
end
|
31
35
|
|
32
36
|
def statistics
|
@@ -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
|
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#
|
23
|
-
match 'ostemplates/:node_id/:storage', :to => 'compute_resources#
|
24
|
-
match 'isos/:node_id', :to => 'compute_resources#
|
25
|
-
match 'ostemplates/:node_id', :to => 'compute_resources#
|
26
|
-
match 'storages/:node_id', :to => 'compute_resources#
|
27
|
-
match 'isostorages/:node_id', :to => 'compute_resources#
|
28
|
-
match 'bridges/:node_id', :to => 'compute_resources#
|
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
|
-
|
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
|
@@ -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 :
|
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 :
|
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 :
|
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 :
|
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
|
-
'
|
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' => '
|
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('
|
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('
|
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.
|
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-
|
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
|