foreman_fog_proxmox 0.10.0 → 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.
- checksums.yaml +4 -4
- data/README.md +62 -13
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +13 -13
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js +0 -22
- data/app/helpers/proxmox_compute_selectors_helper.rb +14 -0
- data/app/helpers/proxmox_server_helper.rb +2 -6
- data/app/helpers/proxmox_vm_helper.rb +2 -10
- data/app/models/concerns/fog_extensions/proxmox/server.rb +1 -0
- data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +14 -1
- data/app/models/foreman_fog_proxmox/proxmox_connection.rb +1 -1
- data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +1 -1
- data/app/models/foreman_fog_proxmox/proxmox_pools.rb +56 -0
- data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +5 -1
- data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +4 -4
- data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +6 -7
- data/app/views/api/v2/compute_resources/proxmox.json.rabl +1 -1
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +2 -2
- data/app/views/compute_resources_vms/form/proxmox/_general.html.erb +1 -0
- data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +4 -4
- data/app/views/compute_resources_vms/show/_proxmox.html.erb +1 -0
- data/lib/foreman_fog_proxmox/version.rb +1 -1
- data/locale/en/foreman_fog_proxmox.po +18 -3
- data/locale/foreman_fog_proxmox.pot +48 -28
- data/locale/fr/foreman_fog_proxmox.po +18 -3
- data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +6 -0
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +4 -4
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +10 -9
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +1 -1
- data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +10 -2
- data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +4 -4
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +14 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +29 -1
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +91 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +7 -2
- data/test/unit/foreman_fog_proxmox/semver_test.rb +3 -5
- metadata +22 -25
- data/locale/en/foreman_fog_proxmox.edit.po +0 -508
- data/locale/en/foreman_fog_proxmox.po.time_stamp +0 -0
- data/locale/fr/foreman_fog_proxmox.edit.po +0 -508
- data/locale/fr/foreman_fog_proxmox.po.time_stamp +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce063ca3e1f223b49897b86d1a310bad8c15e1c25baa9eabb2304520e1904001
|
4
|
+
data.tar.gz: a44facfbc190a729c68d2ef82ae37de9d8b91fcd0f49e7808f85bd05911bcd44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b2c86fade0bcf232ca6c29e162a5baba2d02083d078b401f0d3d3e9c23ecd7ffcb41ba8b07e2980ce09186956d19537ee51b26bed3a126d908ee56ef05187d1
|
7
|
+
data.tar.gz: 757d04ed4a596e1d0ea80424ef4d405b258b3d6b9c0bbcc1cc4081e945f087cfbe910043290a341b2cd821dfbdb73f9423683606ae2ee35c93e0928740c4a9e1
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
![ForemanFogProxmox](.github/images/foremanproxmox.png)
|
2
2
|
|
3
|
-
|
3
|
+
![CI](https://github.com/theforeman/foreman_fog_proxmox/workflows/CI/badge.svg)
|
4
4
|
[![Maintainability](https://api.codeclimate.com/v1/badges/922162c278e0fa9207ba/maintainability)](https://codeclimate.com/github/theforeman/foreman_fog_proxmox/maintainability)
|
5
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)
|
6
7
|
|
7
8
|
# ForemanFogProxmox
|
8
9
|
|
@@ -29,6 +30,8 @@ You can support the plugin development via the following methods:
|
|
29
30
|
|<0.9 |<6.0|=0.9|>=1.22|>=2.3|
|
30
31
|
|>=0.9 |>=5.4|>=0.9.1|>=1.22|>=2.3|
|
31
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|
|
32
35
|
|
33
36
|
## Installation
|
34
37
|
|
@@ -128,8 +131,8 @@ git clone https://github.com/theforeman/foreman -b develop
|
|
128
131
|
* Add this line:
|
129
132
|
|
130
133
|
```ruby
|
131
|
-
gem 'foreman_fog_proxmox', :path => '/
|
132
|
-
gem 'fog-proxmox', :path => '/
|
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
|
133
136
|
gem 'ruby-debug-ide' # dev
|
134
137
|
gem 'debase' # dev
|
135
138
|
gem 'simplecov' # test
|
@@ -138,7 +141,10 @@ gem 'simplecov' # test
|
|
138
141
|
* In foreman directory, install dependencies:
|
139
142
|
|
140
143
|
```shell
|
141
|
-
|
144
|
+
gem install bundler
|
145
|
+
# prerequisites postgresql-client library on OS
|
146
|
+
bundle config set without 'libvirt ovirt mysql2'
|
147
|
+
bundle install
|
142
148
|
```
|
143
149
|
|
144
150
|
```shell
|
@@ -151,14 +157,37 @@ npm install
|
|
151
157
|
cp config/settings.yaml.test config/settings.yaml
|
152
158
|
```
|
153
159
|
|
154
|
-
|
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:
|
155
173
|
|
156
174
|
```shell
|
157
175
|
cp config/model.mappings.example config/model.mappings
|
158
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
|
159
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
|
160
189
|
bundle exec bin/rake db:migrate
|
161
|
-
bundle exec bin/rake db:seed
|
190
|
+
bundle exec bin/rake db:seed assets:precompile locale:pack webpack:compile
|
162
191
|
```
|
163
192
|
|
164
193
|
* You can reset admin password if needed:
|
@@ -169,6 +198,13 @@ bundle exec bin/rake permissions:reset
|
|
169
198
|
|
170
199
|
* You should write tests and you can execute those specific to this plugin:
|
171
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
|
+
|
172
208
|
all:
|
173
209
|
|
174
210
|
```shell
|
@@ -180,7 +216,7 @@ or just one:
|
|
180
216
|
|
181
217
|
```shell
|
182
218
|
export DISABLE_SPRING=true
|
183
|
-
bundle exec bin/rake test TEST=test/functional/compute_resources_controller_test.rb
|
219
|
+
bundle exec bin/rake test TEST=test/functional/compute_resources_controller_test.rb DATABASE_URL=nulldb://nohost
|
184
220
|
```
|
185
221
|
|
186
222
|
* Check code syntax with rubocop and foreman rules:
|
@@ -207,16 +243,28 @@ bundle exec bin/rake plugin:assets:precompile[foreman_fog_proxmox]
|
|
207
243
|
bundle exec bin/rake plugin:gettext[foreman_fog_proxmox]
|
208
244
|
```
|
209
245
|
|
210
|
-
* In foreman directory, run
|
246
|
+
* In foreman directory, run in a new terminal the webpack-dev-server:
|
211
247
|
|
212
248
|
```shell
|
213
|
-
|
249
|
+
./node_modules/.bin/webpack-dev-server --config config/webpack.config.js
|
214
250
|
```
|
215
251
|
|
216
|
-
*
|
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:
|
217
259
|
|
218
260
|
```shell
|
219
|
-
|
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
|
220
268
|
```
|
221
269
|
|
222
270
|
* Or you can launch all together:
|
@@ -231,8 +279,9 @@ See details in [foreman plugin development](https://projects.theforeman.org/proj
|
|
231
279
|
|
232
280
|
If you like it and still want to improve it, [sponsor me](https://github.com/sponsors/tristanrobert)!
|
233
281
|
|
234
|
-
You can reach the [contributors](.github/CONTRIBUTORS.md).
|
235
|
-
|
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).
|
236
285
|
|
237
286
|
Please read more information about [how to contribute](.github/CONTRIBUTING.md).
|
238
287
|
|
@@ -103,14 +103,14 @@ function nodeSelected(item) {
|
|
103
103
|
if (type == undefined) type = $("#compute_attribute_vm_attrs_type").val();
|
104
104
|
switch (type) {
|
105
105
|
case 'qemu':
|
106
|
-
updateOptions('isostorages', 'compute_attributes_config_attributes', 'cdrom_storage', 'compute_attributes_config_attributes', 'cdrom_iso', 'storage', node_id);
|
107
|
-
updateOptions('storages', 'compute_attributes_volumes_attributes', 'storage', undefined, undefined, 'storage', node_id);
|
108
|
-
updateOptions('bridges', 'interfaces_attributes', 'compute_attributes_bridge', undefined, undefined, 'iface', node_id);
|
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
109
|
break;
|
110
110
|
case 'lxc':
|
111
|
-
updateOptions('ostemplates', 'compute_attributes_ostemplate', 'storage', 'compute_attributes_ostemplate', 'file', 'storage', node_id);
|
112
|
-
updateOptions('storages', 'compute_attributes_volumes_attributes', 'storage', undefined, undefined, 'storage', node_id);
|
113
|
-
updateOptions('bridges', 'interfaces_attributes', 'compute_attributes_bridge', undefined, undefined, 'iface', node_id);
|
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
114
|
break;
|
115
115
|
default:
|
116
116
|
console.log("unkown type=" + type);
|
@@ -139,9 +139,9 @@ function updateOption(select_id, option, option_id){
|
|
139
139
|
}
|
140
140
|
|
141
141
|
function selectIds(start_options_id, end_options_id){
|
142
|
-
|
143
|
-
|
144
|
-
|
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
145
|
if (end_options_id != undefined) {
|
146
146
|
select_host_id += '[id$=' + end_options_id + ']';
|
147
147
|
select_profile_id += '[id$=' + end_options_id.replace(compute_attributes_regex, '') + ']';
|
@@ -149,10 +149,10 @@ function selectIds(start_options_id, end_options_id){
|
|
149
149
|
return [select_host_id, select_profile_id];
|
150
150
|
}
|
151
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
|
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
153
|
|
154
|
-
|
155
|
-
|
154
|
+
var select_ids = selectIds(start_options_id, end_options_id);
|
155
|
+
var select_second_ids;
|
156
156
|
if ( start_second_options_id != undefined && end_second_options_id != undefined) {
|
157
157
|
select_second_ids = selectIds(start_second_options_id, end_second_options_id);
|
158
158
|
}
|
@@ -173,7 +173,7 @@ function updateOptions(options_path, start_options_id, end_options_id, start_sec
|
|
173
173
|
initOptions(select_second_ids);
|
174
174
|
}
|
175
175
|
$.each(options, function(i,option){
|
176
|
-
for (
|
176
|
+
for (var j = 0; j < select_ids.length; j++) {
|
177
177
|
updateOption(select_ids[j], option, option_id);
|
178
178
|
}
|
179
179
|
});
|
@@ -122,26 +122,4 @@ function computeControllerMaxDevice(controller) {
|
|
122
122
|
default:
|
123
123
|
return 1;
|
124
124
|
}
|
125
|
-
}
|
126
|
-
|
127
|
-
function balloonSelected(item) {
|
128
|
-
var ballooned = $(item).is(':checked');
|
129
|
-
var memory_f = $("input[name$='[config_attributes][memory]']:hidden");
|
130
|
-
var min_memory_f = $("input[id$='config_attributes_min_memory']");
|
131
|
-
var min_memory_hidden_f = $("input[name$='[config_attributes][min_memory]']:hidden");
|
132
|
-
var shares_f = $("input[id$='config_attributes_shares']");
|
133
|
-
var shares_hidden_f = $("input[name$='[config_attributes][shares]']:hidden");
|
134
|
-
if (ballooned) {
|
135
|
-
min_memory_f.removeAttr('disabled');
|
136
|
-
shares_f.removeAttr('disabled');
|
137
|
-
var max = memory_f.val();
|
138
|
-
console.log("max=" + max);
|
139
|
-
min_memory_f.attr('data-soft-max', max);
|
140
|
-
} else {
|
141
|
-
min_memory_f.attr('disabled', 'disabled');
|
142
|
-
min_memory_hidden_f.attr('value', '');
|
143
|
-
shares_f.attr('disabled', 'disabled');
|
144
|
-
shares_hidden_f.attr('value', '');
|
145
|
-
}
|
146
|
-
tfm.numFields.initAll();
|
147
125
|
}
|
@@ -47,6 +47,15 @@ module ProxmoxComputeSelectorsHelper
|
|
47
47
|
ForemanFogProxmox::OptionsSelect.new(name: 'VirtIO Block', id: 'virtio', range: 15)]
|
48
48
|
end
|
49
49
|
|
50
|
+
def proxmox_scsi_controllers_map
|
51
|
+
[OpenStruct.new(id: 'lsi', name: 'LSI 53C895A (Default)'),
|
52
|
+
OpenStruct.new(id: 'lsi53c810', name: 'LSI 53C810'),
|
53
|
+
OpenStruct.new(id: 'virtio-scsi-pci', name: 'VirtIO SCSI'),
|
54
|
+
OpenStruct.new(id: 'virtio-scsi-single', name: 'VirtIO SCSI Single'),
|
55
|
+
OpenStruct.new(id: 'megasas', name: 'MegaRAID SAS 8708EM2'),
|
56
|
+
OpenStruct.new(id: 'pvscsi', name: 'VMware PVSCSI')]
|
57
|
+
end
|
58
|
+
|
50
59
|
def proxmox_operating_systems_map
|
51
60
|
[OpenStruct.new(id: 'other', name: 'Unspecified OS'),
|
52
61
|
OpenStruct.new(id: 'wxp', name: 'Microsoft Windows XP'),
|
@@ -167,4 +176,9 @@ module ProxmoxComputeSelectorsHelper
|
|
167
176
|
OpenStruct.new(id: 'rtl8139', name: 'Realtek RTL8139'),
|
168
177
|
OpenStruct.new(id: 'vmxnet3', name: 'VMware vmxnet3')]
|
169
178
|
end
|
179
|
+
|
180
|
+
def proxmox_bios_map
|
181
|
+
[OpenStruct.new(id: 'seabios', name: '(Default) Seabios'),
|
182
|
+
OpenStruct.new(id: 'ovmf', name: 'OVMF (UEFI)')]
|
183
|
+
end
|
170
184
|
end
|
@@ -38,7 +38,7 @@ module ProxmoxServerHelper
|
|
38
38
|
volumes = parse_server_volumes(vols)
|
39
39
|
cpu_a = ['cpu_type', 'spectre', 'pcid']
|
40
40
|
cpu = parse_server_cpu(config.select { |key, _value| cpu_a.include? key })
|
41
|
-
memory_a = ['memory', '
|
41
|
+
memory_a = ['memory', 'balloon', 'shares']
|
42
42
|
memory = parse_server_memory(config.select { |key, _value| memory_a.include? key })
|
43
43
|
interfaces_attributes = args['interfaces_attributes']
|
44
44
|
interfaces_to_add, interfaces_to_delete = parse_server_interfaces(interfaces_attributes)
|
@@ -64,11 +64,7 @@ module ProxmoxServerHelper
|
|
64
64
|
def parse_server_memory(args)
|
65
65
|
memory = {}
|
66
66
|
memory.store(:memory, args['memory'].to_i) if args['memory']
|
67
|
-
|
68
|
-
if ballooned
|
69
|
-
memory.store(:shares, args['shares'].to_i) if args['shares']
|
70
|
-
memory.store(:min_memory, args['min_memory'].to_i) if args['min_memory']
|
71
|
-
end
|
67
|
+
memory.store(:shares, args['shares'].to_i) if args['shares']
|
72
68
|
memory.store(:balloon, args['balloon'].to_i) if args['balloon']
|
73
69
|
logger.debug("parse_server_memory(): #{memory}")
|
74
70
|
memory
|
@@ -59,7 +59,7 @@ module ProxmoxVmHelper
|
|
59
59
|
|
60
60
|
def convert_memory_sizes(args)
|
61
61
|
convert_memory_size(args['config_attributes'], 'memory')
|
62
|
-
convert_memory_size(args['config_attributes'], '
|
62
|
+
convert_memory_size(args['config_attributes'], 'balloon')
|
63
63
|
convert_memory_size(args['config_attributes'], 'shares')
|
64
64
|
convert_memory_size(args['config_attributes'], 'swap')
|
65
65
|
end
|
@@ -70,7 +70,7 @@ module ProxmoxVmHelper
|
|
70
70
|
|
71
71
|
def convert_sizes(args)
|
72
72
|
convert_memory_size(args['config_attributes'], 'memory')
|
73
|
-
convert_memory_size(args['config_attributes'], '
|
73
|
+
convert_memory_size(args['config_attributes'], 'balloon')
|
74
74
|
convert_memory_size(args['config_attributes'], 'shares')
|
75
75
|
convert_memory_size(args['config_attributes'], 'swap')
|
76
76
|
args['volumes_attributes'].each_value { |value| value['size'] = (value['size'].to_i / GIGA).to_s unless ForemanFogProxmox::Value.empty?(value['size']) }
|
@@ -85,12 +85,4 @@ module ProxmoxVmHelper
|
|
85
85
|
memory = (config_hash[key].to_i / MEGA).to_s == '0' ? config_hash[key] : (config_hash[key].to_i / MEGA).to_s
|
86
86
|
config_hash.store(key, memory)
|
87
87
|
end
|
88
|
-
|
89
|
-
def vm_type(host)
|
90
|
-
host.compute_object.type
|
91
|
-
end
|
92
|
-
|
93
|
-
def node_id(host)
|
94
|
-
host.compute_object.node_id
|
95
|
-
end
|
96
88
|
end
|
@@ -38,12 +38,25 @@ module ForemanFogProxmox
|
|
38
38
|
[:disks, :interfaces, :vmid, :node_id, :node, :type].include?(key) || !vm.config.respond_to?(key)
|
39
39
|
end
|
40
40
|
|
41
|
+
def interface_compute_attributes(interface_attributes)
|
42
|
+
vm_attrs = {}
|
43
|
+
vm_attrs.store(:mac, interface_attributes[:macaddr])
|
44
|
+
vm_attrs.store(:id, interface_attributes[:id])
|
45
|
+
vm_attrs.store(:identifier, interface_attributes[:id])
|
46
|
+
vm_attrs.store(:ip, interface_attributes[:ip])
|
47
|
+
vm_attrs.store(:ip6, interface_attributes[:ip6])
|
48
|
+
vm_attrs[:compute_attributes] = interface_attributes.reject { |k, _v| [:macaddr, :id].include?(k) }
|
49
|
+
vm_attrs
|
50
|
+
end
|
51
|
+
|
41
52
|
def vm_compute_attributes(vm)
|
42
53
|
vm_attrs = {}
|
43
54
|
if vm.respond_to?(:config)
|
44
55
|
vm_attrs = vm_attrs.merge(vmid: vm.identity, node_id: vm.node_id, type: vm.type)
|
45
56
|
vm_attrs[:volumes_attributes] = Hash[vm.config.disks.each_with_index.map { |disk, idx| [idx.to_s, disk.attributes] }] if vm.config.respond_to?(:disks)
|
46
|
-
|
57
|
+
if vm.config.respond_to?(:interfaces)
|
58
|
+
vm_attrs[:interfaces_attributes] = Hash[vm.config.interfaces.each_with_index.map { |interface, idx| [idx.to_s, interface_compute_attributes(interface.attributes)] }]
|
59
|
+
end
|
47
60
|
vm_attrs[:config_attributes] = vm.config.attributes.reject do |key, value|
|
48
61
|
not_config_key?(vm, key) || ForemanFogProxmox::Value.empty?(value.to_s) || Fog::Proxmox::DiskHelper.disk?(key.to_s) || Fog::Proxmox::NicHelper.nic?(key.to_s)
|
49
62
|
end
|
@@ -22,7 +22,7 @@ require 'fog/proxmox'
|
|
22
22
|
module ForemanFogProxmox
|
23
23
|
module ProxmoxConnection
|
24
24
|
def connection_options
|
25
|
-
opts =
|
25
|
+
opts = super
|
26
26
|
opts.store(:ssl_verify_peer, ssl_verify_peer)
|
27
27
|
opts.store(:ssl_cert_store, certs_to_store) if Foreman::Cast.to_bool(ssl_verify_peer)
|
28
28
|
opts
|
@@ -39,7 +39,7 @@ module ForemanFogProxmox
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def os_linux_types_mapping(host)
|
42
|
-
['Debian', 'Redhat', 'Suse', 'Altlinux', 'Archlinux', '
|
42
|
+
['Debian', 'Redhat', 'Suse', 'Altlinux', 'Archlinux', 'Coreos', 'Gentoo'].include?(host.operatingsystem.type) ? available_linux_operating_systems : []
|
43
43
|
end
|
44
44
|
|
45
45
|
def os_windows_types_mapping(host)
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2019 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 ForemanFogProxmox
|
21
|
+
module ProxmoxPools
|
22
|
+
def pools
|
23
|
+
pools = identity_client.pools.all
|
24
|
+
pools.sort_by(&:poolid)
|
25
|
+
end
|
26
|
+
|
27
|
+
def pool_owner(vm)
|
28
|
+
logger.debug(format(_('pool_owner(%<vmid>s)'), vmid: vm&.vmid))
|
29
|
+
pools_owners = pools.select { |pool| pool.has_server?(vm&.vmid) }
|
30
|
+
pool = pools_owners.first
|
31
|
+
logger.debug(format(_('found vm: %<vmid>s member of pool: %<poolid>s'), vmid: vm&.vmid, poolid: pool&.poolid))
|
32
|
+
vm&.config&.pool = pool&.poolid
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_vm_to_pool(poolid, vmid)
|
36
|
+
logger.debug(format(_('add_vm_to_pool(%<poolid>s, %<vmid>s)'), poolid: poolid, vmid: vmid))
|
37
|
+
pool = identity_client.pools.get poolid
|
38
|
+
pool&.add_server vmid
|
39
|
+
end
|
40
|
+
|
41
|
+
def remove_vm_from_pool(poolid, vmid)
|
42
|
+
logger.debug(format(_('remove_vm_from_pool(%<poolid>s, %<vmid>s)'), poolid: poolid, vmid: vmid))
|
43
|
+
pool = identity_client.pools.get poolid
|
44
|
+
pool&.remove_server vmid
|
45
|
+
end
|
46
|
+
|
47
|
+
def update_pool(vm, poolid)
|
48
|
+
pool_owner(vm)
|
49
|
+
vm_pool = vm.config.pool || ''
|
50
|
+
return if vm_pool.eql?(poolid)
|
51
|
+
|
52
|
+
remove_vm_from_pool(vm_pool, vm.vmid)
|
53
|
+
add_vm_to_pool(poolid, vm.vmid)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -20,6 +20,7 @@
|
|
20
20
|
module ForemanFogProxmox
|
21
21
|
module ProxmoxVmCommands
|
22
22
|
include ProxmoxVolumes
|
23
|
+
include ProxmoxPools
|
23
24
|
|
24
25
|
def start_on_boot(vm, args)
|
25
26
|
startonboot = args[:start_after_create].blank? ? false : Foreman::Cast.to_bool(args[:start_after_create])
|
@@ -31,6 +32,7 @@ module ForemanFogProxmox
|
|
31
32
|
vmid = args[:vmid].to_i
|
32
33
|
type = args[:type]
|
33
34
|
node = client.nodes.get(args[:node_id])
|
35
|
+
vmid = node.servers.next_id.to_i if vmid < 1
|
34
36
|
raise ::Foreman::Exception, format(N_('invalid vmid=%<vmid>s'), vmid: vmid) unless node.servers.id_valid?(vmid)
|
35
37
|
|
36
38
|
image_id = args[:image_id]
|
@@ -100,11 +102,13 @@ module ForemanFogProxmox
|
|
100
102
|
volumes_attributes&.each_value { |volume_attributes| save_volume(vm, volume_attributes) }
|
101
103
|
parsed_attr = vm.container? ? parse_container_vm(new_attributes.merge(type: vm.type)) : parse_server_vm(new_attributes.merge(type: vm.type))
|
102
104
|
logger.debug("parsed_attr=#{parsed_attr}")
|
103
|
-
config_attributes = parsed_attr.reject { |key, _value| [:vmid, :templated, :ostemplate, :ostemplate_file, :ostemplate_storage, :volumes_attributes].include? key.to_sym }
|
105
|
+
config_attributes = parsed_attr.reject { |key, _value| [:vmid, :templated, :ostemplate, :ostemplate_file, :ostemplate_storage, :volumes_attributes, :pool].include? key.to_sym }
|
104
106
|
config_attributes = config_attributes.reject { |_key, value| ForemanFogProxmox::Value.empty?(value) }
|
105
107
|
cdrom_attributes = parsed_attr.select { |_key, value| Fog::Proxmox::DiskHelper.cdrom?(value.to_s) }
|
106
108
|
config_attributes = config_attributes.reject { |key, _value| Fog::Proxmox::DiskHelper.disk?(key) }
|
107
109
|
vm.update(config_attributes.merge(cdrom_attributes))
|
110
|
+
poolid = new_attributes['pool'] if new_attributes.key?('pool')
|
111
|
+
update_pool(vm, poolid) if poolid
|
108
112
|
end
|
109
113
|
find_vm_by_uuid(uuid)
|
110
114
|
end
|