fog-hyperv 0.1.0 → 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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fog/hyperv/compute/models/bios.rb +4 -4
  3. data/lib/fog/hyperv/compute/models/cluster.rb +2 -12
  4. data/lib/fog/hyperv/compute/models/clusters.rb +1 -1
  5. data/lib/fog/hyperv/compute/models/com_port.rb +6 -6
  6. data/lib/fog/hyperv/compute/models/dvd_drive.rb +13 -13
  7. data/lib/fog/hyperv/compute/models/firmware.rb +6 -4
  8. data/lib/fog/hyperv/compute/models/floppy_drive.rb +6 -6
  9. data/lib/fog/hyperv/compute/models/hard_drive.rb +17 -21
  10. data/lib/fog/hyperv/compute/models/host.rb +1 -4
  11. data/lib/fog/hyperv/compute/models/integration_service.rb +72 -0
  12. data/lib/fog/hyperv/compute/models/integration_services.rb +29 -0
  13. data/lib/fog/hyperv/compute/models/network_adapter.rb +26 -20
  14. data/lib/fog/hyperv/compute/models/network_adapters.rb +1 -1
  15. data/lib/fog/hyperv/compute/models/security.rb +8 -4
  16. data/lib/fog/hyperv/compute/models/server.rb +55 -26
  17. data/lib/fog/hyperv/compute/models/servers.rb +1 -1
  18. data/lib/fog/hyperv/compute/models/switch.rb +10 -10
  19. data/lib/fog/hyperv/compute/models/switches.rb +1 -1
  20. data/lib/fog/hyperv/compute/models/vhd.rb +23 -10
  21. data/lib/fog/hyperv/compute/models/vhds.rb +1 -1
  22. data/lib/fog/hyperv/compute/requests/connect_vm_network_adapter.rb +1 -1
  23. data/lib/fog/hyperv/compute/requests/disable_vm_integration_service.rb +16 -0
  24. data/lib/fog/hyperv/compute/requests/enable_vm_integration_service.rb +16 -0
  25. data/lib/fog/hyperv/compute/requests/get_cluster.rb +2 -2
  26. data/lib/fog/hyperv/compute/requests/get_vhd.rb +2 -0
  27. data/lib/fog/hyperv/compute/requests/get_vm_com_port.rb +2 -2
  28. data/lib/fog/hyperv/compute/requests/get_vm_dvd_drive.rb +2 -2
  29. data/lib/fog/hyperv/compute/requests/get_vm_floppy_disk_drive.rb +2 -2
  30. data/lib/fog/hyperv/compute/requests/get_vm_hard_disk_drive.rb +2 -2
  31. data/lib/fog/hyperv/compute/requests/get_vm_host_cluster.rb +1 -1
  32. data/lib/fog/hyperv/compute/requests/get_vm_integration_service.rb +15 -0
  33. data/lib/fog/hyperv/compute/requests/new_vhd.rb +1 -1
  34. data/lib/fog/hyperv/compute/requests/new_vm_switch.rb +1 -1
  35. data/lib/fog/hyperv/compute/requests/optimize_vhd.rb +1 -1
  36. data/lib/fog/hyperv/compute/requests/remove_item.rb +1 -1
  37. data/lib/fog/hyperv/compute/requests/remove_vm.rb +1 -1
  38. data/lib/fog/hyperv/compute/requests/rename_vm.rb +2 -2
  39. data/lib/fog/hyperv/compute/requests/rename_vm_network_adapter.rb +1 -1
  40. data/lib/fog/hyperv/compute/requests/rename_vm_switch.rb +8 -1
  41. data/lib/fog/hyperv/compute/requests/resize_vhd.rb +8 -1
  42. data/lib/fog/hyperv/compute/requests/restart_vm.rb +1 -1
  43. data/lib/fog/hyperv/compute/requests/resume_vm.rb +1 -1
  44. data/lib/fog/hyperv/compute/requests/save_vm.rb +1 -1
  45. data/lib/fog/hyperv/compute/requests/set_vm.rb +1 -1
  46. data/lib/fog/hyperv/compute/requests/start_vm.rb +1 -1
  47. data/lib/fog/hyperv/compute/requests/stop_vm.rb +1 -1
  48. data/lib/fog/hyperv/compute/requests/suspend_vm.rb +1 -1
  49. data/lib/fog/hyperv/compute/requests/update_vm.rb +1 -1
  50. data/lib/fog/hyperv/compute.rb +5 -0
  51. data/lib/fog/hyperv/model.rb +2 -2
  52. data/lib/fog/hyperv/utils/powershell.rb +1 -1
  53. data/lib/fog/hyperv/utils/winrm.rb +1 -1
  54. data/lib/fog/hyperv/version.rb +1 -1
  55. data/lib/fog/hyperv.rb +3 -1
  56. metadata +6 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af18f5580ade8fe5abf47b387585468f91015c27629395924701e00b93d91c63
