foreman_fog_proxmox 0.8.0 → 0.8.2

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 (93) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -1
  3. data/Rakefile +3 -1
  4. data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +2 -2
  5. data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +2 -2
  6. data/app/helpers/node_dashboard_helper.rb +13 -14
  7. data/app/helpers/proxmox_compute_selectors_helper.rb +49 -50
  8. data/app/helpers/proxmox_container_helper.rb +42 -36
  9. data/app/helpers/proxmox_form_helper.rb +38 -40
  10. data/app/helpers/proxmox_server_helper.rb +39 -41
  11. data/app/helpers/proxmox_vm_helper.rb +21 -25
  12. data/app/models/concerns/fog_extensions/proxmox/disk.rb +8 -8
  13. data/app/models/concerns/fog_extensions/proxmox/interface.rb +8 -8
  14. data/app/models/concerns/fog_extensions/proxmox/node.rb +24 -22
  15. data/app/models/concerns/fog_extensions/proxmox/server.rb +71 -59
  16. data/app/models/concerns/fog_extensions/proxmox/server_config.rb +47 -39
  17. data/app/models/concerns/fog_extensions/proxmox/volume.rb +8 -8
  18. data/app/models/concerns/host_ext/proxmox/interfaces.rb +21 -13
  19. data/app/models/concerns/orchestration/proxmox/compute.rb +14 -10
  20. data/app/models/foreman_fog_proxmox/options_select.rb +14 -14
  21. data/app/models/foreman_fog_proxmox/proxmox.rb +30 -466
  22. data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +54 -0
  23. data/app/models/foreman_fog_proxmox/proxmox_connection.rb +67 -0
  24. data/app/models/foreman_fog_proxmox/proxmox_console.rb +41 -0
  25. data/app/models/foreman_fog_proxmox/proxmox_images.rb +53 -0
  26. data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +60 -0
  27. data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +49 -0
  28. data/app/models/foreman_fog_proxmox/proxmox_token_expiration.rb +30 -0
  29. data/app/models/foreman_fog_proxmox/proxmox_version.rb +36 -0
  30. data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +108 -0
  31. data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +162 -0
  32. data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +74 -0
  33. data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +85 -0
  34. data/app/overrides/compute_resources_vms/form/add_clone_to_new_vm_compute_detail.rb +7 -6
  35. data/app/overrides/compute_resources_vms/form/add_from_profile_to_compute_attributes_form.rb +13 -11
  36. data/app/overrides/compute_resources_vms/form/add_vm_type_to_networks_form.rb +13 -11
  37. data/app/overrides/compute_resources_vms/form/add_vm_type_to_nic_provider_specific_form.rb +8 -7
  38. data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_edit.rb +7 -6
  39. data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_new_volume.rb +7 -6
  40. data/app/overrides/compute_resources_vms/form/remove_new_vm_from_removable_layout.rb +7 -6
  41. data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +16 -16
  42. data/app/views/api/v2/compute_resources/proxmox.json.rabl +3 -1
  43. data/app/views/compute_resources/form/_proxmox.html.erb +3 -0
  44. data/app/views/compute_resources/show/_proxmox.html.erb +8 -0
  45. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_attributes_form.html.erb +5 -0
  46. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_form.html.erb +6 -1
  47. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_hosts_compute_detail_form.html.erb +6 -0
  48. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_form.html.erb +6 -2
  49. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_new_childs_form.html.erb +8 -2
  50. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +6 -0
  51. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +15 -1
  52. data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +2 -2
  53. data/app/views/compute_resources_vms/form/proxmox/_general.html.erb +1 -1
  54. data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +6 -1
  55. data/app/views/compute_resources_vms/form/proxmox/container/_extended.html.erb +1 -1
  56. data/app/views/compute_resources_vms/form/proxmox/container/_volume_mp.html.erb +1 -1
  57. data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +1 -1
  58. data/app/views/compute_resources_vms/form/proxmox/server/_volume.html.erb +2 -2
  59. data/config/routes.rb +4 -4
  60. data/lib/foreman_fog_proxmox/engine.rb +14 -14
  61. data/lib/foreman_fog_proxmox/semver.rb +78 -78
  62. data/lib/foreman_fog_proxmox/value.rb +5 -3
  63. data/lib/foreman_fog_proxmox/version.rb +1 -1
  64. data/lib/tasks/foreman_fog_proxmox_tasks.rake +3 -13
  65. data/locale/en/foreman_fog_proxmox.edit.po +472 -0
  66. data/locale/en/foreman_fog_proxmox.po +48 -24
  67. data/locale/en/foreman_fog_proxmox.po.time_stamp +0 -0
  68. data/locale/foreman_fog_proxmox.pot +140 -102
  69. data/locale/fr/foreman_fog_proxmox.edit.po +472 -0
  70. data/locale/fr/foreman_fog_proxmox.po +52 -28
  71. data/locale/fr/foreman_fog_proxmox.po.time_stamp +0 -0
  72. data/locale/gemspec.rb +2 -0
  73. data/test/{unit/foreman_fog_proxmox/proxmox_test_helpers.rb → factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb} +4 -140
  74. data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +61 -0
  75. data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +134 -0
  76. data/test/factories/proxmox_factory.rb +15 -15
  77. data/test/functional/compute_resources_controller_test.rb +12 -10
  78. data/test/test_plugin_helper.rb +2 -0
  79. data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +178 -182
  80. data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +122 -126
  81. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +180 -187
  82. data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +116 -0
  83. data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +71 -0
  84. data/test/unit/foreman_fog_proxmox/proxmox_test.rb +9 -479
  85. data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +82 -0
  86. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +207 -0
  87. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +92 -0
  88. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +324 -0
  89. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_test.rb +43 -0
  90. data/test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb +71 -0
  91. data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +63 -0
  92. data/test/unit/foreman_fog_proxmox/semver_test.rb +67 -53
  93. metadata +52 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 481cace7d30a49fb40a61fe50041ff10a278d674fd0420eca29c6bb756dfff9d
