foreman_fog_proxmox 0.8.0 → 0.8.2
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 +11 -1
- data/Rakefile +3 -1
- data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +2 -2
- data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +2 -2
- data/app/helpers/node_dashboard_helper.rb +13 -14
- data/app/helpers/proxmox_compute_selectors_helper.rb +49 -50
- data/app/helpers/proxmox_container_helper.rb +42 -36
- data/app/helpers/proxmox_form_helper.rb +38 -40
- data/app/helpers/proxmox_server_helper.rb +39 -41
- data/app/helpers/proxmox_vm_helper.rb +21 -25
- data/app/models/concerns/fog_extensions/proxmox/disk.rb +8 -8
- data/app/models/concerns/fog_extensions/proxmox/interface.rb +8 -8
- data/app/models/concerns/fog_extensions/proxmox/node.rb +24 -22
- data/app/models/concerns/fog_extensions/proxmox/server.rb +71 -59
- data/app/models/concerns/fog_extensions/proxmox/server_config.rb +47 -39
- data/app/models/concerns/fog_extensions/proxmox/volume.rb +8 -8
- data/app/models/concerns/host_ext/proxmox/interfaces.rb +21 -13
- data/app/models/concerns/orchestration/proxmox/compute.rb +14 -10
- data/app/models/foreman_fog_proxmox/options_select.rb +14 -14
- data/app/models/foreman_fog_proxmox/proxmox.rb +30 -466
- data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +54 -0
- data/app/models/foreman_fog_proxmox/proxmox_connection.rb +67 -0
- data/app/models/foreman_fog_proxmox/proxmox_console.rb +41 -0
- data/app/models/foreman_fog_proxmox/proxmox_images.rb +53 -0
- data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +60 -0
- data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +49 -0
- data/app/models/foreman_fog_proxmox/proxmox_token_expiration.rb +30 -0
- data/app/models/foreman_fog_proxmox/proxmox_version.rb +36 -0
- data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +108 -0
- data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +162 -0
- data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +74 -0
- data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +85 -0
- data/app/overrides/compute_resources_vms/form/add_clone_to_new_vm_compute_detail.rb +7 -6
- data/app/overrides/compute_resources_vms/form/add_from_profile_to_compute_attributes_form.rb +13 -11
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_networks_form.rb +13 -11
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_nic_provider_specific_form.rb +8 -7
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_edit.rb +7 -6
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_new_volume.rb +7 -6
- data/app/overrides/compute_resources_vms/form/remove_new_vm_from_removable_layout.rb +7 -6
- data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +16 -16
- data/app/views/api/v2/compute_resources/proxmox.json.rabl +3 -1
- data/app/views/compute_resources/form/_proxmox.html.erb +3 -0
- data/app/views/compute_resources/show/_proxmox.html.erb +8 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_attributes_form.html.erb +5 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_form.html.erb +6 -1
- data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_hosts_compute_detail_form.html.erb +6 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_form.html.erb +6 -2
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_new_childs_form.html.erb +8 -2
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +6 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +15 -1
- data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +2 -2
- data/app/views/compute_resources_vms/form/proxmox/_general.html.erb +1 -1
- data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +6 -1
- data/app/views/compute_resources_vms/form/proxmox/container/_extended.html.erb +1 -1
- data/app/views/compute_resources_vms/form/proxmox/container/_volume_mp.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/_volume.html.erb +2 -2
- data/config/routes.rb +4 -4
- data/lib/foreman_fog_proxmox/engine.rb +14 -14
- data/lib/foreman_fog_proxmox/semver.rb +78 -78
- data/lib/foreman_fog_proxmox/value.rb +5 -3
- data/lib/foreman_fog_proxmox/version.rb +1 -1
- data/lib/tasks/foreman_fog_proxmox_tasks.rake +3 -13
- data/locale/en/foreman_fog_proxmox.edit.po +472 -0
- data/locale/en/foreman_fog_proxmox.po +48 -24
- data/locale/en/foreman_fog_proxmox.po.time_stamp +0 -0
- data/locale/foreman_fog_proxmox.pot +140 -102
- data/locale/fr/foreman_fog_proxmox.edit.po +472 -0
- data/locale/fr/foreman_fog_proxmox.po +52 -28
- data/locale/fr/foreman_fog_proxmox.po.time_stamp +0 -0
- data/locale/gemspec.rb +2 -0
- data/test/{unit/foreman_fog_proxmox/proxmox_test_helpers.rb → factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb} +4 -140
- data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +61 -0
- data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +134 -0
- data/test/factories/proxmox_factory.rb +15 -15
- data/test/functional/compute_resources_controller_test.rb +12 -10
- data/test/test_plugin_helper.rb +2 -0
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +178 -182
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +122 -126
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +180 -187
- data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +116 -0
- data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +71 -0
- data/test/unit/foreman_fog_proxmox/proxmox_test.rb +9 -479
- data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +82 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +207 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +92 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +324 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_test.rb +43 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb +71 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +63 -0
- data/test/unit/foreman_fog_proxmox/semver_test.rb +67 -53
- metadata +52 -14
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2019 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 ForemanFogProxmox
|
21
|
+
module ProxmoxComputeAttributes
|
22
|
+
def host_compute_attrs(host)
|
23
|
+
super.tap do |_attrs|
|
24
|
+
ostype = host.compute_attributes['config_attributes']['ostype']
|
25
|
+
type = host.compute_attributes['type']
|
26
|
+
case type
|
27
|
+
when 'lxc'
|
28
|
+
host.compute_attributes['config_attributes'].store('hostname', host.name)
|
29
|
+
when 'qemu'
|
30
|
+
unless compute_os_types(host).include?(ostype)
|
31
|
+
raise ::Foreman::Exception, format(_('Operating system family %<type>s is not consistent with %<ostype>s'), type: host.operatingsystem.type, ostype: ostype)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def not_config_key?(vm, key)
|
38
|
+
[:disks, :interfaces, :vmid, :node_id, :node, :type].include?(key) || !vm.config.respond_to?(key)
|
39
|
+
end
|
40
|
+
|
41
|
+
def vm_compute_attributes(vm)
|
42
|
+
vm_attrs = {}
|
43
|
+
if vm.respond_to?(:config)
|
44
|
+
vm_attrs = vm_attrs.merge(vmid: vm.identity, node_id: vm.node_id, type: vm.type)
|
45
|
+
vm_attrs[:volumes_attributes] = Hash[vm.config.disks.each_with_index.map { |disk, idx| [idx.to_s, disk.attributes] }] if vm.config.respond_to?(:disks)
|
46
|
+
vm_attrs[:interfaces_attributes] = Hash[vm.config.interfaces.each_with_index.map { |interface, idx| [idx.to_s, interface.attributes] }] if vm.config.respond_to?(:interfaces)
|
47
|
+
vm_attrs[:config_attributes] = vm.config.attributes.reject do |key, value|
|
48
|
+
not_config_key?(vm, key) || ForemanFogProxmox::Value.empty?(value.to_s) || Fog::Proxmox::DiskHelper.disk?(key.to_s) || Fog::Proxmox::NicHelper.nic?(key.to_s)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
vm_attrs
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2019 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'
|
21
|
+
|
22
|
+
module ForemanFogProxmox
|
23
|
+
module ProxmoxConnection
|
24
|
+
def connection_options
|
25
|
+
opts = http_proxy ? { proxy: http_proxy.full_url } : { disable_proxy: 1 }
|
26
|
+
opts.store(:ssl_verify_peer, ssl_verify_peer)
|
27
|
+
opts.store(:ssl_cert_store, certs_to_store) if Foreman::Cast.to_bool(ssl_verify_peer)
|
28
|
+
opts
|
29
|
+
end
|
30
|
+
|
31
|
+
def fog_credentials
|
32
|
+
credentials = { pve_url: url,
|
33
|
+
pve_username: user,
|
34
|
+
pve_password: password,
|
35
|
+
connection_options: connection_options }
|
36
|
+
ticket = Fog::Proxmox.credentials[:ticket]
|
37
|
+
credentials.store(:pve_ticket, ticket) if renew
|
38
|
+
credentials
|
39
|
+
end
|
40
|
+
|
41
|
+
def credentials_valid?
|
42
|
+
errors[:url].empty? && errors[:user].empty? && errors[:user].include?('@') && errors[:password].empty? && errors[:node_id].empty?
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_connection(options = {})
|
46
|
+
super
|
47
|
+
credentials_valid?
|
48
|
+
version_suitable?
|
49
|
+
rescue StandardError => e
|
50
|
+
errors[:base] << e.message
|
51
|
+
if e.message.include?('SSL')
|
52
|
+
errors[:ssl_certs] << e.message
|
53
|
+
else
|
54
|
+
errors[:url] << e.message
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def disconnect
|
59
|
+
client.terminate if @client
|
60
|
+
@client = nil
|
61
|
+
identity_client.terminate if @identity_client
|
62
|
+
@identity_client = nil
|
63
|
+
network_client.terminate if @network_client
|
64
|
+
@network_client = nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2019 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 ForemanFogProxmox
|
21
|
+
module ProxmoxConsole
|
22
|
+
def console(uuid)
|
23
|
+
vm = find_vm_by_uuid(uuid)
|
24
|
+
options = {}
|
25
|
+
if vm.container?
|
26
|
+
type_console = 'vnc'
|
27
|
+
options.store(:console, type_console)
|
28
|
+
else
|
29
|
+
type_console = vm.config.type_console
|
30
|
+
end
|
31
|
+
options.store(:websocket, 1) if type_console == 'vnc'
|
32
|
+
begin
|
33
|
+
vnc_console = vm.start_console(options)
|
34
|
+
WsProxy.start(:host => host, :host_port => vnc_console['port'], :password => vnc_console['ticket']).merge(:name => vm.name, :type => type_console)
|
35
|
+
rescue StandardError => e
|
36
|
+
logger.error(e)
|
37
|
+
raise ::Foreman::Exception, _('%<s>s console is not supported at this time') % type_console
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2019 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 ForemanFogProxmox
|
21
|
+
module ProxmoxImages
|
22
|
+
def image_exists?(image)
|
23
|
+
!find_vm_by_uuid(image).nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
def images_by_storage(storage_id, type = 'iso')
|
27
|
+
storage = node.storages.get storage_id if storage_id
|
28
|
+
storage.volumes.list_by_content_type(type).sort_by(&:volid) if storage
|
29
|
+
end
|
30
|
+
|
31
|
+
def available_images
|
32
|
+
templates.collect { |template| OpenStruct.new(id: template.vmid) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def templates
|
36
|
+
storage = storages.first
|
37
|
+
images = storage.volumes.list_by_content_type('images')
|
38
|
+
images.select(&:templated?)
|
39
|
+
end
|
40
|
+
|
41
|
+
def template(vmid)
|
42
|
+
find_vm_by_uuid(vmid)
|
43
|
+
end
|
44
|
+
|
45
|
+
def clone_from_image(image_id, args, vmid)
|
46
|
+
logger.debug(format(_('create_vm(): clone %<image_id>s in %<vmid>s'), image_id: image_id, vmid: vmid))
|
47
|
+
image = node.servers.get image_id
|
48
|
+
image.clone(vmid)
|
49
|
+
clone = node.servers.get vmid
|
50
|
+
clone.update(name: args[:name])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2019 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 ForemanFogProxmox
|
21
|
+
module ProxmoxInterfaces
|
22
|
+
def editable_network_interfaces?
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_nic_identifier(nic, index)
|
27
|
+
nic.identifier = format('net%<index>s', index: index) if nic.identifier.empty?
|
28
|
+
raise ::Foreman::Exception, _(format('Invalid identifier interface[%<index>s]. Must be net[n] with n integer >= 0', index: index)) unless Fog::Proxmox::NicHelper.nic?(nic.identifier)
|
29
|
+
end
|
30
|
+
|
31
|
+
def container?(host)
|
32
|
+
host.compute_attributes['type'] == 'lxc'
|
33
|
+
end
|
34
|
+
|
35
|
+
def container_nic_name_valid?(nic)
|
36
|
+
/^(eth)(\d+)$/.match?(nic.compute_attributes['name'])
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_container_interface_name(_host, nic, index)
|
40
|
+
nic.compute_attributes['name'] = format('eth%<index>s', index: index) if nic.compute_attributes['name'].empty?
|
41
|
+
raise ::Foreman::Exception, _(format('Invalid name interface[%<index>s]. Must be eth[n] with n integer >= 0', index: index)) unless container_nic_name_valid?(nic)
|
42
|
+
end
|
43
|
+
|
44
|
+
def host_interfaces_attrs(host)
|
45
|
+
host.interfaces.select(&:physical?).each.with_index.reduce({}) do |hash, (nic, index)|
|
46
|
+
set_nic_identifier(nic, index)
|
47
|
+
set_container_interface_name(host, nic, index) if container?(host)
|
48
|
+
nic_compute_attributes = nic.compute_attributes.merge(id: nic.identifier)
|
49
|
+
mac = nic.mac
|
50
|
+
mac ||= nic.attributes['mac']
|
51
|
+
nic_compute_attributes.store(:macaddr, mac) if mac.present?
|
52
|
+
interface_compute_attributes = host.compute_attributes['interfaces_attributes'] ? host.compute_attributes['interfaces_attributes'].select { |_k, v| v['id'] == nic.identifier } : {}
|
53
|
+
nic_compute_attributes.store(:_delete, interface_compute_attributes[interface_compute_attributes.keys[0]]['_delete']) unless interface_compute_attributes.empty?
|
54
|
+
nic_compute_attributes.store(:ip, nic.ip) if nic.ip.present?
|
55
|
+
nic_compute_attributes.store(:ip6, nic.ip6) if nic.ip6.present?
|
56
|
+
hash.merge(index.to_s => nic_compute_attributes)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2019 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 ForemanFogProxmox
|
21
|
+
module ProxmoxOperatingSystems
|
22
|
+
def compute_os_types(host)
|
23
|
+
os_linux_types_mapping(host).empty? ? os_windows_types_mapping(host) : os_linux_types_mapping(host)
|
24
|
+
end
|
25
|
+
|
26
|
+
def available_operating_systems
|
27
|
+
operating_systems = ['other', 'solaris']
|
28
|
+
operating_systems += available_linux_operating_systems
|
29
|
+
operating_systems += available_windows_operating_systems
|
30
|
+
operating_systems
|
31
|
+
end
|
32
|
+
|
33
|
+
def available_linux_operating_systems
|
34
|
+
['l24', 'l26', 'debian', 'ubuntu', 'centos', 'fedora', 'opensuse', 'archlinux', 'gentoo', 'alpine']
|
35
|
+
end
|
36
|
+
|
37
|
+
def available_windows_operating_systems
|
38
|
+
['wxp', 'w2k', 'w2k3', 'w2k8', 'wvista', 'win7', 'win8', 'win10']
|
39
|
+
end
|
40
|
+
|
41
|
+
def os_linux_types_mapping(host)
|
42
|
+
['Debian', 'Redhat', 'Suse', 'Altlinux', 'Archlinux', 'CoreOs', 'Gentoo'].include?(host.operatingsystem.type) ? available_linux_operating_systems : []
|
43
|
+
end
|
44
|
+
|
45
|
+
def os_windows_types_mapping(host)
|
46
|
+
['Windows'].include?(host.operatingsystem.type) ? available_windows_operating_systems : []
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2019 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 ForemanFogProxmox
|
21
|
+
module ProxmoxTokenExpiration
|
22
|
+
def token_expired?
|
23
|
+
Fog::Proxmox.credentials_has_expired?
|
24
|
+
end
|
25
|
+
|
26
|
+
def token_deadline
|
27
|
+
Fog::Proxmox.credentials[:deadline]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2019 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 'foreman_fog_proxmox/semver'
|
21
|
+
|
22
|
+
module ForemanFogProxmox
|
23
|
+
module ProxmoxVersion
|
24
|
+
def version_suitable?
|
25
|
+
logger.debug(format(_('Proxmox compute resource version is %<version>s'), version: version))
|
26
|
+
raise ::Foreman::Exception, format(_('Proxmox version %<version>s is not semver suitable'), version: version) unless ForemanFogProxmox::Semver.semver?(version)
|
27
|
+
|
28
|
+
ForemanFogProxmox::Semver.to_semver(version) >= ForemanFogProxmox::Semver.to_semver('5.3.0') && ForemanFogProxmox::Semver.to_semver(version) < ForemanFogProxmox::Semver.to_semver('5.5.0')
|
29
|
+
end
|
30
|
+
|
31
|
+
def version
|
32
|
+
v = identity_client.read_version
|
33
|
+
"#{v['version']}.#{v['release']}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2019 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 ForemanFogProxmox
|
21
|
+
module ProxmoxVmCommands
|
22
|
+
include ProxmoxVolumes
|
23
|
+
|
24
|
+
def start_on_boot(vm, args)
|
25
|
+
startonboot = args[:config_attributes][:onboot].blank? ? false : Foreman::Cast.to_bool(args[:config_attributes][:onboot])
|
26
|
+
vm.start if startonboot
|
27
|
+
vm
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_vm(args = {})
|
31
|
+
vmid = args[:vmid].to_i
|
32
|
+
type = args[:type]
|
33
|
+
raise ::Foreman::Exception, format(N_('invalid vmid=%<vmid>s'), vmid: vmid) unless node.servers.id_valid?(vmid)
|
34
|
+
|
35
|
+
image_id = args[:image_id]
|
36
|
+
if image_id
|
37
|
+
clone_from_image(image_id, args, vmid)
|
38
|
+
else
|
39
|
+
convert_sizes(args)
|
40
|
+
remove_deletes(args)
|
41
|
+
case type
|
42
|
+
when 'qemu'
|
43
|
+
vm = node.servers.create(parse_server_vm(args))
|
44
|
+
when 'lxc'
|
45
|
+
hash = parse_container_vm(args)
|
46
|
+
hash = hash.merge(vmid: vmid)
|
47
|
+
vm = node.containers.create(hash.reject { |key, _value| ['ostemplate_storage', 'ostemplate_file'].include? key })
|
48
|
+
end
|
49
|
+
start_on_boot(vm, args)
|
50
|
+
end
|
51
|
+
rescue StandardError => e
|
52
|
+
logger.warn(format(_('failed to create vm: %<e>s'), e: e))
|
53
|
+
destroy_vm vm.id if vm
|
54
|
+
raise e
|
55
|
+
end
|
56
|
+
|
57
|
+
def destroy_vm(uuid)
|
58
|
+
vm = find_vm_by_uuid(uuid)
|
59
|
+
vm.stop if vm.ready?
|
60
|
+
vm.destroy
|
61
|
+
rescue ActiveRecord::RecordNotFound
|
62
|
+
# if the VM does not exists, we don't really care.
|
63
|
+
true
|
64
|
+
end
|
65
|
+
|
66
|
+
def supports_update?
|
67
|
+
true
|
68
|
+
end
|
69
|
+
|
70
|
+
def update_required?(old_attrs, new_attrs)
|
71
|
+
return true if super(old_attrs, new_attrs)
|
72
|
+
|
73
|
+
new_attrs[:interfaces_attributes]&.each do |key, interface|
|
74
|
+
return true if (interface[:id].blank? || interface[:_delete] == '1') && key != 'new_interfaces' # ignore the template
|
75
|
+
end
|
76
|
+
|
77
|
+
new_attrs[:volumes_attributes]&.each do |key, volume|
|
78
|
+
return true if (volume[:id].blank? || volume[:_delete] == '1') && key != 'new_volumes' # ignore the template
|
79
|
+
end
|
80
|
+
|
81
|
+
false
|
82
|
+
end
|
83
|
+
|
84
|
+
def user_data_supported?
|
85
|
+
true
|
86
|
+
end
|
87
|
+
|
88
|
+
def save_vm(uuid, new_attributes)
|
89
|
+
vm = find_vm_by_uuid(uuid)
|
90
|
+
templated = new_attributes['templated']
|
91
|
+
if templated == '1' && !vm.templated?
|
92
|
+
vm.create_template
|
93
|
+
else
|
94
|
+
volumes_attributes = new_attributes['volumes_attributes']
|
95
|
+
volumes_attributes&.each_value { |volume_attributes| save_volume(vm, volume_attributes) }
|
96
|
+
parsed_attr = vm.container? ? parse_container_vm(new_attributes.merge(type: vm.type)) : parse_server_vm(new_attributes.merge(type: vm.type))
|
97
|
+
logger.debug("parsed_attr=#{parsed_attr}")
|
98
|
+
config_attributes = parsed_attr.reject { |key, _value| [:vmid, :templated, :ostemplate, :ostemplate_file, :ostemplate_storage, :volumes_attributes].include? key.to_sym }
|
99
|
+
config_attributes = config_attributes.reject { |_key, value| ForemanFogProxmox::Value.empty?(value) }
|
100
|
+
cdrom_attributes = parsed_attr.select { |_key, value| Fog::Proxmox::DiskHelper.cdrom?(value.to_s) }
|
101
|
+
config_attributes = config_attributes.reject { |key, _value| Fog::Proxmox::DiskHelper.disk?(key) }
|
102
|
+
vm.update(config_attributes.merge(cdrom_attributes))
|
103
|
+
start_on_boot(vm, new_attributes)
|
104
|
+
end
|
105
|
+
find_vm_by_uuid(uuid)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|