fog-hyperv 0.0.9 → 0.1.1

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 +50 -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 +183 -0
  16. data/lib/fog/hyperv/compute/models/hard_drives.rb +28 -0
  17. data/lib/fog/hyperv/compute/models/host.rb +63 -0
  18. data/lib/fog/hyperv/compute/models/hosts.rb +13 -0
  19. data/lib/fog/hyperv/compute/models/network_adapter.rb +368 -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 +16 -0
  69. data/lib/fog/hyperv/compute/requests/resize_vhd.rb +16 -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 +53 -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
@@ -0,0 +1,210 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ # A VM hard drive - VHD - file
5
+ class Vhd < Fog::Hyperv::Model
6
+ # rubocop:disable Layout/HashAlignment
7
+
8
+ # VHD types
9
+ # @note Defined by Microsoft.Vhd.PowerShell.VhdType
10
+ VHD_TYPE_ENUM_VALUES = {
11
+ Unknown: 0,
12
+ Fixed: 2,
13
+ Dynamic: 3,
14
+ Differencing: 4
15
+ }.freeze
16
+
17
+ # VHD formats
18
+ # @note Defined by Microsoft.Vhd.PowerShell.VhdFormat
19
+ VHD_FORMAT_ENUM_VALUES = {
20
+ Unknown: 0,
21
+ VHD: 2,
22
+ VHDX: 3,
23
+ VHDSet: 4
24
+ }.freeze
25
+ # rubocop:enable Layout/HashAlignment
26
+
27
+ # @!attribute [r] disk_identifier
28
+ # @return [String] the guid of this VHD
29
+ identity :disk_identifier
30
+
31
+ # @!attribute [r] computer_name
32
+ # @return [String] the name of the computer hosting this VHD
33
+ attribute :computer_name
34
+
35
+ # @!attribute [r] attached
36
+ # @return [Boolean] is the VHD attached to something
37
+ attribute :attached, type: :boolean
38
+ # @!attribute [r] block_size
39
+ # @return [Integer] the block size of the VHD in bytes
40
+ attribute :block_size, type: :integer
41
+ # @!attribute [r] disk_number
42
+ # @return [Integer,nil] the disk number
43
+ attribute :disk_number
44
+ # @!attribute [r] file_size
45
+ # @return [Integer,nil] the size of the VHD file in bytes
46
+ attribute :file_size
47
+ # @!attribute [r] logical_sector_size
48
+ # @return [512, 4096] the logical sector size for the VHD in bytes
49
+ attribute :logical_sector_size, type: :integer
50
+ # @!attribute [r] minimum_size
51
+ # @return [Integer,nil] the minimum possible size of the VHD in bytes, for shrinking purposes
52
+ attribute :minimum_size
53
+ # @!attribute [r] parent_path
54
+ # @return [String,nil] the path to the parent VHD
55
+ attribute :parent_path
56
+ # @!attribute [r] path
57
+ # @return [String,nil] the path to the VHD on disk
58
+ attribute :path
59
+ # @!attribute [r] pool_name
60
+ # @return [String] the name of the pool storing this VHD
61
+ attribute :pool_name
62
+ # @!attribute physical_sector_size_bytes
63
+ # @return [512, 4096] the physical sector size for the VHD in bytes
64
+ attribute :physical_sector_size, type: :integer
65
+ # @!attribute size
66
+ # @return [Integer,nil] the size of the VHD in bytes
67
+ # @note Defaults to 32GB if not specified
68
+ attribute :size, default: 32 * 1024 * 1024 * 1024
69
+ # @!attribute [r] vhd_format
70
+ # @return [:Unknown, :VHD, :VHDX, :VHDSet] the format of the VHD
71
+ # @see VHD_FORMAT_ENUM_VALUES
72
+ attribute :vhd_format, type: :hypervenum, default: :VHDX, values: VHD_FORMAT_ENUM_VALUES
73
+ # @!attribute [r] vhd_type
74
+ # @return [:Unknown, :Fixed, :Dynamic, :Differencing] the type of the VHD
75
+ # @see VHD_TYPE_ENUM_VALUES
76
+ attribute :vhd_type, type: :hypervenum, default: :Dynamic, values: VHD_TYPE_ENUM_VALUES
77
+
78
+ # @!attribute [r] basename
79
+ # @return [String] the basename of the VHD file, without extension
80
+ attribute :basename
81
+
82
+ # @!attribute [r] unc_path
83
+ # @return [String] the UNC path to the VHD file in a cluster
84
+ def unc_path
85
+ requires :path
86
+
87
+ "\\\\#{computer_name || 'localhost'}\\#{path.tr ':', '$'}"
88
+ end
89
+
90
+ # Save the VHD to Hyper-V
91
+ def create
92
+ if basename
93
+ requires :vm
94
+
95
+ attributes[:path] ||= vm.build_vhd_path("#{basename}.#{vhd_ext}")
96
+ end
97
+
98
+ requires_one :path, :disk_number
99
+
100
+ attrs = {
101
+ source_disk: disk_number,
102
+ logical_sector_size_bytes: logical_sector_size,
103
+ physical_sector_size_bytes: physical_sector_size
104
+ }.compact
105
+ case vhd_type
106
+ when :Dynamic
107
+ attrs[:dynamic] = true
108
+ requires :size unless disk_number
109
+ when :Differencing
110
+ requires :parent_path
111
+ attrs[:differencing] = true
112
+ attrs[:parent_path] = parent_path
113
+ attrs.delete :source_disk
114
+ attrs.delete :logical_sector_size_bytes
115
+ when :Fixed
116
+ attrs[:fixed] = true
117
+ requires :size unless disk_number
118
+ else
119
+ raise "Invalid VHD type #{vhd_type.inspect}, must be :Dynamic, :Fixed, or :Differencing"
120
+ end
121
+
122
+ merge_attributes(
123
+ service.new_vhd(
124
+ computer_name: computer_name,
125
+
126
+ path: path,
127
+ block_size_bytes: block_size,
128
+ size_bytes: size,
129
+ **attrs,
130
+
131
+ _return_fields: self.class.attributes - %i[basename]
132
+ )
133
+ )
134
+ end
135
+
136
+ def update
137
+ requires :path
138
+
139
+ return self unless changed?(:size)
140
+
141
+ service.resize_vhd(
142
+ computer_name: old.computer_name,
143
+ path: old.path,
144
+
145
+ size_bytes: size
146
+ )
147
+ @old.size = size
148
+
149
+ self
150
+ end
151
+
152
+ # Reload the VHD attributes from Hyper-V
153
+ def reload
154
+ requires_one :path, :disk_number
155
+
156
+ data = service.get_vhd(
157
+ computer_name: computer_name,
158
+ path: path,
159
+ disk_number: disk_number,
160
+
161
+ _return_fields: self.class.attributes - %i[basename]
162
+ )
163
+ return unless data
164
+
165
+ merge_attributes(data)
166
+ end
167
+
168
+ # Remove the VHD from disk
169
+ def destroy
170
+ requires :path
171
+
172
+ service.remove_item(
173
+ computer_name: computer_name,
174
+ path: path
175
+ )
176
+ true
177
+ end
178
+
179
+ # Optimizes the VHD on disk
180
+ #
181
+ # @param mode [:full,:pretrimmed,:prezeroed,:quick,:retrim,nil] the optimization mode to use,
182
+ # will default to :full/:quick depending on VHD type
183
+ def optimize(mode: nil)
184
+ requires :path
185
+
186
+ service.optimize_vhd(
187
+ computer_name: computer_name,
188
+ path: path,
189
+ mode: mode
190
+ )
191
+ true
192
+ end
193
+
194
+ private
195
+
196
+ def merge_attributes(new_attributes = {})
197
+ new_attributes[:parent_path] = nil if new_attributes[:parent_path] == ''
198
+ new_attributes[:basename] = File.basename(new_attributes[:path].split('\\').last, '.*') if new_attributes[:path]
199
+
200
+ super
201
+ end
202
+
203
+ def vhd_ext
204
+ ext = vhd_format&.downcase || 'vhdx'
205
+ ext = 'vhds' if ext.downcase == 'vhdset'
206
+ ext = 'vhdx' if ext.downcase == 'unknown'
207
+ ext
208
+ end
209
+ end
210
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Vhds < Fog::Hyperv::Collection
5
+ model Fog::Hyperv::Compute::Vhd
6
+
7
+ get_method :get_vhd
8
+
9
+ attribute :computer_name
10
+
11
+ def get(identifier, **filters)
12
+ id = identifier if identifier =~ /\A#{Fog::Hyperv::GUID}\z/i
13
+ path = identifier unless id
14
+
15
+ raise ArgumentError, 'Must provide a path or GUID' if (id.nil? || id.empty?) && (path.nil? || path.empty?)
16
+
17
+ super(disk_identifier: id, path: path, **filters)
18
+ end
19
+
20
+ protected
21
+
22
+ def search_attributes
23
+ super.merge(
24
+ _return_fields: model.attributes - %i[basename]
25
+ )
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def add_vm_dvd_drive(vm_id:, computer_name: nil, **options)
6
+ run_cmdlist(
7
+ [
8
+ ['$VM = Get-VM', { id: vm_id }],
9
+ ['$VM | Add-VMDvdDrive', { passthru: true, **options }]
10
+ ],
11
+ target_computer: computer_name
12
+ )
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def add_vm_hard_disk_drive(vm_id:, computer_name: nil, **options)
6
+ run_cmdlist(
7
+ [
8
+ ['$VM = Get-VM', { id: vm_id }],
9
+ ['$VM | Add-VMHardDiskDrive', { passthru: true, **options }]
10
+ ],
11
+ target_computer: computer_name
12
+ )
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def add_vm_network_adapter(computer_name: nil, **options)
6
+ requires_one options, :vm_id, :management_os
7
+ options.delete :management_os
8
+
9
+ if options[:vm_id]
10
+ vm_id = options.delete :vm_id
11
+ run_cmdlist(
12
+ [
13
+ ['$VM = Get-VM', { id: vm_id }],
14
+ ['$VM | Add-VMNetworkAdapter', { _always_include: %i[is_legacy], passthru: true, **options }]
15
+ ],
16
+ target_computer: computer_name
17
+ )
18
+ else
19
+ options.delete :vm_id
20
+ run_cmd('Add-VMNetworkAdapter', _target_computer: computer_name, management_os: true, passthru: true, **options)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def connect_vm_network_adapter(id:, computer_name: nil, **options)
6
+ requires_one options, :vm_id, :management_os
7
+ requires_one options, :switch_name, :switch_id
8
+ options.delete :management_os
9
+
10
+ cmdlist = []
11
+ if options[:vm_id]
12
+ vm_id = options.delete :vm_id
13
+ cmdlist += [
14
+ ['$VM = Get-VM', { id: vm_id }],
15
+ ['$NIC = $VM | Get-VMNetworkAdapter', { _by_id: id }]
16
+ ]
17
+ else
18
+ options.delete :vm_id
19
+ cmdlist << ['$NIC = Get-VMNetworkAdapter', { _by_id: id, management_os: true }]
20
+ end
21
+ if options[:switch_id]
22
+ switch_id = options.delete :switch_id
23
+ options.delete :switch_name
24
+ cmdlist += [
25
+ ['$Switch = Get-VMSwitch', { id: switch_id }],
26
+ ['$NIC | Connect-VMNetworkAdapter -VMSwitch @Switch', options]
27
+ ]
28
+ else
29
+ switch_name = options.delete :switch_name
30
+ options.delete :switch_id
31
+ cmdlist << ['$NIC | Connect-VMNetworkAdapter', { switch_name: switch_name, **options }]
32
+ end
33
+
34
+ run_cmdlist(cmdlist, skip_json: true, target_computer: computer_name)
35
+ end
36
+ end
37
+
38
+ class Mock
39
+ def connect_vm_network_adapter(*args); end
40
+ end
41
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def disable_vm_tpm(vm_id:, computer_name: nil, **options)
6
+ run_cmdlist(
7
+ [
8
+ ['$VM = Get-VM', { id: vm_id }],
9
+ ['$VM | Disable-VMTPM', options]
10
+ ],
11
+ skip_json: true,
12
+ target_computer: computer_name
13
+ )
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def disconnect_vm_network_adapter(id:, computer_name: nil, **options)
6
+ requires_one options, :vm_id, :management_os
7
+ options.delete :management_os
8
+
9
+ cmdlist = []
10
+ if options[:vm_id]
11
+ vm_id = options.delete :vm_id
12
+ cmdlist += [
13
+ ['$VM = Get-VM', { id: vm_id }],
14
+ ['$NIC = $VM | Get-VMNetworkAdapter', { _by_id: id }]
15
+ ]
16
+ else
17
+ options.delete :vm_id
18
+ cmdlist << ['$NIC = Get-VMNetworkAdapter', { _by_id: id, management_os: true }]
19
+ end
20
+ cmdlist << ['$NIC | Disconnect-VMNetworkAdapter', options]
21
+
22
+ run_cmdlist(commands, skip_json: true, target_computer: computer_name)
23
+ end
24
+ end
25
+
26
+ class Mock
27
+ def disconnect_vm_network_adapter(*args); end
28
+ end
29
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def enable_vm_tpm(vm_id:, computer_name: nil, **options)
6
+ run_cmdlist(
7
+ [
8
+ ['$VM = Get-VM', { id: vm_id }],
9
+ ['$VM | Enable-VMTPM', options]
10
+ ],
11
+ skip_json: true,
12
+ target_computer: computer_name
13
+ )
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def get_cluster(**options)
6
+ by_id = options.delete(:id)
7
+
8
+ run_cmd 'Get-Cluster', _by_id: by_id, **options
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def get_cluster_node(id:, **options)
6
+ run_cmdlist(
7
+ [
8
+ ['$Cluster = Get-Cluster', { _by_id: id }],
9
+ ['$Cluster | Get-ClusterNode', options]
10
+ ]
11
+ )
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def get_cluster_node(**args)
17
+ data = handle_mock_response args
18
+ data = data.find { |n| n[:name] == args[:name] } if args[:name]
19
+ data
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def get_vhd(computer_name: nil, **options)
6
+ requires_one options, :path, :disk_number unless options[:vm_id]
7
+ run_cmd 'Get-VHD', _target_computer: computer_name, **options
8
+ end
9
+ end
10
+
11
+ class Mock
12
+ def get_vhd(**args)
13
+ requires_one args, :vm_id, :path, :disk_number
14
+ data = handle_mock_response args
15
+
16
+ if args[:vm_id]
17
+ data = case args[:vm_id].downcase
18
+ when '20ff7fe3-fd54-425c-aa97-fbf3c2e7a868'
19
+ data[1..]
20
+ when '416e49fd-28dd-413c-9743-aa3e69e4807d'
21
+ data[0]
22
+ end
23
+ elsif args[:path]
24
+ data = data.find { |d| d[:path].casecmp(args[:path]).zero? }
25
+ elsif args[:disk_number]
26
+ Fog::Mock.not_implemented
27
+ end
28
+
29
+ data
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def get_vm(**options)
6
+ run_cmd('Get-VM', **options)
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def get_vm(**args)
12
+ data = handle_mock_response(**args)
13
+ data = data.find { |v| v[:name].casecmp(args[:name]).zero? } if args[:name]
14
+ data = data.find { |v| v[:id].casecmp(args[:id]).zero? } if args[:id]
15
+ data
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def get_vm_bios(vm_id:, computer_name: nil, **options)
6
+ run_cmdlist(
7
+ [
8
+ ['$VM = Get-VM', { id: vm_id }],
9
+ ['$VM | Get-VMBios', options]
10
+ ],
11
+ target_computer: computer_name
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def get_vm_bios(**args)
18
+ handle_mock_response(args).find { |b| b[:vm_id].casecmp(args[:vm_id]).zero? }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def get_vm_com_port(vm_id:, computer_name: nil, **options)
6
+ by_id = options.delete :id
7
+
8
+ run_cmdlist(
9
+ [
10
+ ['$VM = Get-VM', { id: vm_id }],
11
+ ['$VM | Get-VMComPort', { _by_id: by_id, **options }]
12
+ ],
13
+ target_computer: computer_name
14
+ )
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def get_vm_dvd_drive(vm_id:, computer_name: nil, **options)
6
+ by_id = options.delete :id
7
+
8
+ run_cmdlist(
9
+ [
10
+ ['$VM = Get-VM', { id: vm_id }],
11
+ ['$VM | Get-VMDvdDrive', { _by_id: by_id, **options }]
12
+ ],
13
+ target_computer: computer_name
14
+ )
15
+ end
16
+ end
17
+
18
+ class Mock
19
+ def get_vm_dvd_drive(**options)
20
+ requires options, :vm_id
21
+
22
+ handle_mock_response(args).find { |b| b[:vm_id].casecmp(args[:vm_id]).zero? }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def get_vm_firmware(vm_id:, computer_name: nil, **options)
6
+ run_cmdlist(
7
+ [
8
+ ['$VM = Get-VM', { id: vm_id }],
9
+ ['$VM | Get-VMFirmware', options]
10
+ ],
11
+ target_computer: computer_name
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def get_vm_firmware(**args)
18
+ handle_mock_response(args).find { |b| b[:vm_name].casecmp(args[:vm_name]).zero? }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def get_vm_floppy_disk_drive(vm_id:, computer_name: nil, **options)
6
+ by_id = options.delete :id
7
+ run_cmdlist(
8
+ [
9
+ ['$VM = Get-VM', { id: vm_id }],
10
+ ['$VM | Get-VMFloppyDiskDrive', { _by_id: by_id, **options }]
11
+ ],
12
+ target_computer: computer_name
13
+ )
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def get_vm_group(computer_name: nil, **options)
6
+ requires_version '10.0'
7
+
8
+ run_cmd('Get-VMGroup', _target_computer: computer_name, **options)
9
+ end
10
+ end
11
+
12
+ class Mock
13
+ def get_vm_group(**_options)
14
+ requires_version '10.0'
15
+
16
+ # TODO
17
+ Fog::Mock.not_implemented
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def get_vm_hard_disk_drive(vm_id:, computer_name: nil, **options)
6
+ by_id = options.delete :id
7
+ run_cmdlist(
8
+ [
9
+ ['$VM = Get-VM', { id: vm_id }],
10
+ ['$VM | Get-VMHardDiskDrive', { _by_id: by_id, **options }]
11
+ ],
12
+ target_computer: computer_name
13
+ )
14
+ end
15
+ end
16
+
17
+ class Mock
18
+ def get_vm_hard_disk_drive(**args)
19
+ requires args, :vm_id
20
+
21
+ handle_mock_response(args).find { |b| b[:vm_id].casecmp(args[:vm_id]).zero? }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def get_vm_host(computer_name: nil, **options)
6
+ run_cmd 'Get-VMHost', _target_computer: computer_name, **options
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ def get_vm_host_cluster(cluster_name:, computer_name: nil, **options)
6
+ requires_version '10.0'
7
+
8
+ run_cmd 'Get-VMHostCluster', _target_computer: computer_name, cluster_name: cluster_name, **options
9
+ end
10
+ end
11
+
12
+ class Mock
13
+ def get_vm_host_cluster(**options)
14
+ requires_version '10.0'
15
+ requires options, :cluster_name
16
+
17
+ # TODO
18
+ Fog::Mock.not_implemented
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Fog::Hyperv::Compute
4
+ class Real
5
+ # Retrieve SecureBoot Templates for a VM Host
6
+ def get_vm_host_sbt(computer_name:, **options)
7
+ run_cmd '(Get-VMHost @Args).SecureBootTemplates', _target_computer: computer_name, **options
8
+ end
9
+ end
10
+ end