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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a8a1a5346987d31022f1711c5181ed80fe9d4a5e23a1ec44cb3d65f81c98e4d
4
- data.tar.gz: ead9626148eee34158047668bc15c2a97b83bb6f6779d4478b932af059b808fb
3
+ metadata.gz: 15adca3cf1f65b7b543dcb24972d640c7cbd78ca11c6c7e657a1d1d0da2e250c
4
+ data.tar.gz: 387a162262465681620bf37c69ecac793757b09b7b592cd1209ce97741748a17
5
5
  SHA512:
6
- metadata.gz: acb1466f50ee8c3ec8e6f6b8844ce88e05a1d732960073bd3e8d7b88c61f55a9d69ddde052882f6ded98930128b52a16d909c5d63db3aada9520a51d0fcd907e
7
- data.tar.gz: d69dd9aaf71ee9e21c5cdf8dc6dc25ced882ab98f8e8064084e3f533dcddb362c9ee85784744dcc4e0ddefe66c7109263f85bf477622e62848bb42bf7a43a65f
6
+ metadata.gz: 1222697f1f9a8eba96c0f45156420e1437139b2e8927c31944bc8e78ce915ba37f52e595d3e25edc3ab56ebc96db09f27866677f256674681814909dd57cf9fa
7
+ data.tar.gz: 0d1f4df3e6be994ef693df0d89755123fd440ed9d0eb2bdd660b10a8c55d0cf12bddd425bd0078fc9b1d5a2f14647a90ae7c8b01f9c0e3f6cd866d4f564933fc
data/README.md CHANGED
@@ -32,6 +32,8 @@ You can support the plugin development via the following methods:
32
32
  |>=0.10 |>=5.4|>=0.9.4|>=1.22|>=2.5|
33
33
  |>=0.11 |>=5.4|>=0.10|>=1.22|>=2.5|
34
34
  |>=0.12 |>=6.1|>=0.11|>=2.0|>=2.5|
35
+ |>=0.14 |>=6.2|=0.13.0|>=2.4|>=2.7|
36
+ |>=0.14 |>=6.2|>=0.13.1|>=2.3|>=2.5|
35
37
 
36
38
  ## Installation
37
39
 
