foreman_fog_proxmox 0.11.1 → 0.13.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.

Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -3
  3. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +24 -2
  4. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +124 -52
  5. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js +0 -48
  6. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume.js +39 -0
  7. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume_cdrom.js +63 -0
  8. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume_cloudinit.js +25 -0
  9. data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +1 -1
  10. data/app/helpers/proxmox_compute_controllers_helper.rb +39 -0
  11. data/app/helpers/proxmox_compute_resources_helper.rb +49 -0
  12. data/app/helpers/proxmox_compute_selectors_helper.rb +11 -44
  13. data/app/helpers/proxmox_form_helper.rb +12 -4
  14. data/app/{models/concerns/fog_extensions/proxmox/volume.rb → helpers/proxmox_storages_helper.rb} +5 -8
  15. data/app/{models/foreman_fog_proxmox/proxmox_token_expiration.rb → helpers/proxmox_vm_cdrom_helper.rb} +15 -10
  16. data/app/helpers/proxmox_vm_cloudinit_helper.rb +43 -0
  17. data/app/helpers/proxmox_vm_config_helper.rb +159 -0
  18. data/app/helpers/proxmox_vm_helper.rb +24 -70
  19. data/app/helpers/proxmox_vm_interfaces_helper.rb +85 -0
  20. data/app/helpers/proxmox_vm_os_template_helper.rb +47 -0
  21. data/app/helpers/proxmox_vm_volumes_helper.rb +105 -0
  22. data/app/models/concerns/fog_extensions/proxmox/disk.rb +17 -2
  23. data/app/models/concerns/fog_extensions/proxmox/interface.rb +19 -4
  24. data/app/models/concerns/fog_extensions/proxmox/server.rb +8 -3
  25. data/app/models/concerns/fog_extensions/proxmox/server_config.rb +8 -30
  26. data/app/models/concerns/host_ext/proxmox/interfaces.rb +7 -2
  27. data/app/models/concerns/orchestration/proxmox/compute.rb +1 -0
  28. data/app/models/foreman_fog_proxmox/proxmox.rb +58 -15
  29. data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +20 -12
  30. data/app/models/foreman_fog_proxmox/proxmox_connection.rb +14 -9
  31. data/app/models/foreman_fog_proxmox/proxmox_images.rb +2 -1
  32. data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +53 -28
  33. data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +1 -1
  34. data/app/models/foreman_fog_proxmox/proxmox_version.rb +7 -2
  35. data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +19 -30
  36. data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +108 -94
  37. data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +2 -1
  38. data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +79 -22
  39. data/app/views/compute_resources/form/_proxmox.html.erb +23 -10
  40. data/app/views/compute_resources/show/_proxmox.html.erb +6 -6
  41. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +4 -2
  42. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +46 -29
  43. data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +3 -3
  44. data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +2 -1
  45. data/app/views/compute_resources_vms/form/proxmox/container/_network.html.erb +8 -7
  46. data/app/views/compute_resources_vms/form/proxmox/server/_advanced.html.erb +0 -2
  47. data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +16 -14
  48. data/app/views/compute_resources_vms/form/proxmox/server/_network.html.erb +2 -2
  49. data/app/views/compute_resources_vms/form/proxmox/server/_volume_cdrom.html.erb +34 -0
  50. data/app/views/compute_resources_vms/form/proxmox/server/_volume_cloud_init.html.erb +29 -0
  51. data/app/views/compute_resources_vms/form/proxmox/server/{_volume.html.erb → _volume_hard_disk.html.erb} +7 -3
  52. data/app/views/compute_resources_vms/show/_proxmox.html.erb +2 -0
  53. data/lib/foreman_fog_proxmox/engine.rb +9 -10
  54. data/lib/foreman_fog_proxmox/hash_collection.rb +69 -0
  55. data/lib/foreman_fog_proxmox/version.rb +1 -1
  56. data/lib/tasks/foreman_fog_proxmox_tasks.rake +0 -3
  57. data/test/factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb +20 -8
  58. data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +5 -5
  59. data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +17 -7
  60. data/test/factories/proxmox_factory.rb +4 -4
  61. data/test/functional/compute_resources_controller_test.rb +4 -4
  62. data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +49 -29
  63. data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +53 -30
  64. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +22 -20
  65. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_volumes_helper_test.rb +50 -0
  66. data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +12 -5
  67. data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +38 -10
  68. data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +10 -10
  69. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +34 -24
  70. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +21 -7
  71. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cdrom_test.rb +181 -0
  72. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cloudinit_test.rb +131 -0
  73. 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
  74. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +21 -21
  75. data/test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb +3 -3
  76. metadata +44 -27
  77. data/app/helpers/proxmox_container_helper.rb +0 -163
  78. data/app/helpers/proxmox_server_helper.rb +0 -155
