foreman_fog_proxmox 0.12.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of foreman_fog_proxmox might be problematic. Click here for more details.

Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +619 -0
  3. data/README.md +290 -0
  4. data/Rakefile +49 -0
  5. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +33 -0
  6. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +187 -0
  7. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_container.js +24 -0
  8. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js +125 -0
  9. data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +41 -0
  10. data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +86 -0
  11. data/app/helpers/node_dashboard_helper.rb +35 -0
  12. data/app/helpers/proxmox_compute_selectors_helper.rb +184 -0
  13. data/app/helpers/proxmox_container_helper.rb +163 -0
  14. data/app/helpers/proxmox_form_helper.rb +70 -0
  15. data/app/helpers/proxmox_server_helper.rb +155 -0
  16. data/app/helpers/proxmox_vm_helper.rb +88 -0
  17. data/app/models/concerns/fog_extensions/proxmox/disk.rb +29 -0
  18. data/app/models/concerns/fog_extensions/proxmox/interface.rb +40 -0
  19. data/app/models/concerns/fog_extensions/proxmox/node.rb +41 -0
  20. data/app/models/concerns/fog_extensions/proxmox/server.rb +93 -0
  21. data/app/models/concerns/fog_extensions/proxmox/server_config.rb +71 -0
  22. data/app/models/concerns/fog_extensions/proxmox/volume.rb +29 -0
  23. data/app/models/concerns/host_ext/proxmox/interfaces.rb +52 -0
  24. data/app/models/concerns/orchestration/proxmox/compute.rb +42 -0
  25. data/app/models/foreman_fog_proxmox/options_select.rb +36 -0
  26. data/app/models/foreman_fog_proxmox/proxmox.rb +133 -0
  27. data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +67 -0
  28. data/app/models/foreman_fog_proxmox/proxmox_connection.rb +67 -0
  29. data/app/models/foreman_fog_proxmox/proxmox_console.rb +41 -0
  30. data/app/models/foreman_fog_proxmox/proxmox_images.rb +61 -0
  31. data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +103 -0
  32. data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +49 -0
  33. data/app/models/foreman_fog_proxmox/proxmox_pools.rb +56 -0
  34. data/app/models/foreman_fog_proxmox/proxmox_token_expiration.rb +30 -0
  35. data/app/models/foreman_fog_proxmox/proxmox_version.rb +36 -0
  36. data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +116 -0
  37. data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +178 -0
  38. data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +75 -0
  39. data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +94 -0
  40. data/app/models/foreman_fog_proxmox/vms.rb +37 -0
  41. data/app/overrides/compute_resources_vms/form/add_clone_to_new_vm_compute_detail.rb +25 -0
  42. data/app/overrides/compute_resources_vms/form/add_from_profile_to_compute_attributes_form.rb +34 -0
  43. data/app/overrides/compute_resources_vms/form/add_vm_type_node_to_new_form.rb +25 -0
  44. data/app/overrides/compute_resources_vms/form/add_vm_type_to_networks_form.rb +34 -0
  45. data/app/overrides/compute_resources_vms/form/add_vm_type_to_nic_provider_specific_form.rb +26 -0
  46. data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_edit.rb +25 -0
  47. data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_new_volume.rb +25 -0
  48. data/app/overrides/compute_resources_vms/form/remove_new_vm_from_removable_layout.rb +25 -0
  49. data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +37 -0
  50. data/app/views/api/v2/compute_resources/proxmox.json.rabl +3 -0
  51. data/app/views/compute_resources/form/_proxmox.html.erb +29 -0
  52. data/app/views/compute_resources/show/_proxmox.html.erb +37 -0
  53. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_attributes_form.html.erb +23 -0
  54. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_form.html.erb +23 -0
  55. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_hosts_compute_detail_form.html.erb +24 -0
  56. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_node_to_new_form.html.erb +24 -0
  57. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_form.html.erb +28 -0
  58. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_new_childs_form.html.erb +32 -0
  59. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +30 -0
  60. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +71 -0
  61. data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +39 -0
  62. data/app/views/compute_resources_vms/form/proxmox/_general.html.erb +39 -0
  63. data/app/views/compute_resources_vms/form/proxmox/_network.html.erb +19 -0
  64. data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +27 -0
  65. data/app/views/compute_resources_vms/form/proxmox/container/_advanced.html.erb +31 -0
  66. data/app/views/compute_resources_vms/form/proxmox/container/_config.html.erb +41 -0
  67. data/app/views/compute_resources_vms/form/proxmox/container/_extended.html.erb +27 -0
  68. data/app/views/compute_resources_vms/form/proxmox/container/_network.html.erb +33 -0
  69. data/app/views/compute_resources_vms/form/proxmox/container/_volume_mp.html.erb +27 -0
  70. data/app/views/compute_resources_vms/form/proxmox/container/_volume_rootfs.html.erb +24 -0
  71. data/app/views/compute_resources_vms/form/proxmox/server/_advanced.html.erb +31 -0
  72. data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +60 -0
  73. data/app/views/compute_resources_vms/form/proxmox/server/_network.html.erb +30 -0
  74. data/app/views/compute_resources_vms/form/proxmox/server/_volume.html.erb +28 -0
  75. data/app/views/compute_resources_vms/index/_proxmox.html.erb +49 -0
  76. data/app/views/compute_resources_vms/show/_proxmox.html.erb +42 -0
  77. data/app/views/dashboard/_foreman_fog_proxmox_widget.erb +21 -0
  78. data/app/views/images/form/_proxmox.html.erb +21 -0
  79. data/config/routes.rb +30 -0
  80. data/lib/foreman_fog_proxmox.rb +23 -0
  81. data/lib/foreman_fog_proxmox/engine.rb +105 -0
  82. data/lib/foreman_fog_proxmox/semver.rb +102 -0
  83. data/lib/foreman_fog_proxmox/value.rb +26 -0
  84. data/lib/foreman_fog_proxmox/version.rb +22 -0
  85. data/lib/tasks/foreman_fog_proxmox_tasks.rake +37 -0
  86. data/locale/Makefile +60 -0
  87. data/locale/en/foreman_fog_proxmox.po +401 -0
  88. data/locale/foreman_fog_proxmox.pot +627 -0
  89. data/locale/fr/foreman_fog_proxmox.po +401 -0
  90. data/locale/gemspec.rb +4 -0
  91. data/test/factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb +137 -0
  92. data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +87 -0
  93. data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +134 -0
  94. data/test/factories/proxmox_factory.rb +79 -0
  95. data/test/functional/compute_resources_controller_test.rb +48 -0
  96. data/test/test_plugin_helper.rb +19 -0
  97. data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +204 -0
  98. data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +149 -0
  99. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +216 -0
  100. data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +124 -0
  101. data/test/unit/foreman_fog_proxmox/proxmox_images_test.rb +52 -0
  102. data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +117 -0
  103. data/test/unit/foreman_fog_proxmox/proxmox_test.rb +58 -0
  104. data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +94 -0
  105. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +280 -0
  106. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +110 -0
  107. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +222 -0
  108. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_volumes_test.rb +308 -0
  109. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_test.rb +43 -0
  110. data/test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb +71 -0
  111. data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +68 -0
  112. data/test/unit/foreman_fog_proxmox/semver_test.rb +111 -0
  113. metadata +249 -0