4
- data.tar.gz: ed2a99e90fe6f3352900348c58a35a49a4c958faaa1171e14eba8f7bc2bfe266
3
+ metadata.gz: 967724a9fd59c0978858d86ff438fe64a8eefc884cdeb11d0e6c7e372c28b725
4
+ data.tar.gz: f845028078a57dd1aec509aa7357ac3c58e5aab5d301b833ac00ab01fc8ee726
5
5
  SHA512:
6
- metadata.gz: 6b68ca5623d9bf6cac41b8c1225bb42d7cb64243914bc99b438dc0f77c39379eba129461161bdca8f31d5afd5338092210bcfa275e2eea238116576707b8f205
7
- data.tar.gz: 30719e7bd1f874b8ce11ea283682af5f676d014a742ac04e5ea86c5ab68c01633e615db8a6fdb7b52be75ae0629d79408b9e24bd7c515bdf9ab0584041dd057f
6
+ metadata.gz: e4f71c7887ef726c2281be088d048fa56ceb71b4bd0b1684846bd1accd922a245ea2227e4f562b3acdbb9d57c90f72a930011f63c051b30937187cd1e13bc012
7
+ data.tar.gz: 2ea917dfb9a6fc294ea7ced844661dc3c5772e9775d2e01d77eb3eb2592d742b8a96e5a57ca4ecd9ca527bee1e467d40256cb218f897164e223a7de4b874e5e4
@@ -41,8 +41,8 @@ class Fog::Hyperv::Compute
41
41
  return self unless changes.any?
42
42
 
