foreman_fog_proxmox 0.4.0 → 0.5.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/README.md +24 -12
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +26 -0
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +92 -0
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_container.js +60 -0
- data/app/assets/javascripts/foreman_fog_proxmox/{proxmox.js → proxmox_vm_server.js} +10 -10
- data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +1 -1
- data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +9 -1
- data/app/helpers/node_dashboard_helper.rb +36 -0
- data/app/helpers/proxmox_compute_selectors_helper.rb +23 -0
- data/app/helpers/proxmox_container_helper.rb +157 -0
- data/app/helpers/proxmox_form_helper.rb +67 -0
- data/app/helpers/{proxmox_compute_helper.rb → proxmox_server_helper.rb} +49 -38
- data/app/helpers/proxmox_vm_helper.rb +86 -0
- data/app/models/concerns/fog_extensions/proxmox/container.rb +57 -0
- data/{test/factories/foreman_fog_proxmox_factories.rb → app/models/concerns/fog_extensions/proxmox/container_config.rb} +16 -13
- data/app/models/concerns/fog_extensions/proxmox/server.rb +8 -2
- data/app/models/foreman_fog_proxmox/proxmox.rb +160 -67
- data/app/overrides/compute_resources_vms/form/add_clone_to_new_vm_compute_detail.rb +24 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_networks_form.rb +32 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_nic_provider_specific_form.rb +25 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_edit.rb +24 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_new_volume.rb +24 -0
- data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +37 -0
- data/app/views/compute_resources/form/_proxmox.html.erb +7 -4
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_form.html.erb +23 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_new_childs_form.html.erb +25 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +23 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +73 -0
- data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +16 -23
- data/app/views/compute_resources_vms/form/proxmox/_general.html.erb +37 -0
- data/app/views/compute_resources_vms/form/proxmox/_network.html.erb +2 -7
- data/app/views/compute_resources_vms/form/proxmox/container/_advanced.html.erb +31 -0
- data/app/views/compute_resources_vms/form/proxmox/container/_config.html.erb +41 -0
- data/app/views/compute_resources_vms/form/proxmox/container/_extended.html.erb +26 -0
- data/app/views/compute_resources_vms/form/proxmox/container/_network.html.erb +25 -0
- data/app/views/compute_resources_vms/form/proxmox/container/_volume_mp.html.erb +25 -0
- data/app/views/compute_resources_vms/form/proxmox/container/_volume_rootfs.html.erb +24 -0
- data/app/views/compute_resources_vms/form/proxmox/server/_advanced.html.erb +31 -0
- data/app/views/compute_resources_vms/form/proxmox/{_config.html.erb → server/_config.html.erb} +11 -8
- data/app/views/compute_resources_vms/form/proxmox/server/_network.html.erb +29 -0
- data/app/views/compute_resources_vms/form/proxmox/server/_volume.html.erb +27 -0
- data/app/views/compute_resources_vms/index/_proxmox.html.erb +4 -2
- data/app/views/compute_resources_vms/show/_proxmox.html.erb +9 -2
- data/app/views/dashboard/_foreman_fog_proxmox_widget.erb +4 -2
- data/app/views/images/form/_proxmox.html.erb +17 -0
- data/config/routes.rb +1 -0
- data/lib/foreman_fog_proxmox/engine.rb +10 -3
- data/lib/foreman_fog_proxmox/value.rb +24 -0
- data/lib/foreman_fog_proxmox/version.rb +1 -1
- data/locale/en/foreman_fog_proxmox.edit.po +456 -0
- data/locale/en/foreman_fog_proxmox.po +327 -11
- data/locale/en/foreman_fog_proxmox.po.time_stamp +0 -0
- data/locale/foreman_fog_proxmox.pot +515 -8
- data/locale/fr/foreman_fog_proxmox.edit.po +456 -0
- data/locale/fr/foreman_fog_proxmox.po +327 -11
- data/locale/fr/foreman_fog_proxmox.po.time_stamp +0 -0
- data/test/factories/proxmox_factory.rb +72 -0
- data/test/functional/compute_resources_controller_test.rb +34 -0
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +205 -0
- data/test/{helpers/proxmox_compute_helper_test.rb → unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb} +36 -28
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +240 -0
- data/test/unit/foreman_fog_proxmox/proxmox_test.rb +327 -0
- data/test/unit/foreman_fog_proxmox/proxmox_test_helpers.rb +251 -0
- metadata +83 -14
- data/app/views/compute_resources_vms/form/proxmox/_volume.html.erb +0 -23
- data/test/unit/foreman_fog_proxmox_test.rb +0 -11
@@ -0,0 +1,67 @@
|
|
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 ProxmoxFormHelper
|
21
|
+
|
22
|
+
def password_proxmox_f(f, attr, options = {})
|
23
|
+
unset_button = options.delete(:unset)
|
24
|
+
value = f.object[attr] if options.delete(:keep_value)
|
25
|
+
password_field_tag(:fakepassword, value, :style => 'display: none', :autocomplete => 'new-password-fake') +
|
26
|
+
field(f, attr, options) do
|
27
|
+
options[:autocomplete] ||= 'new-password'
|
28
|
+
options[:placeholder] ||= password_proxmox_placeholder(f.object, attr)
|
29
|
+
options[:disabled] = true if unset_button
|
30
|
+
options[:value] = value if value.present?
|
31
|
+
addClass options, 'form-control'
|
32
|
+
pass = f.password_field(attr, options) +
|
33
|
+
'<span class="glyphicon glyphicon-warning-sign input-addon"
|
34
|
+
title="'.html_safe + _('Caps lock ON') +
|
35
|
+
'" style="display:none"></span>'.html_safe
|
36
|
+
if unset_button
|
37
|
+
button = link_to_function(icon_text("edit", "", :kind => "pficon"), 'toggle_input_group(this)', {:id => 'disable-pass-btn', :class => 'btn btn-default', :title => _("Change the password")})
|
38
|
+
input_group(pass, input_group_btn(button))
|
39
|
+
else
|
40
|
+
pass
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def password_proxmox_placeholder(obj, attr = nil)
|
46
|
+
pass = obj.attributes.has_key?(attr)
|
47
|
+
pass ? "********" : ''
|
48
|
+
end
|
49
|
+
|
50
|
+
def second_child_fields_template(form_builder, association, options = { })
|
51
|
+
unless options[:object].present?
|
52
|
+
association_object = form_builder.object.class.reflect_on_association(association)
|
53
|
+
options[:object] = association_object.klass.new(association_object.foreign_key => form_builder.object.id)
|
54
|
+
end
|
55
|
+
options[:partial] ||= association.to_s.singularize
|
56
|
+
options[:form_builder_local] ||= :f
|
57
|
+
options[:form_builder_attrs] ||= {}
|
58
|
+
|
59
|
+
content_tag(:div, :id => "#{options[:type]}_#{association}", :style => 'display: none') do
|
60
|
+
form_builder.fields_for(association, options[:object], :child_index => "0") do |f|
|
61
|
+
render(:partial => options[:partial], :layout => options[:layout],
|
62
|
+
:locals => { options[:form_builder_local] => f }.merge(options[:form_builder_attrs]))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -19,56 +19,65 @@
|
|
19
19
|
|
20
20
|
require 'fog/proxmox/helpers/disk_helper'
|
21
21
|
require 'fog/proxmox/helpers/nic_helper'
|
22
|
+
require 'foreman_fog_proxmox/value'
|
22
23
|
|
23
|
-
module
|
24
|
+
module ProxmoxServerHelper
|
24
25
|
|
25
26
|
KILO = 1024
|
26
27
|
MEGA = KILO * KILO
|
27
28
|
GIGA = KILO * MEGA
|
28
29
|
|
29
|
-
def
|
30
|
+
def parse_server_vm(args)
|
31
|
+
args = ActiveSupport::HashWithIndifferentAccess.new(args)
|
30
32
|
return {} unless args
|
31
33
|
return {} if args.empty?
|
34
|
+
return {} unless args['type'] == 'qemu'
|
32
35
|
config = args['config_attributes']
|
36
|
+
main_a = %w[name type node vmid]
|
37
|
+
config = args.reject { |key,_value| main_a.include? key } unless config
|
33
38
|
cdrom_a = %w[cdrom cdrom_storage cdrom_iso]
|
34
|
-
cdrom =
|
35
|
-
|
39
|
+
cdrom = parse_server_cdrom(config.select { |key,_value| cdrom_a.include? key })
|
40
|
+
vols = args['volumes_attributes']
|
41
|
+
volumes = parse_server_volumes(vols)
|
36
42
|
cpu_a = %w[cpu_type spectre pcid vcpus cpulimit cpuunits cores sockets numa]
|
37
|
-
cpu =
|
43
|
+
cpu = parse_server_cpu(config.select { |key,_value| cpu_a.include? key })
|
38
44
|
memory_a = %w[memory min_memory balloon shares]
|
39
|
-
memory =
|
45
|
+
memory = parse_server_memory(config.select { |key,_value| memory_a.include? key })
|
40
46
|
interfaces_attributes = args['interfaces_attributes']
|
41
|
-
networks =
|
42
|
-
general_a = %w[node config_attributes volumes_attributes interfaces_attributes firmware_type provision_method]
|
47
|
+
networks = parse_server_interfaces(interfaces_attributes)
|
48
|
+
general_a = %w[node type config_attributes volumes_attributes interfaces_attributes firmware_type provision_method container_volumes server_volumes]
|
43
49
|
logger.debug("general_a: #{general_a}")
|
44
|
-
parsed_vm = args.reject { |key,value| general_a.include?(key) ||
|
50
|
+
parsed_vm = args.reject { |key,value| general_a.include?(key) || ForemanFogProxmox::Value.empty?(value) }
|
45
51
|
config_a = []
|
46
52
|
config_a += cpu_a
|
47
53
|
config_a += cdrom_a
|
48
54
|
config_a += memory_a
|
49
|
-
|
50
|
-
|
55
|
+
config_a += general_a
|
56
|
+
parsed_config = config.reject { |key,value| config_a.include?(key) || ForemanFogProxmox::Value.empty?(value) }
|
57
|
+
logger.debug("parse_server_config(): #{parsed_config}")
|
51
58
|
parsed_vm = parsed_vm.merge(parsed_config).merge(cpu).merge(memory).merge(cdrom)
|
52
59
|
networks.each { |network| parsed_vm = parsed_vm.merge(network) }
|
53
60
|
volumes.each { |volume| parsed_vm = parsed_vm.merge(volume) }
|
54
|
-
logger.debug("
|
61
|
+
logger.debug("parse_server_vm(): #{parsed_vm}")
|
55
62
|
parsed_vm
|
56
63
|
end
|
57
64
|
|
58
|
-
def
|
59
|
-
memory = {
|
65
|
+
def parse_server_memory(args)
|
66
|
+
memory = { }
|
67
|
+
memory.store(:memory,args['memory'].to_i) if args['memory']
|
60
68
|
ballooned = args['balloon'].to_i == 1
|
61
69
|
if ballooned
|
62
|
-
memory.store(:shares,args['shares'].to_i)
|
63
|
-
memory.store(:balloon,args['min_memory'].to_i)
|
70
|
+
memory.store(:shares,args['shares'].to_i) if args['shares']
|
71
|
+
memory.store(:balloon,args['min_memory'].to_i) if args['min_memory']
|
64
72
|
else
|
65
|
-
memory.store(:balloon,args['balloon'].to_i)
|
73
|
+
memory.store(:balloon,args['balloon'].to_i) if args['balloon']
|
66
74
|
end
|
67
|
-
logger.debug("
|
75
|
+
logger.debug("parse_server_memory(): #{memory}")
|
68
76
|
memory
|
69
77
|
end
|
70
78
|
|
71
|
-
def
|
79
|
+
def parse_server_cpu(args)
|
80
|
+
return {} unless args['cpu_type']
|
72
81
|
cpu = "cputype=#{args['cpu_type']}"
|
73
82
|
spectre = args['spectre'].to_i == 1
|
74
83
|
pcid = args['pcid'].to_i == 1
|
@@ -76,65 +85,67 @@ module ProxmoxComputeHelper
|
|
76
85
|
cpu += "+spec-ctrl" if spectre
|
77
86
|
cpu += ";" if spectre && pcid
|
78
87
|
cpu += "+pcid" if pcid
|
79
|
-
args.delete_if { |key,value| %w[cpu_type spectre pcid].include?(key) ||
|
88
|
+
args.delete_if { |key,value| %w[cpu_type spectre pcid].include?(key) || ForemanFogProxmox::Value.empty?(value) }
|
80
89
|
args.each_value { |value| value.to_i }
|
81
90
|
parsed_cpu = { cpu: cpu }.merge(args)
|
82
|
-
logger.debug("
|
91
|
+
logger.debug("parse_server_cpu(): #{parsed_cpu}")
|
83
92
|
parsed_cpu
|
84
93
|
end
|
85
94
|
|
86
|
-
def
|
95
|
+
def parse_server_cdrom(args)
|
87
96
|
cdrom = args['cdrom']
|
88
97
|
cdrom_image = args['cdrom_iso']
|
89
98
|
volid = cdrom_image.empty? ? cdrom : cdrom_image
|
99
|
+
return {} unless volid
|
90
100
|
cdrom = "#{volid},media=cdrom"
|
91
101
|
{ide2: cdrom}
|
92
102
|
end
|
93
103
|
|
94
|
-
def
|
104
|
+
def parse_server_volume(args)
|
95
105
|
disk = {}
|
96
106
|
id = args['id']
|
97
107
|
id = "#{args['controller']}#{args['device']}" unless id
|
108
|
+
return args if ForemanFogProxmox::Value.empty?(id)
|
98
109
|
delete = args['_delete'].to_i == 1
|
99
|
-
args.delete_if { |_key,value|
|
110
|
+
args.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
|
100
111
|
if delete
|
101
|
-
logger.debug("
|
112
|
+
logger.debug("parse_server_volume(): delete id=#{id}")
|
102
113
|
disk.store(:delete, id)
|
103
114
|
disk
|
104
115
|
else
|
105
116
|
disk.store(:id, id)
|
106
117
|
disk.store(:volid, args['volid'])
|
107
118
|
disk.store(:storage, args['storage'].to_s)
|
108
|
-
disk.store(:size, args['size'])
|
119
|
+
disk.store(:size, args['size'].to_i)
|
109
120
|
options = args.reject { |key,_value| %w[id volid controller device storage size _delete].include? key}
|
110
121
|
disk.store(:options, options)
|
111
|
-
logger.debug("
|
122
|
+
logger.debug("parse_server_volume(): add disk=#{disk}")
|
112
123
|
Fog::Proxmox::DiskHelper.flatten(disk)
|
113
124
|
end
|
114
125
|
end
|
115
126
|
|
116
|
-
def
|
127
|
+
def parse_server_volumes(args)
|
117
128
|
volumes = []
|
118
|
-
args.each_value { |value| volumes.push(
|
119
|
-
logger.debug("
|
129
|
+
args.each_value { |value| volumes.push(parse_server_volume(value))} if args
|
130
|
+
logger.debug("parse_server_volumes(): volumes=#{volumes}")
|
120
131
|
volumes
|
121
132
|
end
|
122
133
|
|
123
|
-
def
|
134
|
+
def parse_server_interfaces(args)
|
124
135
|
nics = []
|
125
|
-
args.each_value { |value| nics.push(
|
126
|
-
logger.debug("
|
136
|
+
args.each_value { |value| nics.push(parse_server_interface(value))} if args
|
137
|
+
logger.debug("parse_server_interfaces(): nics=#{nics}")
|
127
138
|
nics
|
128
139
|
end
|
129
140
|
|
130
|
-
def
|
131
|
-
args.delete_if { |_key,value|
|
141
|
+
def parse_server_interface(args)
|
142
|
+
args.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
|
132
143
|
nic = {}
|
133
144
|
id = args['id']
|
134
|
-
logger.debug("
|
145
|
+
logger.debug("parse_server_interface(): id=#{id}")
|
135
146
|
delete = args['_delete'].to_i == 1
|
136
147
|
if delete
|
137
|
-
logger.debug("
|
148
|
+
logger.debug("parse_server_interface(): delete id=#{id}")
|
138
149
|
nic.store(:delete, id)
|
139
150
|
nic
|
140
151
|
else
|
@@ -146,7 +157,7 @@ module ProxmoxComputeHelper
|
|
146
157
|
nic.store(:rate, args['rate'].to_i) if args['rate']
|
147
158
|
nic.store(:link_down, args['disconnect'].to_i) if args['disconnect']
|
148
159
|
nic.store(:queues, args['queues'].to_i) if args['queues']
|
149
|
-
logger.debug("
|
160
|
+
logger.debug("parse_server_interface(): add nic=#{nic}")
|
150
161
|
Fog::Proxmox::NicHelper.flatten(nic)
|
151
162
|
end
|
152
163
|
end
|
@@ -0,0 +1,86 @@
|
|
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 'fog/proxmox/helpers/disk_helper'
|
21
|
+
require 'fog/proxmox/helpers/nic_helper'
|
22
|
+
require 'foreman_fog_proxmox/value'
|
23
|
+
|
24
|
+
module ProxmoxVmHelper
|
25
|
+
|
26
|
+
KILO = 1024
|
27
|
+
MEGA = KILO * KILO
|
28
|
+
GIGA = KILO * MEGA
|
29
|
+
|
30
|
+
def object_to_config_hash(vm,type)
|
31
|
+
vm_h = ActiveSupport::HashWithIndifferentAccess.new
|
32
|
+
main_a = %w[hostname name type node vmid]
|
33
|
+
type = vm.config.attributes['type']
|
34
|
+
type = vm.type unless type
|
35
|
+
main = vm.config.attributes.select { |key,_value| main_a.include? key }
|
36
|
+
disks_regexp = /^(scsi|sata|mp|rootfs|virtio|ide)(\d+){0,1}$/
|
37
|
+
nics_regexp = /^(net)(\d+)/
|
38
|
+
main_a += %w[templated]
|
39
|
+
config = vm.config.attributes.reject { |key,_value| main_a.include?(key) || disks_regexp.match(key) || nics_regexp.match(key) }
|
40
|
+
vm_h = vm_h.merge(main)
|
41
|
+
vm_h = vm_h.merge({'config_attributes': config})
|
42
|
+
vm_h
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_cdrom_to_config_server(vm,config)
|
46
|
+
cd_disks = vm.config.disks.select { |disk| disk.id == 'ide2' }
|
47
|
+
cdrom = {}
|
48
|
+
disk_to_cdrom(cd_disks.first,cdrom)
|
49
|
+
config = config.merge(cdrom)
|
50
|
+
config
|
51
|
+
end
|
52
|
+
|
53
|
+
def disk_to_cdrom(disk,cdrom)
|
54
|
+
volid = disk.volid
|
55
|
+
cdrom_a = %w[none cdrom]
|
56
|
+
if cdrom_a.include? volid
|
57
|
+
cdrom.store('cdrom',volid)
|
58
|
+
else
|
59
|
+
cdrom.store('cdrom','image')
|
60
|
+
cdrom.store('cdrom_iso',volid)
|
61
|
+
cdrom.store('cdrom_storage',disk.storage)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def convert_sizes(args)
|
66
|
+
convert_memory_size(args['config_attributes'],'memory')
|
67
|
+
convert_memory_size(args['config_attributes'],'min_memory')
|
68
|
+
convert_memory_size(args['config_attributes'],'shares')
|
69
|
+
convert_memory_size(args['config_attributes'],'swap')
|
70
|
+
args['volumes_attributes'].each_value { |value| value['size'] = (value['size'].to_i / GIGA).to_s unless ForemanFogProxmox::Value.empty?(value['size']) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def convert_memory_size(config_hash, key)
|
74
|
+
config_hash.store(key, (config_hash[key].to_i / MEGA).to_s) unless ForemanFogProxmox::Value.empty?(config_hash[key])
|
75
|
+
end
|
76
|
+
|
77
|
+
def parse_type_and_vmid(uuid)
|
78
|
+
uuid_regexp = /^(lxc|qemu)\_(\d+)$/
|
79
|
+
raise ::Foreman::Exception.new _("Invalid uuid=[%{uuid}]." % { uuid: uuid }) unless uuid.match(uuid_regexp)
|
80
|
+
id_a = uuid.scan(uuid_regexp).first
|
81
|
+
type = id_a[0]
|
82
|
+
vmid = id_a[1]
|
83
|
+
return type, vmid
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,57 @@
|
|
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 FogExtensions
|
21
|
+
module Proxmox
|
22
|
+
module Container
|
23
|
+
extend ActiveSupport::Concern
|
24
|
+
attr_accessor :ostemplate_storage, :ostemplate_file, :password
|
25
|
+
def to_s
|
26
|
+
name
|
27
|
+
end
|
28
|
+
def persisted?
|
29
|
+
!!identity && !!uptime
|
30
|
+
end
|
31
|
+
def identity
|
32
|
+
"#{type}_#{vmid}"
|
33
|
+
end
|
34
|
+
def volumes
|
35
|
+
config.mount_points
|
36
|
+
end
|
37
|
+
def mount_points
|
38
|
+
config.mount_points.collect { |mp| mp.id+': '+mp.volid }
|
39
|
+
end
|
40
|
+
def memory
|
41
|
+
maxmem.to_i
|
42
|
+
end
|
43
|
+
def interfaces
|
44
|
+
config.interfaces
|
45
|
+
end
|
46
|
+
def vm_description
|
47
|
+
"Name=#{name}, vmid=#{vmid}"
|
48
|
+
end
|
49
|
+
def interfaces_attributes=(attrs); end
|
50
|
+
def volumes_attributes=(attrs); end
|
51
|
+
def config_attributes=(attrs); end
|
52
|
+
def templated?
|
53
|
+
volumes.any? { |volume| volume.templated? }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -17,17 +17,20 @@
|
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
url 'https://192.168.56.101:8006/api2/json'
|
27
|
-
user 'root@pam'
|
28
|
-
password 'proxmox01'
|
29
|
-
end
|
20
|
+
require 'fog/proxmox/helpers/disk_helper'
|
21
|
+
|
22
|
+
module FogExtensions
|
23
|
+
module Proxmox
|
24
|
+
module ContainerConfig
|
25
|
+
extend ActiveSupport::Concern
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
end
|
27
|
+
def rootfs_storage
|
28
|
+
mount_points.rootfs.storage
|
29
|
+
end
|
30
|
+
def rootfs_file
|
31
|
+
mount_points.rootfs.volid
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -21,10 +21,16 @@ module FogExtensions
|
|
21
21
|
module Proxmox
|
22
22
|
module Server
|
23
23
|
extend ActiveSupport::Concern
|
24
|
-
attr_accessor :image_id, :templated
|
24
|
+
attr_accessor :image_id, :templated, :ostemplate_storage, :ostemplate_file
|
25
25
|
def to_s
|
26
26
|
name
|
27
27
|
end
|
28
|
+
def identity
|
29
|
+
"#{type}_#{vmid}"
|
30
|
+
end
|
31
|
+
def container?
|
32
|
+
type == 'lxc'
|
33
|
+
end
|
28
34
|
def persisted?
|
29
35
|
!!identity && !!uptime
|
30
36
|
end
|
@@ -45,7 +51,7 @@ module FogExtensions
|
|
45
51
|
config.mac_addresses.first
|
46
52
|
end
|
47
53
|
def memory
|
48
|
-
|
54
|
+
maxmem.to_i
|
49
55
|
end
|
50
56
|
def state
|
51
57
|
qmpstatus
|