foreman_fog_proxmox 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -12
  3. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +26 -0
  4. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +92 -0
  5. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_container.js +60 -0
  6. data/app/assets/javascripts/foreman_fog_proxmox/{proxmox.js → proxmox_vm_server.js} +10 -10
  7. data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +1 -1
  8. data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +9 -1
  9. data/app/helpers/node_dashboard_helper.rb +36 -0
  10. data/app/helpers/proxmox_compute_selectors_helper.rb +23 -0
  11. data/app/helpers/proxmox_container_helper.rb +157 -0
  12. data/app/helpers/proxmox_form_helper.rb +67 -0
  13. data/app/helpers/{proxmox_compute_helper.rb → proxmox_server_helper.rb} +49 -38
  14. data/app/helpers/proxmox_vm_helper.rb +86 -0
  15. data/app/models/concerns/fog_extensions/proxmox/container.rb +57 -0
  16. data/{test/factories/foreman_fog_proxmox_factories.rb → app/models/concerns/fog_extensions/proxmox/container_config.rb} +16 -13
  17. data/app/models/concerns/fog_extensions/proxmox/server.rb +8 -2
  18. data/app/models/foreman_fog_proxmox/proxmox.rb +160 -67
  19. data/app/overrides/compute_resources_vms/form/add_clone_to_new_vm_compute_detail.rb +24 -0
  20. data/app/overrides/compute_resources_vms/form/add_vm_type_to_networks_form.rb +32 -0
  21. data/app/overrides/compute_resources_vms/form/add_vm_type_to_nic_provider_specific_form.rb +25 -0
  22. data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_edit.rb +24 -0
  23. data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_new_volume.rb +24 -0
  24. data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +37 -0
  25. data/app/views/compute_resources/form/_proxmox.html.erb +7 -4
  26. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_form.html.erb +23 -0
  27. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_new_childs_form.html.erb +25 -0
  28. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +23 -0
  29. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +73 -0
  30. data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +16 -23
  31. data/app/views/compute_resources_vms/form/proxmox/_general.html.erb +37 -0
  32. data/app/views/compute_resources_vms/form/proxmox/_network.html.erb +2 -7
  33. data/app/views/compute_resources_vms/form/proxmox/container/_advanced.html.erb +31 -0
  34. data/app/views/compute_resources_vms/form/proxmox/container/_config.html.erb +41 -0
  35. data/app/views/compute_resources_vms/form/proxmox/container/_extended.html.erb +26 -0
  36. data/app/views/compute_resources_vms/form/proxmox/container/_network.html.erb +25 -0
  37. data/app/views/compute_resources_vms/form/proxmox/container/_volume_mp.html.erb +25 -0
  38. data/app/views/compute_resources_vms/form/proxmox/container/_volume_rootfs.html.erb +24 -0
  39. data/app/views/compute_resources_vms/form/proxmox/server/_advanced.html.erb +31 -0
  40. data/app/views/compute_resources_vms/form/proxmox/{_config.html.erb → server/_config.html.erb} +11 -8
  41. data/app/views/compute_resources_vms/form/proxmox/server/_network.html.erb +29 -0
  42. data/app/views/compute_resources_vms/form/proxmox/server/_volume.html.erb +27 -0
  43. data/app/views/compute_resources_vms/index/_proxmox.html.erb +4 -2
  44. data/app/views/compute_resources_vms/show/_proxmox.html.erb +9 -2
  45. data/app/views/dashboard/_foreman_fog_proxmox_widget.erb +4 -2
  46. data/app/views/images/form/_proxmox.html.erb +17 -0
  47. data/config/routes.rb +1 -0
  48. data/lib/foreman_fog_proxmox/engine.rb +10 -3
  49. data/lib/foreman_fog_proxmox/value.rb +24 -0
  50. data/lib/foreman_fog_proxmox/version.rb +1 -1
  51. data/locale/en/foreman_fog_proxmox.edit.po +456 -0
  52. data/locale/en/foreman_fog_proxmox.po +327 -11
  53. data/locale/en/foreman_fog_proxmox.po.time_stamp +0 -0
  54. data/locale/foreman_fog_proxmox.pot +515 -8
  55. data/locale/fr/foreman_fog_proxmox.edit.po +456 -0
  56. data/locale/fr/foreman_fog_proxmox.po +327 -11
  57. data/locale/fr/foreman_fog_proxmox.po.time_stamp +0 -0
  58. data/test/factories/proxmox_factory.rb +72 -0
  59. data/test/functional/compute_resources_controller_test.rb +34 -0
  60. data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +205 -0
  61. data/test/{helpers/proxmox_compute_helper_test.rb → unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb} +36 -28
  62. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +240 -0
  63. data/test/unit/foreman_fog_proxmox/proxmox_test.rb +327 -0
  64. data/test/unit/foreman_fog_proxmox/proxmox_test_helpers.rb +251 -0
  65. metadata +83 -14
  66. data/app/views/compute_resources_vms/form/proxmox/_volume.html.erb +0 -23
  67. data/test/unit/foreman_fog_proxmox_test.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48e7b9e4bf809304a237b6523af9f5fd3b857734
