foreman_fog_proxmox 0.25.1 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_network_interface_modal.js +11 -0
  3. data/app/assets/stylesheets/foreman_fog_proxmox/network_interface_modal.css +17 -0
  4. data/app/controllers/concerns/foreman_fog_proxmox/hosts_controller.rb +2 -0
  5. data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +31 -23
  6. data/app/helpers/proxmox_compute_selectors_helper.rb +1 -0
  7. data/app/helpers/proxmox_vm_attrs_helper.rb +2 -2
  8. data/app/helpers/proxmox_vm_cloudinit_helper.rb +63 -48
  9. data/app/helpers/proxmox_vm_config_helper.rb +1 -1
  10. data/app/helpers/proxmox_vm_helper.rb +14 -2
  11. data/app/models/concerns/fog_extensions/proxmox/server.rb +1 -1
  12. data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +9 -3
  13. data/app/models/foreman_fog_proxmox/proxmox_images.rb +1 -1
  14. data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +1 -1
  15. data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +4 -10
  16. data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +14 -0
  17. data/app/services/concerns/foreman_fog_proxmox/compute_resource_host_associator.rb +2 -2
  18. data/app/views/compute_resources_vms/form/proxmox/_add_react_component_to_host_form.html.erb +5 -0
  19. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +5 -4
  20. data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +1 -1
  21. data/lib/foreman_fog_proxmox/engine.rb +8 -2
  22. data/lib/foreman_fog_proxmox/version.rb +1 -1
  23. data/package.json +3 -2
  24. data/test/functional/compute_resources_controller_test.rb +41 -0
  25. data/test/unit/foreman_fog_proxmox/compute_resource_host_associator_test.rb +43 -0
  26. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +33 -0
  27. data/test/unit/foreman_fog_proxmox/hosts_controller_test.rb +57 -0
  28. data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +32 -1
  29. data/test/unit/foreman_fog_proxmox/proxmox_images_test.rb +13 -0
  30. data/test/unit/foreman_fog_proxmox/proxmox_operating_systems_test.rb +4 -0
  31. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +12 -9
  32. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +139 -24
  33. data/test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb +40 -0
  34. data/webpack/components/GeneralTabContent.js +100 -61
  35. data/webpack/components/ProxmoxComputeSelectors.js +1 -0
  36. data/webpack/components/ProxmoxVmType.js +20 -0
  37. data/webpack/components/__tests__/GeneralTabContent.test.js +207 -0
  38. data/webpack/components/__tests__/ProxmoxVmType.test.js +36 -1
  39. data/webpack/components/common/FormInputs.js +18 -19
  40. data/webpack/components/hooks/useInheritedImageSelection.js +42 -0
  41. metadata +10 -3
  42. data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +0 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d59641775e4da477886d59bf332dadd576426ef079d1c6af43ef2e9f70b9c5a5
4
- data.tar.gz: 5e24be7c7881de3c05d5a59a06500bd9d35f7c1f06d4c10390df473ec6ef8b01
3
+ metadata.gz: e72cd6c74e6250ab29a3e7fcd79f77251e2997e2b309c477e16718ddb6599ef5
4
+ data.tar.gz: f8dd7ad601d77d25a4530e8cd29dc940f2c285ece0c45f58ff0398c5bfead2bf
5
5
  SHA512:
