foreman_fog_proxmox 0.12.2 → 0.13.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -5
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +36 -2
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +134 -60
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js +2 -50
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume.js +39 -0
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume_cdrom.js +63 -0
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume_cloudinit.js +25 -0
- data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +1 -1
- data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +23 -25
- data/app/helpers/proxmox_compute_controllers_helper.rb +39 -0
- data/app/helpers/proxmox_compute_resources_helper.rb +49 -0
- data/app/helpers/proxmox_compute_selectors_helper.rb +6 -44
- data/app/helpers/proxmox_form_helper.rb +12 -4
- data/app/{models/concerns/fog_extensions/proxmox/volume.rb → helpers/proxmox_storages_helper.rb} +5 -8
- data/app/helpers/proxmox_vm_cdrom_helper.rb +35 -0
- data/app/helpers/proxmox_vm_cloudinit_helper.rb +43 -0
- data/app/helpers/proxmox_vm_config_helper.rb +160 -0
- data/app/helpers/proxmox_vm_helper.rb +24 -62
- data/app/helpers/proxmox_vm_interfaces_helper.rb +85 -0
- data/app/helpers/proxmox_vm_os_template_helper.rb +47 -0
- data/app/{models/foreman_fog_proxmox/proxmox_token_expiration.rb → helpers/proxmox_vm_uuid_helper.rb} +14 -10
- data/app/helpers/proxmox_vm_volumes_helper.rb +105 -0
- data/app/models/concerns/fog_extensions/proxmox/disk.rb +17 -2
- data/app/models/concerns/fog_extensions/proxmox/interface.rb +19 -4
- data/app/models/concerns/fog_extensions/proxmox/server.rb +12 -3
- data/app/models/concerns/fog_extensions/proxmox/server_config.rb +8 -30
- data/app/models/concerns/host_ext/proxmox/interfaces.rb +7 -2
- data/app/models/concerns/orchestration/proxmox/compute.rb +49 -0
- data/app/models/foreman_fog_proxmox/proxmox.rb +58 -15
- data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +14 -18
- data/app/models/foreman_fog_proxmox/proxmox_connection.rb +14 -9
- data/app/models/foreman_fog_proxmox/proxmox_images.rb +2 -1
- data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +53 -28
- data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +1 -1
- data/app/models/foreman_fog_proxmox/proxmox_version.rb +7 -2
- data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +19 -31
- data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +108 -94
- data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +9 -6
- data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +79 -22
- data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +6 -2
- data/app/views/api/v2/compute_resources/proxmox.json.rabl +1 -1
- data/app/views/compute_resources/form/_proxmox.html.erb +23 -10
- data/app/views/compute_resources/show/_proxmox.html.erb +6 -6
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +3 -1
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +46 -29
- data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +3 -3
- data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +2 -1
- data/app/views/compute_resources_vms/form/proxmox/container/_network.html.erb +8 -7
- data/app/views/compute_resources_vms/form/proxmox/server/_advanced.html.erb +0 -2
- data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +15 -14
- data/app/views/compute_resources_vms/form/proxmox/server/_network.html.erb +2 -2
- data/app/views/compute_resources_vms/form/proxmox/server/_volume_cdrom.html.erb +34 -0
- data/app/views/compute_resources_vms/form/proxmox/server/_volume_cloud_init.html.erb +29 -0
- data/app/views/compute_resources_vms/form/proxmox/server/{_volume.html.erb → _volume_hard_disk.html.erb} +7 -3
- data/app/views/compute_resources_vms/show/_proxmox.html.erb +2 -0
- data/config/routes.rb +7 -7
- data/db/migrate/20210312105013_update_proxmox_uuid_host.rb +29 -0
- data/lib/foreman_fog_proxmox/engine.rb +15 -10
- data/lib/foreman_fog_proxmox/hash_collection.rb +69 -0
- data/lib/foreman_fog_proxmox/version.rb +1 -1
- data/lib/tasks/foreman_fog_proxmox_tasks.rake +0 -3
- data/test/factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb +20 -8
- data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +5 -5
- data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +17 -7
- data/test/factories/proxmox_factory.rb +4 -4
- data/test/functional/compute_resources_controller_test.rb +4 -4
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +53 -32
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +56 -31
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +22 -20
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_uuid_helper_test.rb +38 -0
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_volumes_helper_test.rb +50 -0
- data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +10 -11
- data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +38 -10
- data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +10 -10
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +34 -24
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +8 -8
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cdrom_test.rb +181 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cloudinit_test.rb +131 -0
- data/test/unit/foreman_fog_proxmox/{proxmox_vm_commands_server_update_volumes_test.rb → proxmox_vm_commands_server_update_hard_disk_test.rb} +45 -19
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +21 -21
- data/test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb +3 -3
- data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +3 -3
- metadata +44 -23
- data/app/helpers/proxmox_container_helper.rb +0 -163
- data/app/helpers/proxmox_server_helper.rb +0 -155
@@ -18,19 +18,19 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
|
|
18
18
|
<%= javascript_include_tag 'foreman_fog_proxmox/proxmox_vm_server', "data-turbolinks-track" => true %>
|
19
19
|
|
20
20
|
<% server = type == 'qemu' %>
|
21
|
+
<% logger.debug("_config.html.erb server_config=#{f.object.inspect}") %>
|
21
22
|
|
22
23
|
<%= field_set_tag n_("Main option", "Main options", 2), :id => "server_config_options", :class => 'hide', :disabled => !server do %>
|
23
24
|
<%= textarea_f f, :description, :label => _('Description'), :label_size => "col-md-2" %>
|
24
|
-
<%= text_f f, :boot, :label => _('Boot device order'), :label_size => "col-md-2", :label_help => _('
|
25
|
+
<%= text_f f, :boot, :label => _('Boot device order'), :label_size => "col-md-2", :label_help => _('Order your devices, e.g. order=net0;ide2;scsi0. Default empty (any)') %>
|
25
26
|
<%= checkbox_f f, :onboot, :label => _('Start at boot') %>
|
26
27
|
<%= checkbox_f f, :agent, :label => _('Qemu Agent') %>
|
27
28
|
<%= checkbox_f f, :kvm, :label => _('KVM'), :label_help => _('Enable/disable KVM hardware virtualization') %>
|
28
|
-
<%= select_f f, :keyboard, proxmox_keyboards_map, :id, :name, { }, :label => _('Keyboard'), :label_size => "col-md-2" %>
|
29
29
|
<%= select_f f, :vga, proxmox_vgas_map, :id, :name, { :include_blank => true }, :label => _('VGA'), :label_size => "col-md-2" %>
|
30
30
|
<%= select_f f, :scsihw, proxmox_scsi_controllers_map, :id, :name, { }, :label => _('SCSI Controller'), :label_size => "col-md-2" %>
|
31
31
|
<%= select_f f, :bios, proxmox_bios_map, :id, :name, { }, :label => _('BIOS'), :label_size => "col-md-2" %>
|
32
32
|
<% end %>
|
33
|
-
<%= field_set_tag _("
|
33
|
+
<%= field_set_tag _("CPUs"), :id => "server_config_cpu", :class => 'hide', :disabled => !server do %>
|
34
34
|
<%= select_f f, :cpu_type, proxmox_cpus_map, :id, :name, { }, :label => _('Type'), :label_size => "col-md-2" %>
|
35
35
|
<%= counter_f f, :sockets, :class => "input-mini", :label => _('Sockets'), :label_size => "col-md-2" %>
|
36
36
|
<%= counter_f f, :cores, :class => "input-mini", :label => _('Cores'), :label_size => "col-md-2" %>
|
@@ -38,23 +38,24 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
|
|
38
38
|
<%= counter_f f, :cpulimit, :class => "input-mini", :label => _('CPU limit'), :label_size => "col-md-2" %>
|
39
39
|
<%= counter_f f, :cpuunits, :class => "input-mini", :label => _('CPU units'), :label_size => "col-md-2" %>
|
40
40
|
<%= checkbox_f f, :numa, :label => _('Enable NUMA') %>
|
41
|
-
<%=
|
42
|
-
|
41
|
+
<%= field_set_tag _("CPU Flags"), :id => "server_config_cpu_flags" do %>
|
42
|
+
<% Fog::Proxmox::CpuHelper.flags.each do |flag_key, flag_value| %>
|
43
|
+
<%= select_f f, flag_key, proxmox_cpu_flags_map, :id, :name, { }, :label => _(flag_value) %>
|
44
|
+
<% end %>
|
45
|
+
<% end %>
|
43
46
|
<% end %>
|
44
47
|
<%= field_set_tag _("Memory"), :id => "server_config_memory", :class => 'hide', :disabled => !server do %>
|
45
48
|
<%= byte_size_f f, :memory, :class => "input-mini", :label => _('Memory'), :label_size => "col-md-2" %>
|
46
49
|
<%= byte_size_f f, :balloon, :class => "input-mini", :label => _('Minimum memory'), :label_size => "col-md-2" %>
|
47
50
|
<%= counter_f f, :shares, :class => "input-mini", :label => _('Shares'), :label_size => "col-md-2" %>
|
48
51
|
<% end %>
|
49
|
-
<%= field_set_tag _("CD-ROM"), :id => "server_config_cdrom", :class => 'hide', :disabled => !server do %>
|
50
|
-
<%= radio_button_f f, :cdrom, :value => 'none', :text => _('None'), :onclick => 'cdromSelected(this)' %>
|
51
|
-
<%= radio_button_f f, :cdrom, :value => 'cdrom' , :text => _('Physical'), :onclick => 'cdromSelected(this)' %>
|
52
|
-
<%= radio_button_f f, :cdrom, :value => 'image' , :text => _('Image'), :onclick => 'cdromSelected(this)' %>
|
53
|
-
<div id='cdrom_image_form' class='<%= 'hide' if %[none cdrom].include? f.object.cdrom %>'>
|
54
|
-
<%= select_f f, :cdrom_storage, compute_resource.storages(node_id,'iso'), :storage, :storage, { :include_blank => true }, :label => _('Storage'), :label_size => "col-md-2", :onchange => 'storageIsoSelected(this)' %>
|
55
|
-
<%= select_f f, :cdrom_iso, compute_resource.images_by_storage(f.object.cdrom_storage, 'iso'), :volid, :volid, { :include_blank => true }, :label => _('Image ISO'), :label_size => "col-md-2" %>
|
56
|
-
</div>
|
57
|
-
<% end %>
|
58
52
|
<%= field_set_tag _("Operating System"), :id => "server_config_os", :class => 'hide', :disabled => !server do %>
|
59
53
|
<%= select_f f, :ostype, proxmox_operating_systems_map, :id, :name, { :include_blank => true }, :label => _('OS type'), :label_size => "col-md-2" %>
|
54
|
+
<% end %>
|
55
|
+
<%= field_set_tag _("Cloud-init"), :id => "server_config_cloud_init", :class => ('hide' unless cloudinit), :disabled => (!cloudinit) do %>
|
56
|
+
<%= text_f f, :ciuser, :label => _('User'), :label_size => "col-md-2" %>
|
57
|
+
<%= text_f f, :cipassword, :label => _('Password'), :label_size => "col-md-2" %>
|
58
|
+
<%= text_f f, :searchdomain, :label => _('DNS domain'), :label_size => "col-md-2" %>
|
59
|
+
<%= text_f f, :nameserver, :label => _('DNS servers'), :label_size => "col-md-2" %>
|
60
|
+
<%= textarea_f f, :sshkeys, :label => _("SSH public key"), :size => "col-md-4" %>
|
60
61
|
<% end %>
|
@@ -25,6 +25,6 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
|
|
25
25
|
<%= counter_f f, :tag, :class => "input-mini", :label => _('VLAN tag'), :label_size => "col-md-2" %>
|
26
26
|
<%= counter_f f, :rate, :class => "input-mini", :label => _('Rate limit'), :label_size => "col-md-2" %>
|
27
27
|
<%= counter_f f, :queues, :class => "input-mini", :label => _('Multiqueue'), :label_size => "col-md-2" %>
|
28
|
-
<%= checkbox_f f, :firewall, :label => _('Firewall') %>
|
29
|
-
<%= checkbox_f f, :link_down, :label => _('Disconnect') %>
|
28
|
+
<%= checkbox_f f, :firewall, { :label => _('Firewall') }, '1', '0' %>
|
29
|
+
<%= checkbox_f f, :link_down, { :label => _('Disconnect') }, '1', '0' %>
|
30
30
|
<% end %>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<%# Copyright 2018 Tristan Robert
|
2
|
+
|
3
|
+
This file is part of ForemanFogProxmox.
|
4
|
+
|
5
|
+
ForemanFogProxmox is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
|
10
|
+
ForemanFogProxmox is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU General Public License
|
16
|
+
along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
|
17
|
+
|
18
|
+
<%= javascript_include_tag 'foreman_fog_proxmox/proxmox_volume_cdrom', "data-turbolinks-track" => true %>
|
19
|
+
|
20
|
+
<% cdrom = f.object.cdrom? %>
|
21
|
+
<% new_volume = f.object.volid.nil? %>
|
22
|
+
|
23
|
+
<%= field_set_tag _("CD-ROM"), :id => "server_volume_cdrom_#{f.index}", :class => ('hide' unless cdrom), :disabled => !cdrom do %>
|
24
|
+
<%= field_set_tag _("Media"), :id => "cdrom_media_form_#{f.index}" do %>
|
25
|
+
<%= f.hidden_field :storage_type %>
|
26
|
+
<%= radio_button_f f, :cdrom, :value => 'none', :text => _('None'), :onclick => 'cdromSelected(this)' %>
|
27
|
+
<%= radio_button_f f, :cdrom, :value => 'cdrom' , :text => _('Physical'), :onclick => 'cdromSelected(this)' %>
|
28
|
+
<%= radio_button_f f, :cdrom, :value => 'image' , :text => _('Image'), :onclick => 'cdromSelected(this)' %>
|
29
|
+
<% end %>
|
30
|
+
<%= field_set_tag(_("Image"), :id => "cdrom_image_form_#{f.index}", :class => ('hide' unless %[image].include? f.object.cdrom), :disabled => (%[cdrom none].include? f.object.cdrom)) do %>
|
31
|
+
<%= select_f f, :storage, compute_resource.storages(node_id,'iso'), :storage, :storage, { :include_blank => true }, :label => _('Storage'), :label_size => "col-md-2", :onchange => 'storageIsoSelected(this)' %>
|
32
|
+
<%= select_f f, :volid, compute_resource.images_by_storage(node_id, f.object.storage, 'iso'), :volid, :volid, { :include_blank => true }, :label => _('Image ISO'), :label_size => "col-md-2" %>
|
33
|
+
<% end %>
|
34
|
+
<% end %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<%# Copyright 2018 Tristan Robert
|
2
|
+
|
3
|
+
This file is part of ForemanFogProxmox.
|
4
|
+
|
5
|
+
ForemanFogProxmox is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
|
10
|
+
ForemanFogProxmox is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU General Public License
|
16
|
+
along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
|
17
|
+
|
18
|
+
<%= javascript_include_tag 'foreman_fog_proxmox/proxmox_volume_cloudinit', "data-turbolinks-track" => true %>
|
19
|
+
|
20
|
+
<% cloud_init = f.object.cloud_init? %>
|
21
|
+
<% new_volume = f.object.volid.nil? %>
|
22
|
+
|
23
|
+
<%= field_set_tag _("Cloud-init"), :id => "server_volume_cloud_init_#{f.index}", :class => ('hide' unless cloud_init), :disabled => !cloud_init do %>
|
24
|
+
<%= f.hidden_field :volid if !new_volume %>
|
25
|
+
<%= f.hidden_field :storage_type %>
|
26
|
+
<%= select_f f, :storage, compute_resource.storages(node_id), :storage, :storage, { :include_blank => true }, :label => _('Storage'), :label_size => "col-md-2", :disabled => !new_volume %>
|
27
|
+
<%= select_f f, :controller, proxmox_controllers_cloudinit_map, :id, :name, { :include_blank => true }, :label => _('Controller'), :label_size => "col-md-2", :onchange => 'cloudinitControllerSelected(this)', :disabled => !new_volume %>
|
28
|
+
<%= text_f f, :device, :label => _('Device'), :label_size => "col-md-2", :'data-min' => 0, :'data-soft-max' => proxmox_max_device(f.object.controller), :disabled => !new_volume %>
|
29
|
+
<% end %>
|
@@ -15,11 +15,15 @@ GNU General Public License for more details.
|
|
15
15
|
You should have received a copy of the GNU General Public License
|
16
16
|
along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
|
17
17
|
|
18
|
-
<%
|
18
|
+
<% hard_disk = f.object.hard_disk? %>
|
19
|
+
<% logger.debug("_volume_hard_disk.html f.object=#{f.object.inspect}") %>
|
20
|
+
<% logger.debug("_volume_hard_disk.html f.object.hard_disk?=#{f.object.hard_disk?}") %>
|
21
|
+
<% logger.debug("_volume_hard_disk.html f.object.storage_type=#{f.object.storage_type}") %>
|
19
22
|
<% new_volume = f.object.volid.nil? %>
|
20
23
|
|
21
|
-
<%= field_set_tag _(
|
22
|
-
<%= f.hidden_field :volid if !
|
24
|
+
<%= field_set_tag _('Hard disk'), :id => "server_volume_hard_disk_#{f.index}", :class => ('hide' unless hard_disk), :disabled => !hard_disk do %>
|
25
|
+
<%= f.hidden_field :volid if !new_volume %>
|
26
|
+
<%= f.hidden_field :storage_type %>
|
23
27
|
<%= select_f f, :storage, compute_resource.storages(node_id), :storage, :storage, { }, :label => _('Storage'), :label_size => "col-md-2" %>
|
24
28
|
<%= select_f f, :controller, proxmox_controllers_map, :id, :name, { }, :label => _('Controller'), :label_size => "col-md-2", :disabled => !new_volume, :onchange => 'controllerSelected(this)' %>
|
25
29
|
<%= text_f f, :device, :label => _('Device'), :label_size => "col-md-2", :disabled => !new_volume, :'data-min' => 0, :'data-soft-max' => proxmox_max_device(f.object.controller), :onchange => 'deviceSelected(this)' %>
|
data/config/routes.rb
CHANGED
@@ -19,12 +19,12 @@
|
|
19
19
|
|
20
20
|
Rails.application.routes.draw do
|
21
21
|
namespace :foreman_fog_proxmox do
|
22
|
-
match 'isos/:node_id/:storage', :to => 'compute_resources#
|
23
|
-
match 'ostemplates/:node_id/:storage', :to => 'compute_resources#
|
24
|
-
match 'isos/:node_id', :to => 'compute_resources#
|
25
|
-
match 'ostemplates/:node_id', :to => 'compute_resources#
|
26
|
-
match 'storages/:node_id', :to => 'compute_resources#
|
27
|
-
match 'isostorages/:node_id', :to => 'compute_resources#
|
28
|
-
match 'bridges/:node_id', :to => 'compute_resources#
|
22
|
+
match 'isos/:compute_resource_id/:node_id/:storage', :to => 'compute_resources#isos_by_id_and_node_and_storage', :via => 'get'
|
23
|
+
match 'ostemplates/:compute_resource_id/:node_id/:storage', :to => 'compute_resources#ostemplates_by_id_and_node_and_storage', :via => 'get'
|
24
|
+
match 'isos/:compute_resource_id/:node_id', :to => 'compute_resources#isos_by_id_and_node', :via => 'get'
|
25
|
+
match 'ostemplates/:compute_resource_id/:node_id', :to => 'compute_resources#ostemplates_by_id_and_node', :via => 'get'
|
26
|
+
match 'storages/:compute_resource_id/:node_id', :to => 'compute_resources#storages_by_id_and_node', :via => 'get'
|
27
|
+
match 'isostorages/:compute_resource_id/:node_id', :to => 'compute_resources#iso_storages_by_id_and_node', :via => 'get'
|
28
|
+
match 'bridges/:compute_resource_id/:node_id', :to => 'compute_resources#bridges_by_id_and_node', :via => 'get'
|
29
29
|
end
|
30
30
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
include ProxmoxVmUuidHelper
|
2
|
+
class UpdateProxmoxUuidHost < ActiveRecord::Migration[6.0]
|
3
|
+
|
4
|
+
def up
|
5
|
+
execute(sql(:concat))
|
6
|
+
end
|
7
|
+
|
8
|
+
def down
|
9
|
+
execute(sql(:substring))
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def concat
|
15
|
+
"concat(h.compute_resource_id, '_', h.uuid) "
|
16
|
+
end
|
17
|
+
|
18
|
+
def substring
|
19
|
+
"substring(h.uuid, position('_' in h.uuid) + 1, length(h.uuid)) "
|
20
|
+
end
|
21
|
+
|
22
|
+
def sql(func_type)
|
23
|
+
sql = 'update hosts h set uuid = '
|
24
|
+
sql += send(func_type)
|
25
|
+
sql += 'from compute_resources cr '
|
26
|
+
sql += "where cr.id = h.compute_resource_id and cr.type = 'ForemanFogProxmox::Proxmox';"
|
27
|
+
sql
|
28
|
+
end
|
29
|
+
end
|
@@ -45,8 +45,14 @@ module ForemanFogProxmox
|
|
45
45
|
# add dashboard widget
|
46
46
|
widget 'foreman_fog_proxmox_widget', name: N_('Foreman Fog Proxmox widget'), sizex: 8, sizey: 1
|
47
47
|
security_block :foreman_fog_proxmox do
|
48
|
-
permission :view_compute_resource, { :
|
49
|
-
|
48
|
+
permission :view_compute_resource, { :compute_resources =>
|
49
|
+
[:ostemplates_by_id_and_node_and_storage,
|
50
|
+
:isos_by_id_and_node_and_storage,
|
51
|
+
:ostemplates_by_id_and_node,
|
52
|
+
:isos_by_id_and_node,
|
53
|
+
:storages_by_id_and_node,
|
54
|
+
:iso_storages_by_id_and_node,
|
55
|
+
:bridges_by_id_and_node] }
|
50
56
|
end
|
51
57
|
end
|
52
58
|
end
|
@@ -84,18 +90,17 @@ module ForemanFogProxmox
|
|
84
90
|
end
|
85
91
|
|
86
92
|
config.to_prepare do
|
87
|
-
require 'fog/compute/
|
88
|
-
require 'fog/compute/
|
89
|
-
require 'fog/compute/
|
90
|
-
require 'fog/compute/
|
91
|
-
require 'fog/compute/
|
92
|
-
require 'fog/compute/
|
93
|
+
require 'fog/proxmox/compute/models/server'
|
94
|
+
require 'fog/proxmox/compute/models/server_config'
|
95
|
+
require 'fog/proxmox/compute/models/disk'
|
96
|
+
require 'fog/proxmox/compute/models/interface'
|
97
|
+
require 'fog/proxmox/compute/models/volume'
|
98
|
+
require 'fog/proxmox/compute/models/node'
|
93
99
|
|
94
100
|
Fog::Proxmox::Compute::Server.include FogExtensions::Proxmox::Server
|
95
101
|
Fog::Proxmox::Compute::ServerConfig.include FogExtensions::Proxmox::ServerConfig
|
96
|
-
Fog::Proxmox::Compute::Disk.include FogExtensions::Proxmox::Disk
|
97
102
|
Fog::Proxmox::Compute::Interface.include FogExtensions::Proxmox::Interface
|
98
|
-
Fog::Proxmox::Compute::
|
103
|
+
Fog::Proxmox::Compute::Disk.include FogExtensions::Proxmox::Disk
|
99
104
|
::ComputeResourcesController.include ForemanFogProxmox::Controller::Parameters::ComputeResource
|
100
105
|
Fog::Proxmox::Compute::Node.include FogExtensions::Proxmox::Node
|
101
106
|
::Host::Managed.include Orchestration::Proxmox::Compute
|
@@ -0,0 +1,69 @@
|
|
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 'foreman_fog_proxmox/value'
|
21
|
+
|
22
|
+
module ForemanFogProxmox
|
23
|
+
module HashCollection
|
24
|
+
def self.add_and_format_element(dest, dest_key, origin, origin_key, format = :to_s)
|
25
|
+
dest[dest_key] = origin[origin_key].send(format) if origin && origin[origin_key]
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.remove_empty_values(h)
|
29
|
+
h.delete_if { |_key, value| ForemanFogProxmox::Value.empty?(value) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.remove_keys(h, excluded_keys)
|
33
|
+
h.delete_if { |key, _value| excluded_keys.include?(key) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.new_hash_reject_keys(h, excluded_keys)
|
37
|
+
h.reject { |key, _value| excluded_keys.include?(key) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.new_hash_reject_empty_values(h)
|
41
|
+
h.reject { |_key, value| ForemanFogProxmox::Value.empty?(value) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.new_hash_transform_values(h, transformation)
|
45
|
+
h.transform_values { |value| value.send(transformation) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.equals?(h1, h2)
|
49
|
+
new_h1 = new_hash_transform_values(h1, :to_s)
|
50
|
+
new_sorted_h1 = new_h1.sort_by { |key, _value| key }.to_h
|
51
|
+
new_h2 = new_hash_transform_values(h2, :to_s)
|
52
|
+
new_sorted_h2 = new_h2.sort_by { |key, _value| key }.to_h
|
53
|
+
new_sorted_h1.keys == new_sorted_h2.keys && new_sorted_h1.values == new_sorted_h2.values
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.stringify_keys(old_h)
|
57
|
+
h = old_h.map do |k, v|
|
58
|
+
v_str = if v.instance_of? Hash
|
59
|
+
v.stringify_keys
|
60
|
+
else
|
61
|
+
v
|
62
|
+
end
|
63
|
+
|
64
|
+
[k.to_s, v_str]
|
65
|
+
end
|
66
|
+
Hash[h]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -32,6 +32,3 @@ namespace :foreman_fog_proxmox do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
Rake::Task[:test].enhance ['test:foreman_fog_proxmox']
|
35
|
-
|
36
|
-
load 'tasks/jenkins.rake'
|
37
|
-
Rake::Task['jenkins:unit'].enhance ['test:foreman_fog_proxmox', 'foreman_fog_proxmox:rubocop'] if Rake::Task.task_defined?(:'jenkins:unit')
|
@@ -19,14 +19,15 @@
|
|
19
19
|
|
20
20
|
module ForemanFogProxmox
|
21
21
|
module ProxmoxContainerMockFactory
|
22
|
-
def
|
23
|
-
|
24
|
-
id: 'net0',
|
25
|
-
mac: '36:25:8C:53:0C:50',
|
22
|
+
def mock_container_interface_attributes
|
23
|
+
compute_attributes = {
|
26
24
|
model: nil,
|
27
25
|
name: 'eth0',
|
26
|
+
hwaddr: '36:25:8C:53:0C:50',
|
28
27
|
ip: nil,
|
29
28
|
ip6: nil,
|
29
|
+
gw: nil,
|
30
|
+
gw6: nil,
|
30
31
|
bridge: 'vmbr0',
|
31
32
|
firewall: nil,
|
32
33
|
link_down: nil,
|
@@ -34,8 +35,19 @@ module ForemanFogProxmox
|
|
34
35
|
queues: nil,
|
35
36
|
tag: nil
|
36
37
|
}
|
38
|
+
interface_attributes = {
|
39
|
+
id: 'net0',
|
40
|
+
mac: '36:25:8C:53:0C:50',
|
41
|
+
ip: nil,
|
42
|
+
ip6: nil,
|
43
|
+
compute_attributes: compute_attributes
|
44
|
+
}
|
45
|
+
interface_attributes
|
46
|
+
end
|
47
|
+
|
48
|
+
def mock_container_vm
|
37
49
|
interface = mock('interface')
|
38
|
-
interface.stubs(:attributes).returns(
|
50
|
+
interface.stubs(:attributes).returns(mock_container_interface_attributes)
|
39
51
|
interfaces = [interface]
|
40
52
|
volume_attributes = {
|
41
53
|
id: 'rootfs',
|
@@ -96,13 +108,13 @@ module ForemanFogProxmox
|
|
96
108
|
vm.stubs(:config).returns(config)
|
97
109
|
vm.stubs(:type).returns('lxc')
|
98
110
|
vm.stubs(:identity).returns(100)
|
99
|
-
vm.stubs(:node_id).returns('
|
111
|
+
vm.stubs(:node_id).returns('proxmox')
|
100
112
|
vm.stubs(:identity).returns(100)
|
101
113
|
service = mock('service')
|
102
114
|
vm_attributes = {
|
103
115
|
vmid: 100,
|
104
116
|
id: 'lxc/100',
|
105
|
-
node_id: '
|
117
|
+
node_id: 'proxmox',
|
106
118
|
service: service,
|
107
119
|
config: config,
|
108
120
|
name: 'test',
|
@@ -131,7 +143,7 @@ module ForemanFogProxmox
|
|
131
143
|
}
|
132
144
|
vm.stubs(:attributes).returns(vm_attributes)
|
133
145
|
vm.stubs(:container?).returns(true)
|
134
|
-
[vm, config_attributes, volume_attributes,
|
146
|
+
[vm, config_attributes, volume_attributes, mock_container_interface_attributes]
|
135
147
|
end
|
136
148
|
end
|
137
149
|
end
|
@@ -22,7 +22,7 @@ module ForemanFogProxmox
|
|
22
22
|
def mock_node_servers(cr, servers)
|
23
23
|
node = mock('node')
|
24
24
|
nodes = mock('nodes')
|
25
|
-
node.stubs(:node).returns('
|
25
|
+
node.stubs(:node).returns('proxmox')
|
26
26
|
node.stubs(:servers).returns(servers)
|
27
27
|
nodes.stubs(:get).returns(node)
|
28
28
|
nodes.stubs(:all).returns([node])
|
@@ -35,7 +35,7 @@ module ForemanFogProxmox
|
|
35
35
|
def mock_node_containers(cr, containers)
|
36
36
|
node = mock('node')
|
37
37
|
nodes = mock('nodes')
|
38
|
-
node.stubs(:node).returns('
|
38
|
+
node.stubs(:node).returns('proxmox')
|
39
39
|
node.stubs(:containers).returns(containers)
|
40
40
|
nodes.stubs(:get).returns(node)
|
41
41
|
nodes.stubs(:all).returns([node])
|
@@ -47,7 +47,7 @@ module ForemanFogProxmox
|
|
47
47
|
|
48
48
|
def mock_node_servers_containers(cr, servers, containers)
|
49
49
|
node = mock('node')
|
50
|
-
node.stubs(:node).returns('
|
50
|
+
node.stubs(:node).returns('proxmox')
|
51
51
|
node.stubs(:containers).returns(containers)
|
52
52
|
node.stubs(:servers).returns(servers)
|
53
53
|
nodes = mock('nodes')
|
@@ -69,8 +69,8 @@ module ForemanFogProxmox
|
|
69
69
|
node2.stubs(:servers).returns(n2s)
|
70
70
|
node2.stubs(:containers).returns(n2c)
|
71
71
|
nodes = mock('nodes')
|
72
|
-
nodes.stubs(:get).with('
|
73
|
-
nodes.stubs(:get).with('
|
72
|
+
nodes.stubs(:get).with('proxmox').returns(node1)
|
73
|
+
nodes.stubs(:get).with('proxmox2').returns(node2)
|
74
74
|
nodes.stubs(:all).returns([node1, node2])
|
75
75
|
client = mock('client')
|
76
76
|
client.stubs(:nodes).returns(nodes)
|