@@ -0,0 +1,290 @@
1
+ ![ForemanFogProxmox](.github/images/foremanproxmox.png)
2
+
3
+ ![CI](https://github.com/theforeman/foreman_fog_proxmox/workflows/CI/badge.svg)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/922162c278e0fa9207ba/maintainability)](https://codeclimate.com/github/theforeman/foreman_fog_proxmox/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/922162c278e0fa9207ba/test_coverage)](https://codeclimate.com/github/theforeman/foreman_fog_proxmox/test_coverage)
6
+ [![Gem Version](https://badge.fury.io/rb/foreman_fog_proxmox.svg)](https://badge.fury.io/rb/foreman_fog_proxmox)
7
+
8
+ # ForemanFogProxmox
9
+
10
+ [Foreman](http://theforeman.org/) plugin that adds [Proxmox](https://www.proxmox.com/en/proxmox-ve) compute resource: managing virtual machines and containers using the [fog-proxmox](https://github.com/fog/fog-proxmox) module.
11
+
12
+ It is intended to satisfy this [feature](http://projects.theforeman.org/issues/2186).
13
+
14
+ If you like it and need more features you can [contribute](.github/CONTRIBUTING.md) or simply [support](.github/SUPPORT.md) it:
15
+
16
+ ## Support
17
+
18
+ You can support the plugin development via the following methods:
19
+
20
+ * [Donate by PayPal](https://paypal.me/TristanRobert)
21
+ * [Sponsor by Github](https://github.com/sponsors/tristanrobert)
22
+
23
+ ## Compatibility versions
24
+
25
+ |Fog-proxmox|Proxmox|Foreman-fog-proxmox|Foreman|Ruby|
26
+ |--|--|--|--|--|
27
+ |<0.6|<5.3|<0.6|<=1.20|>=2.3|
28
+ |=0.6|<5.4|=0.6|=1.21|>=2.3|
29
+ |<=0.8 |<6.0|>=0.7|>=1.22|>=2.3|
30
+ |<0.9 |<6.0|=0.9|>=1.22|>=2.3|
31
+ |>=0.9 |>=5.4|>=0.9.1|>=1.22|>=2.3|
32
+ |>=0.10 |>=5.4|>=0.9.4|>=1.22|>=2.5|
33
+ |>=0.11 |>=5.4|>=0.10|>=1.22|>=2.5|
34
+ |>=0.12 |>=6.1|>=0.11|>=2.0|>=2.5|
35
+
36
+ ## Installation
37
+
38
+ ### Prerequisites
39
+
40
+ You need [nodejs](https://nodejs.org/en/download/package-manager/) installed in order to use foreman-assets package.
41
+
42
+ ### From gem
43
+
44
+ See complete details in [plugin installation from gem](https://theforeman.org/plugins/#2.3AdvancedInstallationfromGems)
45
+
46
+ Here is a Debian sample:
47
+
48
+ * Install foreman [from OS packages](https://theforeman.org/manuals/1.19/index.html#3.3InstallFromPackages):
49
+
50
+ ```shell
51
+ sudo apt install -y foreman foreman-compute foreman-sqlite3 foreman-assets
52
+ ```
53
+
54
+ * Use only foreman user (**not root!**) `sudo -u foreman ...`
55
+ * In /usr/share/foreman/bundler.d directory, add Gemfile.local.rb file and add this line in it:
56
+
57
+ ```shell
58
+ echo "gem 'foreman_fog_proxmox'" | sudo -u foreman tee /usr/share/foreman/bundler.d/Gemfile.local.rb
59
+ ```
60
+
61
+ * Install the gem plugin:
62
+
63
+ ```shell
64
+ sudo -u foreman /usr/bin/foreman-ruby /usr/bin/bundle install
65
+ ```
66
+
67
+ * Precompile plugin assets:
68
+
69
+ ```shell
70
+ /usr/bin/foreman-ruby /usr/bin/bundle exec bin/rake plugin:assets:precompile[foreman_fog_proxmox]
71
+ ```
72
+
73
+ * Compile plugin translations if (french) needed :
74
+
75
+ ```shell
76
+ /usr/bin/foreman-ruby /usr/bin/bundle exec bin/rake plugin:gettext[foreman_fog_proxmox]
77
+ ```
78
+
79
+ * Complete installation of foreman 1.22 with foreman-installer:
80
+
81
+ ```shell
82
+ sudo apt install -y foreman-installer
83
+ sudo foreman-installer
84
+ ```
85
+
86
+ If you don't want to have HTTP 503 errors when apt is trying to install puppetserver, then add this before launching foreman-installer:
87
+
88
+ ```shell
89
+ echo 'Acquire::http::User-agent "Mozilla/5.0 (Linux)";' | sudo tee /etc/apt/apt.conf.d/96useragent
90
+ ```
91
+
92
+ See complete details in [plugin installation from gem](https://theforeman.org/plugins/#2.3.2Debiandistributions)
93
+
94
+ Then you can check plugin installation after login into your new foreman server seeing the about foreman page:
95
+
96
+ ![About resources](.github/images/about_resources.png)
97
+ ![About greffon](.github/images/about_greffon.png)
98
+
99
+ ### From OS packages
100
+
101
+ Please see the Foreman manual for complete instructions:
102
+
103
+ * [Foreman: How to Install a Plugin](http://theforeman.org/manuals/latest/index.html#6.1InstallaPlugin)
104
+
105
+ Redhat, CentOS or Fedora users should also [setup Selinux](https://projects.theforeman.org/projects/foreman/wiki/SELinux) to allow foreman and all its plugins to work.
106
+
107
+ ## Usage
108
+
109
+ * [Compute resource](.github/compute_resource.md)
110
+ * [Manage hosts](.github/hosts.md)
111
+
112
+ ## Development
113
+
114
+ ### Prerequisites
115
+
116
+ * 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
+
120
+ ### Platform
121
+
122
+ * Fork this github repo.
123
+ * Clone it on your local machine
124
+ * Install foreman v1.22+ on your machine:
125
+
126
+ ```shell
127
+ git clone https://github.com/theforeman/foreman -b develop
128
+ ```
129
+
130
+ * Create a Gemfile.local.rb file in foreman/bundler.d/
131
+ * Add this line:
132
+
133
+ ```ruby
134
+ gem 'foreman_fog_proxmox', :path => '../../theforeman/foreman_fog_proxmox'
135
+ gem 'fog-proxmox', :path => '../../fog/fog-proxmox' # optional if you need to modify fog-proxmox code too
136
+ gem 'ruby-debug-ide' # dev
137
+ gem 'debase' # dev
138
+ gem 'simplecov' # test
139
+ ```
140
+
141
+ * In foreman directory, install dependencies:
142
+
143
+ ```shell
144
+ gem install bundler
145
+ # prerequisites postgresql-client library on OS
146
+ bundle config set without 'libvirt ovirt mysql2'
147
+ bundle install
148
+ ```
149
+
150
+ ```shell
151
+ npm install
152
+ ```
153
+
154
+ * Configure foreman settings:
155
+
156
+ ```shell
157
+ cp config/settings.yaml.test config/settings.yaml
158
+ ```
159
+
160
+ add these lines to config/settings.yml:
161
+
162
+ ```yaml
163
+ :webpack_dev_server: true
164
+ ```
165
+
166
+ * SQLite is no more default rails dev or test database, instead add:
167
+
168
+ ```shell
169
+ DATABASE_URL=nulldb://nohost
170
+ ```
171
+
172
+ * (Optional) test and dev with postgresql database:
173
+
174
+ ```shell
175
+ cp config/model.mappings.example config/model.mappings
176
+ cp config/database.yml.example config/database.yml
177
+ ```
178
+
179
+ add these lines to config/database.yml:
180
+
181
+ ```yaml
182
+ username: foreman
183
+ password: foreman
184
+ ```
185
+
186
+ ```shell
187
+ cp config/ignored_environments.yml.sample config/ignored_environments.yml
188
+ docker run --name foreman-db -e POSTGRES_DB=foreman -e POSTGRES_USER=foreman -e POSTGRES_PASSWORD=foreman -p 5432:5432 -d postgres
189
+ bundle exec bin/rake db:migrate
190
+ bundle exec bin/rake db:seed assets:precompile locale:pack webpack:compile
191
+ ```
192
+
193
+ * You can reset admin password if needed:
194
+
195
+ ```shell
196
+ bundle exec bin/rake permissions:reset
197
+ ```
198
+
199
+ * You should write tests and you can execute those specific to this plugin:
200
+
201
+ first, create database `foreman-test` with psql commands:
202
+
203
+ ```shell
204
+ docker exec -it foreman-db psql -U foreman
205
+ foreman=# create database "foreman-test";
206
+ ```
207
+
208
+ all:
209
+
210
+ ```shell
211
+ export DISABLE_SPRING=true
212
+ bundle exec bin/rake test:foreman_fog_proxmox
213
+ ```
214
+
215
+ or just one:
216
+
217
+ ```shell
218
+ export DISABLE_SPRING=true
219
+ bundle exec bin/rake test TEST=test/functional/compute_resources_controller_test.rb DATABASE_URL=nulldb://nohost
220
+ ```
221
+
222
+ * Check code syntax with rubocop and foreman rules:
223
+
224
+ ```shell
225
+ bundle exec bin/rake foreman_fog_proxmox:rubocop
226
+ ```
227
+
228
+ * See deface overrides result:
229
+
230
+ ```shell
231
+ bundle exec bin/rake deface:get_result['hosts/_compute_detail']
232
+ ```
233
+
234
+ * In foreman directory, after you modify foreman_fog_proxmox specific assets (proxmox.js, etc) you have to precompile it:
235
+
236
+ ```shell
237
+ bundle exec bin/rake plugin:assets:precompile[foreman_fog_proxmox]
238
+ ```
239
+
240
+ * In foreman directory, after you modify foreman_fog_proxmox translations (language, texts in new files, etc) you have to compile it:
241
+
242
+ ```shell
243
+ bundle exec bin/rake plugin:gettext[foreman_fog_proxmox]
244
+ ```
245
+
246
+ * In foreman directory, run in a new terminal the webpack-dev-server:
247
+
248
+ ```shell
249
+ ./node_modules/.bin/webpack-dev-server --config config/webpack.config.js
250
+ ```
251
+
252
+ * Or without webpack-dev-server, add this line in config/settings.yml:
253
+
254
+ ```yml
255
+ :webpack_dev_server: false
256
+ ```
257
+
258
+ then compile webpack assets:
259
+
260
+ ```shell
261
+ bundle exec bin/rake webpack:compile
262
+ ```
263
+
264
+ * In foreman directory, run rails server:
265
+
266
+ ```shell
267
+ bundle exec bin/rails server
268
+ ```
269
+
270
+ * Or you can launch all together:
271
+
272
+ ```shell
273
+ bundle exec foreman start
274
+ ```
275
+
276
+ See details in [foreman plugin development](https://projects.theforeman.org/projects/foreman/wiki/How_to_Create_a_Plugin)
277
+
278
+ ## Contributing
279
+
280
+ If you like it and still want to improve it, [sponsor me](https://github.com/sponsors/tristanrobert)!
281
+
282
+ * You can reach the [contributors](.github/CONTRIBUTORS.md).
283
+ * [Translate it in your favorite language](https://www.transifex.com/foreman/foreman/foreman_fog_proxmox/)
284
+ * Bug reports and pull requests are welcome on GitHub at [ForemanFogProxmox](https://github.com/theforeman/foreman_fog_proxmox).
285
+
286
+ Please read more information about [how to contribute](.github/CONTRIBUTING.md).
287
+
288
+ ## License
289
+
290
+ The code is available as open source under the terms of the [GNU Public License v3](LICENSE).
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env rake
2
+ # frozen_string_literal: true
3
+
4
+ begin
5
+ require 'bundler/setup'
6
+ rescue LoadError
7
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
8
+ end
9
+ begin
10
+ require 'rdoc/task'
11
+ rescue LoadError
12
+ require 'rdoc/rdoc'
13
+ require 'rake/rdoctask'
14
+ RDoc::Task = Rake::RDocTask
15
+ end
16
+
17
+ RDoc::Task.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'ForemanFogProxmox'
20
+ rdoc.options << '--line-numbers'
21
+ rdoc.rdoc_files.include('README.rdoc')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
26
+
27
+ Bundler::GemHelper.install_tasks
28
+
29
+ require 'rake/testtask'
30
+
31
+ Rake::TestTask.new(:test) do |t|
32
+ t.libs << 'lib'
33
+ t.libs << 'test'
34
+ t.pattern = 'test/**/*_test.rb'
35
+ t.verbose = false
36
+ end
37
+
38
+ task default: :test
39
+
40
+ begin
41
+ require 'rubocop/rake_task'
42
+ RuboCop::RakeTask.new
43
+ rescue StandardError => _e
44
+ puts 'Rubocop not loaded.'
45
+ end
46
+
47
+ task :default do
48
+ Rake::Task['rubocop'].execute
49
+ end
@@ -0,0 +1,33 @@
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(sslVerifyPeerSelected);
20
+
21
+ function sslVerifyPeerSelected(){
22
+ var selected = $("#compute_resource_ssl_verify_peer").is(':checked');
23
+ var ssl_certs_block = $('#compute_resource_ssl_certs').parents('.clearfix');
24
+ var ssl_certs_textarea = $('#compute_resource_ssl_certs');
25
+ if (selected) {
26
+ ssl_certs_block.show();
27
+ ssl_certs_textarea.show();
28
+ } else {
29
+ ssl_certs_block.hide();
30
+ ssl_certs_textarea.text('');
31
+ ssl_certs_textarea.hide();
32
+ }
33
+ }
@@ -0,0 +1,187 @@
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
+ default:
61
+ console.log("unkown type="+selected);
62
+ break;
63
+ }
64
+ }
65
+
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;
97
+ }
98
+ }
99
+
100
+ function nodeSelected(item) {
101
+ var node_id = $(item).val();
102
+ var type = $("#host_compute_attributes_type").val();
103
+ if (type == undefined) type = $("#compute_attribute_vm_attrs_type").val();
104
+ switch (type) {
105
+ case 'qemu':
106
+ updateOptions('isostorages', 'compute_attributes_config_attributes', 'cdrom_storage', 'compute_attributes_config_attributes', 'cdrom_iso', 'storage', node_id, undefined);
107
+ updateOptions('storages', 'compute_attributes_volumes_attributes', 'storage', undefined, undefined, 'storage', node_id, undefined);
108
+ updateOptions('bridges', 'interfaces_attributes', 'compute_attributes_bridge', undefined, undefined, 'iface', node_id, undefined);
109
+ break;
110
+ case 'lxc':
111
+ updateOptions('ostemplates', 'compute_attributes_ostemplate', 'storage', 'compute_attributes_ostemplate', 'file', 'storage', node_id, undefined);
112
+ updateOptions('storages', 'compute_attributes_volumes_attributes', 'storage', undefined, undefined, 'storage', node_id, undefined);
113
+ updateOptions('bridges', 'interfaces_attributes', 'compute_attributes_bridge', undefined, undefined, 'iface', node_id, undefined);
114
+ break;
115
+ default:
116
+ console.log("unkown type=" + type);
117
+ break;
118
+ }
119
+ }
120
+
121
+ function emptySelect(select){
122
+ $(select).empty();
123
+ $(select).append($("<option></option>").val('').text(''));
124
+ $(select).val('');
125
+ }
126
+
127
+ function initOptions(select_ids){
128
+ console.log('initOptions(' + select_ids[0] + ')');
129
+ select_ids.forEach(emptySelect);
130
+ select_ids.forEach(function(select){
131
+ $(select + ' option:selected').prop('selected',false);
132
+ $(select).val('');
133
+ });
134
+ }
135
+
136
+ function updateOption(select_id, option, option_id){
137
+ console.log('update '+ select_id + ' with '+ option[option_id]);
138
+ $(select_id).append($('<option></option>').val(option[option_id]).text(option[option_id]));
139
+ }
140
+
141
+ function selectIds(start_options_id, end_options_id){
142
+ var select_host_id = 'select[id^=host_' + start_options_id + ']';
143
+ var compute_attributes_regex = /compute_attributes_/gi;
144
+ var select_profile_id = 'select[id^=compute_attribute_vm_attrs_' + start_options_id.replace(compute_attributes_regex, '') + ']';
145
+ if (end_options_id != undefined) {
146
+ select_host_id += '[id$=' + end_options_id + ']';
147
+ select_profile_id += '[id$=' + end_options_id.replace(compute_attributes_regex, '') + ']';
148
+ }
149
+ return [select_host_id, select_profile_id];
150
+ }
151
+
152
+ function updateOptions(options_path, start_options_id, end_options_id, start_second_options_id, end_second_options_id, option_id, node_id, second_id) {
153
+
154
+ var select_ids = selectIds(start_options_id, end_options_id);
155
+ var select_second_ids;
156
+ if ( start_second_options_id != undefined && end_second_options_id != undefined) {
157
+ select_second_ids = selectIds(start_second_options_id, end_second_options_id);
158
+ }
159
+ var url = '/foreman_fog_proxmox/' + options_path + '/' + node_id;
160
+ if (second_id != undefined) url += '/' + second_id;
161
+ tfm.tools.showSpinner();
162
+ $.getJSON({
163
+ type: 'get',
164
+ url: url,
165
+ error: function(j,status,error){
166
+ var errorMsg = 'Error=' + error + ', status=' + status + ' loading ' + options_path + ' for node_id=' + node_id;
167
+ if (second_id != undefined) errorMsg += ' and second_id=' + second_id;
168
+ console.log(errorMsg);
169
+ },
170
+ success: function(options) {
171
+ initOptions(select_ids);
172
+ if (select_second_ids != undefined) {
173
+ initOptions(select_second_ids);
174
+ }
175
+ $.each(options, function(i,option){
176
+ for (var j = 0; j < select_ids.length; j++) {
177
+ updateOption(select_ids[j], option, option_id);
178
+ }
179
+ });
180
+ },
181
+ complete: function(item){
182
+ // eslint-disable-next-line no-undef
183
+ reloadOnAjaxComplete(item);
184
+ tfm.tools.hideSpinner();
185
+ }
186
+ });
187
+ }