6
- metadata.gz: e04095637c92c2a341043e96f345d4d9ddcd5a3f86b4285fc1ee5199a0e9c36fd542e40a28e748d66d4da56cec743618d144300b907be7c4d82a0a4daac21d82
7
- data.tar.gz: 18a1bb26c3d35273d36826012d35c7e5f21a9c65193e86b7ab9babbde49ae5d15dcea828fa37a024e91740bdfb5a29788047f8ad8cd5829215324e21267e4079
6
+ metadata.gz: 2ef10ad730bde03e902a9e7780c4637d857678e083f7c35cda505d1dac4d5812b55a10a4925ad823c0fd0218f3678e477bacf7bd85b845993ca05f6fcb3bef26
7
+ data.tar.gz: 4ea8aebed65ffb32547a020ee981ab8b1ce4bfae235a5d88751b2ef2e7bf37672b94f443ae8f9415662ade4179fb80cd31cc1476864c36784673619cfd315182
@@ -0,0 +1,11 @@
1
+ $(document)
2
+ .on('show.bs.modal', '#interfaceModal', function () {
3
+ var modal = $(this);
4
+ modal.toggleClass(
5
+ 'proxmox-interface-modal',
6
+ modal.find('.proxmox-interface-form').length > 0
7
+ );
8
+ })
9
+ .on('hidden.bs.modal', '#interfaceModal', function () {
10
+ $(this).removeClass('proxmox-interface-modal');
11
+ });
@@ -0,0 +1,17 @@
1
+ #interfaceModal.proxmox-interface-modal {
2
+ overflow-y: hidden;
3
+ }
4
+
5
+ #interfaceModal.proxmox-interface-modal .modal-content {
6
+ display: flex;
7
+ flex-direction: column;
8
+ max-height: 90vh;
9
+ overflow: hidden;
10
+ }
11
+
12
+ #interfaceModal.proxmox-interface-modal .modal-body {
13
+ flex: 1 1 auto;
14
+ min-height: 0;
15
+ overflow-y: auto;
16
+ overflow-x: hidden;
17
+ }
@@ -38,6 +38,8 @@ module ForemanFogProxmox
38
38
  @host.compute_attributes[:volumes_attributes].each do |index, volume_attributes|
39
39
  @host.compute_attributes[:volumes_attributes][index] = volume_attributes.merge(volid: nil)
40
40
  end
41
+ efidisk = @host.compute_attributes.dig(:config_attributes, :efidisk)
42
+ efidisk.volid = "#{efidisk.storage}:0" if efidisk
41
43
  end
42
44
 
43
45
  private
@@ -95,20 +95,21 @@ module ForemanFogProxmox
95
95
  # GET foreman_fog_proxmox/metadata/:compute_resource_id
96
96
  def metadata
97
97
  cr = ComputeResource.find(params[:compute_resource_id])
98
+ nodes = Array(cr.nodes)
98
99
 
99
100
  render json: {
100
- nodes: extract_nodes(cr),
101
+ nodes: extract_nodes(nodes),
101
102
  pools: extract_pools(cr),
102
- storages: extract_storages(cr),
103
- bridges: extract_bridges(cr),
103
+ storages: extract_storages(cr, nodes),
104
+ bridges: extract_bridges(cr, nodes),
104
105
  images: extract_images(cr),
105
106
  }
106
107
  end
107
108
 
108
109
  private
109
110
 
110
- def extract_nodes(compute_resource)
111
- Array(compute_resource.nodes).map { |n| { node: n.node } }
111
+ def extract_nodes(nodes)
112
+ nodes.map { |n| { node: n.node } }
112
113
  end
113
114
 
114
115
  def extract_pools(compute_resource)
@@ -118,27 +119,34 @@ module ForemanFogProxmox
118
119
  end
119
120
  end
120
121
 
121
- def extract_storages(compute_resource)
122
- Array(compute_resource.storages).map do |s|
123
- h = s.respond_to?(:as_json) ? s.as_json : s
124
- {
125
- storage: (h[:storage] || h['storage']),
126
- node_id: (h[:node_id] || h['node_id']),
127
- content: (h[:content] || h['content']),
128
- avail: (h[:avail] || h['avail']),
129
- used: (h[:used] || h['used']),
130
- total: (h[:total] || h['total']),
131
- }
122
+ def extract_storages(compute_resource, nodes)
123
+ nodes.flat_map do |node|
124
+ node_id = node.node
125
+ Array(compute_resource.storages(node_id)).map do |storage|
126
+ h = storage.respond_to?(:as_json) ? storage.as_json : storage
127
+ {
128
+ storage: (h[:storage] || h['storage']),
129
+ node_id: node_id,
130
+ content: (h[:content] || h['content']),
131
+ avail: (h[:avail] || h['avail']),
132
+ used: (h[:used] || h['used']),
133
+ total: (h[:total] || h['total']),
134
+ shared: (h[:shared] || h['shared']),
135
+ }
136
+ end
132
137
  end
133
138
  end
134
139
 