4
- data.tar.gz: ff60cb1dd7b8793c19146431ed0c41b7f15a9e7a2379474f7b6ef80f6c8ee213
3
+ metadata.gz: a89e9ca117817df602b86ef2526b7b9609ada877f243537dafa986bfd914ba1d
4
+ data.tar.gz: d446b8b4fa4ec604e8c6a883c5c1ded87787df79dc1243c445e3c5e6bc3a811e
5
5
  SHA512:
6
- metadata.gz: e6eb265bcc6d768b55d10df5987bd3fa003960f7adbb54072d54edb46a84e5f5bb51b16565665f497ef2848ae996a80f58132ebe8c2be8370ce044cb945a9ff6
7
- data.tar.gz: ccc4f415b32b1ef39a628a2d30048464612c35707c5be757248e0e69dddf2c314f5dbbf066c0f219506a164e61610935af7794f76bdf26864f4897e42b7ac139
6
+ metadata.gz: b0623b6a0ab2b6d8b9b247e3bad1808fc07cf49edf58997a3199161567c151aea9e464eba9f60724aa6d0d3192f93f59c621e3b3aad45e3c1c262bb163f12b3a
7
+ data.tar.gz: 48c023299b4d8801b6b6a2784530a52e92ba74ddb4a8c288a5ccc1b7ae9db9be2cafcd6ee35cf8239aa757d4f975fddc60b0e160fb1db4489a90a3fb86425b46
data/README.md CHANGED
@@ -18,7 +18,7 @@ If you like it and need more features you can [support](.github/SUPPORT.md) it.
18
18
  |--|--|--|--|--|
19
19
  |<0.6|<5.3|<0.6|<=1.20|>=2.3|
20
20
  |=0.6|=5.3|=0.6|=1.21|>=2.3|
21
- |>=0.7|=5.4|>=0.7|>=1.22|>=2.3|
21
+ |<= 0.8 |=5.4|>=0.7|>=1.22|>=2.3|
22
22
 
23
23
  ## Installation
24
24
 
@@ -131,6 +131,10 @@ gem 'simplecov' # test
131
131
  bundle install --without libvirt postgresql mysql2
132
132
  ```
133
133
 
134
+ ```shell
135
+ npm install
136
+ ```
137
+
134
138
  * Configure foreman settings:
135
139
 
136
140
  ```shell
@@ -169,6 +173,12 @@ export DISABLE_SPRING=true
169
173
  bundle exec bin/rake test TEST=test/functional/compute_resources_controller_test.rb
170
174
  ```
171
175
 
176
+ * See deface overrides result:
177
+
178
+ ```shell
179
+ bundle exec bin/rake deface:get_result['hosts/_compute_detail']
180
+ ```
181
+
172
182
  * In foreman directory, after you modify foreman_fog_proxmox specific assets (proxmox.js, etc) you have to precompile it:
173
183
 
174
184
  ```shell
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rake
2
+ # frozen_string_literal: true
3
+
2
4
  begin
3
5
  require 'bundler/setup'
4
6
  rescue LoadError
@@ -38,7 +40,7 @@ task default: :test
38
40
  begin
39
41
  require 'rubocop/rake_task'
40
42
  RuboCop::RakeTask.new
41
- rescue StandardError => _
43
+ rescue StandardError => _e
42
44
  puts 'Rubocop not loaded.'
43
45
  end
44
46
 
@@ -25,9 +25,9 @@ module ForemanFogProxmox
25
25
 
26
26
  class_methods do
27
27
  def compute_resource_params_filter
28
- super.tap do |filter|
28
+ super.tap do |filter|
29
29
  filter.permit :ssl_verify_peer,
