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.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -5
  3. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +36 -2
  4. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +134 -60
  5. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js +2 -50
  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/controllers/foreman_fog_proxmox/compute_resources_controller.rb +23 -25
  11. data/app/helpers/proxmox_compute_controllers_helper.rb +39 -0
  12. data/app/helpers/proxmox_compute_resources_helper.rb +49 -0
  13. data/app/helpers/proxmox_compute_selectors_helper.rb +6 -44
  14. data/app/helpers/proxmox_form_helper.rb +12 -4
  15. data/app/{models/concerns/fog_extensions/proxmox/volume.rb → helpers/proxmox_storages_helper.rb} +5 -8
  16. data/app/helpers/proxmox_vm_cdrom_helper.rb +35 -0
  17. data/app/helpers/proxmox_vm_cloudinit_helper.rb +43 -0
  18. data/app/helpers/proxmox_vm_config_helper.rb +160 -0
  19. data/app/helpers/proxmox_vm_helper.rb +24 -62
  20. data/app/helpers/proxmox_vm_interfaces_helper.rb +85 -0
  21. data/app/helpers/proxmox_vm_os_template_helper.rb +47 -0
  22. data/app/{models/foreman_fog_proxmox/proxmox_token_expiration.rb → helpers/proxmox_vm_uuid_helper.rb} +14 -10
  23. data/app/helpers/proxmox_vm_volumes_helper.rb +105 -0
  24. data/app/models/concerns/fog_extensions/proxmox/disk.rb +17 -2
  25. data/app/models/concerns/fog_extensions/proxmox/interface.rb +19 -4
  26. data/app/models/concerns/fog_extensions/proxmox/server.rb +12 -3
  27. data/app/models/concerns/fog_extensions/proxmox/server_config.rb +8 -30
  28. data/app/models/concerns/host_ext/proxmox/interfaces.rb +7 -2
  29. data/app/models/concerns/orchestration/proxmox/compute.rb +49 -0
  30. data/app/models/foreman_fog_proxmox/proxmox.rb +58 -15
  31. data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +14 -18
  32. data/app/models/foreman_fog_proxmox/proxmox_connection.rb +14 -9
  33. data/app/models/foreman_fog_proxmox/proxmox_images.rb +2 -1
  34. data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +53 -28
  35. data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +1 -1
  36. data/app/models/foreman_fog_proxmox/proxmox_version.rb +7 -2
  37. data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +19 -31
  38. data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +108 -94
  39. data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +9 -6
  40. data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +79 -22
  41. data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +6 -2
  42. data/app/views/api/v2/compute_resources/proxmox.json.rabl +1 -1
  43. data/app/views/compute_resources/form/_proxmox.html.erb +23 -10
  44. data/app/views/compute_resources/show/_proxmox.html.erb +6 -6
  45. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +3 -1
  46. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +46 -29
  47. data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +3 -3
  48. data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +2 -1
  49. data/app/views/compute_resources_vms/form/proxmox/container/_network.html.erb +8 -7
  50. data/app/views/compute_resources_vms/form/proxmox/server/_advanced.html.erb +0 -2
  51. data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +15 -14
  52. data/app/views/compute_resources_vms/form/proxmox/server/_network.html.erb +2 -2
  53. data/app/views/compute_resources_vms/form/proxmox/server/_volume_cdrom.html.erb +34 -0
  54. data/app/views/compute_resources_vms/form/proxmox/server/_volume_cloud_init.html.erb +29 -0
  55. data/app/views/compute_resources_vms/form/proxmox/server/{_volume.html.erb → _volume_hard_disk.html.erb} +7 -3
  56. data/app/views/compute_resources_vms/show/_proxmox.html.erb +2 -0
  57. data/config/routes.rb +7 -7
  58. data/db/migrate/20210312105013_update_proxmox_uuid_host.rb +29 -0
  59. data/lib/foreman_fog_proxmox/engine.rb +15 -10
  60. data/lib/foreman_fog_proxmox/hash_collection.rb +69 -0
  61. data/lib/foreman_fog_proxmox/version.rb +1 -1
  62. data/lib/tasks/foreman_fog_proxmox_tasks.rake +0 -3
  63. data/test/factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb +20 -8
  64. data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +5 -5
  65. data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +17 -7
  66. data/test/factories/proxmox_factory.rb +4 -4
  67. data/test/functional/compute_resources_controller_test.rb +4 -4
  68. data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +53 -32
  69. data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +56 -31
  70. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +22 -20
  71. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_uuid_helper_test.rb +38 -0
  72. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_volumes_helper_test.rb +50 -0
  73. data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +10 -11
  74. data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +38 -10
  75. data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +10 -10
  76. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +34 -24
  77. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +8 -8
  78. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cdrom_test.rb +181 -0
  79. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cloudinit_test.rb +131 -0
  80. 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
  81. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +21 -21
  82. data/test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb +3 -3
  83. data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +3 -3
  84. metadata +44 -23
  85. data/app/helpers/proxmox_container_helper.rb +0 -163
  86. data/app/helpers/proxmox_server_helper.rb +0 -155