135
- def extract_bridges(compute_resource)
136
- Array(compute_resource.bridges).map do |b|
137
- h = b.respond_to?(:as_json) ? b.as_json : b
138
- {
139
- node_id: (h[:node_id] || h['node_id']),
140
- iface: (h[:iface] || h['iface']),
141
- }
140
+ def extract_bridges(compute_resource, nodes)
141
+ nodes.flat_map do |node|
142
+ node_id = node.node
143
+ Array(compute_resource.bridges(node_id)).map do |bridge|
144
+ h = bridge.respond_to?(:as_json) ? bridge.as_json : bridge
145
+ {
146
+ node_id: node_id,
147
+ iface: (h[:iface] || h['iface']),
148
+ }
149
+ end
142
150
  end
143
151
  end
144
152
 
@@ -50,6 +50,7 @@ module ProxmoxComputeSelectorsHelper
50
50
  OpenStruct.new(id: 'win7', name: 'Microsoft Windows 7'),
51
51
  OpenStruct.new(id: 'win8', name: 'Microsoft Windows 8/2012/2012r2'),
52
52
  OpenStruct.new(id: 'win10', name: 'Microsoft Windows 10/2016'),
53
+ OpenStruct.new(id: 'win11', name: 'Microsoft Windows 11/2022/2025'),
53
54
  OpenStruct.new(id: 'l24', name: 'Linux 2.4 Kernel'),
54
55
  OpenStruct.new(id: 'l26', name: 'Linux 2.6/3.X + Kernel'),
55
56
  OpenStruct.new(id: 'solaris', name: 'Solaris/OpenSolaris/OpenIndiania kernel')]
@@ -130,7 +130,8 @@ module ProxmoxVMAttrsHelper
130
130
  hostname: vms.config.hostname,
131
131
  ostemplate_storage: vms.ostemplate_storage,
132
132
  ostemplate_file: vms.ostemplate_file,
133
- start_after_create: vms.start_after_create,
133
+ iso_upload_storage: vms.iso_upload_storage,
134
+ start: start_checked,
134
135
  templated: vms.templated,
135
136
  is_secure_boot: vms.config.secure_boot?,
136
137
  }
@@ -139,7 +140,6 @@ module ProxmoxVMAttrsHelper
139
140
  attributes.each do |key, value|
140
141
  camel_key = key.to_s.include?('_') ? snake_to_camel(key.to_s).to_sym : key
141
142
  nested_key = vms_keys.include?(key) ? "config_attributes[#{key}]" : key
142
- value = start_checked if key == :start_after_create
143
143
  extra_attrs[camel_key] = { name: "#{param_scope}[#{nested_key}]", value: value }
144
144
  end
145
145
  extra_attrs
@@ -21,6 +21,9 @@ require 'fog/proxmox/helpers/disk_helper'
21
21
  require 'fog/proxmox/helpers/nic_helper'
22
22
  require 'foreman_fog_proxmox/value'
23
23
  require 'foreman_fog_proxmox/hash_collection'
24
+ require 'fileutils'
25
+ require 'open3'
26
+ require 'tmpdir'
24
27
 
25
28
  # Convert a foreman form server hash into a fog-proxmox server attributes hash
26
29
  module ProxmoxVMCloudinitHelper
@@ -42,54 +45,59 @@ module ProxmoxVMCloudinitHelper
42
45
  cloudinit_h
43
46
  end
44
47
 
45
- def create_cloudinit_iso(vm_name, configs, ssh)
46
- iso = File.join(default_iso_path, "#{vm_name.tr('.', '_')}_cloudinit.iso")
48
+ def create_cloudinit_iso(vm_name, configs)
49
+ wd = create_temp_directory
50
+ iso = File.join(wd, "#{vm_name.tr('.', '_')}_cloudinit.iso")
47
51
  files = []
48
- wd = create_temp_directory(ssh)
49
52
 
50
53
  configs.each do |config|
51
- config_file = ssh.run("cat <<'EOF' > '#{wd}/#{config[0]}'\n#{config[1]}\nEOF")
52
- unless config_file.first.status.zero?
53
- delete_temp_dir(ssh, wd)
54
- raise ::Foreman::Exception, "Failed to create file #{config[0]}: #{config_file.first.stdout}"
55
- end
56
- files.append(File.join(wd, config[0]))
54
+ config_file = File.join(wd, config[0])
55
+ File.write(config_file, config[1])
56
+ files.append(config_file)
57
57
  end
