fog-hyperv 0.0.9 → 0.1.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 (183) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -2
  3. data/lib/fog/bin/hyperv.rb +6 -4
  4. data/lib/fog/hyperv/collection.rb +89 -0
  5. data/lib/fog/hyperv/compute/models/bios.rb +70 -0
  6. data/lib/fog/hyperv/compute/models/cluster.rb +60 -0
  7. data/lib/fog/hyperv/compute/models/clusters.rb +21 -0
  8. data/lib/fog/hyperv/compute/models/com_port.rb +78 -0
  9. data/lib/fog/hyperv/compute/models/com_ports.rb +29 -0
  10. data/lib/fog/hyperv/compute/models/dvd_drive.rb +126 -0
  11. data/lib/fog/hyperv/compute/models/dvd_drives.rb +29 -0
  12. data/lib/fog/hyperv/compute/models/firmware.rb +78 -0
  13. data/lib/fog/hyperv/compute/models/floppy_drive.rb +64 -0
  14. data/lib/fog/hyperv/compute/models/floppy_drives.rb +18 -0
  15. data/lib/fog/hyperv/compute/models/hard_drive.rb +187 -0
  16. data/lib/fog/hyperv/compute/models/hard_drives.rb +28 -0
  17. data/lib/fog/hyperv/compute/models/host.rb +66 -0
  18. data/lib/fog/hyperv/compute/models/hosts.rb +13 -0
  19. data/lib/fog/hyperv/compute/models/network_adapter.rb +362 -0
  20. data/lib/fog/hyperv/compute/models/network_adapter_vlan.rb +172 -0
  21. data/lib/fog/hyperv/compute/models/network_adapters.rb +32 -0
  22. data/lib/fog/hyperv/compute/models/security.rb +121 -0
  23. data/lib/fog/hyperv/compute/models/server.rb +466 -0
  24. data/lib/fog/hyperv/compute/models/servers.rb +18 -0
  25. data/lib/fog/hyperv/compute/models/switch.rb +117 -0
  26. data/lib/fog/hyperv/compute/models/switches.rb +20 -0
  27. data/lib/fog/hyperv/compute/models/vhd.rb +210 -0
  28. data/lib/fog/hyperv/compute/models/vhds.rb +28 -0
  29. data/lib/fog/hyperv/compute/requests/add_vm_dvd_drive.rb +15 -0
  30. data/lib/fog/hyperv/compute/requests/add_vm_hard_disk_drive.rb +15 -0
  31. data/lib/fog/hyperv/compute/requests/add_vm_network_adapter.rb +24 -0
  32. data/lib/fog/hyperv/compute/requests/connect_vm_network_adapter.rb +41 -0
  33. data/lib/fog/hyperv/compute/requests/disable_vm_tpm.rb +16 -0
  34. data/lib/fog/hyperv/compute/requests/disconnect_vm_network_adapter.rb +29 -0
  35. data/lib/fog/hyperv/compute/requests/enable_vm_tpm.rb +16 -0
  36. data/lib/fog/hyperv/compute/requests/get_cluster.rb +11 -0
  37. data/lib/fog/hyperv/compute/requests/get_cluster_node.rb +22 -0
  38. data/lib/fog/hyperv/compute/requests/get_vhd.rb +32 -0
  39. data/lib/fog/hyperv/compute/requests/get_vm.rb +18 -0
  40. data/lib/fog/hyperv/compute/requests/get_vm_bios.rb +21 -0
  41. data/lib/fog/hyperv/compute/requests/get_vm_com_port.rb +17 -0
  42. data/lib/fog/hyperv/compute/requests/get_vm_dvd_drive.rb +25 -0
  43. data/lib/fog/hyperv/compute/requests/get_vm_firmware.rb +21 -0
  44. data/lib/fog/hyperv/compute/requests/get_vm_floppy_disk_drive.rb +16 -0
  45. data/lib/fog/hyperv/compute/requests/get_vm_group.rb +20 -0
  46. data/lib/fog/hyperv/compute/requests/get_vm_hard_disk_drive.rb +24 -0
  47. data/lib/fog/hyperv/compute/requests/get_vm_host.rb +9 -0
  48. data/lib/fog/hyperv/compute/requests/get_vm_host_cluster.rb +21 -0
  49. data/lib/fog/hyperv/compute/requests/get_vm_host_sbt.rb +10 -0
  50. data/lib/fog/hyperv/compute/requests/get_vm_key_protector.rb +16 -0
  51. data/lib/fog/hyperv/compute/requests/get_vm_network_adapter.rb +41 -0
  52. data/lib/fog/hyperv/compute/requests/get_vm_network_adapter_vlan.rb +41 -0
  53. data/lib/fog/hyperv/compute/requests/get_vm_security.rb +15 -0
  54. data/lib/fog/hyperv/compute/requests/get_vm_switch.rb +10 -0
  55. data/lib/fog/hyperv/compute/requests/mock_files/get_vm.json +4 -0
  56. data/lib/fog/hyperv/compute/requests/new_vhd.rb +9 -0
  57. data/lib/fog/hyperv/compute/requests/new_vm.rb +12 -0
  58. data/lib/fog/hyperv/compute/requests/new_vm_switch.rb +11 -0
  59. data/lib/fog/hyperv/compute/requests/optimize_vhd.rb +9 -0
  60. data/lib/fog/hyperv/compute/requests/remove_item.rb +10 -0
  61. data/lib/fog/hyperv/compute/requests/remove_vm.rb +16 -0
  62. data/lib/fog/hyperv/compute/requests/remove_vm_dvd_drive.rb +17 -0
  63. data/lib/fog/hyperv/compute/requests/remove_vm_hard_disk_drive.rb +17 -0
  64. data/lib/fog/hyperv/compute/requests/remove_vm_network_adapter.rb +29 -0
  65. data/lib/fog/hyperv/compute/requests/remove_vm_switch.rb +9 -0
  66. data/lib/fog/hyperv/compute/requests/rename_vm.rb +16 -0
  67. data/lib/fog/hyperv/compute/requests/rename_vm_network_adapter.rb +25 -0
  68. data/lib/fog/hyperv/compute/requests/rename_vm_switch.rb +9 -0
  69. data/lib/fog/hyperv/compute/requests/resize_vhd.rb +9 -0
  70. data/lib/fog/hyperv/compute/requests/restart_vm.rb +22 -0
  71. data/lib/fog/hyperv/compute/requests/resume_vm.rb +22 -0
  72. data/lib/fog/hyperv/compute/requests/save_vm.rb +22 -0
  73. data/lib/fog/hyperv/compute/requests/set_vm.rb +15 -0
  74. data/lib/fog/hyperv/compute/requests/set_vm_bios.rb +15 -0
  75. data/lib/fog/hyperv/compute/requests/set_vm_com_port.rb +16 -0
  76. data/lib/fog/hyperv/compute/requests/set_vm_dvd_drive.rb +16 -0
  77. data/lib/fog/hyperv/compute/requests/set_vm_firmware.rb +15 -0
  78. data/lib/fog/hyperv/compute/requests/set_vm_floppy_disk_drive.rb +16 -0
  79. data/lib/fog/hyperv/compute/requests/set_vm_hard_disk_drive.rb +16 -0
  80. data/lib/fog/hyperv/compute/requests/set_vm_key_protector.rb +15 -0
  81. data/lib/fog/hyperv/compute/requests/set_vm_network_adapter.rb +25 -0
  82. data/lib/fog/hyperv/compute/requests/set_vm_network_adapter_vlan.rb +25 -0
  83. data/lib/fog/hyperv/compute/requests/set_vm_security.rb +17 -0
  84. data/lib/fog/hyperv/compute/requests/set_vm_switch.rb +9 -0
  85. data/lib/fog/hyperv/compute/requests/start_vm.rb +22 -0
  86. data/lib/fog/hyperv/compute/requests/stop_vm.rb +22 -0
  87. data/lib/fog/hyperv/compute/requests/suspend_vm.rb +22 -0
  88. data/lib/fog/hyperv/compute/requests/update_vm.rb +22 -0
  89. data/lib/fog/hyperv/compute.rb +206 -387
  90. data/lib/fog/hyperv/constants.rb +24 -0
  91. data/lib/fog/hyperv/fog_extensions/associations/collection.rb +11 -0
  92. data/lib/fog/hyperv/fog_extensions/attributes/datetime.rb +28 -0
  93. data/lib/fog/hyperv/fog_extensions/attributes/enum.rb +139 -0
  94. data/lib/fog/hyperv/fog_extensions/attributes/enumarray.rb +149 -0
  95. data/lib/fog/hyperv/fog_extensions/attributes/timespan.rb +27 -0
  96. data/lib/fog/hyperv/model.rb +142 -0
  97. data/lib/fog/hyperv/utils/powershell.rb +88 -0
  98. data/lib/fog/hyperv/utils/winrm.rb +233 -0
  99. data/lib/fog/hyperv/version.rb +4 -1
  100. data/lib/fog/hyperv.rb +51 -44
  101. metadata +187 -105
  102. data/.gitignore +0 -10
  103. data/.travis.yml +0 -11
  104. data/CHANGELOG.md +0 -52
  105. data/Gemfile +0 -4
  106. data/Rakefile +0 -10
  107. data/fog-hyperv.gemspec +0 -25
  108. data/lib/fog/collection.rb +0 -152
  109. data/lib/fog/hyperv/fog_extensions/enum.rb +0 -85
  110. data/lib/fog/hyperv/models/compute/bios.rb +0 -61
  111. data/lib/fog/hyperv/models/compute/cluster.rb +0 -64
  112. data/lib/fog/hyperv/models/compute/clusters.rb +0 -15
  113. data/lib/fog/hyperv/models/compute/com_port.rb +0 -22
  114. data/lib/fog/hyperv/models/compute/dvd_drive.rb +0 -92
  115. data/lib/fog/hyperv/models/compute/dvd_drives.rb +0 -12
  116. data/lib/fog/hyperv/models/compute/firmware.rb +0 -53
  117. data/lib/fog/hyperv/models/compute/floppy_drive.rb +0 -53
  118. data/lib/fog/hyperv/models/compute/floppy_drives.rb +0 -12
  119. data/lib/fog/hyperv/models/compute/hard_drive.rb +0 -110
  120. data/lib/fog/hyperv/models/compute/hard_drives.rb +0 -11
  121. data/lib/fog/hyperv/models/compute/host.rb +0 -45
  122. data/lib/fog/hyperv/models/compute/hosts.rb +0 -15
  123. data/lib/fog/hyperv/models/compute/network_adapter.rb +0 -145
  124. data/lib/fog/hyperv/models/compute/network_adapters.rb +0 -19
  125. data/lib/fog/hyperv/models/compute/server.rb +0 -220
  126. data/lib/fog/hyperv/models/compute/servers.rb +0 -21
  127. data/lib/fog/hyperv/models/compute/switch.rb +0 -65
  128. data/lib/fog/hyperv/models/compute/switches.rb +0 -15
  129. data/lib/fog/hyperv/models/compute/vhd.rb +0 -101
  130. data/lib/fog/hyperv/models/compute/vhds.rb +0 -16
  131. data/lib/fog/hyperv/requests/compute/add_vm_dvd_drive.rb +0 -12
  132. data/lib/fog/hyperv/requests/compute/add_vm_hard_disk_drive.rb +0 -12
  133. data/lib/fog/hyperv/requests/compute/add_vm_network_adapter.rb +0 -12
  134. data/lib/fog/hyperv/requests/compute/connect_vm_network_adapter.rb +0 -12
  135. data/lib/fog/hyperv/requests/compute/disconnect_vm_network_adapter.rb +0 -12
  136. data/lib/fog/hyperv/requests/compute/get_cluster.rb +0 -11
  137. data/lib/fog/hyperv/requests/compute/get_cluster_node.rb +0 -19
  138. data/lib/fog/hyperv/requests/compute/get_vhd.rb +0 -34
  139. data/lib/fog/hyperv/requests/compute/get_vm.rb +0 -20
  140. data/lib/fog/hyperv/requests/compute/get_vm_bios.rb +0 -21
  141. data/lib/fog/hyperv/requests/compute/get_vm_dvd_drive.rb +0 -20
  142. data/lib/fog/hyperv/requests/compute/get_vm_firmware.rb +0 -19
  143. data/lib/fog/hyperv/requests/compute/get_vm_floppy_disk_drive.rb +0 -20
  144. data/lib/fog/hyperv/requests/compute/get_vm_group.rb +0 -23
  145. data/lib/fog/hyperv/requests/compute/get_vm_hard_disk_drive.rb +0 -20
  146. data/lib/fog/hyperv/requests/compute/get_vm_host.rb +0 -12
  147. data/lib/fog/hyperv/requests/compute/get_vm_host_cluster.rb +0 -25
  148. data/lib/fog/hyperv/requests/compute/get_vm_network_adapter.rb +0 -27
  149. data/lib/fog/hyperv/requests/compute/get_vm_switch.rb +0 -27
  150. data/lib/fog/hyperv/requests/compute/mock_files/get_vm.json +0 -1
  151. data/lib/fog/hyperv/requests/compute/new_vhd.rb +0 -12
  152. data/lib/fog/hyperv/requests/compute/new_vm.rb +0 -15
  153. data/lib/fog/hyperv/requests/compute/new_vm_switch.rb +0 -13
  154. data/lib/fog/hyperv/requests/compute/remove_item.rb +0 -13
  155. data/lib/fog/hyperv/requests/compute/remove_vm.rb +0 -15
  156. data/lib/fog/hyperv/requests/compute/remove_vm_dvd_drive.rb +0 -12
  157. data/lib/fog/hyperv/requests/compute/remove_vm_hard_disk_drive.rb +0 -12
  158. data/lib/fog/hyperv/requests/compute/remove_vm_network_adapter.rb +0 -12
  159. data/lib/fog/hyperv/requests/compute/restart_vm.rb +0 -15
  160. data/lib/fog/hyperv/requests/compute/set_vm.rb +0 -12
  161. data/lib/fog/hyperv/requests/compute/set_vm_bios.rb +0 -13
  162. data/lib/fog/hyperv/requests/compute/set_vm_dvd_drive.rb +0 -12
  163. data/lib/fog/hyperv/requests/compute/set_vm_firmware.rb +0 -13
  164. data/lib/fog/hyperv/requests/compute/set_vm_hard_disk_drive.rb +0 -12
  165. data/lib/fog/hyperv/requests/compute/set_vm_network_adapter.rb +0 -12
  166. data/lib/fog/hyperv/requests/compute/set_vm_network_adapter_vlan.rb +0 -12
  167. data/lib/fog/hyperv/requests/compute/set_vm_switch.rb +0 -13
  168. data/lib/fog/hyperv/requests/compute/start_vm.rb +0 -15
  169. data/lib/fog/hyperv/requests/compute/stop_vm.rb +0 -15
  170. data/lib/fog/model.rb +0 -91
  171. data/test/fog/hyperv_test.rb +0 -7
  172. data/test/test_helper.rb +0 -4
  173. /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_cluster.json +0 -0
  174. /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_cluster_node.json +0 -0
  175. /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_vhd.json +0 -0
  176. /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_vm_bios.json +0 -0
  177. /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_vm_dvd_drive.json +0 -0
  178. /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_vm_firmware.json +0 -0
  179. /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_vm_floppy_disk_drive.json +0 -0
  180. /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_vm_hard_disk_drive.json +0 -0
  181. /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_vm_host.json +0 -0
  182. /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_vm_network_adapter.json +0 -0
  183. /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_vm_switch.json +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 366c601e6615f5b716341d88c28d02fe80360121f7e5570bee5e414b9a4b6e5e