@@ -1,155 +0,0 @@
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
-
24
- module ProxmoxServerHelper
25
- def parse_server_vm(args)
26
- logger.debug("parse_server_vm args=#{args}")
27
- args = ActiveSupport::HashWithIndifferentAccess.new(args)
28
- return {} unless args
29
- return {} if args.empty?
30
- return {} unless args['type'] == 'qemu'
31
-
32
- config = args['config_attributes']
33
- main_a = ['name', 'type', 'node_id', 'vmid', 'interfaces', 'mount_points', 'disks']
34
- config ||= args.reject { |key, _value| main_a.include? key }
35
- cdrom_a = ['cdrom', 'cdrom_storage', 'cdrom_iso']
36
- cdrom = parse_server_cdrom(config.select { |key, _value| cdrom_a.include? key })
37
- vols = args['volumes_attributes']
38
- volumes = parse_server_volumes(vols)
39
- cpu_a = ['cpu_type', 'spectre', 'pcid']
40
- cpu = parse_server_cpu(config.select { |key, _value| cpu_a.include? key })
41
- memory_a = ['memory', 'balloon', 'shares']
42
- memory = parse_server_memory(config.select { |key, _value| memory_a.include? key })
43
- interfaces_attributes = args['interfaces_attributes']
44
- interfaces_to_add, interfaces_to_delete = parse_server_interfaces(interfaces_attributes)
45
- general_a = ['node_id', 'type', 'config_attributes', 'volumes_attributes', 'interfaces_attributes']
46
- general_a += ['firmware_type', 'provision_method', 'container_volumes', 'server_volumes', 'start_after_create']
47
- logger.debug("general_a: #{general_a}")
48
- parsed_vm = args.reject { |key, value| general_a.include?(key) || ForemanFogProxmox::Value.empty?(value) }
49
- config_a = []
50
- config_a += cpu_a
51
- config_a += cdrom_a
52
- config_a += memory_a
53
- config_a += general_a
54
- parsed_config = config.reject { |key, value| config_a.include?(key) || ForemanFogProxmox::Value.empty?(value) }
55
- logger.debug("parse_server_config(): #{parsed_config}")
56
- parsed_vm = parsed_vm.merge(parsed_config).merge(cpu).merge(memory).merge(cdrom)
57
- interfaces_to_add.each { |interface| parsed_vm = parsed_vm.merge(interface) }
58
- parsed_vm = parsed_vm.merge(delete: interfaces_to_delete.join(',')) unless interfaces_to_delete.empty?
59
- volumes.each { |volume| parsed_vm = parsed_vm.merge(volume) }
60
- logger.debug("parse_server_vm(): #{parsed_vm}")
61
- parsed_vm
62
- end
63
-
64
- def parse_server_memory(args)
65
- memory = {}
66
- memory.store(:memory, args['memory'].to_i) if args['memory']
67
- memory.store(:shares, args['shares'].to_i) if args['shares']
68
- memory.store(:balloon, args['balloon'].to_i) if args['balloon']
69
- logger.debug("parse_server_memory(): #{memory}")
70
- memory
71
- end
72
-
73
- def parse_server_cpu(args)
74
- return {} unless args['cpu_type']
75
-
76
- cpu = "cputype=#{args['cpu_type']}"
77
- spectre = args['spectre'].to_i == 1
78
- pcid = args['pcid'].to_i == 1
79
- cpu += ',flags=' if spectre || pcid
80
- cpu += '+spec-ctrl' if spectre
81
- cpu += ';' if spectre && pcid
82
- cpu += '+pcid' if pcid
83
- args.delete_if { |key, value| ['cpu_type', 'spectre', 'pcid'].include?(key) || ForemanFogProxmox::Value.empty?(value) }
84
- args.each_value(&:to_i)
85
- parsed_cpu = { cpu: cpu }.merge(args)
86
- logger.debug("parse_server_cpu(): #{parsed_cpu}")
87
- parsed_cpu
88
- end
89
-
90
- def parse_server_cdrom(args)
91
- cdrom = args['cdrom']
92
- cdrom_image = args['cdrom_iso']
93
- volid = cdrom_image.empty? ? cdrom : cdrom_image
94
- return {} unless volid
95
-
96
- cdrom = "#{volid},media=cdrom"
97
- { ide2: cdrom }
98
- end
99
-
100
- def parse_server_volume(args)
101
- disk = {}
102
- volid = args['volid'] if args.key?('volid')
103
- id = args['id'] if volid
104
- id = "#{args['controller']}#{args['device']}" if args.key?('controller') && args.key?('device') && !id
105
- return args if ForemanFogProxmox::Value.empty?(id) || id == 'rootfs'
106
-
107
- args.delete_if { |_key, value| ForemanFogProxmox::Value.empty?(value) }
108
- disk.store(:id, id)
109
- disk.store(:volid, args['volid']) if args.key?('volid')
110
- disk.store(:storage, args['storage'].to_s) if args.key?('storage')
111
- disk.store(:size, args['size'].to_i) if args.key?('size')
112
- options = args.reject { |key, _value| ['id', 'volid', 'controller', 'device', 'storage', 'size', '_delete'].include? key }
113
- disk.store(:options, options)
114
- logger.debug("parse_server_volume(): disk=#{disk}")
115
- Fog::Proxmox::DiskHelper.flatten(disk)
116
- end
117
-
118
- def parse_server_volumes(args)
119
- volumes = []
120
- args&.each_value { |value| volumes.push(parse_server_volume(value)) }
121
- logger.debug("parse_server_volumes(): volumes=#{volumes}")
122
- volumes
123
- end
124
-
125
- def parse_server_interfaces(interfaces_attributes)
126
- interfaces_to_add = []
127
- interfaces_to_delete = []
128
- interfaces_attributes&.each_value { |value| add_server_interface(value, interfaces_to_delete, interfaces_to_add) }
129
- logger.debug("parse_server_interfaces(): interfaces_to_delete=#{interfaces_to_delete} interfaces_to_add=#{interfaces_to_add}")
130
- [interfaces_to_add, interfaces_to_delete]
131
- end
132
-
133
- def add_server_interface(interface_attributes, interfaces_to_delete, interfaces_to_add)
134
- interface_attributes.delete_if { |_key, value| ForemanFogProxmox::Value.empty?(value) }
135
- nic = {}
136
- id = interface_attributes['id']
137
- logger.debug("add_server_interface(): id=#{id}")
138
- delete = interface_attributes['_delete'].to_i == 1
139
- if delete
140
- interfaces_to_delete.push(id.to_s)
141
- else
142
- nic.store(:id, id)
143
- nic.store(:macaddr, interface_attributes['macaddr']) if interface_attributes['macaddr']
144
- nic.store(:tag, interface_attributes['tag'].to_i) if interface_attributes['tag']
145
- nic.store(:model, interface_attributes['model'].to_s)
146
- nic.store(:bridge, interface_attributes['bridge'].to_s) if interface_attributes['bridge']
147
- nic.store(:firewall, interface_attributes['firewall'].to_i) if interface_attributes['firewall']
148
- nic.store(:rate, interface_attributes['rate'].to_i) if interface_attributes['rate']
149
- nic.store(:link_down, interface_attributes['link_down'].to_i) if interface_attributes['link_down']
150
- nic.store(:queues, interface_attributes['queues'].to_i) if interface_attributes['queues']
151
- logger.debug("add_server_interface(): add nic=#{nic}")
152
- interfaces_to_add.push(Fog::Proxmox::NicHelper.flatten(nic))
153
- end
154
- end
155
- end