58
- generated_iso = ssh.run(generate_iso_command(iso, files))
59
- unless generated_iso.first.status.zero?
60
- delete_temp_dir(ssh, wd)
61
- raise Foreman::Exception, N_("ISO build failed: #{generated_iso.first.stdout}")
62
- end
63
- delete_temp_dir(ssh, wd)
64
- iso
58
+ logger.debug("Generating cloud-init ISO at #{iso}")
59
+ stdout, stderr, status = Open3.capture3(*generate_iso_command(iso, files))
60
+ raise Foreman::Exception, N_("ISO build failed: #{stderr.presence || stdout}") unless status.success?
61
+
62
+ yield iso
63
+ ensure
64
+ delete_temp_dir(wd) if wd && Dir.exist?(wd)
65
65
  end
66
66
 
67
67
  def generate_iso_command(iso_file, config_files)
68
- arguments = ["genisoimage", "-output #{iso_file}", '-volid', 'cidata', '-joliet', '-rock']
69
- iso_command = arguments.concat(config_files).join(' ')
70
- logger.debug("iso image generation args: #{iso_command}")
71
- iso_command
68
+ arguments = ["genisoimage", '-output', iso_file, '-volid', 'cidata', '-joliet', '-rock']
69
+ arguments.concat(config_files)
70
+ logger.debug("iso image generation args: #{arguments.join(' ')}")
71
+ arguments
72
72
  end
73
73
 
74
- def create_temp_directory(ssh)
75
- res = ssh.run("mktemp -d")
76
- raise ::Foreman::Exception, "Could not create working directory to store cloudinit config data: #{res.first.stdout}." unless res.first.status.zero?
77
- res.first.stdout.chomp
74
+ def create_temp_directory
75
+ Dir.mktmpdir
76
+ rescue StandardError => e
77
+ raise ::Foreman::Exception, "Could not create working directory to store cloudinit config data: #{e}."
78
78
  end
79
79
 
80
- def delete_temp_dir(ssh, working_dir)
81
- ssh.run("rm -rf #{working_dir}")
82
- rescue Foreman::Exception => e
80
+ def delete_temp_dir(working_dir)
81
+ FileUtils.remove_entry(working_dir)
82
+ rescue StandardError => e
83
83
  logger.warn("Could not delete directory for config files: #{e}. Please delete it manually at #{working_dir}")
84
84
  end
85
85
 
86
- def parse_cloudinit_config(args)
86
+ def cloudinit_clone_args(args, vm_instance)
87
+ return args unless args[:user_data]
88
+
89
+ actual_node = vm_instance.node_id
90
+ logger.info("Cloud-init ISO storage will be validated for cloned VM node #{actual_node} instead of selected node #{args[:node_id]}") if args[:node_id] != actual_node
91
+
92
+ parse_cloudinit_config(args, vm_node: actual_node)
93
+ end
94
+
95
+ def parse_cloudinit_config(args, vm_node: args[:node_id])
87
96
  filenames = ["meta-data"]
88
97
  config_data = ["instance-id: #{args[:name]}"]
89
98
  user_data = args.delete(:user_data)
90
99
  return args if user_data == ''
91
100
  check_template_format(user_data)
92
- ssh = vm_ssh
93
101
 
94
102
  if user_data.include?('#network-config') && user_data.include?('#cloud-config')
95
103
  config_data.concat(user_data.split('#network-config'))
@@ -105,32 +113,39 @@ module ProxmoxVMCloudinitHelper
105
113
  return args if config_data.length == 1
106
114
  configs = filenames.zip(config_data).to_h
107
115
 
108
- iso = create_cloudinit_iso(args[:name], configs, ssh)
109
- args.merge!(attach_cloudinit_iso(args[:node_id], iso))
116
+ create_cloudinit_iso(args[:name], configs) do |iso|
117
+ storage = upload_iso(args[:node_id], args[:iso_upload_storage], iso, vm_node: vm_node)
118
+ args.merge!(attach_cloudinit_iso(vm_node, storage, iso))
119
+ end
110
120
  end
111
121
 