30
- :ssl_certs, :node_id, :disable_proxy, :cr_id
30
+ :ssl_certs, :node_id, :disable_proxy, :cr_id, :renew
31
31
  end
32
32
  end
33
33
 
@@ -23,7 +23,7 @@ module ForemanFogProxmox
23
23
 
24
24
  # GET foreman_fog_proxmox/isos/:storage
25
25
  def isos
26
- volumes = @compute_resource.images_by_storage('iso',params[:storage])
26
+ volumes = @compute_resource.images_by_storage(params[:storage], 'iso')
27
27
  respond_to do |format|
28
28
  format.json { render :json => volumes }
29
29
  end
@@ -31,7 +31,7 @@ module ForemanFogProxmox
31
31
 
32
32
  # GET foreman_fog_proxmox/ostemplates/:storage
33
33
  def ostemplates
34
- volumes = @compute_resource.images_by_storage('vztmpl',params[:storage])
34
+ volumes = @compute_resource.images_by_storage(params[:storage], 'vztmpl')
35
35
  respond_to do |format|
36
36
  format.json { render :json => volumes }
37
37
  end
@@ -18,19 +18,18 @@
18
18
  # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module NodeDashboardHelper
21
-
22
- def compute_data(statistics)
23
- data = []
24
- statistics.each do |statistic|
25
- t = Time.at(statistic['time'])
26
- x = t.hour.to_s + ':' + t.min.to_s
27
- data << [x,statistic['loadavg']*100]
28
- end
29
- data
21
+ def compute_data(statistics)
22
+ data = []
23
+ statistics.each do |statistic|
24
+ t = Time.zone.at(statistic['time'])
25
+ x = t.hour.to_s + ':' + t.min.to_s
26
+ data << [x, statistic['loadavg'] * 100]
30
27
  end
28
+ data
29
+ end
31
30
 
32
- def render_node_statistics(statistics,options = {})
33
- data = compute_data(statistics)
34
- flot_bar_chart("node_statistics", _("Time"), _("Average load (x100)"), data, options)
35
- end
36
- end
31
+ def render_node_statistics(statistics, options = {})
32
+ data = compute_data(statistics)
33
+ flot_bar_chart('node_statistics', _('Time'), _('Average load (x100)'), data, options)
34
+ end
35
+ end
@@ -18,7 +18,6 @@
18
18
  # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module ProxmoxComputeSelectorsHelper
21
-
22
21
  def proxmox_types_map
23
22
  [OpenStruct.new(id: 'qemu', name: 'KVM/Qemu server'),
24
23
  OpenStruct.new(id: 'lxc', name: 'LXC container')]
@@ -28,7 +27,7 @@ module ProxmoxComputeSelectorsHelper
28
27
  [OpenStruct.new(id: 'amd64', name: '64 bits'),
29
28
  OpenStruct.new(id: 'i386', name: '32 bits')]
30
29
  end
31
-
30
+
32
31
  def proxmox_ostypes_map
