foreman_fog_proxmox 0.22.0 → 0.23.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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +11 -1
- data/app/helpers/proxmox_form_helper.rb +5 -2
- data/app/helpers/proxmox_vm_interfaces_helper.rb +11 -0
- data/app/models/concerns/fog_extensions/proxmox/server.rb +7 -1
- data/app/models/foreman_fog_proxmox/compute_attributes_update_detector.rb +41 -0
- data/app/models/foreman_fog_proxmox/proxmox.rb +4 -1
- data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +21 -4
- data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +13 -2
- data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +12 -2
- data/app/views/compute_resources/form/_proxmox.html.erb +4 -5
- data/app/views/compute_resources_vms/index/_proxmox.html.erb +1 -0
- data/lib/foreman_fog_proxmox/version.rb +1 -1
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_form_helper_test.rb +51 -0
- data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +69 -2
- data/test/unit/foreman_fog_proxmox/proxmox_operating_systems_test.rb +48 -0
- data/test/unit/foreman_fog_proxmox/proxmox_test.rb +81 -0
- data/webpack/components/ProxmoxContainer/ProxmoxContainerStorage.js +2 -3
- data/webpack/global_index.js +2 -0
- metadata +7 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f08732412c42423f30a2f448a7bc48c6249bbf0a62050b28e43a56f4a774caac
|
|
4
|
+
data.tar.gz: ffecc9919a3f2c64f200b272a7e33065f43584f6734be25c74f794585beed665
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d54a0db2ef661feeffb82d8002f7466bd1a8eb1d3b0b3d11215928b07600fbe591d9ca5cffeb36ff2d293e82523509406b949c8d81a8c2ab80ebdcf83bf95295
|
|
7
|
+
data.tar.gz: '0740284790c3189d29502bae8359fbf57faace0e1d27bc0e625b37ff17d0d93b31dfbd213f803e5ff2afcacb3726630cfb7176aa2d8c753ac0d31f7f0836393a'
|
|
@@ -23,11 +23,14 @@ $(document).ready(function () {
|
|
|
23
23
|
function sslVerifyPeerSelected() {
|
|
24
24
|
var selected = $("#compute_resource_ssl_verify_peer").is(':checked');
|
|
25
25
|
var ssl_certs_block = $('#compute_resource_ssl_certs').parents('.clearfix');
|
|
26
|
+
var ssl_certs_group = $('#compute_resource_ssl_certs').parents('.form-group');
|
|
26
27
|
var ssl_certs_textarea = $('#compute_resource_ssl_certs');
|
|
27
28
|
if (selected) {
|
|
29
|
+
ssl_certs_group.removeClass('hide');
|
|
28
30
|
ssl_certs_block.show();
|
|
29
31
|
ssl_certs_textarea.show();
|
|
30
32
|
} else {
|
|
33
|
+
ssl_certs_group.addClass('hide');
|
|
31
34
|
ssl_certs_block.hide();
|
|
32
35
|
ssl_certs_textarea.text('');
|
|
33
36
|
ssl_certs_textarea.hide();
|
|
@@ -62,4 +65,11 @@ function authMethodSelected() {
|
|
|
62
65
|
authMethods().forEach(function(method){
|
|
63
66
|
toggleFieldset(method, selected);
|
|
64
67
|
});
|
|
65
|
-
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
window.tfm = window.tfm || {};
|
|
71
|
+
window.tfm.computeResource = window.tfm.computeResource || {};
|
|
72
|
+
window.tfm.computeResource.proxmox = {
|
|
73
|
+
authMethodSelected: authMethodSelected,
|
|
74
|
+
sslVerifyPeerSelected: sslVerifyPeerSelected,
|
|
75
|
+
};
|
|
@@ -130,8 +130,11 @@ module ProxmoxFormHelper
|
|
|
130
130
|
def proxmox_valid_interface_compute_attributes?(compute_attributes, vm_type)
|
|
131
131
|
return false unless compute_attributes.respond_to?(:keys)
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
compute_attribute_keys = compute_attributes.keys.map(&:to_s)
|
|
134
|
+
required_keys = interface_compute_attributes_required_typed_keys(vm_type)
|
|
135
|
+
missing_keys = required_keys - compute_attribute_keys
|
|
136
|
+
|
|
137
|
+
required_keys.any? && missing_keys.empty?
|
|
135
138
|
end
|
|
136
139
|
|
|
137
140
|
def extract_attr(attrs, key)
|
|
@@ -55,6 +55,17 @@ module ProxmoxVMInterfacesHelper
|
|
|
55
55
|
keys
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
+
def interface_compute_attributes_required_typed_keys(type)
|
|
59
|
+
case type
|
|
60
|
+
when 'qemu'
|
|
61
|
+
['model']
|
|
62
|
+
when 'lxc'
|
|
63
|
+
['name']
|
|
64
|
+
else
|
|
65
|
+
[]
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
58
69
|
def interface_common_typed_keys(type)
|
|
59
70
|
['id', (type == 'qemu') ? 'macaddr' : 'hwaddr']
|
|
60
71
|
end
|
|
@@ -21,12 +21,18 @@ module FogExtensions
|
|
|
21
21
|
module Proxmox
|
|
22
22
|
module Server
|
|
23
23
|
extend ActiveSupport::Concern
|
|
24
|
-
attr_accessor :image_id, :templated, :ostemplate_storage, :ostemplate_file, :password, :start_after_create
|
|
24
|
+
attr_accessor :image_id, :templated, :ostemplate_storage, :ostemplate_file, :password, :start_after_create, :compute_resource_id
|
|
25
25
|
|
|
26
26
|
def unique_cluster_identity(compute_resource)
|
|
27
27
|
compute_resource.id.to_s + '_' + identity.to_s
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
def foreman_uuid
|
|
31
|
+
return identity.to_s if compute_resource_id.nil?
|
|
32
|
+
|
|
33
|
+
compute_resource_id.to_s + '_' + identity.to_s
|
|
34
|
+
end
|
|
35
|
+
|
|
30
36
|
def start
|
|
31
37
|
action('start')
|
|
32
38
|
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2026
|
|
4
|
+
|
|
5
|
+
# This file is part of ForemanFogProxmox.
|
|
6
|
+
|
|
7
|
+
# ForemanFogProxmox is free software: you can redistribute it and/or modify
|
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
# (at your option) any later version.
|
|
11
|
+
|
|
12
|
+
# ForemanFogProxmox is distributed in the hope that it will be useful,
|
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
# GNU General Public License for more details.
|
|
16
|
+
|
|
17
|
+
# You should have received a copy of the GNU General Public License
|
|
18
|
+
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
|
|
19
|
+
|
|
20
|
+
module ForemanFogProxmox
|
|
21
|
+
module ComputeAttributesUpdateDetector
|
|
22
|
+
def update_required?(old_attrs, new_attrs)
|
|
23
|
+
old_attrs = old_attrs.deep_symbolize_keys
|
|
24
|
+
new_attrs = new_attrs.deep_symbolize_keys
|
|
25
|
+
new_attrs.each do |key, new_v|
|
|
26
|
+
old_v = old_attrs[key]
|
|
27
|
+
if new_v.is_a?(Hash)
|
|
28
|
+
unless old_v.is_a?(Hash)
|
|
29
|
+
logger.debug "Scheduling compute instance update because #{key} changed it's value from '#{old_v}' (#{old_v.class}) to '#{new_v}' (#{new_v.class})"
|
|
30
|
+
return true
|
|
31
|
+
end
|
|
32
|
+
return true if update_required?(old_v, new_v)
|
|
33
|
+
elsif old_v.to_s != new_v.to_s
|
|
34
|
+
logger.debug "Scheduling compute instance update because #{key} changed it's value from '#{old_v}' (#{old_v.class}) to '#{new_v}' (#{new_v.class})"
|
|
35
|
+
return true
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
false
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -35,6 +35,7 @@ module ForemanFogProxmox
|
|
|
35
35
|
include ProxmoxOperatingSystems
|
|
36
36
|
include ProxmoxVersion
|
|
37
37
|
include ProxmoxConsole
|
|
38
|
+
include ComputeAttributesUpdateDetector
|
|
38
39
|
validates :url, :format => { :with => URI::DEFAULT_PARSER.make_regexp }, :presence => true
|
|
39
40
|
validates :auth_method, :presence => true, :inclusion => { in: ['access_ticket', 'user_token'],
|
|
40
41
|
message: ->(value) do format('%<value>s is not a valid authentication method', { value: value }) end }
|
|
@@ -45,6 +46,7 @@ module ForemanFogProxmox
|
|
|
45
46
|
|
|
46
47
|
def provided_attributes
|
|
47
48
|
super.merge(
|
|
49
|
+
:uuid => :foreman_uuid,
|
|
48
50
|
:mac => :mac
|
|
49
51
|
)
|
|
50
52
|
end
|
|
@@ -62,10 +64,11 @@ module ForemanFogProxmox
|
|
|
62
64
|
end
|
|
63
65
|
|
|
64
66
|
def associated_host(vm)
|
|
65
|
-
associate_by('mac', vm
|
|
67
|
+
associate_by('mac', vm&.mac)
|
|
66
68
|
end
|
|
67
69
|
|
|
68
70
|
def associate_by(name, attributes)
|
|
71
|
+
return nil if attributes.blank?
|
|
69
72
|
Host.authorized(:view_hosts,
|
|
70
73
|
Host).joins(:primary_interface).where(:nics => { :primary => true }).where("nics.#{name}".downcase => attributes.downcase).readonly(false).first
|
|
71
74
|
end
|
|
@@ -19,8 +19,13 @@
|
|
|
19
19
|
|
|
20
20
|
module ForemanFogProxmox
|
|
21
21
|
module ProxmoxComputeAttributes
|
|
22
|
+
FOREMAN_INTERFACE_ATTRIBUTES = [:id, :mac, :ip, :ip6].freeze
|
|
23
|
+
PROXMOX_MAC_ATTRIBUTES = [:macaddr, :hwaddr].freeze
|
|
24
|
+
PROXMOX_INTERFACE_METADATA = [:identifier, :compute_attributes].freeze
|
|
25
|
+
|
|
22
26
|
def host_compute_attrs(host)
|
|
23
|
-
|
|
27
|
+
config = host.compute_attributes['config_attributes'] || {}
|
|
28
|
+
ostype = config['ostype']
|
|
24
29
|
type = host.compute_attributes['type']
|
|
25
30
|
case type
|
|
26
31
|
when 'lxc'
|
|
@@ -41,9 +46,21 @@ module ForemanFogProxmox
|
|
|
41
46
|
end
|
|
42
47
|
|
|
43
48
|
def interface_compute_attributes(interface_attributes)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
attrs = interface_attributes.with_indifferent_access
|
|
50
|
+
provider_attrs = attrs[:compute_attributes].present? ? attrs[:compute_attributes].with_indifferent_access : ActiveSupport::HashWithIndifferentAccess.new
|
|
51
|
+
|
|
52
|
+
vm_attrs = FOREMAN_INTERFACE_ATTRIBUTES.index_with do |key|
|
|
53
|
+
attrs[key] || provider_attrs.delete(key)
|
|
54
|
+
end.compact
|
|
55
|
+
vm_attrs[:mac] ||= attrs[:macaddr] || attrs[:hwaddr] || provider_attrs.delete(:macaddr) || provider_attrs.delete(:hwaddr)
|
|
56
|
+
|
|
57
|
+
attrs.except(*FOREMAN_INTERFACE_ATTRIBUTES, *PROXMOX_MAC_ATTRIBUTES, *PROXMOX_INTERFACE_METADATA).each do |key, value|
|
|
58
|
+
provider_attrs[key] = value
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
provider_attrs[:dhcp] = (vm_attrs[:ip] == 'dhcp') ? '1' : '0'
|
|
62
|
+
provider_attrs[:dhcp6] = (vm_attrs[:ip6] == 'dhcp') ? '1' : '0'
|
|
63
|
+
vm_attrs[:compute_attributes] = provider_attrs
|
|
47
64
|
vm_attrs
|
|
48
65
|
end
|
|
49
66
|
|
|
@@ -20,16 +20,20 @@
|
|
|
20
20
|
module ForemanFogProxmox
|
|
21
21
|
module ProxmoxOperatingSystems
|
|
22
22
|
def compute_os_types(host)
|
|
23
|
-
os_linux_types_mapping(host)
|
|
23
|
+
[os_linux_types_mapping(host), os_windows_types_mapping(host), os_other_types_mapping(host)].find(&:any?) || []
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def available_operating_systems
|
|
27
|
-
operating_systems =
|
|
27
|
+
operating_systems = available_other_operating_systems
|
|
28
28
|
operating_systems += available_linux_operating_systems
|
|
29
29
|
operating_systems += available_windows_operating_systems
|
|
30
30
|
operating_systems
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
def available_other_operating_systems
|
|
34
|
+
['other', 'solaris']
|
|
35
|
+
end
|
|
36
|
+
|
|
33
37
|
def available_linux_operating_systems
|
|
34
38
|
['l24', 'l26', 'debian', 'ubuntu', 'centos', 'fedora', 'opensuse', 'archlinux', 'gentoo', 'alpine']
|
|
35
39
|
end
|
|
@@ -50,5 +54,12 @@ module ForemanFogProxmox
|
|
|
50
54
|
def os_windows_types_mapping(host)
|
|
51
55
|
['Windows'].include?(host.operatingsystem.type) ? available_windows_operating_systems : []
|
|
52
56
|
end
|
|
57
|
+
|
|
58
|
+
def os_other_types_mapping(host)
|
|
59
|
+
{
|
|
60
|
+
'Freebsd' => ['other'],
|
|
61
|
+
'Solaris' => ['solaris'],
|
|
62
|
+
}.fetch(host.operatingsystem.type, [])
|
|
63
|
+
end
|
|
53
64
|
end
|
|
54
65
|
end
|
|
@@ -46,9 +46,10 @@ module ForemanFogProxmox
|
|
|
46
46
|
def vms(opts = {})
|
|
47
47
|
vms = []
|
|
48
48
|
nodes.each { |node| vms += node.servers.all + node.containers.all }
|
|
49
|
+
vms.each { |vm| attach_compute_resource_id(vm) }
|
|
49
50
|
if opts.key?(:eager_loading) && opts[:eager_loading]
|
|
50
51
|
vms_eager = []
|
|
51
|
-
vms.each { |vm| vms_eager << vm.collection.get(vm.identity) }
|
|
52
|
+
vms.each { |vm| vms_eager << attach_compute_resource_id(vm.collection.get(vm.identity)) }
|
|
52
53
|
vms = vms_eager
|
|
53
54
|
end
|
|
54
55
|
ForemanFogProxmox::Vms.new(vms)
|
|
@@ -71,12 +72,21 @@ module ForemanFogProxmox
|
|
|
71
72
|
def find_vm_in_servers_by_vmid(servers, vmid)
|
|
72
73
|
vm = servers.get(vmid) unless ForemanFogProxmox::Value.empty?(vmid)
|
|
73
74
|
pool_owner(vm) if vm
|
|
74
|
-
vm
|
|
75
|
+
attach_compute_resource_id(vm)
|
|
75
76
|
rescue Fog::Errors::NotFound
|
|
76
77
|
nil
|
|
77
78
|
rescue StandardError => e
|
|
78
79
|
Foreman::Logging.exception(format(_('Failed retrieving proxmox server vm by vmid=%<vmid>s'), vmid: vmid), e)
|
|
79
80
|
raise(ActiveRecord::RecordNotFound, e)
|
|
80
81
|
end
|
|
82
|
+
|
|
83
|
+
private
|
|
84
|
+
|
|
85
|
+
def attach_compute_resource_id(virtual_machine)
|
|
86
|
+
return virtual_machine if virtual_machine.nil?
|
|
87
|
+
|
|
88
|
+
virtual_machine.compute_resource_id = id if virtual_machine.respond_to?(:compute_resource_id=)
|
|
89
|
+
virtual_machine
|
|
90
|
+
end
|
|
81
91
|
end
|
|
82
92
|
end
|
|
@@ -15,12 +15,10 @@ GNU General Public License for more details.
|
|
|
15
15
|
You should have received a copy of the GNU General Public License
|
|
16
16
|
along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
|
|
17
17
|
|
|
18
|
-
<%= javascript_include_tag 'foreman_fog_proxmox/proxmox_compute_resource', "data-turbolinks-track" => true %>
|
|
19
|
-
|
|
20
18
|
<% user_token = f.object.auth_method == 'user_token' %>
|
|
21
19
|
<% access_ticket = f.object.auth_method == 'access_ticket' %>
|
|
22
|
-
<% ssl_verify_peer = f.object.ssl_verify_peer
|
|
23
|
-
<%= select_f f, :auth_method, proxmox_auth_methods_map, :id, :name, { }, :label_help => _("Click Test connection button before changing it"), :label => _('Authentication method'), :label_size => "col-md-2", :required => true, :onchange => 'authMethodSelected();' %>
|
|
20
|
+
<% ssl_verify_peer = f.object.ssl_verify_peer %>
|
|
21
|
+
<%= select_f f, :auth_method, proxmox_auth_methods_map, :id, :name, { }, :label_help => _("Click Test connection button before changing it"), :label => _('Authentication method'), :label_size => "col-md-2", :required => true, :onchange => 'tfm.computeResource.proxmox.authMethodSelected();' %>
|
|
24
22
|
<%= field_set_tag _("Common fields"), :id => "compute_ressource_common_field_set" do %>
|
|
25
23
|
<%= text_f f, :url, :help_block => _("e.g. https://127.0.0.1:8006/api2/json") %>
|
|
26
24
|
<%= text_f f, :user , :help_block => _("e.g. root@pam") %>
|
|
@@ -33,8 +31,9 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
|
|
|
33
31
|
<%= password_f f, :password, :keep_value => true, :unset => unset_password?, :required => access_ticket %>
|
|
34
32
|
<% end %>
|
|
35
33
|
<%= field_set_tag _("SSL fields"), :id => "compute_ressource_ssl_field_set" do %>
|
|
36
|
-
<%= checkbox_f f, :ssl_verify_peer, :label => _("SSL verify peer"), :label_help => _("Click Test connection button before changing it"), :checked_value => '1', :onchange => 'sslVerifyPeerSelected();' %>
|
|
34
|
+
<%= checkbox_f f, :ssl_verify_peer, :label => _("SSL verify peer"), :label_help => _("Click Test connection button before changing it"), :checked_value => '1', :onchange => 'tfm.computeResource.proxmox.sslVerifyPeerSelected();' %>
|
|
37
35
|
<%= textarea_f f, :ssl_certs, :label => _("X509 Certification Authorities"), :size => "col-md-4",
|
|
36
|
+
:wrapper_class => "form-group #{'hide' unless ssl_verify_peer}",
|
|
38
37
|
:placeholder => _("Optionally provide a CA, or a correctly ordered CA chain. If left blank, disable ssl_verify_peer.") %>
|
|
39
38
|
<% end %>
|
|
40
39
|
<div class="col-md-offset-2">
|
|
@@ -42,6 +42,7 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
|
|
|
42
42
|
<%= action_buttons(
|
|
43
43
|
vm_power_action(vm, authorizer),
|
|
44
44
|
vm_associate_link(vm),
|
|
45
|
+
vm_import_action(vm),
|
|
45
46
|
display_delete_if_authorized(hash_for_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => vm.unique_cluster_identity(@compute_resource)).merge(:auth_object => @compute_resource, :authorizer => authorizer))) %>
|
|
46
47
|
</td>
|
|
47
48
|
</tr>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# This file is part of ForemanFogProxmox.
|
|
4
|
+
|
|
5
|
+
# ForemanFogProxmox is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
|
|
10
|
+
# ForemanFogProxmox is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
require 'test_plugin_helper'
|
|
19
|
+
|
|
20
|
+
module ForemanFogProxmox
|
|
21
|
+
class ProxmoxFormHelperTest < ActiveSupport::TestCase
|
|
22
|
+
include ProxmoxFormHelper
|
|
23
|
+
|
|
24
|
+
describe 'interface compute attribute validation' do
|
|
25
|
+
let(:required_attrs) do
|
|
26
|
+
{
|
|
27
|
+
'qemu' => { 'model' => 'virtio' },
|
|
28
|
+
'lxc' => { 'name' => 'eth0' },
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'rejects attributes when required keys are missing' do
|
|
33
|
+
required_attrs.each_key do |vm_type|
|
|
34
|
+
assert_not send(:proxmox_valid_interface_compute_attributes?, { 'bridge' => 'vmbr0' }, vm_type)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'accepts attributes when required keys are present' do
|
|
39
|
+
required_attrs.each do |vm_type, attrs|
|
|
40
|
+
assert send(:proxmox_valid_interface_compute_attributes?, attrs, vm_type)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'accepts attributes when required keys are present with other keys' do
|
|
45
|
+
required_attrs.each do |vm_type, attrs|
|
|
46
|
+
assert send(:proxmox_valid_interface_compute_attributes?, attrs.merge('bridge' => 'vmbr0'), vm_type)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -60,6 +60,52 @@ module ForemanFogProxmox
|
|
|
60
60
|
assert err.message.end_with?('Operating system family Solaris is not consistent with l26')
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
+
it 'accepts proxmox linux ostype for linux servers' do
|
|
64
|
+
operatingsystem = FactoryBot.build(:debian7_1)
|
|
65
|
+
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :primary => true)
|
|
66
|
+
host = FactoryBot.build(
|
|
67
|
+
:host_empty,
|
|
68
|
+
:interfaces => [physical_nic],
|
|
69
|
+
:operatingsystem => operatingsystem,
|
|
70
|
+
:compute_attributes => {
|
|
71
|
+
'type' => 'qemu',
|
|
72
|
+
'config_attributes' => {
|
|
73
|
+
'ostype' => 'l26',
|
|
74
|
+
},
|
|
75
|
+
'interfaces_attributes' => {
|
|
76
|
+
'0' => physical_nic,
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
@cr.host_compute_attrs(host)
|
|
82
|
+
|
|
83
|
+
assert_equal host.name, host.compute_attributes['config_attributes']['name']
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'accepts proxmox other ostype for FreeBSD servers' do
|
|
87
|
+
operatingsystem = FactoryBot.build(:freebsd)
|
|
88
|
+
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :primary => true)
|
|
89
|
+
host = FactoryBot.build(
|
|
90
|
+
:host_empty,
|
|
91
|
+
:interfaces => [physical_nic],
|
|
92
|
+
:operatingsystem => operatingsystem,
|
|
93
|
+
:compute_attributes => {
|
|
94
|
+
'type' => 'qemu',
|
|
95
|
+
'config_attributes' => {
|
|
96
|
+
'ostype' => 'other',
|
|
97
|
+
},
|
|
98
|
+
'interfaces_attributes' => {
|
|
99
|
+
'0' => physical_nic,
|
|
100
|
+
},
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
@cr.host_compute_attrs(host)
|
|
105
|
+
|
|
106
|
+
assert_equal host.name, host.compute_attributes['config_attributes']['name']
|
|
107
|
+
end
|
|
108
|
+
|
|
63
109
|
it 'sets container hostname with host name' do
|
|
64
110
|
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :primary => true,
|
|
65
111
|
:compute_attributes => { 'dhcp' => '1', 'dhcp6' => '1' })
|
|
@@ -87,6 +133,23 @@ module ForemanFogProxmox
|
|
|
87
133
|
end
|
|
88
134
|
excluded_keys = [:vmid, :disks, :interfaces]
|
|
89
135
|
|
|
136
|
+
it 'maps flat interface attributes into foreman nic structure' do
|
|
137
|
+
vm_attrs = @cr.interface_compute_attributes(
|
|
138
|
+
id: 'net0',
|
|
139
|
+
macaddr: '36:25:8C:53:0C:50',
|
|
140
|
+
model: 'virtio',
|
|
141
|
+
bridge: 'vmbr0'
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
assert_equal 'net0', vm_attrs[:id]
|
|
145
|
+
assert_equal '36:25:8C:53:0C:50', vm_attrs[:mac]
|
|
146
|
+
assert_equal 'virtio', vm_attrs[:compute_attributes][:model]
|
|
147
|
+
assert_equal 'vmbr0', vm_attrs[:compute_attributes][:bridge]
|
|
148
|
+
assert_equal '0', vm_attrs[:compute_attributes][:dhcp]
|
|
149
|
+
assert_equal '0', vm_attrs[:compute_attributes][:dhcp6]
|
|
150
|
+
assert_not vm_attrs[:compute_attributes].key?(:macaddr)
|
|
151
|
+
end
|
|
152
|
+
|
|
90
153
|
it 'converts a server to hash' do
|
|
91
154
|
vm, config_attributes, volume_attributes, interface_attributes = mock_server_vm
|
|
92
155
|
vm_attrs = @cr.vm_compute_attributes(vm)
|
|
@@ -101,11 +164,13 @@ module ForemanFogProxmox
|
|
|
101
164
|
assert_not vm_attrs[:config_attributes].key?(:interfaces)
|
|
102
165
|
assert vm_attrs.key?(:interfaces_attributes)
|
|
103
166
|
assert_equal interface_attributes[:id], vm_attrs[:interfaces_attributes]['0'][:id]
|
|
104
|
-
assert_equal interface_attributes[:mac], vm_attrs[:interfaces_attributes]['0'][:
|
|
167
|
+
assert_equal interface_attributes[:mac], vm_attrs[:interfaces_attributes]['0'][:mac]
|
|
105
168
|
assert_equal interface_attributes[:compute_attributes][:model],
|
|
106
169
|
vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:model]
|
|
107
170
|
assert_equal interface_attributes[:compute_attributes][:bridge],
|
|
108
171
|
vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:bridge]
|
|
172
|
+
assert_equal '0', vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:dhcp]
|
|
173
|
+
assert_equal '0', vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:dhcp6]
|
|
109
174
|
end
|
|
110
175
|
|
|
111
176
|
it 'converts a container to hash' do
|
|
@@ -121,11 +186,13 @@ module ForemanFogProxmox
|
|
|
121
186
|
assert_equal volume_attributes.merge(_delete: '0'), vm_attrs[:volumes_attributes]['0']
|
|
122
187
|
assert vm_attrs.key?(:interfaces_attributes)
|
|
123
188
|
assert_equal interface_attributes[:id], vm_attrs[:interfaces_attributes]['0'][:id]
|
|
189
|
+
assert_equal interface_attributes[:mac], vm_attrs[:interfaces_attributes]['0'][:mac]
|
|
124
190
|
assert_equal interface_attributes[:compute_attributes][:name],
|
|
125
191
|
vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:name]
|
|
126
|
-
assert_equal interface_attributes[:mac], vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:hwaddr]
|
|
127
192
|
assert_equal interface_attributes[:compute_attributes][:bridge],
|
|
128
193
|
vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:bridge]
|
|
194
|
+
assert_equal '0', vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:dhcp]
|
|
195
|
+
assert_equal '0', vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:dhcp6]
|
|
129
196
|
end
|
|
130
197
|
end
|
|
131
198
|
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# This file is part of ForemanFogProxmox.
|
|
4
|
+
|
|
5
|
+
# ForemanFogProxmox is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
|
|
10
|
+
# ForemanFogProxmox is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
require 'test_plugin_helper'
|
|
19
|
+
|
|
20
|
+
module ForemanFogProxmox
|
|
21
|
+
class ProxmoxOperatingSystemsTest < ActiveSupport::TestCase
|
|
22
|
+
def setup
|
|
23
|
+
@cr = FactoryBot.build_stubbed(:proxmox_cr)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
test '#compute_os_types returns linux os types for linux families' do
|
|
27
|
+
assert_equal @cr.available_linux_operating_systems, @cr.compute_os_types(host_with_os_type('Debian'))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
test '#compute_os_types returns windows os types for windows family' do
|
|
31
|
+
assert_equal @cr.available_windows_operating_systems, @cr.compute_os_types(host_with_os_type('Windows'))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
test '#compute_os_types returns other os type for Freebsd family' do
|
|
35
|
+
assert_equal ['other'], @cr.compute_os_types(host_with_os_type('Freebsd'))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
test '#compute_os_types returns solaris os type for Solaris family' do
|
|
39
|
+
assert_equal ['solaris'], @cr.compute_os_types(host_with_os_type('Solaris'))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def host_with_os_type(type)
|
|
45
|
+
stub(operatingsystem: stub(type: type))
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -48,11 +48,92 @@ module ForemanFogProxmox
|
|
|
48
48
|
assert_equal host, (as_admin { cr.associated_host(vm) })
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
+
test '#provided_attributes maps uuid to foreman_uuid' do
|
|
52
|
+
cr = FactoryBot.build_stubbed(:proxmox_cr)
|
|
53
|
+
|
|
54
|
+
assert_equal :foreman_uuid, cr.provided_attributes[:uuid]
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
test '#update_required? detects added HDD attributes' do
|
|
58
|
+
cr = FactoryBot.build_stubbed(:proxmox_cr)
|
|
59
|
+
old_attrs = hdd_compute_attrs(hdd_attrs('0'))
|
|
60
|
+
new_attrs = hdd_compute_attrs(hdd_attrs('0').merge('1' => hdd_attributes('virtio1', 'virtio', '1')))
|
|
61
|
+
|
|
62
|
+
assert cr.update_required?(old_attrs, new_attrs)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
test '#update_required? detects removed HDD attributes' do
|
|
66
|
+
cr = FactoryBot.build_stubbed(:proxmox_cr)
|
|
67
|
+
|
|
68
|
+
old_attrs = hdd_compute_attrs(
|
|
69
|
+
hdd_attrs('0').merge('1' => hdd_attributes('virtio1', 'virtio', '1'))
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
new_attrs = hdd_compute_attrs(
|
|
73
|
+
hdd_attrs('0').merge('1' => { '_delete' => '1' })
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
assert cr.update_required?(old_attrs, new_attrs)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
test '#update_required? detects modified existing HDD attributes' do
|
|
80
|
+
cr = FactoryBot.build_stubbed(:proxmox_cr)
|
|
81
|
+
old_attrs = hdd_compute_attrs(hdd_attrs('0'))
|
|
82
|
+
new_attrs = hdd_compute_attrs(hdd_attrs('0').deep_merge('0' => { 'size' => '20' }))
|
|
83
|
+
|
|
84
|
+
assert cr.update_required?(old_attrs, new_attrs)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
test '#update_required? detects modified CPU flag' do
|
|
88
|
+
cr = FactoryBot.build_stubbed(:proxmox_cr)
|
|
89
|
+
old_attrs = { 'config_attributes' => { 'spectre' => '0' } }
|
|
90
|
+
new_attrs = { 'config_attributes' => { 'spectre' => '+1' } }
|
|
91
|
+
|
|
92
|
+
assert cr.update_required?(old_attrs, new_attrs)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
test '#update_required? detects modified network interface' do
|
|
96
|
+
cr = FactoryBot.build_stubbed(:proxmox_cr)
|
|
97
|
+
old_attrs = { 'interfaces_attributes' => { '0' => { 'id' => 'net0', 'bridge' => 'vmbr0' } } }
|
|
98
|
+
new_attrs = { 'interfaces_attributes' => { '0' => { 'id' => 'net0', 'bridge' => 'vmbr1' } } }
|
|
99
|
+
|
|
100
|
+
assert cr.update_required?(old_attrs, new_attrs)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
test '#update_required? detects added network interface' do
|
|
104
|
+
cr = FactoryBot.build_stubbed(:proxmox_cr)
|
|
105
|
+
old_attrs = { 'interfaces_attributes' => { '0' => { 'id' => 'net0' } } }
|
|
106
|
+
new_attrs = { 'interfaces_attributes' => { '0' => { 'id' => 'net0' }, '1' => { 'id' => 'net1' } } }
|
|
107
|
+
|
|
108
|
+
assert cr.update_required?(old_attrs, new_attrs)
|
|
109
|
+
end
|
|
110
|
+
|
|
51
111
|
test '#node' do
|
|
52
112
|
node = mock('node')
|
|
53
113
|
cr = FactoryBot.build_stubbed(:proxmox_cr)
|
|
54
114
|
cr.stubs(:node).returns(node)
|
|
55
115
|
assert_equal node, (as_admin { cr.node })
|
|
56
116
|
end
|
|
117
|
+
|
|
118
|
+
private
|
|
119
|
+
|
|
120
|
+
def hdd_compute_attrs(volumes_attrs)
|
|
121
|
+
{ 'volumes_attributes' => volumes_attrs }
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def hdd_attrs(index)
|
|
125
|
+
{ index => hdd_attributes('scsi0', 'scsi', '0') }
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def hdd_attributes(id, controller, device)
|
|
129
|
+
{
|
|
130
|
+
'id' => id,
|
|
131
|
+
'storage_type' => 'hard_disk',
|
|
132
|
+
'controller' => controller,
|
|
133
|
+
'device' => device,
|
|
134
|
+
'storage' => 'local-lvm',
|
|
135
|
+
'size' => '10',
|
|
136
|
+
}
|
|
137
|
+
end
|
|
57
138
|
end
|
|
58
139
|
end
|
|
@@ -117,13 +117,12 @@ const ProxmoxContainerStorage = ({
|
|
|
117
117
|
const newMountPoint = {
|
|
118
118
|
id: newNextId,
|
|
119
119
|
data: initMP,
|
|
120
|
-
storagesMap,
|
|
121
120
|
};
|
|
122
121
|
setMountPoints(prev => [...prev, newMountPoint]);
|
|
123
122
|
return newNextId;
|
|
124
123
|
});
|
|
125
124
|
},
|
|
126
|
-
[nextId, paramScope
|
|
125
|
+
[nextId, paramScope]
|
|
127
126
|
);
|
|
128
127
|
|
|
129
128
|
const removeMountPoint = idToRemove => {
|
|
@@ -221,7 +220,7 @@ const ProxmoxContainerStorage = ({
|
|
|
221
220
|
key={mountPoint.id}
|
|
222
221
|
id={mountPoint.id}
|
|
223
222
|
data={mountPoint.data}
|
|
224
|
-
storagesMap={
|
|
223
|
+
storagesMap={storagesMap}
|
|
225
224
|
/>
|
|
226
225
|
</div>
|
|
227
226
|
))}
|
data/webpack/global_index.js
CHANGED
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.
|
|
4
|
+
version: 0.23.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tristan Robert
|
|
@@ -153,6 +153,7 @@ files:
|
|
|
153
153
|
- app/models/concerns/host_ext/proxmox/for_vm.rb
|
|
154
154
|
- app/models/concerns/host_ext/proxmox/interfaces.rb
|
|
155
155
|
- app/models/concerns/orchestration/proxmox/compute.rb
|
|
156
|
+
- app/models/foreman_fog_proxmox/compute_attributes_update_detector.rb
|
|
156
157
|
- app/models/foreman_fog_proxmox/options_select.rb
|
|
157
158
|
- app/models/foreman_fog_proxmox/proxmox.rb
|
|
158
159
|
- app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb
|
|
@@ -254,6 +255,7 @@ files:
|
|
|
254
255
|
- test/functional/compute_resources_controller_test.rb
|
|
255
256
|
- test/test_plugin_helper.rb
|
|
256
257
|
- test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb
|
|
258
|
+
- test/unit/foreman_fog_proxmox/helpers/proxmox_form_helper_test.rb
|
|
257
259
|
- test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb
|
|
258
260
|
- test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb
|
|
259
261
|
- test/unit/foreman_fog_proxmox/helpers/proxmox_vm_uuid_helper_test.rb
|
|
@@ -261,6 +263,7 @@ files:
|
|
|
261
263
|
- test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb
|
|
262
264
|
- test/unit/foreman_fog_proxmox/proxmox_images_test.rb
|
|
263
265
|
- test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb
|
|
266
|
+
- test/unit/foreman_fog_proxmox/proxmox_operating_systems_test.rb
|
|
264
267
|
- test/unit/foreman_fog_proxmox/proxmox_test.rb
|
|
265
268
|
- test/unit/foreman_fog_proxmox/proxmox_version_test.rb
|
|
266
269
|
- test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb
|
|
@@ -321,7 +324,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
321
324
|
- !ruby/object:Gem::Version
|
|
322
325
|
version: '0'
|
|
323
326
|
requirements: []
|
|
324
|
-
rubygems_version: 4.0.
|
|
327
|
+
rubygems_version: 4.0.10
|
|
325
328
|
specification_version: 4
|
|
326
329
|
summary: Foreman plugin that adds Proxmox VE compute resource using fog-proxmox
|
|
327
330
|
test_files:
|
|
@@ -332,6 +335,7 @@ test_files:
|
|
|
332
335
|
- test/functional/compute_resources_controller_test.rb
|
|
333
336
|
- test/test_plugin_helper.rb
|
|
334
337
|
- test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb
|
|
338
|
+
- test/unit/foreman_fog_proxmox/helpers/proxmox_form_helper_test.rb
|
|
335
339
|
- test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb
|
|
336
340
|
- test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb
|
|
337
341
|
- test/unit/foreman_fog_proxmox/helpers/proxmox_vm_uuid_helper_test.rb
|
|
@@ -339,6 +343,7 @@ test_files:
|
|
|
339
343
|
- test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb
|
|
340
344
|
- test/unit/foreman_fog_proxmox/proxmox_images_test.rb
|
|
341
345
|
- test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb
|
|
346
|
+
- test/unit/foreman_fog_proxmox/proxmox_operating_systems_test.rb
|
|
342
347
|
- test/unit/foreman_fog_proxmox/proxmox_test.rb
|
|
343
348
|
- test/unit/foreman_fog_proxmox/proxmox_version_test.rb
|
|
344
349
|
- test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb
|