foreman_fog_proxmox 0.12.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 +7 -0
- data/LICENSE +619 -0
- data/README.md +290 -0
- data/Rakefile +49 -0
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +33 -0
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +187 -0
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_container.js +24 -0
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js +125 -0
- data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +41 -0
- data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +86 -0
- data/app/helpers/node_dashboard_helper.rb +35 -0
- data/app/helpers/proxmox_compute_selectors_helper.rb +184 -0
- data/app/helpers/proxmox_container_helper.rb +163 -0
- data/app/helpers/proxmox_form_helper.rb +70 -0
- data/app/helpers/proxmox_server_helper.rb +155 -0
- data/app/helpers/proxmox_vm_helper.rb +88 -0
- data/app/models/concerns/fog_extensions/proxmox/disk.rb +29 -0
- data/app/models/concerns/fog_extensions/proxmox/interface.rb +40 -0
- data/app/models/concerns/fog_extensions/proxmox/node.rb +41 -0
- data/app/models/concerns/fog_extensions/proxmox/server.rb +93 -0
- data/app/models/concerns/fog_extensions/proxmox/server_config.rb +71 -0
- data/app/models/concerns/fog_extensions/proxmox/volume.rb +29 -0
- data/app/models/concerns/host_ext/proxmox/interfaces.rb +52 -0
- data/app/models/concerns/orchestration/proxmox/compute.rb +42 -0
- data/app/models/foreman_fog_proxmox/options_select.rb +36 -0
- data/app/models/foreman_fog_proxmox/proxmox.rb +133 -0
- data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +67 -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 +61 -0
- data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +103 -0
- data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +49 -0
- data/app/models/foreman_fog_proxmox/proxmox_pools.rb +56 -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 +116 -0
- data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +178 -0
- data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +75 -0
- data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +94 -0
- data/app/models/foreman_fog_proxmox/vms.rb +37 -0
- data/app/overrides/compute_resources_vms/form/add_clone_to_new_vm_compute_detail.rb +25 -0
- data/app/overrides/compute_resources_vms/form/add_from_profile_to_compute_attributes_form.rb +34 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_node_to_new_form.rb +25 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_networks_form.rb +34 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_nic_provider_specific_form.rb +26 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_edit.rb +25 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_new_volume.rb +25 -0
- data/app/overrides/compute_resources_vms/form/remove_new_vm_from_removable_layout.rb +25 -0
- data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +37 -0
- data/app/views/api/v2/compute_resources/proxmox.json.rabl +3 -0
- data/app/views/compute_resources/form/_proxmox.html.erb +29 -0
- data/app/views/compute_resources/show/_proxmox.html.erb +37 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_attributes_form.html.erb +23 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_form.html.erb +23 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_hosts_compute_detail_form.html.erb +24 -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 +28 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_new_childs_form.html.erb +32 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +30 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +71 -0
- data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +39 -0
- data/app/views/compute_resources_vms/form/proxmox/_general.html.erb +39 -0
- data/app/views/compute_resources_vms/form/proxmox/_network.html.erb +19 -0
- data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +27 -0
- 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 +27 -0
- data/app/views/compute_resources_vms/form/proxmox/container/_network.html.erb +33 -0
- data/app/views/compute_resources_vms/form/proxmox/container/_volume_mp.html.erb +27 -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/server/_config.html.erb +60 -0
- data/app/views/compute_resources_vms/form/proxmox/server/_network.html.erb +30 -0
- data/app/views/compute_resources_vms/form/proxmox/server/_volume.html.erb +28 -0
- data/app/views/compute_resources_vms/index/_proxmox.html.erb +49 -0
- data/app/views/compute_resources_vms/show/_proxmox.html.erb +42 -0
- data/app/views/dashboard/_foreman_fog_proxmox_widget.erb +21 -0
- data/app/views/images/form/_proxmox.html.erb +21 -0
- data/config/routes.rb +30 -0
- data/lib/foreman_fog_proxmox.rb +23 -0
- data/lib/foreman_fog_proxmox/engine.rb +105 -0
- data/lib/foreman_fog_proxmox/semver.rb +102 -0
- data/lib/foreman_fog_proxmox/value.rb +26 -0
- data/lib/foreman_fog_proxmox/version.rb +22 -0
- data/lib/tasks/foreman_fog_proxmox_tasks.rake +37 -0
- data/locale/Makefile +60 -0
- data/locale/en/foreman_fog_proxmox.po +401 -0
- data/locale/foreman_fog_proxmox.pot +627 -0
- data/locale/fr/foreman_fog_proxmox.po +401 -0
- data/locale/gemspec.rb +4 -0
- data/test/factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb +137 -0
- data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +87 -0
- data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +134 -0
- data/test/factories/proxmox_factory.rb +79 -0
- data/test/functional/compute_resources_controller_test.rb +48 -0
- data/test/test_plugin_helper.rb +19 -0
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +204 -0
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +149 -0
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +216 -0
- data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +124 -0
- data/test/unit/foreman_fog_proxmox/proxmox_images_test.rb +52 -0
- data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +117 -0
- data/test/unit/foreman_fog_proxmox/proxmox_test.rb +58 -0
- data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +94 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +280 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +110 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +222 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_volumes_test.rb +308 -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 +68 -0
- data/test/unit/foreman_fog_proxmox/semver_test.rb +111 -0
- metadata +249 -0
@@ -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
|
+
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 interface_compute_attributes(interface_attributes)
|
42
|
+
vm_attrs = {}
|
43
|
+
vm_attrs.store(:mac, interface_attributes[:macaddr])
|
44
|
+
vm_attrs.store(:id, interface_attributes[:id])
|
45
|
+
vm_attrs.store(:identifier, interface_attributes[:id])
|
46
|
+
vm_attrs.store(:ip, interface_attributes[:ip])
|
47
|
+
vm_attrs.store(:ip6, interface_attributes[:ip6])
|
48
|
+
vm_attrs[:compute_attributes] = interface_attributes.reject { |k, _v| [:macaddr, :id].include?(k) }
|
49
|
+
vm_attrs
|
50
|
+
end
|
51
|
+
|
52
|
+
def vm_compute_attributes(vm)
|
53
|
+
vm_attrs = {}
|
54
|
+
if vm.respond_to?(:config)
|
55
|
+
vm_attrs = vm_attrs.merge(vmid: vm.identity, node_id: vm.node_id, type: vm.type)
|
56
|
+
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)
|
57
|
+
if vm.config.respond_to?(:interfaces)
|
58
|
+
vm_attrs[:interfaces_attributes] = Hash[vm.config.interfaces.each_with_index.map { |interface, idx| [idx.to_s, interface_compute_attributes(interface.attributes)] }]
|
59
|
+
end
|
60
|
+
vm_attrs[:config_attributes] = vm.config.attributes.reject do |key, value|
|
61
|
+
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)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
vm_attrs
|
65
|
+
end
|
66
|
+
end
|
67
|
+
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 = super
|
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,61 @@
|
|
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(node_id, storage_id, type = 'iso')
|
27
|
+
node = client.nodes.get node_id
|
28
|
+
node ||= default_node
|
29
|
+
storage = node.storages.get storage_id if storage_id
|
30
|
+
storage.volumes.list_by_content_type(type).sort_by(&:volid) if storage
|
31
|
+
end
|
32
|
+
|
33
|
+
def available_images
|
34
|
+
templates.collect { |template| OpenStruct.new(id: template.vmid.to_s) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def templates
|
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?)
|
44
|
+
end
|
45
|
+
|
46
|
+
def template(vmid)
|
47
|
+
find_vm_by_uuid(vmid)
|
48
|
+
end
|
49
|
+
|
50
|
+
def clone_from_image(image_id, args, vmid)
|
51
|
+
logger.debug(format(_('create_vm(): clone %<image_id>s in %<vmid>s'), image_id: image_id, vmid: vmid))
|
52
|
+
image = find_vm_by_uuid(image_id)
|
53
|
+
image.clone(vmid)
|
54
|
+
clone = find_vm_by_uuid(vmid)
|
55
|
+
options = {}
|
56
|
+
options.store(:name, args[:name]) unless clone.container?
|
57
|
+
options.store(:hostname, args[:name]) if clone.container?
|
58
|
+
clone.update(options)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,103 @@
|
|
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/helpers/ip_helper'
|
21
|
+
|
22
|
+
module ForemanFogProxmox
|
23
|
+
module ProxmoxInterfaces
|
24
|
+
def editable_network_interfaces?
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_nic_identifier(nic, index)
|
29
|
+
nic.identifier = format('net%<index>s', index: index) if nic.identifier.empty?
|
30
|
+
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)
|
31
|
+
end
|
32
|
+
|
33
|
+
def container?(host)
|
34
|
+
host.compute_attributes['type'] == 'lxc'
|
35
|
+
end
|
36
|
+
|
37
|
+
def container_nic_name_valid?(nic)
|
38
|
+
/^(eth)(\d+)$/.match?(nic.compute_attributes['name'])
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_container_interface_name(_host, nic, index)
|
42
|
+
nic.compute_attributes['name'] = format('eth%<index>s', index: index) if nic.compute_attributes['name'].empty?
|
43
|
+
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)
|
44
|
+
end
|
45
|
+
|
46
|
+
def cidr_prefix(nic_compute_attributes, v6 = false)
|
47
|
+
attr_name = 'cidrv'
|
48
|
+
attr_name += v6 ? '6' : '4'
|
49
|
+
attr_name += '_prefix'
|
50
|
+
nic_compute_attributes[attr_name] if nic_compute_attributes[attr_name].presence
|
51
|
+
end
|
52
|
+
|
53
|
+
def set_ip(host, nic, nic_compute_attributes, v6 = false)
|
54
|
+
return 'dhcp' if dhcp?(nic_compute_attributes, v6)
|
55
|
+
|
56
|
+
ip = v6 ? nic.ip6 : nic.ip
|
57
|
+
return ip unless container?(host) || cidr_prefix(nic_compute_attributes, v6)
|
58
|
+
|
59
|
+
valid = v6 ? Fog::Proxmox::IpHelper.cidr6_prefix?(cidr_prefix(nic_compute_attributes, v6)) : Fog::Proxmox::IpHelper.cidr_prefix?(cidr_prefix(nic_compute_attributes, v6))
|
60
|
+
ipv = v6 ? 'IPv6' : 'IPv4'
|
61
|
+
max = v6 ? 128 : 32
|
62
|
+
unless valid
|
63
|
+
raise ::Foreman::Exception, _(format('Invalid Interface Proxmox CIDR %<ip>s. If %<ip>s is not empty, Proxmox CIDR prefix must be an integer between 0 and %<max>i.', ip: ipv, max: max))
|
64
|
+
end
|
65
|
+
|
66
|
+
v6 ? Fog::Proxmox::IpHelper.to_cidr6(nic.ip6, cidr_prefix(nic_compute_attributes, v6)) : Fog::Proxmox::IpHelper.to_cidr(nic.ip, cidr_prefix(nic_compute_attributes, v6))
|
67
|
+
end
|
68
|
+
|
69
|
+
def set_gw(nic_compute_attributes, v6 = false)
|
70
|
+
attr_name = 'gwv'
|
71
|
+
attr_name += v6 ? '6' : '4'
|
72
|
+
nic_compute_attributes[attr_name] if nic_compute_attributes[attr_name].presence
|
73
|
+
end
|
74
|
+
|
75
|
+
def to_boolean(value)
|
76
|
+
[1, true, '1', 'true'].include?(value)
|
77
|
+
end
|
78
|
+
|
79
|
+
def dhcp?(nic_compute_attributes, v6 = false)
|
80
|
+
attr_name = 'dhcpv'
|
81
|
+
attr_name += v6 ? '6' : '4'
|
82
|
+
to_boolean(nic_compute_attributes[attr_name]) if nic_compute_attributes[attr_name].present?
|
83
|
+
end
|
84
|
+
|
85
|
+
def host_interfaces_attrs(host)
|
86
|
+
host.interfaces.select(&:physical?).each.with_index.reduce({}) do |hash, (nic, index)|
|
87
|
+
set_nic_identifier(nic, index)
|
88
|
+
set_container_interface_name(host, nic, index) if container?(host)
|
89
|
+
nic_compute_attributes = nic.compute_attributes.merge(id: nic.identifier)
|
90
|
+
mac = nic.mac
|
91
|
+
mac ||= nic.attributes['mac']
|
92
|
+
nic_compute_attributes.store(:macaddr, mac) if mac.present?
|
93
|
+
interface_compute_attributes = host.compute_attributes['interfaces_attributes'] ? host.compute_attributes['interfaces_attributes'].select { |_k, v| v['id'] == nic.identifier } : {}
|
94
|
+
nic_compute_attributes.store(:_delete, interface_compute_attributes[interface_compute_attributes.keys[0]]['_delete']) unless interface_compute_attributes.empty?
|
95
|
+
nic_compute_attributes.store(:ip, set_ip(host, nic, nic_compute_attributes))
|
96
|
+
nic_compute_attributes.store(:gw, set_gw(nic_compute_attributes))
|
97
|
+
nic_compute_attributes.store(:ip6, set_ip(host, nic, nic_compute_attributes, true))
|
98
|
+
nic_compute_attributes.store(:gw6, set_gw(nic_compute_attributes, true))
|
99
|
+
hash.merge(index.to_s => nic_compute_attributes)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
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,56 @@
|
|
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 ProxmoxPools
|
22
|
+
def pools
|
23
|
+
pools = identity_client.pools.all
|
24
|
+
pools.sort_by(&:poolid)
|
25
|
+
end
|
26
|
+
|
27
|
+
def pool_owner(vm)
|
28
|
+
logger.debug(format(_('pool_owner(%<vmid>s)'), vmid: vm&.vmid))
|
29
|
+
pools_owners = pools.select { |pool| pool.has_server?(vm&.vmid) }
|
30
|
+
pool = pools_owners.first
|
31
|
+
logger.debug(format(_('found vm: %<vmid>s member of pool: %<poolid>s'), vmid: vm&.vmid, poolid: pool&.poolid))
|
32
|
+
vm&.config&.pool = pool&.poolid
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_vm_to_pool(poolid, vmid)
|
36
|
+
logger.debug(format(_('add_vm_to_pool(%<poolid>s, %<vmid>s)'), poolid: poolid, vmid: vmid))
|
37
|
+
pool = identity_client.pools.get poolid
|
38
|
+
pool&.add_server vmid
|
39
|
+
end
|
40
|
+
|
41
|
+
def remove_vm_from_pool(poolid, vmid)
|
42
|
+
logger.debug(format(_('remove_vm_from_pool(%<poolid>s, %<vmid>s)'), poolid: poolid, vmid: vmid))
|
43
|
+
pool = identity_client.pools.get poolid
|
44
|
+
pool&.remove_server vmid
|
45
|
+
end
|
46
|
+
|
47
|
+
def update_pool(vm, poolid)
|
48
|
+
pool_owner(vm)
|
49
|
+
vm_pool = vm.config.pool || ''
|
50
|
+
return if vm_pool.eql?(poolid)
|
51
|
+
|
52
|
+
remove_vm_from_pool(vm_pool, vm.vmid)
|
53
|
+
add_vm_to_pool(poolid, vm.vmid)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|