foreman_fog_proxmox 0.9.4 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of foreman_fog_proxmox might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +89 -0
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_container.js +5 -41
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js +2 -21
- data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +1 -1
- data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +46 -6
- data/app/helpers/proxmox_container_helper.rb +3 -1
- data/app/helpers/proxmox_server_helper.rb +2 -1
- data/app/helpers/proxmox_vm_helper.rb +19 -0
- data/app/models/concerns/fog_extensions/proxmox/node.rb +0 -5
- data/app/models/concerns/fog_extensions/proxmox/server.rb +1 -1
- data/app/models/foreman_fog_proxmox/proxmox.rb +9 -13
- data/app/models/foreman_fog_proxmox/proxmox_images.rb +10 -5
- data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +6 -2
- data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +22 -6
- data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +9 -7
- data/app/models/foreman_fog_proxmox/vms.rb +37 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_node_to_new_form.rb +25 -0
- data/app/views/compute_resources/form/_proxmox.html.erb +0 -2
- data/app/views/compute_resources/show/_proxmox.html.erb +4 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_node_to_new_form.html.erb +24 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_form.html.erb +2 -1
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_new_childs_form.html.erb +2 -1
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +3 -2
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +6 -5
- data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +3 -3
- data/app/views/compute_resources_vms/form/proxmox/_general.html.erb +2 -1
- data/app/views/compute_resources_vms/form/proxmox/_network.html.erb +2 -2
- data/app/views/compute_resources_vms/form/proxmox/container/_extended.html.erb +3 -2
- data/app/views/compute_resources_vms/form/proxmox/container/_network.html.erb +4 -3
- data/app/views/compute_resources_vms/form/proxmox/container/_volume_mp.html.erb +1 -1
- data/app/views/compute_resources_vms/form/proxmox/container/_volume_rootfs.html.erb +1 -1
- data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +1 -1
- data/app/views/compute_resources_vms/form/proxmox/server/_network.html.erb +4 -3
- data/app/views/compute_resources_vms/form/proxmox/server/_volume.html.erb +1 -1
- data/app/views/compute_resources_vms/index/_proxmox.html.erb +4 -2
- data/config/routes.rb +7 -2
- data/lib/foreman_fog_proxmox/engine.rb +4 -0
- data/lib/foreman_fog_proxmox/version.rb +1 -1
- data/locale/en/foreman_fog_proxmox.edit.po +508 -0
- data/locale/en/foreman_fog_proxmox.po +34 -7
- data/locale/en/foreman_fog_proxmox.po.time_stamp +0 -0
- data/locale/foreman_fog_proxmox.pot +112 -70
- data/locale/fr/foreman_fog_proxmox.edit.po +508 -0
- data/locale/fr/foreman_fog_proxmox.po +39 -12
- data/locale/fr/foreman_fog_proxmox.po.time_stamp +0 -0
- data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +28 -8
- data/test/factories/proxmox_factory.rb +0 -1
- data/test/functional/compute_resources_controller_test.rb +16 -4
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +1 -0
- data/test/unit/foreman_fog_proxmox/proxmox_test.rb +0 -1
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +33 -8
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +2 -2
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +22 -2
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_volumes_test.rb +18 -6
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d5a92b97ae63b9983d1e09d466c72be641abac13618416b3f9f9bc4adf9fe59
|
4
|
+
data.tar.gz: 44d499507243f4f78910adfdfd566e4fff153dd8b3b4783be1727d905fb9633b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61df6f0b8aa1caba1c31ad6c696093f3d92d8900d32e01985a671372b8f3503ee3d3752fd930b7a518dc2cd9a1b6eb56d92255fa5c19ff27eff049c2bfef6ff9
|
7
|
+
data.tar.gz: acac445ca9f9ee687c440707da9fab8e26e35afc455b29a14f325bcc5a42768f263edb5f6def86eb24acfa583658a5cd70729c40e3f86d5f9c740ec3f4555c4e
|
@@ -96,3 +96,92 @@ function toggleFieldset(fieldset, index, fieldsets){
|
|
96
96
|
break;
|
97
97
|
}
|
98
98
|
}
|
99
|
+
|
100
|
+
function nodeSelected(item) {
|
101
|
+
var node_id = $(item).val();
|
102
|
+
var type = $("#host_compute_attributes_type").val();
|
103
|
+
if (type == undefined) type = $("#compute_attribute_vm_attrs_type").val();
|
104
|
+
switch (type) {
|
105
|
+
case 'qemu':
|
106
|
+
updateOptions('isostorages', 'compute_attributes_config_attributes', 'cdrom_storage', 'compute_attributes_config_attributes', 'cdrom_iso', 'storage', node_id);
|
107
|
+
updateOptions('storages', 'compute_attributes_volumes_attributes', 'storage', undefined, undefined, 'storage', node_id);
|
108
|
+
updateOptions('bridges', 'interfaces_attributes', 'compute_attributes_bridge', undefined, undefined, 'iface', node_id);
|
109
|
+
break;
|
110
|
+
case 'lxc':
|
111
|
+
updateOptions('ostemplates', 'compute_attributes_ostemplate', 'storage', 'compute_attributes_ostemplate', 'file', 'storage', node_id);
|
112
|
+
updateOptions('storages', 'compute_attributes_volumes_attributes', 'storage', undefined, undefined, 'storage', node_id);
|
113
|
+
updateOptions('bridges', 'interfaces_attributes', 'compute_attributes_bridge', undefined, undefined, 'iface', node_id);
|
114
|
+
break;
|
115
|
+
default:
|
116
|
+
console.log("unkown type=" + type);
|
117
|
+
break;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
function emptySelect(select){
|
122
|
+
$(select).empty();
|
123
|
+
$(select).append($("<option></option>").val('').text(''));
|
124
|
+
$(select).val('');
|
125
|
+
}
|
126
|
+
|
127
|
+
function initOptions(select_ids){
|
128
|
+
console.log('initOptions(' + select_ids[0] + ')');
|
129
|
+
select_ids.forEach(emptySelect);
|
130
|
+
select_ids.forEach(function(select){
|
131
|
+
$(select + ' option:selected').prop('selected',false);
|
132
|
+
$(select).val('');
|
133
|
+
});
|
134
|
+
}
|
135
|
+
|
136
|
+
function updateOption(select_id, option, option_id){
|
137
|
+
console.log('update '+ select_id + ' with '+ option[option_id]);
|
138
|
+
$(select_id).append($('<option></option>').val(option[option_id]).text(option[option_id]));
|
139
|
+
}
|
140
|
+
|
141
|
+
function selectIds(start_options_id, end_options_id){
|
142
|
+
let select_host_id = 'select[id^=host_' + start_options_id + ']';
|
143
|
+
let compute_attributes_regex = /compute_attributes_/gi;
|
144
|
+
let select_profile_id = 'select[id^=compute_attribute_vm_attrs_' + start_options_id.replace(compute_attributes_regex, '') + ']';
|
145
|
+
if (end_options_id != undefined) {
|
146
|
+
select_host_id += '[id$=' + end_options_id + ']';
|
147
|
+
select_profile_id += '[id$=' + end_options_id.replace(compute_attributes_regex, '') + ']';
|
148
|
+
}
|
149
|
+
return [select_host_id, select_profile_id];
|
150
|
+
}
|
151
|
+
|
152
|
+
function updateOptions(options_path, start_options_id, end_options_id, start_second_options_id, end_second_options_id, option_id, node_id, second_id = undefined) {
|
153
|
+
|
154
|
+
let select_ids = selectIds(start_options_id, end_options_id);
|
155
|
+
let select_second_ids;
|
156
|
+
if ( start_second_options_id != undefined && end_second_options_id != undefined) {
|
157
|
+
select_second_ids = selectIds(start_second_options_id, end_second_options_id);
|
158
|
+
}
|
159
|
+
var url = '/foreman_fog_proxmox/' + options_path + '/' + node_id;
|
160
|
+
if (second_id != undefined) url += '/' + second_id;
|
161
|
+
tfm.tools.showSpinner();
|
162
|
+
$.getJSON({
|
163
|
+
type: 'get',
|
164
|
+
url: url,
|
165
|
+
error: function(j,status,error){
|
166
|
+
var errorMsg = 'Error=' + error + ', status=' + status + ' loading ' + options_path + ' for node_id=' + node_id;
|
167
|
+
if (second_id != undefined) errorMsg += ' and second_id=' + second_id;
|
168
|
+
console.log(errorMsg);
|
169
|
+
},
|
170
|
+
success: function(options) {
|
171
|
+
initOptions(select_ids);
|
172
|
+
if (select_second_ids != undefined) {
|
173
|
+
initOptions(select_second_ids);
|
174
|
+
}
|
175
|
+
$.each(options, function(i,option){
|
176
|
+
for (let j = 0; j < select_ids.length; j++) {
|
177
|
+
updateOption(select_ids[j], option, option_id);
|
178
|
+
}
|
179
|
+
});
|
180
|
+
},
|
181
|
+
complete: function(item){
|
182
|
+
// eslint-disable-next-line no-undef
|
183
|
+
reloadOnAjaxComplete(item);
|
184
|
+
tfm.tools.hideSpinner();
|
185
|
+
}
|
186
|
+
});
|
187
|
+
}
|
@@ -15,46 +15,10 @@
|
|
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
|
-
function initOstemplateStorage(){
|
19
|
-
var select = '#host_compute_attributes_ostemplate_storage';
|
20
|
-
$(select + ' option:selected').prop('selected',false);
|
21
|
-
$(select).val('');
|
22
|
-
}
|
23
|
-
|
24
|
-
function initOstemplateOptions(){
|
25
|
-
var select_ids = ['#host_compute_attributes_ostemplate_file','#compute_attribute_vm_attrs_ostemplate_file'];
|
26
|
-
select_ids.forEach(emptySelect);
|
27
|
-
}
|
28
|
-
|
29
|
-
function emptySelect(select, index, select_ids){
|
30
|
-
$(select).empty();
|
31
|
-
$(select).append($("<option></option>").val('').text(''));
|
32
|
-
$(select).val('');
|
33
|
-
}
|
34
|
-
|
35
18
|
|
36
19
|
function storageOstemplateSelected(item) {
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
url: '/foreman_fog_proxmox/ostemplates/'+storage,
|
43
|
-
complete: function(){
|
44
|
-
tfm.tools.hideSpinner();
|
45
|
-
},
|
46
|
-
error: function(j,status,error){
|
47
|
-
console.log("Error=" + error +", status=" + status + " loading os templates for storage=" + storage);
|
48
|
-
},
|
49
|
-
success: function(ostemplates) {
|
50
|
-
initOstemplateOptions();
|
51
|
-
$.each(ostemplates, function(i,ostemplate){
|
52
|
-
$('#host_compute_attributes_ostemplate_file').append($("<option></option>").val(ostemplate.volid).text(ostemplate.volid));
|
53
|
-
$('#compute_attribute_vm_attrs_ostemplate_file').append($("<option></option>").val(ostemplate.volid).text(ostemplate.volid));
|
54
|
-
});
|
55
|
-
}
|
56
|
-
});
|
57
|
-
} else {
|
58
|
-
initOstemplateOptions();
|
59
|
-
}
|
60
|
-
}
|
20
|
+
var storage = $(item).val();
|
21
|
+
var node_id = $('#host_compute_attributes_node_id').val();
|
22
|
+
if (node_id == undefined) node_id = $("#compute_attribute_vm_attrs_node_id").val();
|
23
|
+
updateOptions('ostemplates', 'compute_attributes_ostemplate', 'file', undefined, undefined, 'volid', node_id, storage);
|
24
|
+
}
|
@@ -56,27 +56,8 @@ function initCdromOptions(name) {
|
|
56
56
|
|
57
57
|
function storageIsoSelected(item) {
|
58
58
|
var storage = $(item).val();
|
59
|
-
|
60
|
-
|
61
|
-
$.getJSON({
|
62
|
-
type: 'get',
|
63
|
-
url: '/foreman_fog_proxmox/isos/' + storage,
|
64
|
-
complete: function () {
|
65
|
-
tfm.tools.hideSpinner();
|
66
|
-
},
|
67
|
-
error: function (j, status, error) {
|
68
|
-
console.log("Error=" + error + ", status=" + status + " loading isos for storage=" + storage);
|
69
|
-
},
|
70
|
-
success: function (isos) {
|
71
|
-
initCdromOptions('iso');
|
72
|
-
$.each(isos, function (i, iso) {
|
73
|
-
$('#host_compute_attributes_config_attributes_cdrom_iso').append($("<option></option>").val(iso.volid).text(iso.volid));
|
74
|
-
});
|
75
|
-
}
|
76
|
-
});
|
77
|
-
} else {
|
78
|
-
initCdromOptions('iso');
|
79
|
-
}
|
59
|
+
var node_id = $('#host_compute_attributes_node_id').val();
|
60
|
+
updateOptions('isos', 'compute_attributes_config_attributes', 'cdrom_iso', undefined, undefined, 'volid', node_id, storage);
|
80
61
|
}
|
81
62
|
|
82
63
|
function attributesPrefixSelector(profile, type) {
|
@@ -21,22 +21,62 @@ module ForemanFogProxmox
|
|
21
21
|
class ComputeResourcesController < ::ApplicationController
|
22
22
|
before_action :load_compute_resource
|
23
23
|
|
24
|
-
# GET foreman_fog_proxmox/isos/:storage
|
25
|
-
def
|
26
|
-
volumes = @compute_resource.images_by_storage(params[:storage], 'iso')
|
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')
|
27
27
|
respond_to do |format|
|
28
28
|
format.json { render :json => volumes }
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
# GET foreman_fog_proxmox/ostemplates/:storage
|
33
|
-
def
|
34
|
-
volumes = @compute_resource.images_by_storage(params[:storage], 'vztmpl')
|
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')
|
35
35
|
respond_to do |format|
|
36
36
|
format.json { render :json => volumes }
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
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')
|
43
|
+
respond_to do |format|
|
44
|
+
format.json { render :json => volumes }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# GET foreman_fog_proxmox/ostemplates/:node_id
|
49
|
+
def ostemplates_by_node
|
50
|
+
storages = @compute_resource.storages(params[:node_id], 'vztmpl')
|
51
|
+
respond_to do |format|
|
52
|
+
format.json { render :json => storages }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# GET foreman_fog_proxmox/storages/:node_id
|
57
|
+
def storages_by_node
|
58
|
+
storages = @compute_resource.storages(params[:node_id])
|
59
|
+
respond_to do |format|
|
60
|
+
format.json { render :json => storages }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# GET foreman_fog_proxmox/isostorages/:node_id
|
65
|
+
def iso_storages_by_node
|
66
|
+
storages = @compute_resource.storages(params[:node_id], 'iso')
|
67
|
+
respond_to do |format|
|
68
|
+
format.json { render :json => storages }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# GET foreman_fog_proxmox/bridges/:node_id
|
73
|
+
def bridges_by_node
|
74
|
+
bridges = @compute_resource.bridges(params[:node_id])
|
75
|
+
respond_to do |format|
|
76
|
+
format.json { render :json => bridges }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
40
80
|
private
|
41
81
|
|
42
82
|
def load_compute_resource
|
@@ -23,7 +23,9 @@ require 'foreman_fog_proxmox/value'
|
|
23
23
|
|
24
24
|
module ProxmoxContainerHelper
|
25
25
|
def config_keys
|
26
|
-
|
26
|
+
general_a = ['node_id', 'name', 'type', 'config_attributes', 'volumes_attributes', 'interfaces_attributes']
|
27
|
+
general_a += ['firmware_type', 'provision_method', 'container_volumes', 'server_volumes', 'start_after_create']
|
28
|
+
keys = { general: general_a }
|
27
29
|
keys.store(:main, ['name', 'type', 'node_id', 'vmid', 'interfaces', 'mount_points', 'disks'])
|
28
30
|
keys.store(:cpu, ['arch', 'cpulimit', 'cpuunits', 'cores'])
|
29
31
|
keys.store(:memory, ['memory', 'swap'])
|
@@ -42,7 +42,8 @@ module ProxmoxServerHelper
|
|
42
42
|
memory = parse_server_memory(config.select { |key, _value| memory_a.include? key })
|
43
43
|
interfaces_attributes = args['interfaces_attributes']
|
44
44
|
interfaces_to_add, interfaces_to_delete = parse_server_interfaces(interfaces_attributes)
|
45
|
-
general_a = ['node_id', 'type', 'config_attributes', 'volumes_attributes', 'interfaces_attributes'
|
45
|
+
general_a = ['node_id', 'type', 'config_attributes', 'volumes_attributes', 'interfaces_attributes']
|
46
|
+
general_a += ['firmware_type', 'provision_method', 'container_volumes', 'server_volumes', 'start_after_create']
|
46
47
|
logger.debug("general_a: #{general_a}")
|
47
48
|
parsed_vm = args.reject { |key, value| general_a.include?(key) || ForemanFogProxmox::Value.empty?(value) }
|
48
49
|
config_a = []
|
@@ -57,6 +57,17 @@ module ProxmoxVmHelper
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
def convert_memory_sizes(args)
|
61
|
+
convert_memory_size(args['config_attributes'], 'memory')
|
62
|
+
convert_memory_size(args['config_attributes'], 'min_memory')
|
63
|
+
convert_memory_size(args['config_attributes'], 'shares')
|
64
|
+
convert_memory_size(args['config_attributes'], 'swap')
|
65
|
+
end
|
66
|
+
|
67
|
+
def convert_volumes_size(args)
|
68
|
+
args['volumes_attributes'].each_value { |value| value['size'] = (value['size'].to_i / GIGA).to_s unless ForemanFogProxmox::Value.empty?(value['size']) }
|
69
|
+
end
|
70
|
+
|
60
71
|
def convert_sizes(args)
|
61
72
|
convert_memory_size(args['config_attributes'], 'memory')
|
62
73
|
convert_memory_size(args['config_attributes'], 'min_memory')
|
@@ -74,4 +85,12 @@ module ProxmoxVmHelper
|
|
74
85
|
memory = (config_hash[key].to_i / MEGA).to_s == '0' ? config_hash[key] : (config_hash[key].to_i / MEGA).to_s
|
75
86
|
config_hash.store(key, memory)
|
76
87
|
end
|
88
|
+
|
89
|
+
def vm_type(host)
|
90
|
+
host.compute_object.type
|
91
|
+
end
|
92
|
+
|
93
|
+
def node_id(host)
|
94
|
+
host.compute_object.node_id
|
95
|
+
end
|
77
96
|
end
|
@@ -21,7 +21,7 @@ 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
|
24
|
+
attr_accessor :image_id, :templated, :ostemplate_storage, :ostemplate_file, :password, :start_after_create
|
25
25
|
|
26
26
|
def start
|
27
27
|
action('start')
|
@@ -41,7 +41,6 @@ module ForemanFogProxmox
|
|
41
41
|
validates :url, :format => { :with => URI::DEFAULT_PARSER.make_regexp }, :presence => true
|
42
42
|
validates :user, :format => { :with => /(\w+)[@]{1}(\w+)/ }, :presence => true
|
43
43
|
validates :password, :presence => true
|
44
|
-
validates :node_id, :presence => true
|
45
44
|
before_create :test_connection
|
46
45
|
|
47
46
|
def provided_attributes
|
@@ -66,18 +65,6 @@ module ForemanFogProxmox
|
|
66
65
|
associate_by('mac', vm.mac)
|
67
66
|
end
|
68
67
|
|
69
|
-
def node_id
|
70
|
-
attrs[:node_id]
|
71
|
-
end
|
72
|
-
|
73
|
-
def node_id=(value)
|
74
|
-
attrs[:node_id] = value
|
75
|
-
end
|
76
|
-
|
77
|
-
def node
|
78
|
-
client.nodes.get node_id
|
79
|
-
end
|
80
|
-
|
81
68
|
def ssl_certs
|
82
69
|
attrs[:ssl_certs]
|
83
70
|
end
|
@@ -120,14 +107,23 @@ module ForemanFogProxmox
|
|
120
107
|
|
121
108
|
def client
|
122
109
|
@client ||= ::Fog::Proxmox::Compute.new(fog_credentials)
|
110
|
+
rescue StandardError => e
|
111
|
+
logger.error(e)
|
112
|
+
raise ::Foreman::Exception, format(N_('Failed retrieving proxmox compute client caused by %<e>s'), e: e)
|
123
113
|
end
|
124
114
|
|
125
115
|
def identity_client
|
126
116
|
@identity_client ||= ::Fog::Proxmox::Identity.new(fog_credentials)
|
117
|
+
rescue StandardError => e
|
118
|
+
logger.error(e)
|
119
|
+
raise ::Foreman::Exception, format(N_('Failed retrieving proxmox identity client caused by %<e>s'), e: e)
|
127
120
|
end
|
128
121
|
|
129
122
|
def network_client
|
130
123
|
@network_client ||= ::Fog::Proxmox::Network.new(fog_credentials)
|
124
|
+
rescue StandardError => e
|
125
|
+
logger.error(e)
|
126
|
+
raise ::Foreman::Exception, format(N_('Failed retrieving proxmox network client caused by %<e>s'), e: e)
|
131
127
|
end
|
132
128
|
|
133
129
|
def host
|
@@ -23,19 +23,24 @@ module ForemanFogProxmox
|
|
23
23
|
!find_vm_by_uuid(image).nil?
|
24
24
|
end
|
25
25
|
|
26
|
-
def images_by_storage(storage_id, type = 'iso')
|
26
|
+
def images_by_storage(node_id, storage_id, type = 'iso')
|
27
|
+
node = client.nodes.get node_id
|
28
|
+
node ||= default_node
|
27
29
|
storage = node.storages.get storage_id if storage_id
|
28
30
|
storage.volumes.list_by_content_type(type).sort_by(&:volid) if storage
|
29
31
|
end
|
30
32
|
|
31
33
|
def available_images
|
32
|
-
templates.collect { |template| OpenStruct.new(id: template.vmid) }
|
34
|
+
templates.collect { |template| OpenStruct.new(id: template.vmid.to_s) }
|
33
35
|
end
|
34
36
|
|
35
37
|
def templates
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
volumes = []
|
39
|
+
nodes.each do |node|
|
40
|
+
storage = storages(node.node).first
|
41
|
+
volumes += storage.volumes.list_by_content_type('images')
|
42
|
+
end
|
43
|
+
volumes.select(&:templated?)
|
39
44
|
end
|
40
45
|
|
41
46
|
def template(vmid)
|
@@ -22,7 +22,7 @@ module ForemanFogProxmox
|
|
22
22
|
include ProxmoxVolumes
|
23
23
|
|
24
24
|
def start_on_boot(vm, args)
|
25
|
-
startonboot = args[:
|
25
|
+
startonboot = args[:start_after_create].blank? ? false : Foreman::Cast.to_bool(args[:start_after_create])
|
26
26
|
vm.start if startonboot
|
27
27
|
vm
|
28
28
|
end
|
@@ -30,6 +30,7 @@ module ForemanFogProxmox
|
|
30
30
|
def create_vm(args = {})
|
31
31
|
vmid = args[:vmid].to_i
|
32
32
|
type = args[:type]
|
33
|
+
node = client.nodes.get(args[:node_id])
|
33
34
|
raise ::Foreman::Exception, format(N_('invalid vmid=%<vmid>s'), vmid: vmid) unless node.servers.id_valid?(vmid)
|
34
35
|
|
35
36
|
image_id = args[:image_id]
|
@@ -88,9 +89,13 @@ module ForemanFogProxmox
|
|
88
89
|
def save_vm(uuid, new_attributes)
|
89
90
|
vm = find_vm_by_uuid(uuid)
|
90
91
|
templated = new_attributes['templated']
|
92
|
+
node_id = new_attributes['node_id']
|
91
93
|
if templated == '1' && !vm.templated?
|
92
94
|
vm.create_template
|
95
|
+
elsif vm.node_id != node_id
|
96
|
+
vm.migrate(node_id)
|
93
97
|
else
|
98
|
+
convert_memory_sizes(new_attributes)
|
94
99
|
volumes_attributes = new_attributes['volumes_attributes']
|
95
100
|
volumes_attributes&.each_value { |volume_attributes| save_volume(vm, volume_attributes) }
|
96
101
|
parsed_attr = vm.container? ? parse_container_vm(new_attributes.merge(type: vm.type)) : parse_server_vm(new_attributes.merge(type: vm.type))
|
@@ -100,7 +105,6 @@ module ForemanFogProxmox
|
|
100
105
|
cdrom_attributes = parsed_attr.select { |_key, value| Fog::Proxmox::DiskHelper.cdrom?(value.to_s) }
|
101
106
|
config_attributes = config_attributes.reject { |key, _value| Fog::Proxmox::DiskHelper.disk?(key) }
|
102
107
|
vm.update(config_attributes.merge(cdrom_attributes))
|
103
|
-
start_on_boot(vm, new_attributes)
|
104
108
|
end
|
105
109
|
find_vm_by_uuid(uuid)
|
106
110
|
end
|