foreman_hyperv 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +2 -0
- data/app/assets/javascripts/compute_resources/hyperv/base.js +30 -4
- data/app/models/foreman_hyperv/hyperv.rb +24 -18
- data/app/views/compute_resources_vms/form/hyperv/_base.html.erb +11 -5
- data/app/views/compute_resources_vms/show/_hyperv.html.erb +28 -3
- data/foreman_hyperv.gemspec +1 -1
- data/lib/foreman_hyperv/engine.rb +12 -1
- data/lib/foreman_hyperv/version.rb +1 -1
- metadata +5 -5
- data/app/helpers/hyperv_helpers.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 710168316d53c6c4bb3276fa02faa45a28c602bb
|
4
|
+
data.tar.gz: 484471496d5c678718430e539639d4d6bc4b38d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19eb7700b2fc5030f2d4c7711d31dd3c77d5445b5442ac66e199cf7da0cdcd01c91609240a911e59036696411436f2a59e5e7314a10afef8ffdffed436f03245
|
7
|
+
data.tar.gz: 3a03d174196f13b3e8967f25c1eb23fb524f12919ede792dc8000ab8c34d5e88bb632182a4529a7e73740fcf288ec7a71261b7bfcbff33ee5a70a1646bdcb190
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
## v0.0.2 2017-09-30
|
2
|
+
|
3
|
+
- Add Dynamic memory settings
|
4
|
+
- Add JS for disabling unavailable settings to improve UX
|
5
|
+
- Fix secure boot setting to actually apply
|
6
|
+
- Skip several unnecessary Hyper-V calls to improve performance
|
7
|
+
- Improve VM properties view to look a little better and house another few nuggets of information
|
8
|
+
|
9
|
+
## v0.0.1 2017-09-28
|
10
|
+
|
11
|
+
- Initial release
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Foreman Hyper-V
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/foreman_hyperv.svg)](https://badge.fury.io/rb/foreman_hyperv)
|
4
|
+
|
3
5
|
Microsoft Hyper-V compute resource for Foreman
|
4
6
|
|
5
7
|
Uses the in-development `fog-hyperv` gem found [here](https://github.com/ace13/fog-hyperv).
|
@@ -1,6 +1,32 @@
|
|
1
|
-
|
1
|
+
function hypervGenerationChange(item) {
|
2
|
+
var toIter = ['#host_compute_attributes_secure_boot_enabled', '#compute_attribute_vm_attrs_secure_boot_enabled'];
|
3
|
+
gen = $(item).val();
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
if (gen == 1) {
|
6
|
+
for (var i = 0; i < toIter.length; ++i) {
|
7
|
+
$(toIter[i]).attr('disabled', true);
|
8
|
+
}
|
9
|
+
} else {
|
10
|
+
for (var i = 0; i < toIter.length; ++i) {
|
11
|
+
$(toIter[i]).removeAttr('disabled');
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
function hypervDynamicMemoryChange(item) {
|
17
|
+
var toIter = [
|
18
|
+
'#host_compute_attributes_memory_maximum',
|
19
|
+
'#host_compute_attributes_memory_minimum',
|
20
|
+
'#compute_attribute_vm_attrs_memory_maximum',
|
21
|
+
'#compute_attribute_vm_attrs_memory_minimum',
|
22
|
+
];
|
23
|
+
if (item.checked) {
|
24
|
+
for (var i = 0; i < toIter.length; ++i) {
|
25
|
+
$(toIter[i]).removeAttr('disabled');
|
26
|
+
}
|
27
|
+
} else {
|
28
|
+
for (var i = 0; i < toIter.length; ++i) {
|
29
|
+
$(toIter[i]).attr('disabled', true);
|
30
|
+
}
|
31
|
+
}
|
6
32
|
}
|
@@ -15,10 +15,10 @@ module ForemanHyperv
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_connection(options = {})
|
18
|
-
super
|
18
|
+
super
|
19
19
|
client.valid?
|
20
|
-
rescue Fog::Hyperv::Errors::ServiceError, ArgumentError, WinRM::WinRMAuthorizationError
|
21
|
-
|
20
|
+
rescue Fog::Hyperv::Errors::ServiceError, ArgumentError, WinRM::WinRMAuthorizationError => e
|
21
|
+
errors[:base] << e.message
|
22
22
|
end
|
23
23
|
|
24
24
|
def provided_attributes
|
@@ -53,11 +53,12 @@ module ForemanHyperv
|
|
53
53
|
|
54
54
|
def create_vm(args = {})
|
55
55
|
args = vm_instance_defaults.merge(args.to_hash.deep_symbolize_keys)
|
56
|
-
logger.debug "Creating a VM with arguments; #{args}"
|
56
|
+
client.logger.debug "Creating a VM with arguments; #{args}"
|
57
|
+
|
57
58
|
pre_create = {
|
58
59
|
boot_device: 'NetworkAdapter',
|
59
60
|
generation: args[:generation].to_i,
|
60
|
-
memory_startup: args[:memory_startup].presence,
|
61
|
+
memory_startup: args[:memory_startup].presence.to_i,
|
61
62
|
name: args[:name],
|
62
63
|
no_vhd: true
|
63
64
|
}
|
@@ -65,7 +66,9 @@ module ForemanHyperv
|
|
65
66
|
vm = client.servers.create pre_create
|
66
67
|
|
67
68
|
post_save = {
|
68
|
-
dynamic_memory_enabled:
|
69
|
+
dynamic_memory_enabled: Foreman::Cast.to_bool(args[:dynamic_memory_enabled]),
|
70
|
+
memory_minimum: args[:memory_minimum].presence.to_i,
|
71
|
+
memory_maximum: args[:memory_maximum].presence.to_i,
|
69
72
|
notes: args[:notes].presence,
|
70
73
|
processor_count: args[:processor_count].to_i
|
71
74
|
}
|
@@ -75,9 +78,9 @@ module ForemanHyperv
|
|
75
78
|
|
76
79
|
vm.save if vm.dirty?
|
77
80
|
|
78
|
-
if vm.generation == 2 &&
|
81
|
+
if vm.generation == 2 && args[:secure_boot_enabled].present?
|
79
82
|
f = vm.firmware
|
80
|
-
f.secure_boot =
|
83
|
+
f.secure_boot = Foreman::Cast.to_bool(args[:secure_boot_enabled]) ? :On : :Off
|
81
84
|
f.save if f.dirty?
|
82
85
|
end
|
83
86
|
|
@@ -93,17 +96,20 @@ module ForemanHyperv
|
|
93
96
|
|
94
97
|
def save_vm(uuid, attr)
|
95
98
|
vm = find_vm_by_uuid(uuid)
|
96
|
-
logger.debug "Saving a VM with arguments; #{attr}"
|
99
|
+
client.logger.debug "Saving a VM with arguments; #{attr}"
|
97
100
|
attr.each do |k, v|
|
98
101
|
vm.send("#{k}=".to_sym, v) if vm.respond_to?("#{k}=".to_sym)
|
99
102
|
end
|
100
|
-
|
103
|
+
|
104
|
+
if vm.generation == 2 && attr[:secure_boot_enabled].present?
|
101
105
|
f = vm.firmware
|
102
|
-
f.secure_boot =
|
106
|
+
f.secure_boot = Foreman::Cast.to_bool(attr[:secure_boot_enabled]) ? :On : :Off
|
103
107
|
f.save if f.dirty?
|
104
108
|
end
|
109
|
+
|
105
110
|
update_interfaces(vm, attr[:interfaces_attributes])
|
106
111
|
update_volumes(vm, attr[:volumes_attributes])
|
112
|
+
|
107
113
|
vm.save if vm.dirty?
|
108
114
|
vm
|
109
115
|
end
|
@@ -177,9 +183,9 @@ module ForemanHyperv
|
|
177
183
|
vm.network_adapters.each(&:destroy)
|
178
184
|
|
179
185
|
interfaces = nested_attributes_for :interfaces, attrs
|
180
|
-
logger.debug "Building interfaces with: #{interfaces}"
|
186
|
+
client.logger.debug "Building interfaces with: #{interfaces}"
|
181
187
|
interfaces.each do |iface|
|
182
|
-
nic = vm.network_adapters.
|
188
|
+
nic = vm.network_adapters.new name: iface[:name], switch_name: iface[:network]
|
183
189
|
if iface[:mac]
|
184
190
|
nic.mac = iface[:mac]
|
185
191
|
nic.dynamic_mac_address_enabled = false
|
@@ -200,7 +206,7 @@ module ForemanHyperv
|
|
200
206
|
|
201
207
|
def create_volumes(vm, attrs)
|
202
208
|
volumes = nested_attributes_for :volumes, attrs
|
203
|
-
logger.debug "Building volumes with: #{volumes}"
|
209
|
+
client.logger.debug "Building volumes with: #{volumes}"
|
204
210
|
volumes.each do |vol|
|
205
211
|
vhd = vm.vhds.create path: vm.folder_name + '\\' + vol[:path], size: vol[:size]
|
206
212
|
vm.hard_drives.create path: vhd.path
|
@@ -210,7 +216,7 @@ module ForemanHyperv
|
|
210
216
|
|
211
217
|
def update_interfaces(vm, attrs)
|
212
218
|
interfaces = nested_attributes_for :interfaces, attrs
|
213
|
-
logger.debug "Updating interfaces with: #{interfaces}"
|
219
|
+
client.logger.debug "Updating interfaces with: #{interfaces}"
|
214
220
|
interfaces.each do |interface|
|
215
221
|
if interface[:id].blank? && interface[:_delete] != '1'
|
216
222
|
nic = vm.network_adapters.create interface
|
@@ -232,14 +238,14 @@ module ForemanHyperv
|
|
232
238
|
|
233
239
|
def update_volumes(vm, attrs)
|
234
240
|
volumes = nested_attributes_for :volumes, attrs
|
235
|
-
logger.debug "Updating volumes with: #{volumes}"
|
241
|
+
client.logger.debug "Updating volumes with: #{volumes}"
|
236
242
|
volumes.each do |volume|
|
237
243
|
if volume[:_delete] == '1' && volume[:id].present?
|
238
|
-
hd = vm.hard_drives.
|
244
|
+
hd = vm.hard_drives.find { |h| h.id == volume[:id] }
|
239
245
|
hd.vhd.destroy
|
240
246
|
hd.destroy
|
241
247
|
end
|
242
|
-
vm.hard_drives.create(path: volume[:path], size: volume[:size]) if volume[:id].blank?
|
248
|
+
vm.hard_drives.create(path: volume[:path], size: volume[:size]) if volume[:id].blank? && volume[:_delete] != '1'
|
243
249
|
end
|
244
250
|
end
|
245
251
|
end
|
@@ -1,15 +1,19 @@
|
|
1
|
-
<%#= compute_specific_js(compute_resource, 'base') %>
|
2
1
|
<%= javascript_tag("$(document).on('ContentLoad', tfm.numFields.initAll)") %>
|
3
2
|
|
4
3
|
<%
|
5
4
|
generations = [ [1, 'Generation 1 (BIOS)'], [2, 'Generation 2 (UEFI)'] ]
|
6
5
|
%>
|
7
|
-
<%= select_f f, :generation, generations, :first, :last, {}, label: 'Generation', disabled: !new_host, onchange: 'hypervGenerationChange()'
|
8
|
-
|
6
|
+
<%= select_f f, :generation, generations, :first, :last, {}, label: 'Generation', disabled: !new_host, onchange: 'hypervGenerationChange(this);' %>
|
7
|
+
<% if new_host || f.object.generation == 2 %>
|
8
|
+
<%= checkbox_f f, :secure_boot_enabled, { label: _('Use Secure Boot'), disabled: f.object.generation == 1 }, 'true', 'false' %>
|
9
|
+
<% end %>
|
9
10
|
|
10
11
|
<%= counter_f f, :processor_count, label: _('CPUs'), label_size: 'col-md-2' %>
|
11
|
-
<%= byte_size_f f, :memory_startup, class: 'col-md-2', label: _('Memory') %>
|
12
|
-
|
12
|
+
<%= byte_size_f f, :memory_startup, class: 'col-md-2', label: _('Memory (Startup)') %>
|
13
|
+
|
14
|
+
<%= byte_size_f f, :memory_maximum, class: 'col-md-2', label: _('Memory Maximum'), disabled: !f.object.dynamic_memory_enabled %>
|
15
|
+
<%= byte_size_f f, :memory_minimum, class: 'col-md-2', label: _('Memory Minimum'), disabled: !f.object.dynamic_memory_enabled %>
|
16
|
+
<%= checkbox_f f, :dynamic_memory_enabled, { label: _('Use Dynamic Memory'), onchange: 'hypervDynamicMemoryChange(this);' }, 'true', 'false' %>
|
13
17
|
|
14
18
|
<% if new_host %>
|
15
19
|
<% checked = params[:host] && params[:host][:compute_attributes] && params[:host][:compute_attributes][:start] || '1' %>
|
@@ -18,3 +22,5 @@
|
|
18
22
|
|
19
23
|
<%= textarea_f f, :notes, rows: '3', label: _('Notes') %>
|
20
24
|
<%= f.hidden_field :id %>
|
25
|
+
|
26
|
+
<%= compute_specific_js(compute_resource, 'base') %>
|
@@ -1,4 +1,18 @@
|
|
1
1
|
<% title @vm.name %>
|
2
|
+
<%
|
3
|
+
def memory_prop(method)
|
4
|
+
content_tag :tr do
|
5
|
+
result = content_tag(:td) do
|
6
|
+
method.to_s.humanize
|
7
|
+
end
|
8
|
+
result += content_tag(:td) do
|
9
|
+
value = @vm.send(method) rescue nil
|
10
|
+
value && number_to_human_size(value)
|
11
|
+
end
|
12
|
+
result
|
13
|
+
end
|
14
|
+
end
|
15
|
+
%>
|
2
16
|
|
3
17
|
<div class='col-md-12'>
|
4
18
|
<table class="<%= table_css_classes %>">
|
@@ -8,11 +22,22 @@
|
|
8
22
|
<tbody>
|
9
23
|
<%= prop :id %>
|
10
24
|
<%#= prop :cluster %>
|
11
|
-
<%= prop :
|
25
|
+
<%= prop :name %>
|
26
|
+
<tr>
|
27
|
+
<td>Generation</td>
|
28
|
+
<td><%= @vm.generation == 1 ? 'Generation 1 (BIOS)' : 'Generation 2 (UEFI)' %></td>
|
29
|
+
</tr>
|
30
|
+
<% if @vm.generation != 1 %>
|
31
|
+
<tr>
|
32
|
+
<td>SecureBoot</td>
|
33
|
+
<td><%= @vm.firmware.secure_boot %></td>
|
34
|
+
</tr>
|
35
|
+
<% end %>
|
12
36
|
<% if @vm.dynamic_memory_enabled %>
|
13
|
-
<%=
|
14
|
-
<%=
|
37
|
+
<%= memory_prop :memory_maximum %>
|
38
|
+
<%= memory_prop :memory_minimum %>
|
15
39
|
<% end %>
|
40
|
+
<%= memory_prop :memory_startup %>
|
16
41
|
<%= prop :public_ip_address %>
|
17
42
|
<%= prop :mac %>
|
18
43
|
<%= prop :processor_count %>
|
data/foreman_hyperv.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^test\/})
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_runtime_dependency 'fog-hyperv', '~> 0.0.
|
22
|
+
spec.add_runtime_dependency 'fog-hyperv', '~> 0.0.2'
|
23
23
|
|
24
24
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
25
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
@@ -9,8 +9,19 @@ module ForemanHyperv
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
assets_to_precompile =
|
13
|
+
Dir.chdir(root) do
|
14
|
+
Dir['app/assets/javascripts/**/*'].map do |f|
|
15
|
+
f.split(File::SEPARATOR, 4).last
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
12
19
|
initializer 'foreman_hyperv.assets.precompile' do |app|
|
13
|
-
app.config.assets.precompile +=
|
20
|
+
app.config.assets.precompile += assets_to_precompile
|
21
|
+
end
|
22
|
+
|
23
|
+
initializer 'foreman_hyperv.configure_assets', group: :assets do
|
24
|
+
SETTINGS[:foreman_hyperv] = { assets: { precompile: assets_to_precompile } }
|
14
25
|
end
|
15
26
|
|
16
27
|
config.to_prepare do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_hyperv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Olofsson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog-hyperv
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.0.
|
19
|
+
version: 0.0.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.0.
|
26
|
+
version: 0.0.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,12 +77,12 @@ files:
|
|
77
77
|
- ".rubocop.yml"
|
78
78
|
- ".rubocop_todo.yml"
|
79
79
|
- ".travis.yml"
|
80
|
+
- CHANGELOG.md
|
80
81
|
- Gemfile
|
81
82
|
- LICENSE.txt
|
82
83
|
- README.md
|
83
84
|
- Rakefile
|
84
85
|
- app/assets/javascripts/compute_resources/hyperv/base.js
|
85
|
-
- app/helpers/hyperv_helpers.rb
|
86
86
|
- app/models/concerns/fog_extensions/hyperv/compute.rb
|
87
87
|
- app/models/concerns/fog_extensions/hyperv/network_adapter.rb
|
88
88
|
- app/models/concerns/fog_extensions/hyperv/server.rb
|