@@ -22,75 +22,29 @@ require 'fog/proxmox/helpers/nic_helper'
22
22
  require 'foreman_fog_proxmox/value'
23
23
 
24
24
  module ProxmoxVmHelper
25
- KILO = 1024
26
- MEGA = KILO * KILO
27
- GIGA = KILO * MEGA
28
-
29
- def object_to_config_hash(vm)
30
- vm_h = ActiveSupport::HashWithIndifferentAccess.new
31
- main_a = ['hostname', 'name', 'vmid']
32
- main = vm.attributes.select { |key, _value| main_a.include? key }
33
- main_a += ['templated']
34
- config = vm.config.attributes.reject { |key, _value| main_a.include?(key) || Fog::Proxmox::DiskHelper.disk?(key) || Fog::Proxmox::NicHelper.nic?(key) }
35
- vm_h = vm_h.merge(main)
36
- vm_h = vm_h.merge('config_attributes': config)
37
- vm_h
38
- end
39
-
40
- def add_cdrom_to_config_server(vm, config)
41
- cd_disks = vm.config.disks.select { |disk| disk.id == 'ide2' }
42
- cdrom = {}
43
- disk_to_cdrom(cd_disks.first, cdrom)
44
- config = config.merge(cdrom)
45
- config
46
- end
47
-
48
- def disk_to_cdrom(disk, cdrom)
49
- volid = disk.volid
50
- cdrom_a = ['none', 'cdrom']
51
- if cdrom_a.include? volid
52
- cdrom.store('cdrom', volid)
53
- else
54
- cdrom.store('cdrom', 'image')
55
- cdrom.store('cdrom_iso', volid)
56
- cdrom.store('cdrom_storage', disk.storage)
57
- end
58
- end
59
-
60
- def convert_memory_sizes(args)
61
- convert_memory_size(args['config_attributes'], 'memory')
62
- convert_memory_size(args['config_attributes'], 'balloon')
63
- convert_memory_size(args['config_attributes'], 'shares')
64
- convert_memory_size(args['config_attributes'], 'swap')
65
- end
66
-
67
- def convert_volumes_size(args)
68
- args['volumes_attributes'].each_value { |value| value['size'] = (value['size'].to_i / GIGA).to_s unless ForemanFogProxmox::Value.empty?(value['size']) }
69
- end
70
-
71
- def convert_sizes(args)
72
- convert_memory_size(args['config_attributes'], 'memory')
73
- convert_memory_size(args['config_attributes'], 'balloon')
74
- convert_memory_size(args['config_attributes'], 'shares')
75
- convert_memory_size(args['config_attributes'], 'swap')
76
- args['volumes_attributes'].each_value { |value| value['size'] = (value['size'].to_i / GIGA).to_s unless ForemanFogProxmox::Value.empty?(value['size']) }
77
- end
78
-
79
- def remove_deletes(args)
80
- args['volumes_attributes']&.delete_if { |_key, value| value.key? '_delete' }
81
- end
82
-
83
- def convert_memory_size(config_hash, key)
84
- # default unit memory size is Mb
85
- memory = (config_hash[key].to_i / MEGA).to_s == '0' ? config_hash[key] : (config_hash[key].to_i / MEGA).to_s
86
- config_hash.store(key, memory)
87
- end
88
-
89
- def vm_type(host)
90
- host.compute_object.type
91
- end
92
-
93
- def node_id(host)
94
- host.compute_object.node_id
25
+ include ProxmoxVmInterfacesHelper
26
+ include ProxmoxVmVolumesHelper
27
+ include ProxmoxVmConfigHelper
28
+ include ProxmoxVmOsTemplateHelper
29
+
30
+ def vm_collection(type)
31
+ collection = :servers
32
+ collection = :containers if type == 'lxc'
33
+ collection
34
+ end
35
+
36
+ # Convert a foreman form server/container vm hash into a fog-proxmox server/container attributes hash
37
+ def parse_typed_vm(args, type)
38
+ args = ActiveSupport::HashWithIndifferentAccess.new(args)
39
+ return {} unless args
40
+ return {} if args.empty?
41
+ return {} unless args['type'] == type
42
+
43
+ logger.debug("parse_typed_vm(#{type}): args=#{args}")
44
+ parsed_vm = parsed_typed_config(args, type)
45
+ parsed_vm = parsed_typed_interfaces(args, type, parsed_vm)
46
+ parsed_vm = parsed_typed_volumes(args, type, parsed_vm)
47
+ logger.debug("parse_typed_vm(#{type}): parsed_vm=#{parsed_vm}")
48
+ parsed_vm
95
49
  end