33
32
  [OpenStruct.new(id: 'debian', name: 'Debian'),
34
33
  OpenStruct.new(id: 'ubuntu', name: 'Ubuntu'),
@@ -42,29 +41,29 @@ module ProxmoxComputeSelectorsHelper
42
41
  end
43
42
 
44
43
  def proxmox_controllers_map
45
- [ForemanFogProxmox::OptionsSelect.new(id:'ide', name: 'IDE', range: 3),
46
- ForemanFogProxmox::OptionsSelect.new(id:'sata', name: 'SATA', range: 5),
47
- ForemanFogProxmox::OptionsSelect.new(id:'scsi', name: 'SCSI', range: 13),
48
- ForemanFogProxmox::OptionsSelect.new(name:'VirtIO Block', id: 'virtio', range: 15)]
44
+ [ForemanFogProxmox::OptionsSelect.new(id: 'ide', name: 'IDE', range: 3),
45
+ ForemanFogProxmox::OptionsSelect.new(id: 'sata', name: 'SATA', range: 5),
46
+ ForemanFogProxmox::OptionsSelect.new(id: 'scsi', name: 'SCSI', range: 13),
47
+ ForemanFogProxmox::OptionsSelect.new(name: 'VirtIO Block', id: 'virtio', range: 15)]
49
48
  end
50
49
 
51
50
  def proxmox_operating_systems_map
52
- [OpenStruct.new(id: 'other', name: 'Unspecified OS'),
53
- OpenStruct.new(id: 'wxp', name: 'Microsoft Windows XP'),
54
- OpenStruct.new(id: 'w2k', name: 'Microsoft Windows 2000'),
55
- OpenStruct.new(id: 'w2k3', name: 'Microsoft Windows 2003'),
56
- OpenStruct.new(id: 'w2k8', name: 'Microsoft Windows 2008'),
57
- OpenStruct.new(id: 'wvista', name: 'Microsoft Windows Vista'),
58
- OpenStruct.new(id: 'win7', name: 'Microsoft Windows 7'),
59
- OpenStruct.new(id: 'win8', name: 'Microsoft Windows 8/2012/2012r2'),
60
- OpenStruct.new(id: 'win10', name: 'Microsoft Windows 10/2016'),
61
- OpenStruct.new(id: 'l24', name: 'Linux 2.4 Kernel'),
62
- OpenStruct.new(id: 'l26', name: 'Linux 2.6/3.X + Kernel'),
63
- OpenStruct.new(id: 'solaris', name: 'Solaris/OpenSolaris/OpenIndiania kernel')]
51
+ [OpenStruct.new(id: 'other', name: 'Unspecified OS'),
52
+ OpenStruct.new(id: 'wxp', name: 'Microsoft Windows XP'),
53
+ OpenStruct.new(id: 'w2k', name: 'Microsoft Windows 2000'),
54
+ OpenStruct.new(id: 'w2k3', name: 'Microsoft Windows 2003'),
55
+ OpenStruct.new(id: 'w2k8', name: 'Microsoft Windows 2008'),
56
+ OpenStruct.new(id: 'wvista', name: 'Microsoft Windows Vista'),
57
+ OpenStruct.new(id: 'win7', name: 'Microsoft Windows 7'),
58
+ OpenStruct.new(id: 'win8', name: 'Microsoft Windows 8/2012/2012r2'),
59
+ OpenStruct.new(id: 'win10', name: 'Microsoft Windows 10/2016'),
60
+ OpenStruct.new(id: 'l24', name: 'Linux 2.4 Kernel'),
61
+ OpenStruct.new(id: 'l26', name: 'Linux 2.6/3.X + Kernel'),
62
+ OpenStruct.new(id: 'solaris', name: 'Solaris/OpenSolaris/OpenIndiania kernel')]
64
63
  end
65
64
 
66
65
  def proxmox_vgas_map
67
- [OpenStruct.new(id: 'std', name: 'Standard VGA'),
66
+ [OpenStruct.new(id: 'std', name: 'Standard VGA'),
68
67
  OpenStruct.new(id: 'vmware', name: 'Vmware compatible'),
69
68
  OpenStruct.new(id: 'qxl', name: 'SPICE'),
70
69
  OpenStruct.new(id: 'qxl2', name: 'SPICE 2 monnitors'),
@@ -78,39 +77,39 @@ module ProxmoxComputeSelectorsHelper
78
77
 
79
78
  def proxmox_keyboards_map
80
79
  [OpenStruct.new(id: 'de', name: 'Deutsch'),
81
- OpenStruct.new(id: 'de-ch', name: 'Deutsch (Swiss)'),
82
- OpenStruct.new(id: 'da', name: 'Danish'),
83
- OpenStruct.new(id: 'en-gb', name: 'English (UK)'),
84
- OpenStruct.new(id: 'en-us', name: 'English (US)'),
85
- OpenStruct.new(id: 'es', name: 'Spanish'),
86
- OpenStruct.new(id: 'fi', name: 'Finnish'),
87
- OpenStruct.new(id: 'fr', name: 'French'),
88
- OpenStruct.new(id: 'fr-be', name: 'French (Belgium)'),
89
- OpenStruct.new(id: 'fr-ca', name: 'French (Canadian)'),
90
- OpenStruct.new(id: 'fr-ch', name: 'French (Swiss)'),
91
- OpenStruct.new(id: 'hu', name: 'Hungarian'),
92
- OpenStruct.new(id: 'is', name: 'Israelian'),
93
- OpenStruct.new(id: 'it', name: 'Italian'),
94
- OpenStruct.new(id: 'ja', name: 'Japanese'),
95
- OpenStruct.new(id: 'lt', name: 'Lituanian'),
96
- OpenStruct.new(id: 'mk', name: ''),
97
- OpenStruct.new(id: 'nl', name: 'Nederland'),
98
- OpenStruct.new(id: 'no', name: 'Norway'),
99
- OpenStruct.new(id: 'pl', name: 'Polish'),
100
- OpenStruct.new(id: 'pt', name: 'Portugese'),
101
- OpenStruct.new(id: 'pt-br', name: 'Portugese (Brasilian)'),
102
- OpenStruct.new(id: 'sv', name: 'Sv'),
103
- OpenStruct.new(id: 'sl', name: 'Slovakian'),
104
- OpenStruct.new(id: 'tr', name: 'Tr')]
80
+ OpenStruct.new(id: 'de-ch', name: 'Deutsch (Swiss)'),
81
+ OpenStruct.new(id: 'da', name: 'Danish'),
82
+ OpenStruct.new(id: 'en-gb', name: 'English (UK)'),
83
+ OpenStruct.new(id: 'en-us', name: 'English (US)'),
84
+ OpenStruct.new(id: 'es', name: 'Spanish'),
85
+ OpenStruct.new(id: 'fi', name: 'Finnish'),
86
+ OpenStruct.new(id: 'fr', name: 'French'),
87
+ OpenStruct.new(id: 'fr-be', name: 'French (Belgium)'),
88
+ OpenStruct.new(id: 'fr-ca', name: 'French (Canadian)'),
89
+ OpenStruct.new(id: 'fr-ch', name: 'French (Swiss)'),
90
+ OpenStruct.new(id: 'hu', name: 'Hungarian'),
91
+ OpenStruct.new(id: 'is', name: 'Israelian'),
92
+ OpenStruct.new(id: 'it', name: 'Italian'),
93
+ OpenStruct.new(id: 'ja', name: 'Japanese'),
94
+ OpenStruct.new(id: 'lt', name: 'Lituanian'),
95
+ OpenStruct.new(id: 'mk', name: ''),
96
+ OpenStruct.new(id: 'nl', name: 'Nederland'),
97
+ OpenStruct.new(id: 'no', name: 'Norway'),
98
+ OpenStruct.new(id: 'pl', name: 'Polish'),
99
+ OpenStruct.new(id: 'pt', name: 'Portugese'),
100
+ OpenStruct.new(id: 'pt-br', name: 'Portugese (Brasilian)'),
101
+ OpenStruct.new(id: 'sv', name: 'Sv'),
102
+ OpenStruct.new(id: 'sl', name: 'Slovakian'),
103
+ OpenStruct.new(id: 'tr', name: 'Tr')]
105
104
  end
106
105
 
107
106
  def get_controller(id)
108
- proxmox_controllers_map.find { |controller| controller.id == id}
107
+ proxmox_controllers_map.find { |controller| controller.id == id }
109
108
  end
110
109
 
111
110
  def proxmox_max_device(id)
112
111
  options_select = get_controller(id)
113
- options_select ? options_select.range : 1
112
+ options_select ? options_select.range : 1
114
113
  end
115
114
 
116
115
  def proxmox_caches_map
@@ -158,14 +157,14 @@ module ProxmoxComputeSelectorsHelper
158
157
  OpenStruct.new(id: 'lsi53c810', name: 'lsi53c810'),
159
158
  OpenStruct.new(id: 'megasas', name: 'megasas'),
160
159
  OpenStruct.new(id: 'virtio-scsi-pci', name: 'virtio-scsi-pci'),
161
- OpenStruct.new(id: 'virtio-scsi-single', name: 'virtio-scsi-single'),
160
+ OpenStruct.new(id: 'virtio-scsi-single', name: 'virtio-scsi-single'),
162
161
  OpenStruct.new(id: 'pvscsi', name: 'pvscsi')]
163
162
  end
164
163
 
165
164
  def proxmox_networkcards_map
166
- [OpenStruct.new(id: 'e1000', name: 'Intel E1000'),
167
- OpenStruct.new(id: 'virtio', name: 'VirtIO (paravirtualized)'),
168
- OpenStruct.new(id: 'rtl8139', name: 'Realtek RTL8139'),
169
- OpenStruct.new(id: 'vmxnet3', name: 'VMware vmxnet3')]
165
+ [OpenStruct.new(id: 'e1000', name: 'Intel E1000'),
166
+ OpenStruct.new(id: 'virtio', name: 'VirtIO (paravirtualized)'),
167
+ OpenStruct.new(id: 'rtl8139', name: 'Realtek RTL8139'),
168
+ OpenStruct.new(id: 'vmxnet3', name: 'VMware vmxnet3')]
170
169
  end
171
170
  end
@@ -22,10 +22,25 @@ require 'fog/proxmox/helpers/nic_helper'
22
22
  require 'foreman_fog_proxmox/value'
23
23
 
24
24
  module ProxmoxContainerHelper
25
+ def config_keys
26
+ keys = { general: ['node_id', 'name', 'type', 'config_attributes', 'volumes_attributes', 'interfaces_attributes', 'firmware_type', 'provision_method', 'container_volumes', 'server_volumes'] }
27
+ keys.store(:main, ['name', 'type', 'node_id', 'vmid', 'interfaces', 'mount_points', 'disks'])
28
+ keys.store(:cpu, ['arch', 'cpulimit', 'cpuunits', 'cores'])
29
+ keys.store(:memory, ['memory', 'swap'])
30
+ keys
31
+ end
25
32
 
26
- KILO = 1024
27
- MEGA = KILO * KILO
28
- GIGA = KILO * MEGA
33
+ def ostemplate_keys
34
+ ['ostemplate', 'ostemplate_storage', 'ostemplate_file']
35
+ end
36
+
37
+ def parse_ostemplate_without_keys(args)
38
+ parse_container_ostemplate(args.select { |key, _value| ostemplate_keys.include? key })
39
+ end
40
+
41
+ def config_general_or_ostemplate_key?(key)
42
+ config_keys[:general].include?(key) || ostemplate_keys.include?(key)
43
+ end
29
44
 
30
45
  def parse_container_vm(args)
31
46
  logger.debug("parse_container_vm args=#{args}")
@@ -33,28 +48,19 @@ module ProxmoxContainerHelper
33
48
  return {} unless args
34
49
  return {} if args.empty?
35
50
  return {} unless args['type'] == 'lxc'
51
+
36
52
  config = args['config_attributes']
37
- main_a = %w[name type node_id vmid interfaces mount_points disks]
38
- config = args.reject { |key,_value| main_a.include? key } unless config
39
- ostemplate_a = %w[ostemplate ostemplate_storage ostemplate_file]
40
- ostemplate = parse_container_ostemplate(args.select { |key,_value| ostemplate_a.include? key })
41
- ostemplate = parse_container_ostemplate(config.select { |key,_value| ostemplate_a.include? key }) unless ostemplate[:ostemplate]
53
+ config ||= args.reject { |key, _value| config_keys[:main].include? key }
54
+ ostemplate = parse_ostemplate_without_keys(args)
55
+ ostemplate = parse_ostemplate_without_keys(config) unless ostemplate[:ostemplate]
42
56
  volumes = parse_container_volumes(args['volumes_attributes'])
43
- cpu_a = %w[arch cpulimit cpuunits cores]
44
- cpu = parse_container_cpu(config.select { |key,_value| cpu_a.include? key })
45
- memory_a = %w[memory swap]
46
- memory = parse_container_memory(config.select { |key,_value| memory_a.include? key })
57
+ cpu = parse_container_cpu(config.select { |key, _value| config_keys[:cpu].include? key })
58
+ memory = parse_container_memory(config.select { |key, _value| config_keys[:memory].include? key })
47
59
  interfaces_attributes = args['interfaces_attributes']
48
60
  interfaces_to_add, interfaces_to_delete = parse_container_interfaces(interfaces_attributes)
49
- general_a = %w[node_id name type config_attributes volumes_attributes interfaces_attributes firmware_type provision_method container_volumes server_volumes]
50
- logger.debug("general_a: #{general_a}")
51
- parsed_vm = args.reject { |key,value| general_a.include?(key) || ostemplate_a.include?(key) || ForemanFogProxmox::Value.empty?(value) }
52
- config_a = []
53
- config_a += cpu_a
54
- config_a += memory_a
55
- config_a += main_a
56
- config_a += general_a
57
- parsed_config = config.reject { |key,value| config_a.include?(key) || ForemanFogProxmox::Value.empty?(value) }
61
+ logger.debug("config_keys[:general]: #{config_keys[:general]}")
62
+ parsed_vm = args.reject { |key, value| config_general_or_ostemplate_key?(key) || ForemanFogProxmox::Value.empty?(value) }
63
+ parsed_config = config.reject { |key, value| config_keys.include?(key) || ForemanFogProxmox::Value.empty?(value) }
58
64
  logger.debug("parse_container_config(): #{parsed_config}")
59
65
  parsed_vm = parsed_vm.merge(parsed_config).merge(cpu).merge(memory).merge(ostemplate)
60
66
  interfaces_to_add.each { |interface| parsed_vm = parsed_vm.merge(interface) }
@@ -65,8 +71,8 @@ module ProxmoxContainerHelper
65
71
  end
66
72
 
67
73
  def parse_container_memory(args)
68
- memory = {}
69
- args.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
74
+ memory = {}
75
+ args.delete_if { |_key, value| ForemanFogProxmox::Value.empty?(value) }
70
76
  memory.store(:memory, args['memory'].to_i) if args['memory']
71
77
  memory.store(:swap, args['swap'].to_i) if args['swap']
72
78
  logger.debug("parse_container_memory(): #{memory}")
@@ -75,7 +81,7 @@ module ProxmoxContainerHelper
75
81
 
76
82
  def parse_container_cpu(args)
77
83
  cpu = {}
78
- args.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
84
+ args.delete_if { |_key, value| ForemanFogProxmox::Value.empty?(value) }
79
85
  cpu.store(:arch, args['arch'].to_s) if args['arch']
80
86
  cpu.store(:cpulimit, args['cpulimit'].to_i) if args['cpulimit']
81
87
  cpu.store(:cpuunits, args['cpuunits'].to_i) if args['cpuunits']
@@ -87,10 +93,10 @@ module ProxmoxContainerHelper
87
93
  def parse_container_ostemplate(args)
88
94
  ostemplate = args['ostemplate']
89
95
  ostemplate_file = args['ostemplate_file']
90
- ostemplate = ostemplate ? ostemplate : ostemplate_file
96
+ ostemplate ||= ostemplate_file
91
97
  ostemplate_storage = args['ostemplate_storage']
92
- ostemplate_storage, ostemplate_file, _size = Fog::Proxmox::DiskHelper.extract_storage_volid_size(ostemplate) unless ForemanFogProxmox::Value.empty?(ostemplate)
93
- parsed_ostemplate = {ostemplate: ostemplate, ostemplate_file: ostemplate_file, ostemplate_storage: ostemplate_storage}
98
+ ostemplate_storage, ostemplate_file, _size = Fog::Proxmox::DiskHelper.extract_storage_volid_size(ostemplate) unless ForemanFogProxmox::Value.empty?(ostemplate)
99
+ parsed_ostemplate = { ostemplate: ostemplate, ostemplate_file: ostemplate_file, ostemplate_storage: ostemplate_storage }
94
100
  logger.debug("parse_container_ostemplate(): #{parsed_ostemplate}")
95
101
  parsed_ostemplate
96
102
  end
@@ -98,15 +104,16 @@ module ProxmoxContainerHelper
98
104
  def parse_container_volume(args)
99
105
  disk = {}
100
106
  id = args['id']
101
- id = "mp#{args['device']}" if args.has_key?('device')
107
+ id = "mp#{args['device']}" if args.key?('device')
102
108
  logger.debug("parse_container_volume() args=#{args}")
103
109
  return args if ForemanFogProxmox::Value.empty?(id) || Fog::Proxmox::DiskHelper.server_disk?(id)
104
- args.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
110
+
111
+ args.delete_if { |_key, value| ForemanFogProxmox::Value.empty?(value) }
105
112
  disk.store(:id, id)
106
113
  disk.store(:volid, args['volid'])
107
114
  disk.store(:storage, args['storage'].to_s)
108
115
  disk.store(:size, args['size'].to_i)
109
- options = args.reject { |key,_value| %w[id volid device storage size _delete].include? key}
116
+ options = args.reject { |key, _value| ['id', 'volid', 'device', 'storage', 'size', '_delete'].include? key }
110
117
  disk.store(:options, options)
111
118
  logger.debug("parse_container_volume(): disk=#{disk}")
112
119
  Fog::Proxmox::DiskHelper.flatten(disk)
@@ -115,7 +122,7 @@ module ProxmoxContainerHelper
115
122
  def parse_container_volumes(args)
116
123
  logger.debug("parse_container_volumes() args=#{args}")
117
124
  volumes = []
118
- args.each_value { |value| volumes.push(parse_container_volume(value))} if args
125
+ args&.each_value { |value| volumes.push(parse_container_volume(value)) }
119
126
  logger.debug("parse_container_volumes(): volumes=#{volumes}")
120
127
  volumes
121
128
  end
@@ -123,13 +130,13 @@ module ProxmoxContainerHelper
123
130
  def parse_container_interfaces(interfaces_attributes)
124
131
  interfaces_to_add = []
125
132
  interfaces_to_delete = []
126
- interfaces_attributes.each_value { |value| add_container_interface(value,interfaces_to_delete,interfaces_to_add) } if interfaces_attributes
133
+ interfaces_attributes&.each_value { |value| add_container_interface(value, interfaces_to_delete, interfaces_to_add) }
127
134
  logger.debug("parse_container_interfaces(): interfaces_to_add=#{interfaces_to_add}, interfaces_to_delete=#{interfaces_to_delete}")
128
135
  [interfaces_to_add, interfaces_to_delete]
129
136
  end
130
137
 
131
138
  def add_container_interface(interface_attributes, interfaces_to_delete, interfaces_to_add)
132
- interface_attributes.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
139
+ interface_attributes.delete_if { |_key, value| ForemanFogProxmox::Value.empty?(value) }
133
140
  nic = {}
134
141
  id = interface_attributes['id']
135
142
  logger.debug("parse_container_interface(): id=#{id}")
@@ -138,7 +145,7 @@ module ProxmoxContainerHelper
138
145
  interfaces_to_delete.push(id.to_s)
139
146
  else
140
147
  nic.store(:id, id)
141
- nic.store(:macaddr, interface_attributes['macaddr']) if interface_attributes['macaddr']
148
+ nic.store(:hwaddr, interface_attributes['macaddr']) if interface_attributes['macaddr']
142
149
  nic.store(:name, interface_attributes['name'].to_s)
143
150
  nic.store(:bridge, interface_attributes['bridge'].to_s) if interface_attributes['bridge']
144
151
  nic.store(:ip, interface_attributes['ip'].to_s) if interface_attributes['ip']
@@ -149,5 +156,4 @@ module ProxmoxContainerHelper
149
156
  interfaces_to_add.push(Fog::Proxmox::NicHelper.flatten(nic))
150
157
  end
151
158
  end
152
-
153
- end
159
+ end
@@ -18,55 +18,53 @@
18
18
  # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module ProxmoxFormHelper
21
-
22
- def password_proxmox_f(f, attr, options = {})
21
+ def password_proxmox_f(f, attr, options = {})
23
22
  unset_button = options.delete(:unset)
24
23
  value = f.object[attr] if options.delete(:keep_value)
25
24
  password_field_tag(:fakepassword, value, :style => 'display: none', :autocomplete => 'new-password-fake') +
26
- field(f, attr, options) do
27
- options[:autocomplete] ||= 'new-password'
28
- options[:placeholder] ||= password_proxmox_placeholder(f.object, attr)
29
- options[:disabled] = true if unset_button
30
- options[:value] = value if value.present?
31
- addClass options, 'form-control'
32
- pass = f.password_field(attr, options) +
33
- '<span class="glyphicon glyphicon-warning-sign input-addon"
34
- title="'.html_safe + _('Caps lock ON') +
35
- '" style="display:none"></span>'.html_safe
36
- if unset_button
37
- button = link_to_function(icon_text("edit", "", :kind => "pficon"), 'toggle_input_group(this)', {:id => 'disable-pass-btn', :class => 'btn btn-default', :title => _("Change the password")})
38
- input_group(pass, input_group_btn(button))
39
- else
40
- pass
41
- end
25
+ field(f, attr, options) do
26
+ options[:autocomplete] ||= 'new-password'
27
+ options[:placeholder] ||= password_proxmox_placeholder(f.object, attr)
28
+ options[:disabled] = true if unset_button
29
+ options[:value] = value if value.present?
30
+ addClass options, 'form-control'
31
+ pass = f.password_field(attr, options) +
32
+ content_tag(:span, '', class: 'glyphicon glyphicon-warning-sign input-addon',
33
+ title: 'Caps lock ON', style: 'display:none')
34
+ if unset_button
35
+ button = link_to_function(icon_text('edit', '', :kind => 'pficon'), 'toggle_input_group(this)', :id => 'disable-pass-btn', :class => 'btn btn-default', :title => _('Change the password'))
36
+ input_group(pass, input_group_btn(button))
37
+ else
38
+ pass
42
39
  end
43
- end
40
+ end
41
+ end
44
42
 
45
43
  def password_proxmox_placeholder(obj, attr = nil)
46
- pass = obj.attributes.has_key?(attr)
47
- pass ? "********" : ''
44
+ pass = obj.attributes.key?(attr)
45
+ pass ? '********' : ''
48
46
  end
49
-
50
- def new_child_fields_template_typed(form_builder, association, options = { })
51
- unless options[:object].present?
52
- association_object = form_builder.object.class.reflect_on_association(association)
53
- options[:object] = association_object.klass.new(association_object.foreign_key => form_builder.object.id)
54
- end
55
- options[:partial] ||= association.to_s.singularize
56
- options[:form_builder_local] ||= :f
57
- options[:form_builder_attrs] ||= {}
58
47
 
59
- content_tag(:div, :class => "#{options[:type]}_#{association}_fields_template form_template #{}", :style => "display: none;") do
60
- form_builder.fields_for(association, options[:object], :child_index => "new_#{options[:type]}_#{association}") do |f|
61
- render(:partial => options[:partial], :layout => options[:layout],
62
- :locals => { options[:form_builder_local] => f }.merge(options[:form_builder_attrs]))
48
+ def new_child_fields_template_typed(form_builder, association, options = {})
49
+ if options[:object].blank?
50
+ association_object = form_builder.object.class.reflect_on_association(association)
51
+ options[:object] = association_object.klass.new(association_object.foreign_key => form_builder.object.id)
52
+ end
53
+ options[:partial] ||= association.to_s.singularize
54
+ options[:form_builder_local] ||= :f
55
+ options[:form_builder_attrs] ||= {}
56
+
57
+ content_tag(:div, :class => "#{options[:type]}_#{association}_fields_template form_template ", :style => 'display: none;') do
58
+ form_builder.fields_for(association, options[:object], :child_index => "new_#{options[:type]}_#{association}") do |f|
59
+ render(:partial => options[:partial], :layout => options[:layout],
60
+ :locals => { options[:form_builder_local] => f }.merge(options[:form_builder_attrs]))
61
+ end
63
62
  end
64
63
  end
65
- end
66
64
 
67
- def add_child_link_typed(name, association, type, opts = {})
68
- opts[:class] = [opts[:class], "add_nested_fields btn btn-primary"].compact.join(" ")
69
- opts[:"data-association"] = (type + '_' + association.to_s).to_sym
70
- link_to_function(name.to_s, "add_child_node(this);tfm.numFields.initAll();", opts)
71
- end
65
+ def add_child_link_typed(name, association, type, opts = {})
66
+ opts[:class] = [opts[:class], 'add_nested_fields btn btn-primary'].compact.join(' ')
67
+ opts[:"data-association"] = (type + '_' + association.to_s).to_sym
68
+ link_to_function(name.to_s, 'add_child_node(this);tfm.numFields.initAll();', opts)
69
+ end
72
70
  end