112
- def attach_cloudinit_iso(node, iso)
113
- volume = nil
114
- storages(node, 'iso').each do |storage|
115
- volume = storage.volumes.detect { |v| v.volid.include? File.basename(iso) }
116
- break if volume
117
- end
122
+ def upload_iso(node, storage_id, iso, vm_node: node)
123
+ raise ::Foreman::Exception, _('ISO upload storage must be selected') if storage_id.blank?
118
124
 
119
- raise ::Foreman::Exception, "Could not find generated cloud-init ISO #{File.basename(iso)} on any ISO storage for node #{node}" unless volume
125
+ iso_storages = storages(node, 'iso')
126
+ storage = iso_storages.find { |s| s.identity == storage_id }
127
+ raise ::Foreman::Exception, "Could not find selected ISO upload storage #{storage_id} for node #{node}" unless storage
120
128
 
121
- { ide2: "#{volume.volid},media=cdrom" }
122
- end
129
+ if node != vm_node
130
+ vm_storage = storages(vm_node, 'iso').find { |s| s.identity == storage_id }
131
+ raise ::Foreman::Exception, "Selected ISO upload storage #{storage_id} is not accessible from cloned VM node #{vm_node}" unless vm_storage
123
132
 
124
- def default_iso_path
125
- "/var/lib/vz/template/iso"
133
+ storage = vm_storage
134
+ end
135
+
136
+ storage.upload_iso(iso)
137
+ storage.identity
126
138
  end
127
139
 
128
- def vm_ssh
129
- ssh = Fog::SSH.new(URI.parse(fog_credentials[:proxmox_url]).host, fog_credentials[:proxmox_username].split('@')[0], { password: fog_credentials[:proxmox_password] })
130
- ssh.run('ls') # test if ssh is successful
131
- ssh
132
- rescue StandardError => e
133
- raise ::Foreman::Exception, "Unable to ssh into proxmox server: #{e}"
140
+ def attach_cloudinit_iso(node, storage_id, iso)
141
+ storage = client.nodes.get(node).storages.get(storage_id)
142
+ volume = storage&.volumes&.all&.detect do |v|
143
+ File.basename(v.volid) == File.basename(iso)
144
+ end
145
+
146
+ raise ::Foreman::Exception, "Could not find generated cloud-init ISO #{File.basename(iso)} on storage #{storage_id} for node #{node}" unless volume
147
+
148
+ { ide2: "#{volume.volid},media=cdrom" }
134
149
  end
135
150
 
136
151
  def check_template_format(user_data)
@@ -41,7 +41,7 @@ module ProxmoxVMConfigHelper
41
41
 
42
42
  def general_a(type)
43
43
  general_a = ['node_id', 'type', 'config_attributes', 'efidisk_attributes', 'volumes_attributes', 'interfaces_attributes', 'image_id']
44
- general_a += ['firmware_type', 'provision_method', 'container_volumes', 'server_volumes', 'start_after_create']
44
+ general_a += ['firmware_type', 'provision_method', 'container_volumes', 'server_volumes', 'start', 'iso_upload_storage']
45
45
  general_a += ['name'] if type == 'lxc'
46
46
  general_a
47
47
  end
@@ -42,10 +42,11 @@ module ProxmoxVMHelper
42
42
  ).merge(type: type)
43
43
  end
44
44
 
45
- def update_boot_order(instance, exclude_cdrom: false, include_network: false)
45
+ def update_boot_order(instance, exclude_cdrom: false, include_network: false, preserve_boot_order: false)
46
46
  return {} unless instance
47
47
 
48
- disks = Array(instance.disks).map { |disk| disk.split(":")[0] }
48
+ disk_ids = Array(instance.disks).map { |disk| disk.split(":")[0] }
49
+ disks = preserve_boot_order ? disks_in_boot_order(instance, disk_ids) : disk_ids
49
50
  disks.delete("ide2") if exclude_cdrom
50
51
  network_interfaces = include_network ? Array(instance.interfaces).map(&:id) : []
51
52
  boot_devices = network_interfaces + disks
@@ -55,6 +56,17 @@ module ProxmoxVMHelper
55
56
  { boot: "order=" + boot_devices.join(";") }
56
57
  end
57
58
 