96
50
  end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+
12
+ # ForemanFogProxmox is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'fog/proxmox/helpers/disk_helper'
21
+ require 'fog/proxmox/helpers/nic_helper'
22
+ require 'foreman_fog_proxmox/value'
23
+ require 'foreman_fog_proxmox/hash_collection'
24
+
25
+ # Convert a foreman form server hash into a fog-proxmox server attributes hash
26
+ module ProxmoxVmInterfacesHelper
27
+ def parsed_typed_interfaces(args, type, parsed_vm)
28
+ interfaces_to_add, interfaces_to_delete = parse_typed_interfaces(args, type)
29
+ interfaces_to_add.each { |interface| parsed_vm = parsed_vm.merge(interface) }
30
+ parsed_vm = parsed_vm.merge(delete: interfaces_to_delete.join(',')) unless interfaces_to_delete.empty?
31
+ parsed_vm
32
+ end
33
+
34
+ def parse_typed_interfaces(args, type)
35
+ interfaces_to_add = []
36
+ interfaces_to_delete = []
37
+ interfaces_attributes = args['interfaces_attributes']
38
+ interfaces_attributes ||= args['config_attributes']['interfaces_attributes'] unless ForemanFogProxmox::Value.empty?(args['config_attributes'])
39
+ interfaces_attributes&.each_value { |value| add_or_delete_typed_interface(value, interfaces_to_delete, interfaces_to_add, type) }
40
+ [interfaces_to_add, interfaces_to_delete]
41
+ end
42
+
43
+ def interface_compute_attributes_typed_keys(type)
44
+ keys = ['rate', 'bridge', 'tag']
45
+ case type
46
+ when 'qemu'
47
+ keys += ['model', 'firewall', 'link_down', 'queues']
48
+ when 'lxc'
49
+ keys += ['name', 'ip', 'ip6', 'gw', 'gw6', 'dhcp', 'dhcp6', 'cidr', 'cidr6', 'firewall']
50
+ end
51
+ keys
52
+ end
53
+
54
+ def interface_common_typed_keys(type)
55
+ [{ origin: 'id', dest: 'id' }, { origin: 'mac', dest: type == 'qemu' ? 'macaddr' : 'hwaddr' }]
56
+ end
57
+
58
+ def compute_dhcps(interface_attributes_h)
59
+ interface_attributes_h[:dhcp] = interface_attributes_h[:ip] == 'dhcp' ? '1' : '0'
60
+ interface_attributes_h[:ip] = '' if interface_attributes_h[:dhcp] == '1'
61
+ interface_attributes_h[:dhcp6] = interface_attributes_h[:ip6] == 'dhcp' ? '1' : '0'
62
+ interface_attributes_h[:ip6] = '' if interface_attributes_h[:dhcp6] == '1'
63
+ end
64
+
65
+ def add_or_delete_typed_interface(interface_attributes, interfaces_to_delete, interfaces_to_add, type)
66
+ logger.debug("add_or_delete_typed_interface(#{type}): interface_attributes=#{interface_attributes}")
67
+ ForemanFogProxmox::HashCollection.remove_empty_values(interface_attributes)
68
+ ForemanFogProxmox::HashCollection.remove_empty_values(interface_attributes['compute_attributes']) if interface_attributes['compute_attributes']
69
+ nic = {}
70
+ id = interface_attributes['id']
71
+ delete = interface_attributes['_delete'].to_i == 1
72
+ if delete
73
+ logger.debug("add_or_delete_typed_interface(#{type}): delete id=#{id}")
74
+ interfaces_to_delete.push(id.to_s)
75
+ else
76
+ interface_common_typed_keys(type).each { |key| ForemanFogProxmox::HashCollection.add_and_format_element(nic, key[:dest].to_sym, interface_attributes, key[:origin]) }
77
+ interface_attributes_h = interface_attributes['compute_attributes']
78
+ interface_attributes_h ||= interface_attributes if ForemanFogProxmox::Value.empty?(interface_attributes['compute_attributes'])
79
+ interface_compute_attributes_typed_keys(type).each { |key| ForemanFogProxmox::HashCollection.add_and_format_element(nic, key.to_sym, interface_attributes_h, key) }
80
+ compute_dhcps(interface_attributes_h)
81
+ logger.debug("add_or_delete_typed_interface(#{type}): add nic=#{nic}")
82
+ interfaces_to_add.push(Fog::Proxmox::NicHelper.flatten(nic))
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+
12
+ # ForemanFogProxmox is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'fog/proxmox/helpers/disk_helper'
21
+ require 'fog/proxmox/helpers/nic_helper'
22
+ require 'foreman_fog_proxmox/value'
23
+ require 'foreman_fog_proxmox/hash_collection'
24
+
25
+ module ProxmoxVmOsTemplateHelper
26
+ def ostemplate_keys
27
+ ['ostemplate_storage', 'ostemplate_file']
28
+ end
29
+
30
+ def parse_ostemplate_without_keys(args)
31
+ parse_container_ostemplate(args.select { |key, _value| ostemplate_keys.include? key })
32
+ end
33
+
34
+ def parse_ostemplate(args, config)
35
+ ostemplate = parse_ostemplate_without_keys(args)
36
+ ostemplate = parse_ostemplate_without_keys(config) unless ostemplate[:ostemplate]
37
+ ostemplate
38
+ end
39
+
40
+ def parse_container_ostemplate(args)
41
+ ostemplate = args['ostemplate']
42
+ ostemplate_file = args['ostemplate_file']
43
+ ostemplate ||= ostemplate_file
44
+ parsed_ostemplate = { ostemplate: ostemplate }
45
+ parsed_ostemplate
46
+ end
47
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+
12
+ # ForemanFogProxmox is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'fog/proxmox/helpers/disk_helper'
21
+ require 'fog/proxmox/helpers/nic_helper'
22
+ require 'foreman_fog_proxmox/value'
23
+ require 'foreman_fog_proxmox/hash_collection'
24
+
25
+ # Convert a foreman form server hash into a fog-proxmox server attributes hash
26
+ module ProxmoxVmVolumesHelper
27
+ include ProxmoxVmCdromHelper
28
+ include ProxmoxVmCloudinitHelper
29
+ KILO = 1024
30
+ MEGA = KILO * KILO
31
+ GIGA = KILO * MEGA
32
+
33
+ def add_disk_options(disk, args)
34
+ options = ForemanFogProxmox::HashCollection.new_hash_reject_keys(args, ['id', 'volid', 'controller', 'device', 'storage', 'size', '_delete', 'storage_type'])
35
+ ForemanFogProxmox::HashCollection.remove_empty_values(options)
36
+ disk[:options] = options
37
+ end
38
+
39
+ def parsed_typed_volumes(args, type, parsed_vm)
40
+ logger.debug(format(_('parsed_typed_volumes(%<type>s): args=%<args>s'), args: args, type: type))
41
+ volumes_attributes = args['volumes_attributes']
42
+ volumes_attributes ||= args['config_attributes']['volumes_attributes'] unless ForemanFogProxmox::Value.empty?(args['config_attributes'])
43
+ volumes_attributes ||= args['vm_attrs']['volumes_attributes'] unless ForemanFogProxmox::Value.empty?(args['vm_attrs'])
44
+ volumes = parse_typed_volumes(volumes_attributes, type)
45
+ volumes.each { |volume| parsed_vm = parsed_vm.merge(volume) }
46
+ parsed_vm
47
+ end
48
+
49
+ def parse_hard_disk_volume(args)
50
+ disk = {}
51
+ disk[:id] = args['id'] if args.key?('id')
52
+ disk[:volid] = args['volid'] if args.key?('volid')
53
+ disk[:storage] = args['storage'].to_s if args.key?('storage')
54
+ disk[:size] = args['size'].to_i if args.key?('size')
55
+ add_disk_options(disk, args)
56
+ disk.key?(:storage) ? disk : {}
57
+ end
58
+
59
+ def volume_type?(args, type)
60
+ if args.key?('storage_type')
61
+ args['storage_type'] == type
62
+ else
63
+ Fog::Proxmox::DiskHelper.cloud_init?(args['volid']) if type == 'cloud_init'
64
+ Fog::Proxmox::DiskHelper.cdrom?(args['volid']) if type == 'cdrom'
65
+ Fog::Proxmox::DiskHelper.disk?(args['id']) if ['hard_disk', 'rootfs', 'mp'].include?(type)
66
+ end
67
+ end
68
+
69
+ def parse_typed_volume(args, type)
70
+ logger.debug(format(_('parse_typed_volume(%<type>s): args=%<args>s'), args: args, type: type))
71
+ disk = parse_hard_disk_volume(args) if volume_type?(args, 'hard_disk') || volume_type?(args, 'mp') || volume_type?(args, 'rootfs')
72
+ disk = parse_server_cloudinit(args) if volume_type?(args, 'cloud_init')
73
+ disk = parse_server_cdrom(args) if volume_type?(args, 'cdrom')
74
+ logger.debug(format(_('parse_typed_volume(%<type>s): disk=%<disk>s'), disk: disk, type: type))
75
+ Fog::Proxmox::DiskHelper.flatten(disk) unless disk.empty?
76
+ end
77
+
78
+ def add_typed_volume(volumes, value, type)
79
+ volume = parse_typed_volume(value, type)
80
+ volumes.push(volume) unless ForemanFogProxmox::Value.empty?(volume)
81
+ end
82
+
83
+ def parse_typed_volumes(args, type)
84
+ logger.debug(format(_('parse_typed_volumes(%<type>s): args=%<args>s'), args: args, type: type))
85
+ volumes = []
86
+ args&.each_value { |value| add_typed_volume(volumes, value, type) }
87
+ volumes
88
+ end
89
+
90
+ def convert_volumes_size(args)
91
+ args['volumes_attributes'].each_value { |value| value['size'] = (value['size'].to_i / GIGA).to_s unless ForemanFogProxmox::Value.empty?(value['size']) }
92
+ end
93
+
94
+ def convert_sizes(args)
95
+ convert_memory_size(args['config_attributes'], 'memory')
96
+ convert_memory_size(args['config_attributes'], 'balloon')
97
+ convert_memory_size(args['config_attributes'], 'shares')
98
+ convert_memory_size(args['config_attributes'], 'swap')
99
+ args['volumes_attributes'].each_value { |value| value['size'] = (value['size'].to_i / GIGA).to_s unless ForemanFogProxmox::Value.empty?(value['size']) }
100
+ end
101
+
102
+ def remove_volume_keys(args)
103
+ args['volumes_attributes'].each_value { |volume_attributes| ForemanFogProxmox::HashCollection.remove_keys(volume_attributes, ['_delete']) } if args.key?('volumes_attributes')
104
+ end
105
+ end
@@ -21,8 +21,23 @@ module FogExtensions
21
21
  module Proxmox