4
- data.tar.gz: 80e37578e713ff575a3044ecc5e0cd93d86a2ddbf9ff19cd18036ee40496e5fa
3
+ metadata.gz: af18f5580ade8fe5abf47b387585468f91015c27629395924701e00b93d91c63
4
+ data.tar.gz: ed2a99e90fe6f3352900348c58a35a49a4c958faaa1171e14eba8f7bc2bfe266
5
5
  SHA512:
6
- metadata.gz: 735d793469f62b025edd6adf35e8f57120769eaa71d36c6fea8e25e25c27515c8d9fd338e0c66e5b1645a2863175ee4356008e7438bdeadd70ec5d0be9de222a
7
- data.tar.gz: 05356cabc6caa6eef04872f2afb1ad795f12acd1cfdc0b4662bf2910ff2864f3601e1e184b90928369e744982874239f077ac957e7de82d2c0f139d0fbc0eb4f
6
+ metadata.gz: 6b68ca5623d9bf6cac41b8c1225bb42d7cb64243914bc99b438dc0f77c39379eba129461161bdca8f31d5afd5338092210bcfa275e2eea238116576707b8f205
7
+ data.tar.gz: 30719e7bd1f874b8ce11ea283682af5f676d014a742ac04e5ea86c5ab68c01633e615db8a6fdb7b52be75ae0629d79408b9e24bd7c515bdf9ab0584041dd057f
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Fog Hyper-V
2
2
 
