fog-hyperv 0.1.1 → 0.2.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.
- checksums.yaml +4 -4
- data/lib/fog/hyperv/compute/models/firmware.rb +2 -0
- data/lib/fog/hyperv/compute/models/hard_drive.rb +1 -1
- data/lib/fog/hyperv/compute/models/integration_service.rb +72 -0
- data/lib/fog/hyperv/compute/models/integration_services.rb +29 -0
- data/lib/fog/hyperv/compute/models/security.rb +8 -4
- data/lib/fog/hyperv/compute/models/server.rb +40 -11
- data/lib/fog/hyperv/compute/models/vhd.rb +14 -1
- data/lib/fog/hyperv/compute/requests/disable_vm_integration_service.rb +16 -0
- data/lib/fog/hyperv/compute/requests/enable_vm_integration_service.rb +16 -0
- data/lib/fog/hyperv/compute/requests/get_vhd.rb +2 -0
- data/lib/fog/hyperv/compute/requests/get_vm_integration_service.rb +15 -0
- data/lib/fog/hyperv/compute.rb +5 -0
- data/lib/fog/hyperv/version.rb +1 -1
- metadata +6 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 967724a9fd59c0978858d86ff438fe64a8eefc884cdeb11d0e6c7e372c28b725
|
|
4
|
+
data.tar.gz: f845028078a57dd1aec509aa7357ac3c58e5aab5d301b833ac00ab01fc8ee726
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e4f71c7887ef726c2281be088d048fa56ceb71b4bd0b1684846bd1accd922a245ea2227e4f562b3acdbb9d57c90f72a930011f63c051b30937187cd1e13bc012
|
|
7
|
+
data.tar.gz: 2ea917dfb9a6fc294ea7ced844661dc3c5772e9775d2e01d77eb3eb2592d742b8a96e5a57ca4ecd9ca527bee1e467d40256cb218f897164e223a7de4b874e5e4
|
|
@@ -67,7 +67,7 @@ class Fog::Hyperv::Compute
|
|
|
67
67
|
return associations[:vhd] if associations[:vhd]
|
|
68
68
|
return unless path
|
|
69
69
|
|
|
70
|
-
associations[:vhd] = service.vhds.get(path, computer_name: computer_name)
|
|
70
|
+
associations[:vhd] = (vm || service).vhds.get(path, computer_name: computer_name)
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
def vhd=(new_vhd)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Fog::Hyperv::Compute
|
|
4
|
+
class IntegrationService < Fog::Hyperv::Model
|
|
5
|
+
# rubocop:disable Layout/HashAlignment
|
|
6
|
+
|
|
7
|
+
# Integration service statuses
|
|
8
|
+
# @note Defined by Microsoft.HyperV.PowerShell.VMIntegrationComponentOperationalStatus
|
|
9
|
+
INTEGRATION_SERVICE_STATUS_ENUM_VALUES = {
|
|
10
|
+
Ok: 2,
|
|
11
|
+
Degraded: 3,
|
|
12
|
+
Error: 6,
|
|
13
|
+
NonRecoverableError: 7,
|
|
14
|
+
NoContact: 12,
|
|
15
|
+
LostCommunication: 13,
|
|
16
|
+
Disabled: 32_896,
|
|
17
|
+
ProtocolMismatch: 32_775,
|
|
18
|
+
ApplicationCritical: 32_782,
|
|
19
|
+
CommunicationTimedOut: 32_783,
|
|
20
|
+
CommunicationFailed: 32_784
|
|
21
|
+
}.freeze
|
|
22
|
+
# rubocop:enable Layout/HashAlignment
|
|
23
|
+
|
|
24
|
+
# @!attribute [r] name
|
|
25
|
+
# @return [String] the name of the integration service
|
|
26
|
+
identity :name
|
|
27
|
+
|
|
28
|
+
# @!attribute [r] computer_name
|
|
29
|
+
# @return [String] the name of the computer running the VM that this integration service is attached to
|
|
30
|
+
attribute :computer_name
|
|
31
|
+
# @!attribute [r] vm_id
|
|
32
|
+
# @return [String] the GUID of the VM this integration service is attached to
|
|
33
|
+
attribute :vm_id
|
|
34
|
+
|
|
35
|
+
# @!attribute enabled
|
|
36
|
+
# @return [Boolean] if the integration service is enabled or not
|
|
37
|
+
attribute :enabled, type: :boolean
|
|
38
|
+
# @!attribute [r] operational_status
|
|
39
|
+
# @return [Symbol] the statuses of the integration service
|
|
40
|
+
# @see INTEGRATION_SERVICE_STATUS_ENUM_VALUES
|
|
41
|
+
attribute :operational_status, type: :hypervenumarray, values: INTEGRATION_SERVICE_STATUS_ENUM_VALUES
|
|
42
|
+
|
|
43
|
+
def update
|
|
44
|
+
requires :name, :vm_id
|
|
45
|
+
|
|
46
|
+
return self unless changed? :enabled
|
|
47
|
+
|
|
48
|
+
method = enabled ? :enable : :disable
|
|
49
|
+
service.send(:"#{method}_vm_integration_service", computer_name: computer_name, vm_id: vm_id, name: name)
|
|
50
|
+
|
|
51
|
+
old.enabled = attributes[:enabled]
|
|
52
|
+
self
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def reload
|
|
56
|
+
requires :name, :vm_id
|
|
57
|
+
|
|
58
|
+
data = service.get_vm_integration_service computer_name: computer_name, vm_id: vm_id, name: name
|
|
59
|
+
return unless data
|
|
60
|
+
|
|
61
|
+
merge_attributes(data)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
protected
|
|
65
|
+
|
|
66
|
+
def merge_attributes(new_attributes = {})
|
|
67
|
+
new_attributes[:operational_status] = [] if new_attributes[:operational_status] == ''
|
|
68
|
+
|
|
69
|
+
super
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Fog::Hyperv::Compute
|
|
4
|
+
# A collection of integration services available for a VM
|
|
5
|
+
#
|
|
6
|
+
# @note Requires a vm_id to be specified, as integration services are not retrievable as loose objects
|
|
7
|
+
class IntegrationServices < Fog::Hyperv::Collection
|
|
8
|
+
model Fog::Hyperv::Compute::IntegrationService
|
|
9
|
+
|
|
10
|
+
get_method :get_vm_integration_service
|
|
11
|
+
|
|
12
|
+
# @!attribute vm_id
|
|
13
|
+
# @return [String] the GUID of the VM containing the COM ports
|
|
14
|
+
attribute :vm_id
|
|
15
|
+
# @!attribute computer_name
|
|
16
|
+
# @return [String] the name of the computer running the VM that these COM ports are attached to
|
|
17
|
+
attribute :computer_name
|
|
18
|
+
|
|
19
|
+
requires :vm_id
|
|
20
|
+
|
|
21
|
+
# Get an integration service by name
|
|
22
|
+
# @param id [String] the name of the integration service to retrieve
|
|
23
|
+
def get(name, **filters)
|
|
24
|
+
raise ArgumentError, 'Must provide a name' if name.nil? || name.empty?
|
|
25
|
+
|
|
26
|
+
super(name: name, **filters)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -36,10 +36,14 @@ class Fog::Hyperv::Compute
|
|
|
36
36
|
def key_protector
|
|
37
37
|
requires :vm
|
|
38
38
|
|
|
39
|
-
@key_protector ||=
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
@key_protector ||= begin
|
|
40
|
+
value = service.get_vm_key_protector(
|
|
41
|
+
computer_name: vm.computer_name,
|
|
42
|
+
vm_id: vm.id
|
|
43
|
+
)[:value]
|
|
44
|
+
value = nil if value == [0, 0, 0, 4]
|
|
45
|
+
value
|
|
46
|
+
end
|
|
43
47
|
end
|
|
44
48
|
|
|
45
49
|
# Change the key protector for a VM
|
|
@@ -141,6 +141,9 @@ class Fog::Hyperv::Compute
|
|
|
141
141
|
# @!attribute notes
|
|
142
142
|
# @return [String] user-specified notes for the VM
|
|
143
143
|
attribute :notes, type: :string
|
|
144
|
+
# @!attribute path
|
|
145
|
+
# @return [String] the path on disk where the VM configuration is stored
|
|
146
|
+
attribute :path, type: :string
|
|
144
147
|
# @!attribute processor_count
|
|
145
148
|
# @return [Integer] the number of processors in the VM
|
|
146
149
|
attribute :processor_count, type: :integer, default: 1
|
|
@@ -161,6 +164,9 @@ class Fog::Hyperv::Compute
|
|
|
161
164
|
# @!attribute hard_drives
|
|
162
165
|
# @return [Array<HardDrive>] the hard drives on the VM
|
|
163
166
|
collection :hard_drives
|
|
167
|
+
# @!attribute integration_services
|
|
168
|
+
# @return [Array<IntegrationService>] the integration services on the VM
|
|
169
|
+
collection :integration_services
|
|
164
170
|
# @!attribute network_adapters
|
|
165
171
|
# @return [Array<NetworkAdapter>] the network adapters on the VM
|
|
166
172
|
collection :network_adapters
|
|
@@ -212,16 +218,21 @@ class Fog::Hyperv::Compute
|
|
|
212
218
|
# @!attribute [r] security
|
|
213
219
|
# @return [Security] UEFI security configuration, if #generation is +:UEFI+
|
|
214
220
|
def security
|
|
215
|
-
|
|
216
|
-
return nil unless generation == :UEFI
|
|
221
|
+
return unless persisted?
|
|
217
222
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
223
|
+
requires :generation
|
|
224
|
+
return unless generation == :UEFI
|
|
225
|
+
|
|
226
|
+
security = service.get_vm_security(
|
|
227
|
+
computer_name: computer_name,
|
|
228
|
+
vm_id: vm_id,
|
|
222
229
|
|
|
223
|
-
|
|
224
|
-
|
|
230
|
+
_return_fields: Fog::Hyperv::Compute::Security.attributes
|
|
231
|
+
)
|
|
232
|
+
return unless security.is_a? Hash
|
|
233
|
+
|
|
234
|
+
associations[:security] ||= Fog::Hyperv::Compute::Security.new(
|
|
235
|
+
**security,
|
|
225
236
|
|
|
226
237
|
vm: self,
|
|
227
238
|
service: @service,
|
|
@@ -305,21 +316,31 @@ class Fog::Hyperv::Compute
|
|
|
305
316
|
end
|
|
306
317
|
|
|
307
318
|
# Remove the VM object from Hyper-V
|
|
319
|
+
# @param [Boolean] underlying remove the underlying configuration directory from disk on the Hyper-V host
|
|
308
320
|
#
|
|
309
321
|
# @note if the VM has VHDs, make sure to remove them first to not leave the VM data remaining on disk
|
|
310
|
-
|
|
322
|
+
# @note underlying will remove the +full+ path of the VM, make sure this is what you want before using it
|
|
323
|
+
def destroy(underlying = nil)
|
|
324
|
+
underlying = true if underlying.nil? && attributes[:path]&.end_with?(attributes[:name])
|
|
325
|
+
|
|
311
326
|
requires :id
|
|
327
|
+
requires :path if underlying
|
|
312
328
|
stop turn_off: true if ready?
|
|
313
329
|
|
|
314
330
|
service.remove_vm(computer_name: computer_name, id: id)
|
|
331
|
+
service.remove_item(path: path, computer_name: computer_name, recurse: true) if underlying
|
|
315
332
|
true
|
|
316
333
|
end
|
|
317
334
|
|
|
318
335
|
# Create the VM object if it doesn't exist
|
|
319
336
|
# @param [Symbol] boot_device the default boot device to configure the VM with, one of BOOT_DEVICE
|
|
320
337
|
# @param [String] switch_name the name of a Switch to connect the VM to on creation
|
|
338
|
+
# @option attrs [String] :path
|
|
339
|
+
# a custom path to store the VM configuration under - will use a subdir under the default config path if relative
|
|
321
340
|
def create(boot_device: nil, switch_name: nil, **attrs)
|
|
322
341
|
attrs[:no_vhd] = true unless attrs[:new_vhd_path]
|
|
342
|
+
attrs[:path] = [computer.virtual_machine_path, attrs[:path]].join('\\') \
|
|
343
|
+
if attrs[:path] && attrs[:path] !~ %r{^(\w:[\\/]|[\\/]{2}\w+[\\/])}i
|
|
323
344
|
|
|
324
345
|
# Attributes that can't be set as part of the New-VM call
|
|
325
346
|
post_create_attributes = {
|
|
@@ -422,10 +443,18 @@ class Fog::Hyperv::Compute
|
|
|
422
443
|
|
|
423
444
|
# Build a path for where to store a VHD of a given name
|
|
424
445
|
# @return [String] the absolute path for the VHD
|
|
425
|
-
def build_vhd_path(filename)
|
|
446
|
+
def build_vhd_path(filename = nil)
|
|
447
|
+
requires :name
|
|
448
|
+
|
|
449
|
+
[computer.virtual_hard_disk_path, name, filename].compact.join('\\')
|
|
450
|
+
end
|
|
451
|
+
|
|
452
|
+
# Build a path for where to store configuration files
|
|
453
|
+
# @return [String] the absolute path for the configuration store
|
|
454
|
+
def build_config_path(subdir = nil)
|
|
426
455
|
requires :name
|
|
427
456
|
|
|
428
|
-
[computer.
|
|
457
|
+
[computer.virtual_machine_path, name, subdir].compact.join('\\')
|
|
429
458
|
end
|
|
430
459
|
|
|
431
460
|
# Get the username of the main system account
|
|
@@ -171,8 +171,21 @@ class Fog::Hyperv::Compute
|
|
|
171
171
|
|
|
172
172
|
service.remove_item(
|
|
173
173
|
computer_name: computer_name,
|
|
174
|
-
path: path
|
|
174
|
+
path: [path, "#{path}.*"],
|
|
175
175
|
)
|
|
176
|
+
components = path.split('\\')
|
|
177
|
+
if components[-2] == vm.name
|
|
178
|
+
# if (!Test-Path -Path ...\*) { Remove-Item -Path ... -Recurse -Force }
|
|
179
|
+
vmpath = components[0..-2].join '\\'
|
|
180
|
+
service.run_cmdlist(
|
|
181
|
+
[
|
|
182
|
+
["$anyFiles = Test-Path", { path: [vmpath, '*'].join('\\') }],
|
|
183
|
+
['if (-not $anyFiles) { Remove-Item @Args }', { path: vmpath, recurse: true, force: true }]
|
|
184
|
+
],
|
|
185
|
+
skip_json: true,
|
|
186
|
+
target_computer: computer_name,
|
|
187
|
+
)
|
|
188
|
+
end
|
|
176
189
|
true
|
|
177
190
|
end
|
|
178
191
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Fog::Hyperv::Compute
|
|
4
|
+
class Real
|
|
5
|
+
def disable_vm_integration_service(name:, vm_id:, computer_name: nil, **options)
|
|
6
|
+
run_cmdlist(
|
|
7
|
+
[
|
|
8
|
+
['$VM = Get-VM', { id: vm_id }],
|
|
9
|
+
['$VM | Disable-VMIntegrationService', { name: name, **options }]
|
|
10
|
+
],
|
|
11
|
+
skip_json: true,
|
|
12
|
+
target_computer: computer_name
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Fog::Hyperv::Compute
|
|
4
|
+
class Real
|
|
5
|
+
def enable_vm_integration_service(name:, vm_id:, computer_name: nil, **options)
|
|
6
|
+
run_cmdlist(
|
|
7
|
+
[
|
|
8
|
+
['$VM = Get-VM', { id: vm_id }],
|
|
9
|
+
['$VM | Enable-VMIntegrationService', { name: name, **options }]
|
|
10
|
+
],
|
|
11
|
+
skip_json: true,
|
|
12
|
+
target_computer: computer_name
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -4,6 +4,8 @@ class Fog::Hyperv::Compute
|
|
|
4
4
|
class Real
|
|
5
5
|
def get_vhd(computer_name: nil, **options)
|
|
6
6
|
requires_one options, :path, :disk_number unless options[:vm_id]
|
|
7
|
+
options.delete :vm_id if options[:path] || options[:disk_number]
|
|
8
|
+
|
|
7
9
|
run_cmd 'Get-VHD', _target_computer: computer_name, **options
|
|
8
10
|
end
|
|
9
11
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Fog::Hyperv::Compute
|
|
4
|
+
class Real
|
|
5
|
+
def get_vm_integration_service(vm_id:, computer_name: nil, **options)
|
|
6
|
+
run_cmdlist(
|
|
7
|
+
[
|
|
8
|
+
['$VM = Get-VM', { id: vm_id }],
|
|
9
|
+
['$VM | Get-VMIntegrationService', options]
|
|
10
|
+
],
|
|
11
|
+
target_computer: computer_name
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/fog/hyperv/compute.rb
CHANGED
|
@@ -25,6 +25,8 @@ module Fog::Hyperv
|
|
|
25
25
|
collection :hard_drives
|
|
26
26
|
model :host
|
|
27
27
|
collection :hosts
|
|
28
|
+
model :integration_service
|
|
29
|
+
collection :integration_services
|
|
28
30
|
model :network_adapter
|
|
29
31
|
model :network_adapter_vlan
|
|
30
32
|
collection :network_adapters
|
|
@@ -41,8 +43,10 @@ module Fog::Hyperv
|
|
|
41
43
|
request :add_vm_hard_disk_drive
|
|
42
44
|
request :add_vm_network_adapter
|
|
43
45
|
request :connect_vm_network_adapter
|
|
46
|
+
request :disable_vm_integration_service
|
|
44
47
|
request :disable_vm_tpm
|
|
45
48
|
request :disconnect_vm_network_adapter
|
|
49
|
+
request :enable_vm_integration_service
|
|
46
50
|
request :enable_vm_tpm
|
|
47
51
|
request :get_cluster
|
|
48
52
|
request :get_cluster_node
|
|
@@ -58,6 +62,7 @@ module Fog::Hyperv
|
|
|
58
62
|
request :get_vm_host
|
|
59
63
|
request :get_vm_host_cluster
|
|
60
64
|
request :get_vm_host_sbt
|
|
65
|
+
request :get_vm_integration_service
|
|
61
66
|
request :get_vm_key_protector
|
|
62
67
|
request :get_vm_network_adapter
|
|
63
68
|
request :get_vm_network_adapter_vlan
|
data/lib/fog/hyperv/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fog-hyperv
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexander Olofsson
|
|
@@ -176,6 +176,8 @@ files:
|
|
|
176
176
|
- lib/fog/hyperv/compute/models/hard_drives.rb
|
|
177
177
|
- lib/fog/hyperv/compute/models/host.rb
|
|
178
178
|
- lib/fog/hyperv/compute/models/hosts.rb
|
|
179
|
+
- lib/fog/hyperv/compute/models/integration_service.rb
|
|
180
|
+
- lib/fog/hyperv/compute/models/integration_services.rb
|
|
179
181
|
- lib/fog/hyperv/compute/models/network_adapter.rb
|
|
180
182
|
- lib/fog/hyperv/compute/models/network_adapter_vlan.rb
|
|
181
183
|
- lib/fog/hyperv/compute/models/network_adapters.rb
|
|
@@ -190,8 +192,10 @@ files:
|
|
|
190
192
|
- lib/fog/hyperv/compute/requests/add_vm_hard_disk_drive.rb
|
|
191
193
|
- lib/fog/hyperv/compute/requests/add_vm_network_adapter.rb
|
|
192
194
|
- lib/fog/hyperv/compute/requests/connect_vm_network_adapter.rb
|
|
195
|
+
- lib/fog/hyperv/compute/requests/disable_vm_integration_service.rb
|
|
193
196
|
- lib/fog/hyperv/compute/requests/disable_vm_tpm.rb
|
|
194
197
|
- lib/fog/hyperv/compute/requests/disconnect_vm_network_adapter.rb
|
|
198
|
+
- lib/fog/hyperv/compute/requests/enable_vm_integration_service.rb
|
|
195
199
|
- lib/fog/hyperv/compute/requests/enable_vm_tpm.rb
|
|
196
200
|
- lib/fog/hyperv/compute/requests/get_cluster.rb
|
|
197
201
|
- lib/fog/hyperv/compute/requests/get_cluster_node.rb
|
|
@@ -207,6 +211,7 @@ files:
|
|
|
207
211
|
- lib/fog/hyperv/compute/requests/get_vm_host.rb
|
|
208
212
|
- lib/fog/hyperv/compute/requests/get_vm_host_cluster.rb
|
|
209
213
|
- lib/fog/hyperv/compute/requests/get_vm_host_sbt.rb
|
|
214
|
+
- lib/fog/hyperv/compute/requests/get_vm_integration_service.rb
|
|
210
215
|
- lib/fog/hyperv/compute/requests/get_vm_key_protector.rb
|
|
211
216
|
- lib/fog/hyperv/compute/requests/get_vm_network_adapter.rb
|
|
212
217
|
- lib/fog/hyperv/compute/requests/get_vm_network_adapter_vlan.rb
|