22
22
  module Disk
23
23
  extend ActiveSupport::Concern
24
- def templated?
25
- volid ? volid.match(/^([\w-]+)[:]base-(\d+)-disk-(\d+)/) : false
24
+
25
+ attr_accessor :ciuser, :cipassword, :searchdomain, :nameserver, :sshkeys
26
+
27
+ def storage_type
28
+ return 'cdrom' if cdrom?
29
+
30
+ cloud_init? ? 'cloud_init' : 'hard_disk'
31
+ end
32
+
33
+ def cdrom
34
+ return 'none' unless cdrom? || volid.nil?
35
+
36
+ ['none', 'cdrom'].include?(volid) ? volid : 'image'
37
+ end
38
+
39
+ def cloudinit
40
+ cloud_init? ? 'disk' : 'none'
26
41
  end
27
42
  end
28
43
  end
@@ -23,17 +23,32 @@ module FogExtensions
23
23
  module Proxmox
24
24
  module Interface
25
25
  extend ActiveSupport::Concern
26
- attr_accessor :dhcpv4, :dhcpv6, :gwv4, :gwv6
27
26
  def mac
28
27
  macaddr
29
28
  end
30
29
 
31
- def cidrv4_prefix
30
+ def dhcp
31
+ ip == 'dhcp'
32
+ end
33
+
34
+ def dhcp6
35
+ ip6 == 'dhcp'
36
+ end
37
+
38
+ def dhcp=(value)
39
+ @dhcp = value
40
+ end
41
+
42
+ def dhcp6=(value)
43
+ @dhcp6 = value
44
+ end
45
+
46
+ def cidr
32
47
  Fog::Proxmox::IpHelper.prefix(ip) if ip