@@ -114,8 +116,8 @@ Redhat, CentOS or Fedora users should also [setup Selinux](https://projects.thef
114
116
  ### Prerequisites
115
117
 
116
118
  * You need a Proxmox VE 5.4+ server running.
117
- * You need ruby >= 2.5. You can install it with [rbenv](https://github.com/rbenv/rbenv).
118
- * You also need nodejs in your dev machine to run webpack-dev-server. You can install it with [nvm](https://github.com/creationix/nvm).
119
+ * You need ruby >= 2.5. You can install it with [asdf-vm](https://asdf-vm.com).
120
+ * You also need nodejs in your dev machine to run webpack-dev-server. You can install it with [asdf-vm](https://asdf-vm.com).
119
121
 
120
122
  ### Platform
121
123
 
@@ -135,6 +137,7 @@ gem 'foreman_fog_proxmox', :path => '../../theforeman/foreman_fog_proxmox'
135
137
  gem 'fog-proxmox', :path => '../../fog/fog-proxmox' # optional if you need to modify fog-proxmox code too
136
138
  gem 'ruby-debug-ide' # dev
137
139
  gem 'debase' # dev
140
+ gem 'solargraph' # dev
138
141
  gem 'simplecov' # test
139
142
  ```
140
143
 
@@ -142,8 +145,9 @@ gem 'simplecov' # test
142
145
 
143
146
  ```shell
144
147
  gem install bundler
145
- # prerequisites postgresql-client library on OS
148
+ # prerequisites postgresql-XX-client library on OS (XX=major release installed in OS)
146
149
  bundle config set without 'libvirt ovirt mysql2'
150
+ bundle config build.pg --with-pg-config=/usr/pgsql-XX/bin/pg_config
147
151
  bundle install
148
152
  ```
149
153
 
@@ -176,7 +180,7 @@ cp config/model.mappings.example config/model.mappings
176
180
  cp config/database.yml.example config/database.yml
177
181
  ```
178
182
 
179
- add these lines to config/database.yml:
183
+ add these lines to each environment in config/database.yml:
180
184
 
181
185
  ```yaml
182
186
  username: foreman
@@ -187,6 +191,7 @@ add these lines to config/database.yml:
187
191
  cp config/ignored_environments.yml.sample config/ignored_environments.yml
188
192
  docker run --name foreman-db -e POSTGRES_DB=foreman -e POSTGRES_USER=foreman -e POSTGRES_PASSWORD=foreman -p 5432:5432 -d postgres
189
193
  bundle exec bin/rake db:migrate
194
+ # reboot if settings.NAME error in schema
190
195
  bundle exec bin/rake db:seed assets:precompile locale:pack webpack:compile
191
196
  ```
192
197
 
@@ -205,7 +210,15 @@ docker exec -it foreman-db psql -U foreman
205
210
  foreman=# create database "foreman-test";
206
211
  ```
207
212
 
208
- all:
213
+ then add test schema and seeds:
214
+
215
+ ```shell
216
+ RAILS_ENV=test bundle exec bin/rake db:migrate
217
+ # reboot if error: "ActiveRecord::RecordNotFound: Couldn't find Setting with [WHERE "settings"."name" = $1]"
218
+ RAILS_ENV=test bundle exec bin/rake db:seed
219
+ ```
220
+
221
+ Finally you can test all:
209
222
 
210
223
  ```shell
211
224
  export DISABLE_SPRING=true
@@ -273,6 +286,12 @@ bundle exec bin/rails server
273
286
  bundle exec foreman start
274
287
  ```
275
288
 
289
+ If you want to delete vm on host destroy, add this line in config/settings.yml:
290
+
291
+ ```yml
292
+ :destroy_vm_on_host_delete: false
293
+ ```
294
+
276
295
  See details in [foreman plugin development](https://projects.theforeman.org/projects/foreman/wiki/How_to_Create_a_Plugin)
277
296
 
278
297
  ## Contributing
@@ -16,9 +16,13 @@
16
16
  // along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
  $(document).on('ContentLoad', tfm.numFields.initAll);
19
- $(document).ready(sslVerifyPeerSelected);
20
19
 
21
- function sslVerifyPeerSelected(){
20
+ $(document).ready(function () {
21
+ sslVerifyPeerSelected();
22
+ authMethodSelected();
23
+ });
24
+
25
+ function sslVerifyPeerSelected() {
22
26
  var selected = $("#compute_resource_ssl_verify_peer").is(':checked');
23
27
  var ssl_certs_block = $('#compute_resource_ssl_certs').parents('.clearfix');
24
28
  var ssl_certs_textarea = $('#compute_resource_ssl_certs');
@@ -31,3 +35,33 @@ function sslVerifyPeerSelected(){
31
35
  ssl_certs_textarea.hide();
32
36
  }
33
37
  }
38
+
39
+ function enableField(item) {
40
+ $(item).show();
41
+ $(item).removeAttr('disabled');
42
+ }
43
+
44
+ function disableField(item) {
45
+ $(item).hide();
46
+ $(item).attr('disabled','disabled');
47
+ }
48
+
49
+ function toggleFieldset(method, selected){
50
+ return method === selected ? enableField(authMethodFieldsetId(method)) : disableField(authMethodFieldsetId(method));
51
+ }
52
+
53
+ function authMethods(){
54
+ return ['user_token', 'access_ticket'];
55
+ }
56
+
57
+ function authMethodFieldsetId(method){
58
+ return '#compute_ressource_' + method + '_field_set';
59
+ }
60
+
61
+ function authMethodSelected() {
62
+ var selected = $("#compute_resource_auth_method").val();
63
+ console.log("auth_method="+selected);
64
+ authMethods().forEach(function(method){
65
+ toggleFieldset(method, selected);
66
+ });
67
+ }
@@ -34,67 +34,139 @@ function vmTypeSelected() {
34
34
  fieldsets.push({id: 'config_cdrom', toggle: false, new_vm: new_vm, selected: selected});
35
35
  fieldsets.push({id: 'config_os', toggle: false, new_vm: new_vm, selected: selected});
36
36
  fieldsets.push({id: 'config_dns', toggle: false, new_vm: new_vm, selected: selected});
37
- fieldsets.forEach(toggleFieldset);
37
+ fieldsets.forEach(toggleFieldsets);
38
38
  toggleVolumes(selected);
39
39
  return false;
40
40
  }
41
41
 
42
+ function volumeButtonAddId(item){
43
+ return $("a[data-association='" + item + "_volumes']");
44
+ }
45
+
46
+ function volumeFieldsetId(item, type){
47
+ return $("fieldset[id^='" + type + "_volume_"+ item +"']").not("fieldset[id$='_new_" + item +"_volumes']");
48
+ }
49
+
50
+ function indexByIdAndType(item, storage_type, vm_type){
51
+ var regex = new RegExp(vm_type +"_volume_" + storage_type +"_(\\d+)");
52
+ return item.match(regex)[1];
53
+ }
54
+
55
+ function volidByIndexAndTag(index, tag){
56
+ return $(tag + "[id='host_compute_attributes_volumes_attributes_" + index + "_volid']").val();
57
+ }
58
+
59
+ function hasCloudinit(){
60
+ result = false;
61
+ var volume_id = volumeFieldsetId('cloud_init', 'server').attr('id');
62
+ if (volume_id !== undefined){
63
+ var index = indexByIdAndType(volume_id, 'cloud_init', 'server');
64
+ var volid = volidByIndexAndTag(index, 'input');
65
+ result = volid.includes("cloudinit");
66
+ }
67
+ return result;
68
+ }
69
+
70
+ function hasCdrom(){
71
+ result = false;
72
+ var volume_id = volumeFieldsetId('cdrom', 'server').attr('id');
73
+ if (volume_id !== undefined){
74
+ var index = indexByIdAndType(volume_id, 'cdrom', 'server');
75
+ var checked = $("input[id^='host_compute_attributes_volumes_attributes_" + index + "_cdrom']:checked").val();
76
+ var isCdrom = checked === 'cdrom';
77
+ result = isCdrom;
78
+ var isImage = checked === 'image';
79
+ if (isImage) {
80
+ var volid = volidByIndexAndTag(index, 'select');
81
+ result = volid.includes("iso");
82
+ }
83
+ }
84
+ return result;
85
+ }
86
+
87
+ function cloudinit(item){
88
+ return item === 'cloud_init' && hasCloudinit();
89
+ }
90
+
91
+ function cdrom(item){
92
+ return item === 'cdrom' && hasCdrom();
93
+ }
94
+
95
+ function enableVolume(volume_id, type){
96
+ volumeFieldsetId(volume_id, type).show();
97
+ volumeButtonAddId(volume_id).show();
98
+ if (cloudinit(volume_id) || cdrom(volume_id)){
99
+ volumeButtonAddId(volume_id).hide();
100
+ }
101
+ volumeFieldsetId(volume_id, type).removeAttr('disabled');
102
+ }
103
+
104
+ function disableVolume(volume_id, type){
105
+ volumeFieldsetId(volume_id, type).hide();
106
+ volumeButtonAddId(volume_id).hide();
107
+ volumeFieldsetId(volume_id, type).attr('disabled','disabled');
108
+ }
109
+
110
+ function volumes(type){
111
+ return type === 'qemu' ? ['hard_disk', 'cdrom', 'cloud_init'] : ['mp', 'rootfs'];
112
+ }
113
+
114
+ function volume(type){
115
+ return type === 'qemu' ? 'server' : 'container';
116
+ }
117
+
118
+ function toggleVolume(volume_id, type1, type2){
119
+ type1 === type2 ? enableVolume(volume_id, volume(type1)) : disableVolume(volume_id, volume(type1));
120
+ }
121
+
42
122
  function toggleVolumes(selected){
43
- var div_container = $("div[id^='container_volumes']");
44
- var div_server = $("div[id^='server_volumes']");
45
- var a_container = $("a[data-association='container_volumes']");
46
- var a_server = $("a[data-association='server_volumes']");
47
- switch (selected) {
48
- case 'qemu':
49
- div_container.hide();
50
- div_server.show();
51
- a_container.hide();
52
- a_server.show();
53
- break;
54
- case 'lxc':
55
- div_container.show();
56
- div_server.hide();
57
- a_container.show();
58
- a_server.hide();
59
- break;
60
- default:
61
- console.log("unkown type="+selected);
62
- break;
123
+ ['qemu', 'lxc'].forEach(function(type){
124
+ volumes(type).forEach(function(volume_id){
125
+ toggleVolume(volume_id, selected, type);
126
+ });
127
+ });
128
+ }
129
+
130
+ function enableFieldset(fieldsetId, fieldset) {
131
+ if (fieldset.toggle && fieldset.new_vm){
132
+ fieldset_id(fieldsetId, fieldset).show();
63
133
  }
134
+ fieldset_id(fieldsetId, fieldset).removeAttr('disabled');
135
+ input_hidden_id(fieldsetId).removeAttr('disabled');
64
136
  }
65
137
 
66
- function toggleFieldset(fieldset, index, fieldsets){
67
- var server_input_hidden = $("div[id^='server_volumes']" + " + input:hidden");
68
- var container_input_hidden = $("div[id^='container_volumes']" + " + input:hidden");
69
- var removable_input_hidden = $("div.removable-item[style='display: none;']" + " + input:hidden");
70
- var server_fieldset = $("fieldset[id^='server_"+fieldset.id+"']");
71
- var container_fieldset = $("fieldset[id^='container_"+fieldset.id+"']");
72
- removable_input_hidden.attr('disabled','disabled');
73
- switch (fieldset.selected) {
74
- case 'qemu':
75
- if (fieldset.toggle && fieldset.new_vm){
76
- server_fieldset.show();
77
- container_fieldset.hide();
78
- }
79
- server_fieldset.removeAttr('disabled');
80
- container_fieldset.attr('disabled','disabled');
81
- server_input_hidden.removeAttr('disabled');
82
- container_input_hidden.attr('disabled','disabled');
83
- break;
84
- case 'lxc':
85
- if (fieldset.toggle && fieldset.new_vm){
86
- server_fieldset.hide();
87
- container_fieldset.show();
88
- }
89
- server_fieldset.attr('disabled','disabled');
90
- container_fieldset.removeAttr('disabled');
91
- container_input_hidden.removeAttr('disabled');
92
- server_input_hidden.attr('disabled','disabled');
93
- break;
94
- default:
95
- console.log("unkown type="+fieldset.selected);
96
- break;
138
+ function disableFieldset(fieldsetId, fieldset) {
139
+ if (fieldset.toggle && fieldset.new_vm){
140
+ fieldset_id(fieldsetId, fieldset).hide();
97
141
  }
142
+ fieldset_id(fieldsetId, fieldset).attr('disabled','disabled');
143
+ input_hidden_id(fieldsetId).attr('disabled','disabled');
144
+ }
145
+
146
+ function toggleFieldset(fieldsetId, fieldset, type1, type2) {
147
+ type1 === type2 ? enableFieldset(fieldsetId, fieldset) : disableFieldset(fieldsetId, fieldset);
148
+ }
149
+
150
+ function input_hidden_id(volume_id){
151
+ return $("div[id^='"+ volume_id +"_volumes']" + " + input:hidden");
152
+ }
153
+
154
+ function fieldset_id(fieldsetId, fieldset){
155
+ return $("fieldset[id^='" + fieldsetId + "_"+fieldset.id+"']");
156
+ }
157
+
158
+ function fieldsets(type){
159
+ return type === 'qemu' ? ['server'] : ['container'];
160
+ }
161
+
162
+ function toggleFieldsets(fieldset){
163
+ var removable_input_hidden = $("div.removable-item[style='display: none;']" + " + input:hidden");
164
+ removable_input_hidden.attr('disabled','disabled');
165
+ ['qemu', 'lxc'].forEach(function(type){
166
+ fieldsets(type).forEach(function(fieldsetId){
167
+ toggleFieldset(fieldsetId, fieldset, fieldset.selected, type);
168
+ });
169
+ });
98
170
  }
99
171
 
100
172
  function nodeSelected(item) {
@@ -118,18 +190,18 @@ function nodeSelected(item) {
118
190
  }
119
191
  }
120
192
 
121
- function emptySelect(select){
122
- $(select).empty();
123
- $(select).append($("<option></option>").val('').text(''));
124
- $(select).val('');
193
+ function emptySelect(select_id){
194
+ $(select_id).empty();
195
+ $(select_id).append($("<option></option>").val('').text(''));
196
+ $(select_id).val('');
125
197
  }
126
198
 
127
199
  function initOptions(select_ids){
128
200
  console.log('initOptions(' + select_ids[0] + ')');
129
201
  select_ids.forEach(emptySelect);
130
- select_ids.forEach(function(select){
131
- $(select + ' option:selected').prop('selected',false);
132
- $(select).val('');
202
+ select_ids.forEach(function(select_id){
203
+ $(select_id + ' option:selected').prop('selected',false);
204
+ $(select_id).val('');
133
205
  });
134
206
  }
135
207
 
@@ -156,7 +228,9 @@ function updateOptions(options_path, start_options_id, end_options_id, start_sec
156
228
  if ( start_second_options_id != undefined && end_second_options_id != undefined) {
157
229
  select_second_ids = selectIds(start_second_options_id, end_second_options_id);
158
230
  }
159
- var url = '/foreman_fog_proxmox/' + options_path + '/' + node_id;
231
+ var compute_resource_id = $("#host_compute_resource_id").val();
232
+ if (compute_resource_id == undefined) compute_resource_id = $("#compute_attribute_compute_resource_id").val(); // profil
233
+ var url = '/foreman_fog_proxmox/' + options_path + '/' + compute_resource_id + '/' + node_id;
160
234
  if (second_id != undefined) url += '/' + second_id;
161
235
  tfm.tools.showSpinner();
162
236
  $.getJSON({
@@ -15,51 +15,6 @@
15
15
  // You should have received a copy of the GNU General Public License
16
16
  // along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
- function cdromSelected(item) {
19
- var selected = $(item).val();
20
- var cdrom_image_form = $('#cdrom_image_form');
21
-
22
- switch (selected) {
23
- case 'none':
24
- initCdromStorage();
25
- initCdromOptions('iso');
26
- cdrom_image_form.hide();
27
- break;
28
- case 'cdrom':
29
- initCdromStorage();
30
- initCdromOptions('iso');
31
- cdrom_image_form.hide();
32
- break;
33
- case 'image':
34
- initCdromStorage();
35
- initCdromOptions('iso');
36
- cdrom_image_form.show();
37
- break;
38
- default:
39
- break;
40
- }
41
- return false;
42
- }
43
-
44
- function initCdromStorage() {
45
- var select = '#host_compute_attributes_config_attributes_cdrom_storage';
46
- $(select + ' option:selected').prop('selected', false);
47
- $(select).val('');
48
- }
49
-
50
- function initCdromOptions(name) {
51
- var select = '#host_compute_attributes_config_attributes_cdrom_' + name;
52
- $(select).empty();
53
- $(select).append($("<option></option>").val('').text(''));
54
- $(select).val('');
55
- }
56
-
57
- function storageIsoSelected(item) {
58
- var storage = $(item).val();
59
- var node_id = $('#host_compute_attributes_node_id').val();
60
- updateOptions('isos', 'compute_attributes_config_attributes', 'cdrom_iso', undefined, undefined, 'volid', node_id, storage);
61
- }
62
-
63
18
  function attributesPrefixSelector(profile, type) {
64
19
  return profile ? '#compute_attribute_vm_attrs_' + type + '_attributes_': '#host_compute_attributes_' + type + '_attributes_';
65
20
  }
@@ -69,11 +24,10 @@ function volumesAttributesSelector(profile,index,selector) {
69
24
  }
70
25
 
71
26
  function getIndex(item) {
72
- var id = $(item).attr('id');
27
+ var index_id = $(item).attr('id');
73
28
  var pattern = /(host_compute_attributes_volumes_attributes_||compute_attribute_vm_attrs_volumes_attributes_)(\d+)[_](.*)/i;
74
- pattern_a = pattern.exec(id);
29
+ pattern_a = pattern.exec(index_id);
75
30
  var index = pattern_a[2];
76
- console.log("index=" + index);
77
31
  return index;
78
32
  }
79
33
 
@@ -86,7 +40,6 @@ function controllerSelected(item) {
86
40
  var index = getIndex(item);
87
41
  var max = computeControllerMaxDevice(controller);
88
42
  var profile = isProfile();
89
- console.log("profile="+profile);
90
43
  var device_selector = volumesAttributesSelector(profile,index,'device');
91
44
  var id_selector = volumesAttributesSelector(profile,index,'id');
92
45
  $(device_selector).attr('data-soft-max', max);
@@ -100,7 +53,6 @@ function deviceSelected(item) {
100
53
  var device = $(item).limitedSpinner('value');
101
54
  var index = getIndex(item);
102
55
  var profile = isProfile();
103
- console.log("profile="+profile);
104
56
  var controller_selector = volumesAttributesSelector(profile,index,'controller');
105
57
  var id_selector = volumesAttributesSelector(profile,index,'id');
106
58
  var controller = $(controller_selector).val();