43
43
  data = service.set_vm_bios(
44
- computer_name:,
45
- vm_id:,
44
+ computer_name: computer_name,
45
+ vm_id: vm_id,
46
46
 
47
47
  **changes,
48
48
 
@@ -57,8 +57,8 @@ class Fog::Hyperv::Compute
57
57
  requires :vm_id
58
58
 
59
59
  data = service.get_vm_bios(
60
- computer_name:,
61
- vm_id:,
60
+ computer_name: computer_name,
61
+ vm_id: vm_id,
62
62
 
63
63
  _return_fields: self.class.attributes
64
64
  )
@@ -31,11 +31,7 @@ class Fog::Hyperv::Compute
31
31
  def reload
32
32
  requires :id
33
33
 
34
- data = service.get_cluster(
35
- id:,
36
-
37
- _return_fields: self.class.attributes
38
- )
34
+ data = service.get_cluster id: id, _return_fields: self.class.attributes
39
35
  return unless data
40
36
 
41
37
  merge_attributes(data.attributes)
@@ -48,13 +44,7 @@ class Fog::Hyperv::Compute
48
44
 
49
45
  requires :id
50
46
 
51
- [
52
- service.get_cluster_node(
53
- id:,
54
-
55
- _return_fields: %i[name]
56
- )
57
- ].flatten
47
+ [service.get_cluster_node(id: id, _return_fields: %i[name])].flatten
58
48
  end
59
49
  end
60
50
  end
@@ -15,7 +15,7 @@ class Fog::Hyperv::Compute
15
15
 
16
16
  raise ArgumentError, 'Must provide a name or GUID' if (id.nil? || id.empty?) && (name.nil? || name.empty?)
17
17
 
18
- super(name:, _by_id: id, **filters)
18
+ super(name: name, _by_id: id, **filters)
19
19
  end
20
20
  end
21
21
  end
@@ -39,9 +39,9 @@ class Fog::Hyperv::Compute
39
39
 
40
40
  merge_attributes(
41
41
  service.set_vm_com_port(
42
- computer_name:,
43
- vm_id:,
44
- id:,
42
+ computer_name: computer_name,
43
+ vm_id: vm_id,
44
+ id: id,
45
45
 
46
46
  **changes,
47
47
 
@@ -56,9 +56,9 @@ class Fog::Hyperv::Compute
56
56
  requires :vm_id, :id
57
57
 
58
58
  data = service.get_vm_com_port(
59
- computer_name:,
60
- vm_id:,
61
- id:,
59
+ computer_name: computer_name,
60
+ vm_id: vm_id,
61
+ id: id,
62
62
 
63
63
  _return_fields: self.class.attributes
64
64
  )
@@ -53,13 +53,13 @@ class Fog::Hyperv::Compute
53
53
 
54
54
  merge_attributes(
55
55
  service.add_vm_dvd_drive(
56
- computer_name:,
57
- vm_id:,
56
+ computer_name: computer_name,
57
+ vm_id: vm_id,
58
58
 
59
- allow_unverified_paths:,
60
- controller_number:,
61
- controller_location:,
62
- path:,
59
+ allow_unverified_paths: allow_unverified_paths,
60
+ controller_number: controller_numbere,
61
+ controller_location: controller_location,
62
+ path: path,
63
63
  resource_pool_name: pool_name,
64
64
 
65
65
  _return_fields: self.class.attributes
@@ -86,7 +86,7 @@ class Fog::Hyperv::Compute
86
86
  vm_id: old.vm_id,
87
87
  id: old.id,
88
88
 
89
- allow_unverified_paths:,
89
+ allow_unverified_paths: allow_unverified_paths,
90
90
  **changes,
91
91
 
92
92
  _always_include: changes.keys,
@@ -100,9 +100,9 @@ class Fog::Hyperv::Compute
100
100
  requires :id, :vm_id
101
101
 
102
102
  service.remove_vm_dvd_drive(
103
- computer_name:,
104
- vm_id:,
105
- id:
103
+ computer_name: computer_name,
104
+ vm_id: vm_id,
105
+ id: id
106
106
  )
107
107
  true
108
108
  end
@@ -112,9 +112,9 @@ class Fog::Hyperv::Compute
112
112
  requires :id, :vm_id
113
113
 
114
114
  data = service.get_vm_dvd_drive(
115
- computer_name:,
116
- vm_id:,
117
- id:,
115
+ computer_name: computer_name,
116
+ vm_id: vm_id,
117
+ id: id,
118
118
 
119
119
  _return_fields: self.class.attributes
120
120
  )
@@ -52,8 +52,10 @@ class Fog::Hyperv::Compute
52
52
 
53
53
  merge_attributes(
54
54
  service.set_vm_firmware(
55
- computer_name:,
56
- vm_id:,
55
+ computer_name: computer_name,
56
+ vm_id: vm_id,
57
+
58
+ **changes,
57
59
 
58
60
  _return_fields: self.class.attributes
59
61
  )
@@ -65,8 +67,8 @@ class Fog::Hyperv::Compute
65
67
  requires :vm_id
66
68
 
67
69
  data = service.get_vm_firmware(
68
- computer_name:,
69
- vm_id:,
70
+ computer_name: computer_name,
71
+ vm_id: vm_id,
70
72
 
71
73
  _return_fields: self.class.attributes
72
74
  )
@@ -34,9 +34,9 @@ class Fog::Hyperv::Compute
34
34
 
35
35
  merge_attributes(
36
36
  service.set_vm_floppy_disk_drive(
37
- computer_name:,
38
- vm_id:,
39
- id:,
37
+ computer_name: computer_name,
38
+ vm_id: vm_id,
39
+ id: id,
40
40
 
41
41
  **changes,
42
42
 
@@ -50,9 +50,9 @@ class Fog::Hyperv::Compute
50
50
  requires :vm_id, :id
51
51
 
52
52
  data = service.get_vm_floppy_disk_drive(
53
- computer_name:,
54
- vm_id:,
55
- id:,
53
+ computer_name: computer_name,
54
+ vm_id: vm_id,
55
+ id: id,
56
56
 
57
57
  _return_fields: self.class.attributes
58
58
  )
@@ -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:)
70
+ associations[:vhd] = (vm || service).vhds.get(path, computer_name: computer_name)
71
71
  end
72
72
 
73
73
  def vhd=(new_vhd)
@@ -99,17 +99,17 @@ class Fog::Hyperv::Compute
99
99
 
100
100
  merge_attributes(
101
101
  service.add_vm_hard_disk_drive(
102
- computer_name:,
103
- vm_id:,
104
-
105
- allow_unverified_paths:,
106
- controller_location:,
107
- controller_number:,
108
- controller_type:,
109
- # disk_number: disk&.number,
110
- maximum_iops:,
111
- minimum_iops:,
112
- path:,
102
+ **attributes.slice(
103
+ :computer_name,
104
+ :vm_id,
105
+ :allow_unverified_paths,
106
+ :controller_location,
107
+ :controller_number,
108
+ :controller_type,
109
+ :maximum_iops,
110
+ :minimum_iops,
111
+ :path
112
+ ),
113
113
  resource_pool_name: pool_name,
114
114
 
115
115
  _return_fields: self.class.attributes - %i[allow_unverified_paths vhd]
@@ -139,7 +139,7 @@ class Fog::Hyperv::Compute
139
139
  id: old.id,
140
140
 
141
141
  **changes,
142
- allow_unverified_paths:,
142
+ allow_unverified_paths: allow_unverified_paths,
143
143
 
144
144
  _always_include: changes.keys,
145
145
  _return_fields: self.class.attributes - %i[allow_unverified_paths vhd]
@@ -159,9 +159,9 @@ class Fog::Hyperv::Compute
159
159
  requires :id, :vm_id
160
160
 
161
161
  data = service.get_vm_hard_disk_drive(
162
- computer_name:,
163
- vm_id:,
164
- id:,
162
+ computer_name: computer_name,
163
+ vm_id: vm_id,
164
+ id: id,
165
165
 
166
166
  _return_fields: self.class.attributes - %i[allow_unverified_paths vhd]
167
167
  )
@@ -175,11 +175,7 @@ class Fog::Hyperv::Compute
175
175
 
176
176
  requires :id, :vm_id
177
177
 
178
- service.remove_vm_hard_disk_drive(
179
- computer_name:,
180
- vm_id:,
181
- id:
182
- )
178
+ service.remove_vm_hard_disk_drive computer_name: computer_name, vm_id: vm_id, id: id
183
179
  vhd.destroy if underlying && vhd?
184
180
  true
185
181
  end
@@ -54,10 +54,7 @@ class Fog::Hyperv::Compute
54
54
  def reload
55
55
  requires :name
56
56
 
57
- data = service.get_vm_host(
58
- computer_name:,
59
- name:
60
- )
57
+ data = service.get_vm_host computer_name: computer_name, name: name
61
58
  return unless data
62
59
 
63
60
  merge_attributes(data)
@@ -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
@@ -118,10 +118,10 @@ class Fog::Hyperv::Compute
118
118
 
119
119
  associations[:vlan_setting] = Fog::Hyperv::Compute::NetworkAdapterVlan.new(
120
120
  **service.get_vm_network_adapter_vlan(
121
- computer_name:,
121
+ computer_name: computer_name,
122
122
  management_os: is_management_os,
123
- vm_id:,
124
- id:,
123
+ vm_id: vm_id,
124
+ id: id,
125
125
 
126
126
  _return_fields: Fog::Hyperv::Compute::NetworkAdapterVlan.attributes
127
127
  ),
@@ -147,9 +147,9 @@ class Fog::Hyperv::Compute
147
147
  options[:management_os] = true if is_management_os
148
148
 
149
149
  service.connect_vm_network_adapter(
150
- computer_name:,
151
- vm_id:,
152
- id:,
150
+ computer_name: computer_name,
151
+ vm_id: vm_id,
152
+ id: id,
153
153
 
154
154
  switch_id: new_switch_id,
155
155
  switch_name: new_switch_name,
@@ -168,9 +168,9 @@ class Fog::Hyperv::Compute
168
168
 
169
169
  options[:management_os] = true if is_management_os
170
170
  service.disconnect_vm_network_adapter(
171
- computer_name:,
172
- vm_id:,
173
- id:,
171
+ computer_name: computer_name,
172
+ vm_id: vm_id,
173
+ id: id,
174
174
 
175
175
  **options
176
176
  )
@@ -185,7 +185,13 @@ class Fog::Hyperv::Compute
185
185
  # @see connect
186
186
  # @see disconnect
187
187
  def switch
188
- service.switches.get(switch_id:, switch_name:, computer_name:) if switch_name.any? || switch_id.any?
188
+ return unless switch_name.any? || switch_id.any?
189
+
190
+ service.switches.get(
191
+ switch_id: switch_id,
192
+ switch_name: switch_name,
193
+ computer_name: computer_name
194
+ )
189
195
  end
190
196
 
191
197
  def switch=(new_switch)
@@ -212,7 +218,7 @@ class Fog::Hyperv::Compute
212
218
  selector[:vm_id] = vm_id
213
219
  end
214
220
 
215
- args = { name:, switch_name: }
221
+ args = attributes.slice(:name, :switch_name)
216
222
  args[:is_legacy] = true if is_legacy
217
223
  if !dynamic_mac_address_enabled && mac_address != NIC_FALLBACK_MAC
218
224
  args[:static_mac_address] = mac_address
@@ -221,7 +227,7 @@ class Fog::Hyperv::Compute
221
227
  end
222
228
  data = service.add_vm_network_adapter(
223
229
  **selector,
224
- computer_name:,
230
+ computer_name: computer_name,
225
231
 
226
232
  **args,
227
233
 
@@ -293,9 +299,9 @@ class Fog::Hyperv::Compute
293
299
  requires :vm_id unless is_management_os
294
300
 
295
301
  service.remove_vm_network_adapter(
296
- computer_name:,
297
- vm_id:,
298
- id:,
302
+ computer_name: computer_name,
303
+ vm_id: vm_id,
304
+ id: id,
299
305
  management_os: is_management_os
300
306
  )
301
307
  true
@@ -306,9 +312,9 @@ class Fog::Hyperv::Compute
306
312
  requires :vm_id unless is_management_os
307
313
 
308
314
  data = service.get_vm_network_adapter(
309
- computer_name:,
310
- vm_id:,
311
- id:,
315
+ computer_name: computer_name,
316
+ vm_id: vm_id,
317
+ id: id,
312
318
  management_os: is_management_os,
313
319
 
314
320
  _return_fields: self.class.attributes
@@ -348,11 +354,11 @@ class Fog::Hyperv::Compute
348
354
  end
349
355
 
350
356
  def save_switch
351
- selector = { computer_name:, vm_id:, id: }.compact
357
+ selector = attributes.slice(:computer_name, :vm_id, :id).compact
352
358
  selector[:management_os] = true if is_management_os
353
359
 
354
360
  if switch_name || switch_id
355
- service.connect_vm_network_adapter(**selector, switch_name:, switch_id:)
361
+ service.connect_vm_network_adapter(**selector, switch_name: switch_name, switch_id: switch_id)
356
362
  else
357
363
  service.disconnect_vm_network_adapter(**selector)
358
364
  end
@@ -18,7 +18,7 @@ class Fog::Hyperv::Compute
18
18
 
19
19
  raise ArgumentError, 'Must provide a name or combined GUID' if id.nil? && name.nil?
20
20
 
21
- super(name:, _by_id: id, **filters)
21
+ super(name: name, _by_id: id, **filters)
22
22
  end
23
23
 
24
24
  protected
@@ -36,10 +36,14 @@ class Fog::Hyperv::Compute
36
36
  def key_protector
37
37
  requires :vm
38
38
 
39
- @key_protector ||= service.get_vm_key_protector(
40
- computer_name: vm.computer_name,
41
- vm_id: vm.id
42
- )[:value]
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