33
48
  end
34
49
 
35
- def cidrv6_prefix
36
- Fog::Proxmox::IpHelper.prefix6(ip) if ip
50
+ def cidr6
51
+ Fog::Proxmox::IpHelper.prefix6(ip6) if ip6
37
52
  end
38
53
  end
39
54
  end
@@ -55,7 +55,7 @@ module FogExtensions
55
55
  delegate :description, to: :config
56
56
 
57
57
  def vm_description
58
- "Name=#{name}, vmid=#{vmid}"
58
+ format(_('Type %<type>s, node %<node>s, %<cpus>s CPUs and %<memory>s MB memory'), type: type, node: node_id, cpus: config.cores || '0', memory: config.memory / (1024 * 1024) || '0')
59
59
  end
60
60
 
61
61
  def select_nic(fog_nics, nic)
@@ -69,7 +69,7 @@ module FogExtensions
69
69
  end
70
70
 
71
71
  def volumes
72
- config.disks.reject(&:cdrom?)
72
+ config.disks
73
73
  end
74
74
 
75
75
  def disks
@@ -78,6 +78,7 @@ module FogExtensions
78
78
 
79
79
  delegate :vga, to: :config
80
80
  delegate :pool, to: :config
81
+ delegate :cloud_init?, to: :config
81
82
 