59
+ def disks_in_boot_order(instance, disk_ids)
60
+ configured_boot = instance.config&.boot.to_s
61
+
62
+ return disk_ids if configured_boot.empty?
63
+
64
+ configured_boot
65
+ .delete_prefix("order=")
66
+ .split(";")
67
+ .select { |device| disk_ids.include?(device) }
68
+ end
69
+
58
70
  # Convert a foreman form server/container vm hash into a fog-proxmox server/container attributes hash
59
71
  def parse_typed_vm(args, type)
60
72
  args = process_firmware_attributes(args, type)
@@ -21,7 +21,7 @@ module FogExtensions
21
21
  module Proxmox
22
22
  module Server
23
23
  extend ActiveSupport::Concern
24
- attr_accessor :image_id, :templated, :ostemplate_storage, :ostemplate_file, :password, :start_after_create, :compute_resource_id
24
+ attr_accessor :image_id, :templated, :ostemplate_storage, :ostemplate_file, :iso_upload_storage, :password, :compute_resource_id
25
25
 
26
26
  def unique_cluster_identity(compute_resource)
27
27
  compute_resource.id.to_s + '_' + identity.to_s
@@ -75,6 +75,14 @@ module ForemanFogProxmox
75
75
  cdrom_compute_attributes(attrs) || attrs
76
76
  end
77
77
 
78
+ def config_compute_attributes(vm)
79
+ attrs = vm.config.attributes.reject do |key, value|
80
+ 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)
81
+ end
82
+ attrs[:is_secure_boot] = vm.config.secure_boot? if vm.type == 'qemu'
83
+ attrs
84
+ end
85
+
78
86
  def vm_compute_attributes(vm)
79
87
  vm_attrs = {}
80
88
  vm_attrs = vm_attrs.merge(vmid: vm.identity, node_id: vm.node_id, type: vm.type)
@@ -89,9 +97,7 @@ module ForemanFogProxmox
89
97
  [idx.to_s, interface_compute_attributes(interface.attributes)]
90
98
  end ]
91
99
  end
92
- vm_attrs[:config_attributes] = vm.config.attributes.reject do |key, value|
93
- 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)
94
- end
100
+ vm_attrs[:config_attributes] = config_compute_attributes(vm)
95
101
  end
96
102
  vm_attrs
97
103
  end
@@ -41,7 +41,7 @@ module ForemanFogProxmox
41
41
  end
42
42
 
43
43
  def available_images
44
- templates.collect { |template| OpenStruct.new(id: template_uuid(template), name: template_name(template)) }
44
+ templates.collect { |template| OpenStruct.new(id: template_uuid(template), name: template_name(template)) }.uniq
45
45
  end
46
46
 
47
47
  def templates
@@ -39,7 +39,7 @@ module ForemanFogProxmox
39
39
  end
40
40
 
41
41
  def available_windows_operating_systems
42
- ['wxp', 'w2k', 'w2k3', 'w2k8', 'wvista', 'win7', 'win8', 'win10']
42
+ ['wxp', 'w2k', 'w2k3', 'w2k8', 'wvista', 'win7', 'win8', 'win10', 'win11']
43
43
  end
44
44
 
45
45
  def os_linux_types_mapping(host)
@@ -26,12 +26,6 @@ module ForemanFogProxmox
26
26
  include ProxmoxPools
27
27
  include ProxmoxVMHelper
28
28
 
29
- def start_on_boot(vm, args)
30
- startonboot = args[:start_after_create].blank? ? false : Foreman::Cast.to_bool(args[:start_after_create])
31
- vm.start if startonboot
32
- vm
33
- end
34
-
35
29
  def create_vm(args = {})
36
30
  type = args[:type]
37
31
  node = client.nodes.get(args[:node_id])
@@ -42,7 +36,8 @@ module ForemanFogProxmox
42
36
  image = find_vm_by_uuid(image_id)
43
37
  validate_image_template_disk_slots!(image, args) if type == 'qemu'
44
38
  vm = clone_from_image(image, vmid)
45
- vm.update(compute_clone_attributes(args, vm.container?, type, image: image))
39
+ cloudinit_args = cloudinit_clone_args(args, vm)
40
+ vm.update(compute_clone_attributes(cloudinit_args, vm.container?, type, image: image))
46
41
  update_pool(vm, args[:pool]) if args[:pool]