4
- data.tar.gz: f8e212e7b449f735deb8ebcdb9f7a53e742d555c
3
+ metadata.gz: 475afb51f19055c5bf62055527903df576d3eafe
4
+ data.tar.gz: ed7c4afa8aee30e7e80f7fcc7258d13ae3dbca72
5
5
  SHA512:
6
- metadata.gz: e4f01062b1b8fa2d850ff0552abbe36a3616e01a82e1710e08907d0d1ae81c0690f292372df469dc5721c8c5fb96fc2656646a4498571a6f4cca05ed067cb9f3
7
- data.tar.gz: 85d5e82a63ac3a7e264b4c1884dcfa44f4409884b24955f2d542bc9ae7d0ef9e2f06f26fc29250a911fd59117eb76f0f06eecb35ba5bf781490446ba185bfd2a
6
+ metadata.gz: 604c52d8435cbda0f9fe498d07c2fe3a58576152303148f9005fff7c59c3b2dbe1bb24e50bd6c8a77f79e8a8584b54cd895e60fbe40a5936a4cb696c79e74995
7
+ data.tar.gz: a4afeaac998b8e596efb70a48dfc2a5ea44701dcd8688566e791644d54c0a9f5cfe4c31bc9a452a1684d58d2bf4b2879868c19933c459a7721a4f3684e7b2346
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  ![ForemanFogProxmox](.github/images/foremanproxmox.png)
2
2
 