82
83
  def interfaces_attributes=(attrs); end
83
84
 
@@ -86,7 +87,11 @@ module FogExtensions
86
87
  def config_attributes=(attrs); end
87
88
 
88
89
  def templated?
89
- volumes.any?(&:templated?)
90
+ volumes.any?(&:template?)
91
+ end
92
+
93
+ def cdrom?
94
+ volumes.any?(&:cdrom?)
90
95
  end
91
96
  end
92
97
  end
@@ -24,38 +24,12 @@ module FogExtensions
24
24
  module ServerConfig
25
25
  extend ActiveSupport::Concern
26
26
  def cpu_type
27
- Fog::Proxmox::CpuHelper.extract_type(cpu)
27
+ Fog::Proxmox::CpuHelper.extract_cputype(cpu)
28
28
  end
29
29
 
30
- def spectre
31
- Fog::Proxmox::CpuHelper.has_spectre?(cpu)
32
- end
33
-
34
- def pcid
35
- Fog::Proxmox::CpuHelper.has_pcid?(cpu)
36
- end
37
-
38
- def cdrom
39
- if disks.cdrom
40
- ['none', 'cdrom'].include?(disks.cdrom.volid) ? disks.cdrom.volid : 'image'
41
- else
42
- 'none'
43
- end
44
- end
45
-
46
- def cdrom_storage
47
- disks.cdrom ? disks.cdrom.storage : ''
48
- end
49
-
50
- def cdrom_iso
51
- disks.cdrom ? disks.cdrom.volid : ''
52
- end
53
-
54
- def cdrom_image
55
- if disks.cdrom
56
- ['none', 'cdrom'].include?(disks.cdrom.volid) ? disks.cdrom.volid : 'image'
57
- else
58
- 'none'
30
+ Fog::Proxmox::CpuHelper.flags.each do |flag_key, flag_value|
31
+ define_method(flag_key) do
32
+ Fog::Proxmox::CpuHelper.flag_value(cpu, flag_value)
59
33
  end
60
34
  end
61
35
 
@@ -66,6 +40,10 @@ module FogExtensions
66
40
  def rootfs_file
67
41
  disks.rootfs&.volid
68
42
  end
43
+
44
+ def cloud_init?
45
+ disks.any?(&:cloud_init?)
46
+ end
69
47
  end
70
48
  end
71
49
  end