3
- [![Build Status](https://travis-ci.org/ananace/fog-hyperv.svg?branch=master)](https://travis-ci.org/ananace/fog-hyperv) [![Gem Version](https://badge.fury.io/rb/fog-hyperv.svg)](https://badge.fury.io/rb/fog-hyperv)
3
+ [![Gem Version](https://badge.fury.io/rb/fog-hyperv.svg)](https://badge.fury.io/rb/fog-hyperv)
4
4
 
5
5
  Manage your Hyper-V instance with the help of the Fog cloud service abstractions.
6
6
 
@@ -43,11 +43,21 @@ compute.servers.all
43
43
  #=> ...
44
44
  ```
45
45
 
46
+ ## Troubleshooting
47
+
48
+ If you're getting `WinRM::AuthorizationErrors` from the negotiate transport
49
+ even when using a valid user, make sure that the WinRM service is configured
50
+ for Negotiate auth.
51
+
52
+ If you're using a local (non-domain) user, you may also need to set the DWORD
53
+ registry value `LocalAccountTokenFilterPolicy` at `HKLM\software\Microsoft\Windows\CurrentVersion\Policies\system`
54
+ to `1`.
55
+
46
56
  ## Development
47
57
 
48
58
  After checking out the repo, run `bundle install` to install dependencies. Then, run `rake test` to run the tests. You can also run `bundle exec irb` for an interactive prompt that will allow you to experiment.
49
59
 
50
60
  ## Contributing
51
61
 
52
- Bug reports and pull requests are welcome on GitHub at https://github.com/ananace/fog-hyperv.
62
+ Bug reports and pull requests are welcome on the LiU GitLab at https://gitlab.liu.se/ITI/fog-hyperv or GitHub at https://github.com/ananace/fog-hyperv
53
63
 
@@ -1,24 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Hyperv < Fog::Bin
2
4
  class << self
3
5
  def class_for(key)
4
6
  case key
5
7
  when :compute
6
- Fog::Compute::Hyperv
8
+ Fog::Hyperv::Compute
7
9
  else
8
10
  raise ArgumentError, "Unsupported #{self} service: #{key}"
9
11
  end
10
12
  end
11
13
 
12
14
  def [](service)
13
- @@connections ||= Hash.new do |h, k|
15
+ @connections ||= Hash.new do |h, k|
14
16
  h[k] = case key
15
17
  when :compute
16
- Fog::Compute.new(provider: 'Hyperv')
18
+ Fog::Hyperv::Compute.new
17
19
  else
18
20
  raise ArgumentError, "Unrecognized service: #{key.inspect}"
19
21
  end
20
22
  end
21
- @@connections[service]
23
+ @connections[service]
22
24
  end
23
25
 
24
26
  def services
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fog::Hyperv
4
+ # Expanded Fog::Collection with Hyper-V specific configuration
5
+ class Collection < Fog::Collection
6
+ # Define the service request that is used to retrieve data for this collection
7
+ def self.get_method(method = nil)
8
+ @get_method ||= method
9
+ end
10
+
11
+ # Add required attributes for retrieving data for this collection
12
+ def self.requires(*attr)
13
+ @requires ||= []
14
+ @requires += attr if attr.any?
15
+ @requires
16
+ end
17
+
18
+ # Check if the collection requires a specific attribute
19
+ def self.requires?(req)
20
+ requires.include? req
21
+ end
22
+
23
+ def initialize(attributes = {})
24
+ @vm = attributes.delete(:vm)
25
+ @computer = attributes.delete(:computer)
26
+ @network_adapter = attributes.delete(:network_adapter)
27
+ @cluster = attributes.delete(:cluster)
28
+
29
+ super
30
+ end
31
+
32
+ # Retrieve all instances for the collection
33
+ def all(filters = {})
34
+ requires(*self.class.requires)
35
+
36
+ data = service.send(method, **search_attributes, **filters)
37
+ data ||= []
38
+ # Hyper-V will either return an array or a single value depending on the number of entries found
39
+ data = [data].flatten
40
+ return clone.load(data) if filters.any?
41
+
42
+ load data
43
+ @loaded = true
44
+ self
45
+ end
46
+
47
+ # Get a specific instance in the collection
48
+ def get(**filters)
49
+ new [service.send(method, **search_attributes, **filters)].flatten.first
50
+ rescue Fog::Hyperv::Errors::PSError => e
51
+ raise Fog::Errors::NotFound, e if e.message =~ /Hyper-V was unable to find|^No .* is found/
52
+
53
+ raise
54
+ end
55
+
56
+ # Create a new instance in the collection
57
+ def new(attributes = {})
58
+ requires(*self.class.requires)
59
+
60
+ attributes = attributes.attributes if attributes.is_a? Fog::Model
61
+ super(creation_attributes.merge(attributes))
62
+ end
63
+
64
+ protected
65
+
66
+ def search_attributes
67
+ attributes.merge(
68
+ _return_fields: model.attributes
69
+ )
70
+ end
71
+
72
+ def creation_attributes
73
+ attributes.merge(
74
+ {
75
+ vm: @vm,
76
+ computer: @computer,
77
+ network_adapter: @network_adapter,
78
+ cluster: @cluster
79
+ }.compact
80
+ )
81
+ end
82
+
83
+ private
84
+
85
+ def method
86
+ self.class.get_method
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ # Configuration for the BIOS settings of a VM
5
+ #
6
+ # @see https://learn.microsoft.com/en-us/powershell/module/hyper-v/set-vmbios for set-request
7
+ class Bios < Fog::Hyperv::Model
8
+ # @!attribute [r] vm_id
9
+ # @return [String] the GUID of the VM this BIOS configuration is attached to
10
+ identity :vm_id, type: :string
11
+
12
+ # @!attribute [r] computer_name
13
+ # @return [String] the name of the computer running the VM that this BIOS configuration is attached to
14
+ attribute :computer_name, type: :string
15
+
16
+ # attribute :is_deleted, type: :boolean
17
+ # @!attribute num_lock_enabled
18
+ # @return [Boolean] if num-lock should be enabled on boot
19
+ attribute :num_lock_enabled, type: :boolean
20
+ # @!attribute startup_order
21
+ # @note Hyper-V only really allows reordering these entries, not adding/removing from the list
22
+ # @return [Array<Symbol>] the boot order of the VM
23
+ # @see Fog::Hyperv::BOOT_DEVICE_ENUM_VALUES
24
+ # @example Set legacy net boot as default - if possible
25
+ # netboot = bios.startup_order.delete :LegacyNetworkAdapter
26
+ # bios.startup_order.unshift netboot if netboot
27
+ # bios.save
28
+ attribute :startup_order, type: :hypervenumarray, values: Fog::Hyperv::BOOT_DEVICE_ENUM_VALUES
29
+
30
+ # Save any modifications to Hyper-V
31
+ def update
32
+ requires :vm_id
33
+
34
+ # raise ArgumentError, 'Startup order can only be rearranged, not modified' \
35
+ # if changed?(:startup_order) && startup_order.sort != old.startup_order.sort
36
+
37
+ changes = {
38
+ startup_order: changed!(:startup_order)
39
+ }.compact
40
+ changes[num_lock_enabled ? :enable_num_lock : :disable_num_lock] = true if changed?(:num_lock_enabled)
41
+ return self unless changes.any?
42
+
43
+ data = service.set_vm_bios(
44
+ computer_name:,
45
+ vm_id:,
46
+
47
+ **changes,
48
+
49
+ _return_fields: self.class.attributes
50
+ )
51
+
52
+ merge_attributes(data)
53
+ end
54
+
55
+ # Reload attributes from Hyper-V
56
+ def reload
57
+ requires :vm_id
58
+
59
+ data = service.get_vm_bios(
60
+ computer_name:,
61
+ vm_id:,
62
+
63
+ _return_fields: self.class.attributes
64
+ )
65
+ return unless data
66
+
67
+ merge_attributes(data)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ # A cluster known to Hyper-V
5
+ #
6
+ # This model is read-only and strictly informative
7
+ class Cluster < Fog::Hyperv::Model
8
+ # @!attribute [r] id
9
+ # @return [String] the GUID of the cluster
10
+ identity :id, type: :string
11
+
12
+ # @!attribute [r] description
13
+ # @return [String] the description of the cluster
14
+ attribute :description, type: :string
15
+ # @!attribute [r] domain
16
+ # @return [String] the domain of the cluster
17
+ attribute :domain, type: :string
18
+ # @!attribute [r] name
19
+ # @return [String] the name of the cluster
20
+ attribute :name, type: :string
21
+
22
+ # @!attribute [r] hosts
23
+ # @return [Array<Host>] the list of hosts in the cluster
24
+ def hosts
25
+ return [] unless persisted?
26
+
27
+ cluster_nodes.map { |n| service.hosts.get(n[:name]) }
28
+ end
29
+
30
+ # Reload the cluster information from Hyper-V
31
+ def reload
32
+ requires :id
33
+
34
+ data = service.get_cluster(
35
+ id:,
36
+
37
+ _return_fields: self.class.attributes
38
+ )
39
+ return unless data
40
+
41
+ merge_attributes(data.attributes)
42
+ end
43
+
44
+ private
45
+
46
+ def cluster_nodes
47
+ return [] unless persisted?
48
+
49
+ requires :id
50
+
51
+ [
52
+ service.get_cluster_node(
53
+ id:,
54
+
55
+ _return_fields: %i[name]
56
+ )
57
+ ].flatten
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ # A collection of clusters known by Hyper-V
5
+ class Clusters < Fog::Hyperv::Collection
6
+ model Fog::Hyperv::Compute::Cluster
7
+
8
+ get_method :get_cluster
9
+
10
+ # Get an instance of a cluster by name or id
11
+ # @param identifier [String] the name or GUID of the cluster
12
+ def get(identifier, **filters)
13
+ id = identifier if identifier =~ /\A#{Fog::Hyperv::GUID}\z/i
14
+ name = identifier unless id
15
+
16
+ raise ArgumentError, 'Must provide a name or GUID' if (id.nil? || id.empty?) && (name.nil? || name.empty?)
17
+
18
+ super(name:, _by_id: id, **filters)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ # The configuration of a virtual COM port on a VM
5
+ #
6
+ # @see https://learn.microsoft.com/en-us/powershell/module/hyper-v/set-vmcomport for set-request
7
+ class ComPort < Fog::Hyperv::Model
8
+ # @!attribute [r] id
9
+ # @return [String] the combined GUID of this COM port
10
+ identity :id, type: :string
11
+
12
+ # @!attribute [r] vm_id
13
+ # @return [String] the GUID of the VM this COM port is attached to
14
+ attribute :vm_id, type: :string
15
+ # @!attribute [r] computer_name
16
+ # @return [String] the name of the computer running the VM that this COM port is attached to
17
+ attribute :computer_name, type: :string
18
+
19
+ # @!attribute debugger_mode
20
+ # @return [:On,:Off] if a debugger enabled on this COM port
21
+ attribute :debugger_mode, type: :hypervenum, values: Fog::Hyperv::ON_OFF_STATE_ENUM_VALUES
22
+ # @!attribute [r] name
23
+ # @return [String] the name of this COM port
24
+ attribute :name, type: :string
25
+ # @!attribute path
26
+ # @return [String] the path of the file/socket this COM port is attached to
27
+ attribute :path
28
+
29
+ # Save any modifications to Hyper-V
30
+ def update
31
+ requires :vm_id, :id
32
+
33
+ changes = {
34
+ debugger_mode: changed!(:debugger_mode)
35
+ }.compact
36
+ # Ensure path: nil is sent
37
+ changes[:path] = path if changed? :path
38
+ return self unless changes.any?
39
+
40
+ merge_attributes(
41
+ service.set_vm_com_port(
42
+ computer_name:,
43
+ vm_id:,
44
+ id:,
45
+
46
+ **changes,
47
+
48
+ _always_include: changes.keys,
49
+ _return_fields: self.class.attributes
50
+ )
51
+ )
52
+ end
53
+
54
+ # Reload attributes from Hyper-V
55
+ def reload
56
+ requires :vm_id, :id
57
+
58
+ data = service.get_vm_com_port(
59
+ computer_name:,
60
+ vm_id:,
61
+ id:,
62
+
63
+ _return_fields: self.class.attributes
64
+ )
65
+ return unless data
66
+
67
+ merge_attributes(data)
68
+ end
69
+
70
+ private
71
+
72
+ def merge_attributes(new_attributes = {})
73
+ new_attributes[:path] = nil if new_attributes[:path] == ''
74
+
75
+ super
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ # A collection of COM ports attached to a VM
5
+ #
6
+ # @note Requires a vm_id to be specified, as COM ports are not retrievable as loose objects
7
+ class ComPorts < Fog::Hyperv::Collection
8
+ model Fog::Hyperv::Compute::ComPort
9
+
10
+ get_method :get_vm_com_port
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 a COM port by ID
22
+ # @param id [String] the combined GUID of the COM port to retrieve
23
+ def get(id, **filters)
24
+ raise ArgumentError, 'Must provide a combined GUID' if id.nil? || id.empty?
25
+
26
+ super(_by_id: id, **filters)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ # A virtual DVD drive attached to a VM
5
+ #
6
+ # @see https://learn.microsoft.com/en-us/powershell/module/hyper-v/set-vmdvddrive for set-request
7
+ class DvdDrive < Fog::Hyperv::Model
8
+ # @!attribute [r] id
9
+ # @return [String] the GUID of this DVD drive
10
+ identity :id
11
+
12
+ # @!attribute [r] computer_name
13
+ # @return [String] the name of the computer running the VM that this DVD drive is attached to
14
+ attribute :computer_name
15
+ # @!attribute [r] vm_id
16
+ # @return [String] the GUID of the VM this DVD drive is attached to
17
+ attribute :vm_id
18
+
19
+ # @!attribute [r] name
20
+ # @return [String] the name of this DVD drive
21
+ attribute :name
22
+ # @!attribute path
23
+ # @return [String] the path of the underlying image inserted into this DVD drive
24
+ attribute :path
25
+ # @!attribute pool_name
26
+ # @return [String] the pool storing this DVD drive's image
27
+ attribute :pool_name
28
+ # @!attribute controller_location
29
+ # @return [String] the controller location this DVD drive is attached to
30
+ attribute :controller_location
31
+ # @!attribute controller_number
32
+ # @return [Integer] the controller number this DVD drive is attached to
33
+ attribute :controller_number, type: :integer
34
+ # @!attribute [r] controller_type
35
+ # @return [:IDE, :SCSI] the controller type this DVD drive is attached to
36
+ attribute :controller_type, type: :hypervenum, values: %i[IDE SCSI]
37
+ # @!attribute [r] dvd_media_type
38
+ # @return [:None, :ISO, :Passthrough] the current type of media in the DVD drive
39
+ attribute :dvd_media_type, type: :hypervenum, values: %i[None ISO Passthrough]
40
+ # TODO? VM Snapshots?
41
+ #
42
+
43
+ # Should non-verifiable paths be allowed to be set
44
+ attr_accessor :allow_unverified_paths
45
+
46
+ # Create a new instance of a DVD drive
47
+ #
48
+ # @note Requires vm_id, as well as either controller settings or a path
49
+ # @see https://learn.microsoft.com/en-us/powershell/module/hyper-v/add-vmdvddrive for the add-request
50
+ def create
51
+ requires :vm_id
52
+ requires_one :controller_location, :controller_number, :controller_type, :path
53
+
54
+ merge_attributes(
55
+ service.add_vm_dvd_drive(
56
+ computer_name:,
57
+ vm_id:,
58
+
59
+ allow_unverified_paths:,
60
+ controller_number:,
61
+ controller_location:,
62
+ path:,
63
+ resource_pool_name: pool_name,
64
+
65
+ _return_fields: self.class.attributes
66
+ )
67
+ )
68
+ end
69
+
70
+ # Save any modifications to Hyper-V
71
+ def update
72
+ requires :id, :vm_id
73
+
74
+ changes = {
75
+ resource_pool_name: changed!(:pool_name),
76
+ to_controller_number: changed!(:controller_number),
77
+ to_controller_location: changed!(:controller_location)
78
+ }.compact
79
+ # Ensure path: nil is sent
80
+ changes[:path] = path if changed? :path
81
+ return self unless changes.any?
82
+
83
+ merge_attributes(
84
+ service.set_vm_dvd_drive(
85
+ computer_name: old.computer_name,
86
+ vm_id: old.vm_id,
87
+ id: old.id,
88
+
89
+ allow_unverified_paths:,
90
+ **changes,
91
+
92
+ _always_include: changes.keys,
93
+ _return_fields: self.class.attributes
94
+ )
95
+ )
96
+ end
97
+
98
+ # Remove the DVD drive from Hyper-V
99
+ def destroy
100
+ requires :id, :vm_id
101
+
102
+ service.remove_vm_dvd_drive(
103
+ computer_name:,
104
+ vm_id:,
105
+ id:
106
+ )
107
+ true
108
+ end
109
+
110
+ # Reload attributes from Hyper-V
111
+ def reload
112
+ requires :id, :vm_id
113
+
114
+ data = service.get_vm_dvd_drive(
115
+ computer_name:,
116
+ vm_id:,
117
+ id:,
118
+
119
+ _return_fields: self.class.attributes
120
+ )
121
+ return unless data
122
+
123
+ merge_attributes(data)
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ # A collection of DVD drives attached to a VM
5
+ #
6
+ # @note Requires a vm_id to be specified, as DVD drives are not retrievable as loose objects
7
+ class DvdDrives < Fog::Hyperv::Collection
8
+ model Fog::Hyperv::Compute::DvdDrive
9
+
10
+ get_method :get_vm_dvd_drive
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 a DVD drive by ID
22
+ # @param id [String] the GUID of the DVD drive to retrieve
23
+ def get(id, **filters)
24
+ raise ArgumentError, 'Must provide a GUID' if id.nil? || id.empty?
25
+
26
+ super(_by_id: id, **filters)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ # UEFI firmware settings for a VM
5
+ #
6
+ # @see https://learn.microsoft.com/en-us/powershell/module/hyper-v/set-vmfirmware for set-request
7
+ class Firmware < Fog::Hyperv::Model
8
+ # @!attribute [r] vm_id
9
+ # @return [String] the GUID of the VM this UEFI configuration is attached to
10
+ identity :vm_id
11
+ # @!attribute [r] computer_name
12
+ # @return [String] the name of the computer running the VM that this UEFI configuration is attached to
13
+ attribute :computer_name
14
+
15
+ # @!attribute [r] boot_order
16
+ # @todo should be mapped to VM models; HDD/NIC/DVD, needs additional work
17
+ # @return [Array<String>] the boot order of the VM
18
+ attribute :boot_order
19
+ # @!attribute console_mode
20
+ # @return [:Default, :COM1, :COM2, :None] where the console output should be directed
21
+ attribute :console_mode, type: :hypervenum, values: %i[Default COM1 COM2 None]
22
+ # @!attribute preferred_network_boot_protocol
23
+ # @return [:IPv4, :IPv6] the preferred IP protocol for PXE
24
+ attribute :preferred_network_boot_protocol, type: :hypervenum, values: %i[IPv4 IPv6]
25
+ # @!attribute secure_boot
26
+ # @return [:On, :Off] if secure boot should be enabled
27
+ attribute :secure_boot, type: :hypervenum, values: Fog::Hyperv::ON_OFF_STATE_ENUM_VALUES
28
+ # @!attribute secure_boot_template
29
+ # @return [String] the template to use for the secure boot configuration
30
+ # @see Host#secure_boot_templates
31
+ attribute :secure_boot_template
32
+ # @!attribute [r] secure_boot_template_id
33
+ # @return [String] the template id to use for the secure boot configuration
34
+ # @see Host#secure_boot_templates
35
+ attribute :secure_boot_template_id
36
+ # @!attribute pause_after_boot_failure
37
+ # @return [:On, :Off] if the VM should pause after failing boot
38
+ attribute :pause_after_boot_failure, type: :hypervenum, values: Fog::Hyperv::ON_OFF_STATE_ENUM_VALUES
39
+
40
+ # Save any modifications to Hyper-V
41
+ def update
42
+ requires :vm_id
43
+
44
+ changes = {
45
+ enable_secure_boot: changed!(:secure_boot),
46
+ secure_boot_template: changed!(:secure_boot_template),
47
+ preferred_network_boot_protocol: changed!(:preferred_network_boot_protocol),
48
+ console_mode: changed!(:console_mode),
49
+ pause_after_boot_failure: changed!(:pause_after_boot_failure)
50
+ }.compact
51
+ return self unless changes.any?
52
+
53
+ merge_attributes(
54
+ service.set_vm_firmware(
55
+ computer_name:,
56
+ vm_id:,
57
+
58
+ _return_fields: self.class.attributes
59
+ )
60
+ )
61
+ end
62
+
63
+ # Reload attributes from Hyper-V
64
+ def reload
65
+ requires :vm_id
66
+
67
+ data = service.get_vm_firmware(
68
+ computer_name:,
69
+ vm_id:,
70
+
71
+ _return_fields: self.class.attributes
72
+ )
73
+ return unless data
74
+
75
+ merge_attributes(data)
76
+ end
77
+ end
78
+ end