47
42
  else
48
43
  logger.warn("create vm: args=#{args}")
@@ -52,7 +47,7 @@ module ForemanFogProxmox
52
47
  vm.update(boot_order) if boot_order
53
48
  end
54
49
  end
55
- start_on_boot(vm, args)
50
+ vm
56
51
  rescue StandardError => e
57
52
  logger.warn("failed to create vm: #{e}")
58
53
  destroy_vm id.to_s + '_' + vm.vmid.to_s if vm
@@ -71,8 +66,7 @@ module ForemanFogProxmox
71
66
  end
72
67
 
73
68
  def compute_clone_attributes(args, container, type, image: nil)
74
- args = parse_cloudinit_config(args) if args[:user_data]
75
- args[:config_attributes].merge!(update_boot_order(image)) if image && args[:config_attributes]
69
+ args[:config_attributes].merge!(update_boot_order(image, preserve_boot_order: true)) if image && args[:config_attributes]
76
70
  parsed_args = parse_typed_vm(args, type)
77
71
  if container
78
72
  options = { :hostname => args[:name] }
@@ -195,6 +195,17 @@ module ForemanFogProxmox
195
195
  vm_h[:is_secure_boot] = secure_boot if type == 'qemu' && secure_boot
196
196
  end
197
197
 
198
+ def add_image_attribute(vm_h, options)
199
+ image_id = options['image_id']
200
+ vm_h[:image_id] = image_id if image_id.present?
201
+ end
202
+
203
+ def add_iso_upload_storage_attribute(vm_h, options, type)
204
+ iso_upload_storage = options['iso_upload_storage']
205
+ vm_h[:iso_upload_storage] = iso_upload_storage if type == 'qemu' && iso_upload_storage.present?
206
+ end
207
+
208
+ # rubocop:disable Metrics/AbcSize
198
209
  def new_typed_vm(new_attr, type)
199
210
  convert_config_attributes(new_attr) if new_attr.key?(:config_attributes)
200
211
  node_id = new_attr['node_id']
@@ -210,11 +221,14 @@ module ForemanFogProxmox
210
221
  logger.debug("new_typed_vm(#{type}): options=#{options}")
211
222
  vm_h = parse_typed_vm(options, type).deep_symbolize_keys
212
223
  add_secure_boot_attribute(vm_h, options, type)
224
+ add_image_attribute(vm_h, options)
225
+ add_iso_upload_storage_attribute(vm_h, options, type)
213
226
  logger.debug("new_typed_vm(#{type}): vm_h=#{vm_h}")
214
227
  vm_h = vm_h.merge(vm_typed_instance_defaults(type)) if vm_h.empty?
215
228
  logger.debug(format(_('new_typed_vm(%<type>s) with vm_typed_instance_defaults: vm_h=%<vm_h>s'), type: type, vm_h: vm_h))
216
229
  node.send(vm_collection(type)).new(vm_h)
217
230
  end
231
+ # rubocop:enable Metrics/AbcSize
218
232
  end
219
233
  end
220
234
 
@@ -24,8 +24,8 @@ module ForemanFogProxmox
24
24
  prepend Overrides
25
25
  end
26
26
  module Overrides
27
- def associate_hosts
28
- compute_resource.vms(:eager_loading => true).each do |vm|
27
+ def associate_hosts(vms = compute_resource.vms(:eager_loading => true))
28
+ vms.each do |vm|
29
29
  associate_vm(vm) if Host.for_vm_uuid(compute_resource, vm).empty?
30
30
  end
31
31
  end
@@ -1,4 +1,9 @@
1
+ <% content_for(:stylesheets) do %>
2
+ <%= stylesheet_link_tag 'foreman_fog_proxmox/network_interface_modal' %>
3
+ <% end %>
4
+
1
5
  <% content_for(:javascripts) do %>
6
+ <%= javascript_include_tag 'foreman_fog_proxmox/proxmox_network_interface_modal' %>
2
7
  <%= webpacked_plugins_js_for :foreman_fog_proxmox %>
3
8
  <% end %>
4
9
  <%= react_component('ProxmoxVmType', { registerComp: true }) unless @host.managed %>
@@ -20,12 +20,13 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
20
20
  <% vm_type = vm_type_and_node_id[:vm_type] %>