3
- [![Build Status](https://travis-ci.com/tristanrobert/foreman_proxmox.svg?branch=master)](https://travis-ci.com/tristanrobert/foreman_proxmox)
4
- [![Maintainability](https://api.codeclimate.com/v1/badges/922162c278e0fa9207ba/maintainability)](https://codeclimate.com/github/tristanrobert/foreman_proxmox/maintainability)
5
- [![Test Coverage](https://api.codeclimate.com/v1/badges/922162c278e0fa9207ba/test_coverage)](https://codeclimate.com/github/tristanrobert/foreman_proxmox/test_coverage)
3
+ [![Build Status](https://travis-ci.com/tristanrobert/foreman_fog_proxmox.svg?branch=master)](https://travis-ci.com/tristanrobert/foreman_fog_proxmox)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/922162c278e0fa9207ba/maintainability)](https://codeclimate.com/github/tristanrobert/foreman_fog_proxmox/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/922162c278e0fa9207ba/test_coverage)](https://codeclimate.com/github/tristanrobert/foreman_fog_proxmox/test_coverage)
6
6
 
7
7
  # ForemanFogProxmox
8
8
 
@@ -14,8 +14,8 @@ It is intended to satisfy this [feature](http://projects.theforeman.org/issues/2
14
14
 
15
15
  Tested with:
16
16
 
17
- * Foreman = 1.17.1
18
- * Fog-proxmox >= 0.4.0
17
+ * Foreman = 1.17.3
18
+ * Fog-proxmox >= 0.5.1
19
19
 
20
20
  ## Installation
21
21
 
@@ -54,6 +54,12 @@ sudo -u foreman /usr/bin/foreman-ruby /usr/bin/bundle install
54
54
  /usr/bin/foreman-ruby /usr/bin/bundle exec bin/rake plugin:assets:precompile[foreman_fog_proxmox]
55
55
  ```
56
56
 
57
+ * Compile plugin translations if (french) needed :
58
+
59
+ ```shell
60
+ /usr/bin/foreman-ruby /usr/bin/bundle exec bin/rake plugin:gettext[foreman_fog_proxmox]
61
+ ```
62
+
57
63
  * Complete installation of foreman 1.17 with foreman-installer:
58
64
 
59
65
  ```shell
@@ -99,18 +105,18 @@ You also need nodejs in your dev machine to run webpack-dev-server.
99
105
 
100
106
  * Fork this github repo.
101
107
  * Clone it on your local machine
102
- * Install foreman v1.17 on your machine:
108
+ * Install foreman v1.17.3 on your machine:
103
109
 
104
110
  ```shell
105
111
  git clone https://github.com/theforeman/foreman
106
- git checkout tags/1.17
112
+ git checkout tags/1.17.3
107
113
  ```
108
114
 
109
115
  * Create a Gemfile.local.rb file in foreman/bundler.d/
110
116
  * Add this line:
111
117
 
112
118
  ```ruby
113
- gem 'foreman_fog_proxmox', :path => '/your_path_to/foreman_proxmox'
119
+ gem 'foreman_fog_proxmox', :path => '/your_path_to/foreman_fog_proxmox'
114
120
  ```
115
121
 
116
122
  * In foreman directory, install dependencies:
@@ -129,20 +135,26 @@ cp config/settings.yaml.example config/settings.yaml
129
135
 
130
136
  ```shell
131
137
  cp config/database.yaml.example config/database.yaml
132
- bundle exec rake db:migrate
133
- bundle exec rake db:seed
138
+ bundle exec bin/rake db:migrate
139
+ bundle exec bin/rake db:seed
134
140
  ```
135
141
 
136
142
  * You can reset admin password if needed:
137
143
 
138
144
  ```shell
139
- bundle exec rake permissions:reset
145
+ bundle exec bin/rake permissions:reset
140
146
  ```
141
147
 
142
148
  * In foreman directory, after you modify foreman_fog_proxmox specific assets (proxmox.js, etc) you have to precompile it:
143
149
 
144
150
  ```shell
145
- bundle plugin:assets:precompile[foreman_fog_proxmox]
151
+ bundle exec bin/rake plugin:assets:precompile[foreman_fog_proxmox]
152
+ ```
153
+
154
+ * In foreman directory, after you modify foreman_fog_proxmox translations (language, texts in new files, etc) you have to compile it:
155
+
156
+ ```shell
157
+ bundle exec bin/rake plugin:gettext[foreman_fog_proxmox]
146
158
  ```
147
159
 
148
160
  * In foreman directory, run rails server:
@@ -0,0 +1,26 @@
1
+ // Copyright 2018 Tristan Robert
2
+
3
+ // This file is part of ForemanFogProxmox.
4
+
5
+ // ForemanFogProxmox is free software: you can redistribute it and/or modify
6
+ // it under the terms of the GNU General Public License as published by
7
+ // the Free Software Foundation, either version 3 of the License, or
8
+ // (at your option) any later version.
9
+
10
+ // ForemanFogProxmox is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU General Public License for more details.
14
+
15
+ // You should have received a copy of the GNU General Public License
16
+ // along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ function sslVerifyPeerSelected(item){
19
+ var selected = $(item).is(':checked');
20
+ var ssl_certs_form = $('#compute_resource_ssl_certs').parents('.clearfix');
21
+ if (selected) {
22
+ ssl_certs_form.show();
23
+ } else {
24
+ ssl_certs_form.hide();
25
+ }
26
+ }
@@ -0,0 +1,92 @@
1
+ // Copyright 2018 Tristan Robert
2
+
3
+ // This file is part of ForemanFogProxmox.
4
+
5
+ // ForemanFogProxmox is free software: you can redistribute it and/or modify
6
+ // it under the terms of the GNU General Public License as published by
7
+ // the Free Software Foundation, either version 3 of the License, or
8
+ // (at your option) any later version.
9
+
10
+ // ForemanFogProxmox is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU General Public License for more details.
14
+
15
+ // You should have received a copy of the GNU General Public License
16
+ // along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ $(document).on('ContentLoad', tfm.numFields.initAll);
19
+ $(document).ready(vmTypeSelected);
20
+
21
+ function vmTypeSelected() {
22
+ var selected = $("#host_compute_attributes_type").val();
23
+ if (selected == undefined) selected = $("#compute_attribute_vm_attrs_type").val();
24
+ var host_uuid = $("input[id='host_uuid']").val();
25
+ var new_vm = host_uuid == undefined;
26
+ var fieldsets = [];
27
+ fieldsets.push({id: 'config_advanced_options', toggle: true, new_vm: new_vm, selected: selected});
28
+ fieldsets.push({id: 'config_ext', toggle: true, new_vm: new_vm, selected: selected});
29
+ fieldsets.push({id: 'volume', toggle: true, new_vm: new_vm, selected: selected});
30
+ fieldsets.push({id: 'network', toggle: true, new_vm: true, selected: selected});
31
+ fieldsets.push({id: 'config_options', toggle: false, new_vm: new_vm, selected: selected});
32
+ fieldsets.push({id: 'config_cpu', toggle: false, new_vm: new_vm, selected: selected});
33
+ fieldsets.push({id: 'config_memory', toggle: false, new_vm: new_vm, selected: selected});
34
+ fieldsets.push({id: 'config_cdrom', toggle: false, new_vm: new_vm, selected: selected});
35
+ fieldsets.push({id: 'config_os', toggle: false, new_vm: new_vm, selected: selected});
36
+ fieldsets.push({id: 'config_dns', toggle: false, new_vm: new_vm, selected: selected});
37
+ fieldsets.forEach(toggleFieldset);
38
+ toggleVolumes(selected);
39
+ return false;
40
+ }
41
+
42
+ 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
+ }
61
+ }
62
+
63
+ function toggleFieldset(fieldset, index, fieldsets){
64
+ var server_input_hidden = $("div[id^='server_volumes']" + " > input:hidden");
65
+ var container_input_hidden = $("div[id^='container_volumes']" + " > input:hidden");
66
+ var server_fieldset = $("fieldset[id^='server_"+fieldset.id+"']");
67
+ var container_fieldset = $("fieldset[id^='container_"+fieldset.id+"']");
68
+ switch (fieldset.selected) {
69
+ case 'qemu':
70
+ if (fieldset.toggle && fieldset.new_vm){
71
+ server_fieldset.show();
72
+ container_fieldset.hide();
73
+ }
74
+ server_fieldset.removeAttr('disabled');
75
+ container_fieldset.attr('disabled','disabled');
76
+ server_input_hidden.removeAttr('disabled');
77
+ container_input_hidden.attr('disabled','disabled');
78
+ break;
79
+ case 'lxc':
80
+ if (fieldset.toggle && fieldset.new_vm){
81
+ server_fieldset.hide();
82
+ container_fieldset.show();
83
+ }
84
+ server_fieldset.attr('disabled','disabled');
85
+ container_fieldset.removeAttr('disabled');
86
+ container_input_hidden.removeAttr('disabled');
87
+ server_input_hidden.attr('disabled','disabled');
88
+ break;
89
+ default:
90
+ break;
91
+ }
92
+ }
@@ -0,0 +1,60 @@
1
+ // Copyright 2018 Tristan Robert
2
+
3
+ // This file is part of ForemanFogProxmox.
4
+
5
+ // ForemanFogProxmox is free software: you can redistribute it and/or modify
6
+ // it under the terms of the GNU General Public License as published by
7
+ // the Free Software Foundation, either version 3 of the License, or
8
+ // (at your option) any later version.
9
+
10
+ // ForemanFogProxmox is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU General Public License for more details.
14
+
15
+ // You should have received a copy of the GNU General Public License
16
+ // along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ function initOstemplateStorage(){
19
+ var select = '#host_compute_attributes_ostemplate_storage';
20
+ $(select + ' option:selected').prop('selected',false);
21
+ $(select).val('');
22
+ }
23
+
24
+ function initOstemplateOptions(){
25
+ var select_ids = ['#host_compute_attributes_ostemplate_file','#compute_attribute_vm_attrs_ostemplate_file'];
26
+ select_ids.forEach(emptySelect);
27
+ }
28
+
29
+ function emptySelect(select, index, select_ids){
30
+ $(select).empty();
31
+ $(select).append($("<option></option>").val('').text(''));
32
+ $(select).val('');
33
+ }
34
+
35
+
36
+ function storageOstemplateSelected(item) {
37
+ var storage = $(item).val();
38
+ if (storage != '') {
39
+ tfm.tools.showSpinner();
40
+ $.getJSON({
41
+ type: 'get',
42
+ url: '/foreman_fog_proxmox/ostemplates/'+storage,
43
+ complete: function(){
44
+ tfm.tools.hideSpinner();
45
+ },
46
+ error: function(j,status,error){
47
+ console.log("Error=" + error +", status=" + status + " loading os templates for storage=" + storage);
48
+ },
49
+ success: function(ostemplates) {
50
+ initOstemplateOptions();
51
+ $.each(ostemplates, function(i,ostemplate){
52
+ $('#host_compute_attributes_ostemplate_file').append($("<option></option>").val(ostemplate.volid).text(ostemplate.volid));
53
+ $('#compute_attribute_vm_attrs_ostemplate_file').append($("<option></option>").val(ostemplate.volid).text(ostemplate.volid));
54
+ });
55
+ }
56
+ });
57
+ } else {
58
+ initOstemplateOptions();
59
+ }
60
+ }
@@ -21,18 +21,18 @@ function cdromSelected(item) {
21
21
 
22
22
  switch (selected) {
23
23
  case 'none':
24
- initStorage();
25
- initOptions('iso');
24
+ initCdromStorage();
25
+ initCdromOptions('iso');
26
26
  cdrom_image_form.hide();
27
27
  break;
28
28
  case 'cdrom':
29
- initStorage();
30
- initOptions('iso');
29
+ initCdromStorage();
30
+ initCdromOptions('iso');
31
31
  cdrom_image_form.hide();
32
32
  break;
33
33
  case 'image':
34
- initStorage();
35
- initOptions('iso');
34
+ initCdromStorage();
35
+ initCdromOptions('iso');
36
36
  cdrom_image_form.show();
37
37
  break;
38
38
  default:
@@ -41,13 +41,13 @@ function cdromSelected(item) {
41
41
  return false;
42
42
  }
43
43
 
44
- function initStorage(){
44
+ function initCdromStorage(){
45
45
  var select = '#host_compute_attributes_config_attributes_cdrom_storage';
46
46
  $(select + ' option:selected').prop('selected',false);
47
47
  $(select).val('');
48
48
  }
49
49
 
50
- function initOptions(name){
50
+ function initCdromOptions(name){
51
51
  var select = '#host_compute_attributes_config_attributes_cdrom_'+name;
52
52
  $(select).empty();
53
53
  $(select).append($("<option></option>").val('').text(''));
@@ -68,14 +68,14 @@ function initOptions(name){
68
68
  console.log("Error=" + error +", status=" + status + " loading isos for storage=" + storage);
69
69
  },
70
70
  success: function(isos) {
71
- initOptions('iso');
71
+ initCdromOptions('iso');
72
72
  $.each(isos, function(i,iso){
73
73
  $('#host_compute_attributes_config_attributes_cdrom_iso').append($("<option></option>").val(iso.volid).text(iso.volid));
74
74
  });
75
75
  }
76
76
  });
77
77
  } else {
78
- initOptions('iso');
78
+ initCdromOptions('iso');
79
79
  }
80
80
  }
81
81
 
@@ -27,7 +27,7 @@ module ForemanFogProxmox
27
27
  def compute_resource_params_filter
28
28
  super.tap do |filter|
29
29
  filter.permit :ssl_verify_peer,
30
- :ssl_certs, :disable_proxy
30
+ :ssl_certs, :node_name, :disable_proxy
31
31
  end
32
32
  end
33
33
 
@@ -23,7 +23,15 @@ module ForemanFogProxmox
23
23
 
24
24
  # GET foreman_fog_proxmox/isos/:storage
25
25
  def isos
26
- volumes = @compute_resource.isos(params[:storage])
26
+ volumes = @compute_resource.images_by_storage('iso',params[:storage])
27
+ respond_to do |format|
28
+ format.json { render :json => volumes }
29
+ end
30
+ end
31
+
32
+ # GET foreman_fog_proxmox/ostemplates/:storage
33
+ def ostemplates
34
+ volumes = @compute_resource.images_by_storage('vztmpl',params[:storage])
27
35
  respond_to do |format|
28
36
  format.json { render :json => volumes }
29
37
  end
@@ -0,0 +1,36 @@
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
+ 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
30
+ end
31
+
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
@@ -18,6 +18,29 @@
18
18
  # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module ProxmoxComputeSelectorsHelper
21
+
22
+ def proxmox_types_map
23
+ [OpenStruct.new(id: 'qemu', name: 'KVM/Qemu server'),
24
+ OpenStruct.new(id: 'lxc', name: 'LXC container')]
25
+ end
26
+
27
+ def proxmox_archs_map
28
+ [OpenStruct.new(id: 'amd64', name: '64 bits'),
29
+ OpenStruct.new(id: 'i386', name: '32 bits')]
30
+ end
31
+
32
+ def proxmox_ostypes_map
33
+ [OpenStruct.new(id: 'debian', name: 'Debian'),
34
+ OpenStruct.new(id: 'ubuntu', name: 'Ubuntu'),
35
+ OpenStruct.new(id: 'centos', name: 'CentOS'),
36
+ OpenStruct.new(id: 'fedora', name: 'Fedora'),
37
+ OpenStruct.new(id: 'opensuse', name: 'OpenSuse'),
38
+ OpenStruct.new(id: 'archlinux', name: 'ArchLinux'),
39
+ OpenStruct.new(id: 'gentoo', name: 'Gentoo'),
40
+ OpenStruct.new(id: 'alpine', name: 'Alpine'),
41
+ OpenStruct.new(id: 'unmanaged', name: 'Unmanaged')]
42
+ end
43
+
21
44
  def proxmox_controllers_map
22
45
  [ForemanFogProxmox::OptionsSelect.new(id:'ide', name: 'IDE', range: 3),
23
46
  ForemanFogProxmox::OptionsSelect.new(id:'sata', name: 'SATA', range: 5),
@@ -0,0 +1,157 @@
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 ProxmoxContainerHelper
25
+
26
+ KILO = 1024
27
+ MEGA = KILO * KILO
28
+ GIGA = KILO * MEGA
29
+
30
+ def parse_container_vm(args)
31
+ args = ActiveSupport::HashWithIndifferentAccess.new(args)
32
+ return {} unless args
33
+ return {} if args.empty?
34
+ return {} unless args['type'] == 'lxc'
35
+ config = args['config_attributes']
36
+ main_a = %w[name type node vmid]
37
+ config = args.reject { |key,_value| main_a.include? key } unless config
38
+ ostemplate_a = %w[ostemplate ostemplate_storage ostemplate_file]
39
+ ostemplate = parse_container_ostemplate(args.select { |key,_value| ostemplate_a.include? key })
40
+ ostemplate = parse_container_ostemplate(config.select { |key,_value| ostemplate_a.include? key }) unless ostemplate[:ostemplate]
41
+ volumes = parse_container_volumes(args['volumes_attributes'])
42
+ cpu_a = %w[arch cpulimit cpuunits cores]
43
+ cpu = parse_container_cpu(config.select { |key,_value| cpu_a.include? key })
44
+ memory_a = %w[memory swap]
45
+ memory = parse_container_memory(config.select { |key,_value| memory_a.include? key })
46
+ interfaces_attributes = args['interfaces_attributes']
47
+ networks = parse_container_interfaces(interfaces_attributes)
48
+ general_a = %w[node name type config_attributes volumes_attributes interfaces_attributes firmware_type provision_method container_volumes server_volumes]
49
+ logger.debug("general_a: #{general_a}")
50
+ parsed_vm = args.reject { |key,value| general_a.include?(key) || ostemplate_a.include?(key) || ForemanFogProxmox::Value.empty?(value) }
51
+ config_a = []
52
+ config_a += cpu_a
53
+ config_a += memory_a
54
+ config_a += main_a
55
+ config_a += general_a
56
+ parsed_config = config.reject { |key,value| config_a.include?(key) || ForemanFogProxmox::Value.empty?(value) }
57
+ logger.debug("parse_container_config(): #{parsed_config}")
58
+ parsed_vm = parsed_vm.merge(parsed_config).merge(cpu).merge(memory).merge(ostemplate)
59
+ networks.each { |network| parsed_vm = parsed_vm.merge(network) }
60
+ volumes.each { |volume| parsed_vm = parsed_vm.merge(volume) }
61
+ logger.debug("parse_container_vm(): #{parsed_vm}")
62
+ parsed_vm
63
+ end
64
+
65
+ def parse_container_memory(args)
66
+ memory = {}
67
+ args.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
68
+ memory.store(:memory, args['memory'].to_i) if args['memory']
69
+ memory.store(:swap, args['swap'].to_i) if args['swap']
70
+ logger.debug("parse_container_memory(): #{memory}")
71
+ memory
72
+ end
73
+
74
+ def parse_container_cpu(args)
75
+ cpu = {}
76
+ args.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
77
+ cpu.store(:arch, args['arch'].to_s) if args['arch']
78
+ cpu.store(:cpulimit, args['cpulimit'].to_i) if args['cpulimit']
79
+ cpu.store(:cpuunits, args['cpuunits'].to_i) if args['cpuunits']
80
+ cpu.store(:cores, args['cores'].to_i) if args['cores']
81
+ logger.debug("parse_container_cpu(): #{cpu}")
82
+ cpu
83
+ end
84
+
85
+ def parse_container_ostemplate(args)
86
+ ostemplate = args['ostemplate']
87
+ ostemplate_file = args['ostemplate_file']
88
+ ostemplate = ostemplate ? ostemplate : ostemplate_file
89
+ ostemplate_storage = args['ostemplate_storage']
90
+ ostemplate_storage, ostemplate_file, _size = Fog::Proxmox::DiskHelper.extract_storage_volid_size(ostemplate) unless ForemanFogProxmox::Value.empty?(ostemplate)
91
+ parsed_ostemplate = {ostemplate: ostemplate, ostemplate_file: ostemplate_file, ostemplate_storage: ostemplate_storage}
92
+ logger.debug("parse_container_ostemplate(): #{parsed_ostemplate}")
93
+ parsed_ostemplate
94
+ end
95
+
96
+ def parse_container_volume(args)
97
+ disk = {}
98
+ id = args['id']
99
+ id = "mp#{args['device']}" unless id
100
+ delete = args['_delete'].to_i == 1
101
+ logger.debug("parse_container_volume() args=#{args}")
102
+ args.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
103
+ if delete
104
+ logger.debug("parse_container_volume(): delete id=#{id}")
105
+ disk.store(:delete, id)
106
+ disk
107
+ else
108
+ disk.store(:id, id)
109
+ disk.store(:volid, args['volid'])
110
+ disk.store(:storage, args['storage'].to_s)
111
+ disk.store(:size, args['size'].to_i)
112
+ options = args.reject { |key,_value| %w[id volid device storage size _delete].include? key}
113
+ disk.store(:options, options)
114
+ logger.debug("parse_container_volume(): add disk=#{disk}")
115
+ Fog::Proxmox::DiskHelper.flatten(disk)
116
+ end
117
+ end
118
+
119
+ def parse_container_volumes(args)
120
+ logger.debug("parse_container_volumes() args=#{args}")
121
+ volumes = []
122
+ args.each_value { |value| volumes.push(parse_container_volume(value))} if args
123
+ logger.debug("parse_container_volumes(): volumes=#{volumes}")
124
+ volumes
125
+ end
126
+
127
+ def parse_container_interfaces(args)
128
+ nics = []
129
+ args.each_value { |value| nics.push(parse_container_interface(value))} if args
130
+ logger.debug("parse_container_interfaces(): nics=#{nics}")
131
+ nics
132
+ end
133
+
134
+ def parse_container_interface(args)
135
+ args.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
136
+ nic = {}
137
+ id = args['id']
138
+ logger.debug("parse_container_interface(): id=#{id}")
139
+ delete = args['_delete'].to_i == 1
140
+ if delete
141
+ logger.debug("parse_container_interface(): delete id=#{id}")
142
+ nic.store(:delete, id)
143
+ nic
144
+ else
145
+ nic.store(:id, id)
146
+ nic.store(:name, args['name'].to_s)
147
+ nic.store(:bridge, args['bridge'].to_s) if args['bridge']
148
+ nic.store(:ip, args['ip'].to_s) if args['ip']
149
+ nic.store(:ip6, args['ip6'].to_s) if args['ip6']
150
+ nic.store(:rate, args['rate'].to_i) if args['rate']
151
+ nic.store(:tag, args['tag'].to_i) if args['tag']
152
+ logger.debug("parse_container_interface(): add nic=#{nic}")
153
+ Fog::Proxmox::NicHelper.container_flatten(nic)
154
+ end
155
+ end
156
+
157
+ end