21
21
  <% node_id = vm_type_and_node_id[:node_id] %>
22
22
 
23
- <%= f.fields_for 'compute_attributes', OpenStruct.new(compute_attributes) do |f| %>
24
- <%= render provider_partial(@host.compute_resource, 'network'), :f => f, :vm_type => vm_type, :node_id => node_id, :disabled => f.object.persisted?, :compute_resource => @host.compute_resource, :new_host => new_vm, :new_vm => new_vm %>
25
- <% end %>
23
+ <div class="proxmox-interface-form">
24
+ <%= f.fields_for 'compute_attributes', OpenStruct.new(compute_attributes) do |f| %>
25
+ <%= render provider_partial(@host.compute_resource, 'network'), :f => f, :vm_type => vm_type, :node_id => node_id, :disabled => f.object.persisted?, :compute_resource => @host.compute_resource, :new_host => new_vm, :new_vm => new_vm %>
26
+ <% end %>
27
+ </div>
26
28
  <% else %>
27
29
  <%= f.fields_for 'compute_attributes', OpenStruct.new(f.object.compute_attributes) do |f| %>
28
30
  <%= render provider_partial(@host.compute_resource, 'network'), :f => f, :disabled => f.object.persisted?, :compute_resource => @host.compute_resource, :new_host => new_vm, :new_vm => new_vm %>
29
31
  <% end %>
30
32
  <% end %>
31
-
@@ -32,7 +32,7 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
32
32
  <% end %>
33
33
 
34
34
  <% untemplatable = new_vm || f.object.templated? %>
35
- <% checked = (params.dig(:host, :compute_attributes, :start_after_create) || '1') %>
35
+ <% checked = (params.dig(:host, :compute_attributes, :start) || '1') %>
36
36
 
37
37
  <% content_for(:javascripts) do %>
38
38
  <%= webpacked_plugins_js_for :foreman_fog_proxmox %>
@@ -40,7 +40,14 @@ module ForemanFogProxmox
40
40
  register_global_js_file 'global'
41
41
  # Register Proxmox VE compute resource in foreman
42
42
  compute_resource ForemanFogProxmox::Proxmox
43
- parameter_filter(ComputeResource, :uuid)
43
+ parameter_filter ComputeResource,
44
+ :uuid,
45
+ :ssl_verify_peer,
46
+ :ssl_certs,
47
+ :disable_proxy,
48
+ :auth_method,
49
+ :token_id,
50
+ :token
44
51
  # add dashboard widget
45
52
  widget 'foreman_fog_proxmox_widget', name: N_('Foreman Fog Proxmox widget'), sizex: 8, sizey: 1
46
53
 
@@ -111,7 +118,6 @@ module ForemanFogProxmox
111
118
  Fog::Proxmox::Compute::Interface.include FogExtensions::Proxmox::Interface
112
119
  Fog::Proxmox::Compute::Disk.include FogExtensions::Proxmox::Disk
113
120
  Fog::Proxmox::Compute::Node.include FogExtensions::Proxmox::Node
114
- ::ComputeResourcesController.include ForemanFogProxmox::Controller::Parameters::ComputeResource
115
121
  ::ComputeResourcesVmsController.include ForemanFogProxmox::ComputeResourcesVmsController
116
122
  ::HostsController.include ForemanFogProxmox::HostsController
117
123
  ::Host::Managed.include Orchestration::Proxmox::Compute
@@ -18,5 +18,5 @@
18
18
  # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module ForemanFogProxmox
21
- VERSION = '0.25.1'
21
+ VERSION = '1.0.1'
22
22
  end
data/package.json CHANGED
@@ -27,8 +27,9 @@
27
27
  "react-intl": "^2.8.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@babel/core": "^7.7.0",
31
- "@theforeman/builder": ">= 15.0.1",
30
+ "@babel/core": "^7.29.7",
31
+ "@babel/preset-env": "~7.29.7",
32
+ "@babel/preset-react": "~7.29.7",
32
33
  "@theforeman/eslint-plugin-foreman": ">= 15.0.1",
33
34
  "@theforeman/find-foreman": ">= 15.0.1",
34
35
  "@theforeman/test": ">= 15.0.1",