fog-hyperv 0.0.8 → 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.
- checksums.yaml +4 -4
- data/README.md +12 -2
- data/lib/fog/bin/hyperv.rb +6 -4
- data/lib/fog/hyperv/collection.rb +89 -0
- data/lib/fog/hyperv/compute/models/bios.rb +70 -0
- data/lib/fog/hyperv/compute/models/cluster.rb +60 -0
- data/lib/fog/hyperv/compute/models/clusters.rb +21 -0
- data/lib/fog/hyperv/compute/models/com_port.rb +78 -0
- data/lib/fog/hyperv/compute/models/com_ports.rb +29 -0
- data/lib/fog/hyperv/compute/models/dvd_drive.rb +126 -0
- data/lib/fog/hyperv/compute/models/dvd_drives.rb +29 -0
- data/lib/fog/hyperv/compute/models/firmware.rb +78 -0
- data/lib/fog/hyperv/compute/models/floppy_drive.rb +64 -0
- data/lib/fog/hyperv/compute/models/floppy_drives.rb +18 -0
- data/lib/fog/hyperv/compute/models/hard_drive.rb +187 -0
- data/lib/fog/hyperv/compute/models/hard_drives.rb +28 -0
- data/lib/fog/hyperv/compute/models/host.rb +66 -0
- data/lib/fog/hyperv/compute/models/hosts.rb +13 -0
- data/lib/fog/hyperv/compute/models/network_adapter.rb +362 -0
- data/lib/fog/hyperv/compute/models/network_adapter_vlan.rb +172 -0
- data/lib/fog/hyperv/compute/models/network_adapters.rb +32 -0
- data/lib/fog/hyperv/compute/models/security.rb +121 -0
- data/lib/fog/hyperv/compute/models/server.rb +466 -0
- data/lib/fog/hyperv/compute/models/servers.rb +18 -0
- data/lib/fog/hyperv/compute/models/switch.rb +117 -0
- data/lib/fog/hyperv/compute/models/switches.rb +20 -0
- data/lib/fog/hyperv/compute/models/vhd.rb +210 -0
- data/lib/fog/hyperv/compute/models/vhds.rb +28 -0
- data/lib/fog/hyperv/compute/requests/add_vm_dvd_drive.rb +15 -0
- data/lib/fog/hyperv/compute/requests/add_vm_hard_disk_drive.rb +15 -0
- data/lib/fog/hyperv/compute/requests/add_vm_network_adapter.rb +24 -0
- data/lib/fog/hyperv/compute/requests/connect_vm_network_adapter.rb +41 -0
- data/lib/fog/hyperv/compute/requests/disable_vm_tpm.rb +16 -0
- data/lib/fog/hyperv/compute/requests/disconnect_vm_network_adapter.rb +29 -0
- data/lib/fog/hyperv/compute/requests/enable_vm_tpm.rb +16 -0
- data/lib/fog/hyperv/compute/requests/get_cluster.rb +11 -0
- data/lib/fog/hyperv/compute/requests/get_cluster_node.rb +22 -0
- data/lib/fog/hyperv/compute/requests/get_vhd.rb +32 -0
- data/lib/fog/hyperv/compute/requests/get_vm.rb +18 -0
- data/lib/fog/hyperv/compute/requests/get_vm_bios.rb +21 -0
- data/lib/fog/hyperv/compute/requests/get_vm_com_port.rb +17 -0
- data/lib/fog/hyperv/compute/requests/get_vm_dvd_drive.rb +25 -0
- data/lib/fog/hyperv/compute/requests/get_vm_firmware.rb +21 -0
- data/lib/fog/hyperv/compute/requests/get_vm_floppy_disk_drive.rb +16 -0
- data/lib/fog/hyperv/compute/requests/get_vm_group.rb +20 -0
- data/lib/fog/hyperv/compute/requests/get_vm_hard_disk_drive.rb +24 -0
- data/lib/fog/hyperv/compute/requests/get_vm_host.rb +9 -0
- data/lib/fog/hyperv/compute/requests/get_vm_host_cluster.rb +21 -0
- data/lib/fog/hyperv/compute/requests/get_vm_host_sbt.rb +10 -0
- data/lib/fog/hyperv/compute/requests/get_vm_key_protector.rb +16 -0
- data/lib/fog/hyperv/compute/requests/get_vm_network_adapter.rb +41 -0
- data/lib/fog/hyperv/compute/requests/get_vm_network_adapter_vlan.rb +41 -0
- data/lib/fog/hyperv/compute/requests/get_vm_security.rb +15 -0
- data/lib/fog/hyperv/compute/requests/get_vm_switch.rb +10 -0
- data/lib/fog/hyperv/compute/requests/mock_files/get_vm.json +4 -0
- data/lib/fog/hyperv/compute/requests/new_vhd.rb +9 -0
- data/lib/fog/hyperv/compute/requests/new_vm.rb +12 -0
- data/lib/fog/hyperv/compute/requests/new_vm_switch.rb +11 -0
- data/lib/fog/hyperv/compute/requests/optimize_vhd.rb +9 -0
- data/lib/fog/hyperv/compute/requests/remove_item.rb +10 -0
- data/lib/fog/hyperv/compute/requests/remove_vm.rb +16 -0
- data/lib/fog/hyperv/compute/requests/remove_vm_dvd_drive.rb +17 -0
- data/lib/fog/hyperv/compute/requests/remove_vm_hard_disk_drive.rb +17 -0
- data/lib/fog/hyperv/compute/requests/remove_vm_network_adapter.rb +29 -0
- data/lib/fog/hyperv/compute/requests/remove_vm_switch.rb +9 -0
- data/lib/fog/hyperv/compute/requests/rename_vm.rb +16 -0
- data/lib/fog/hyperv/compute/requests/rename_vm_network_adapter.rb +25 -0
- data/lib/fog/hyperv/compute/requests/rename_vm_switch.rb +9 -0
- data/lib/fog/hyperv/compute/requests/resize_vhd.rb +9 -0
- data/lib/fog/hyperv/compute/requests/restart_vm.rb +22 -0
- data/lib/fog/hyperv/compute/requests/resume_vm.rb +22 -0
- data/lib/fog/hyperv/compute/requests/save_vm.rb +22 -0
- data/lib/fog/hyperv/compute/requests/set_vm.rb +15 -0
- data/lib/fog/hyperv/compute/requests/set_vm_bios.rb +15 -0
- data/lib/fog/hyperv/compute/requests/set_vm_com_port.rb +16 -0
- data/lib/fog/hyperv/compute/requests/set_vm_dvd_drive.rb +16 -0
- data/lib/fog/hyperv/compute/requests/set_vm_firmware.rb +15 -0
- data/lib/fog/hyperv/compute/requests/set_vm_floppy_disk_drive.rb +16 -0
- data/lib/fog/hyperv/compute/requests/set_vm_hard_disk_drive.rb +16 -0
- data/lib/fog/hyperv/compute/requests/set_vm_key_protector.rb +15 -0
- data/lib/fog/hyperv/compute/requests/set_vm_network_adapter.rb +25 -0
- data/lib/fog/hyperv/compute/requests/set_vm_network_adapter_vlan.rb +25 -0
- data/lib/fog/hyperv/compute/requests/set_vm_security.rb +17 -0
- data/lib/fog/hyperv/compute/requests/set_vm_switch.rb +9 -0
- data/lib/fog/hyperv/compute/requests/start_vm.rb +22 -0
- data/lib/fog/hyperv/compute/requests/stop_vm.rb +22 -0
- data/lib/fog/hyperv/compute/requests/suspend_vm.rb +22 -0
- data/lib/fog/hyperv/compute/requests/update_vm.rb +22 -0
- data/lib/fog/hyperv/compute.rb +206 -387
- data/lib/fog/hyperv/constants.rb +24 -0
- data/lib/fog/hyperv/fog_extensions/associations/collection.rb +11 -0
- data/lib/fog/hyperv/fog_extensions/attributes/datetime.rb +28 -0
- data/lib/fog/hyperv/fog_extensions/attributes/enum.rb +139 -0
- data/lib/fog/hyperv/fog_extensions/attributes/enumarray.rb +149 -0
- data/lib/fog/hyperv/fog_extensions/attributes/timespan.rb +27 -0
- data/lib/fog/hyperv/model.rb +142 -0
- data/lib/fog/hyperv/utils/powershell.rb +88 -0
- data/lib/fog/hyperv/utils/winrm.rb +233 -0
- data/lib/fog/hyperv/version.rb +4 -1
- data/lib/fog/hyperv.rb +51 -44
- metadata +198 -110
- data/.gitignore +0 -10
- data/.travis.yml +0 -11
- data/CHANGELOG.md +0 -48
- data/Gemfile +0 -4
- data/Rakefile +0 -10
- data/fog-hyperv.gemspec +0 -29
- data/lib/fog/collection.rb +0 -152
- data/lib/fog/hyperv/fog_extensions/enum.rb +0 -85
- data/lib/fog/hyperv/models/compute/bios.rb +0 -61
- data/lib/fog/hyperv/models/compute/cluster.rb +0 -64
- data/lib/fog/hyperv/models/compute/clusters.rb +0 -15
- data/lib/fog/hyperv/models/compute/com_port.rb +0 -22
- data/lib/fog/hyperv/models/compute/dvd_drive.rb +0 -92
- data/lib/fog/hyperv/models/compute/dvd_drives.rb +0 -12
- data/lib/fog/hyperv/models/compute/firmware.rb +0 -53
- data/lib/fog/hyperv/models/compute/floppy_drive.rb +0 -53
- data/lib/fog/hyperv/models/compute/floppy_drives.rb +0 -12
- data/lib/fog/hyperv/models/compute/hard_drive.rb +0 -110
- data/lib/fog/hyperv/models/compute/hard_drives.rb +0 -11
- data/lib/fog/hyperv/models/compute/host.rb +0 -45
- data/lib/fog/hyperv/models/compute/hosts.rb +0 -15
- data/lib/fog/hyperv/models/compute/network_adapter.rb +0 -145
- data/lib/fog/hyperv/models/compute/network_adapters.rb +0 -19
- data/lib/fog/hyperv/models/compute/server.rb +0 -220
- data/lib/fog/hyperv/models/compute/servers.rb +0 -21
- data/lib/fog/hyperv/models/compute/switch.rb +0 -65
- data/lib/fog/hyperv/models/compute/switches.rb +0 -15
- data/lib/fog/hyperv/models/compute/vhd.rb +0 -101
- data/lib/fog/hyperv/models/compute/vhds.rb +0 -16
- data/lib/fog/hyperv/requests/compute/add_vm_dvd_drive.rb +0 -12
- data/lib/fog/hyperv/requests/compute/add_vm_hard_disk_drive.rb +0 -12
- data/lib/fog/hyperv/requests/compute/add_vm_network_adapter.rb +0 -12
- data/lib/fog/hyperv/requests/compute/connect_vm_network_adapter.rb +0 -12
- data/lib/fog/hyperv/requests/compute/disconnect_vm_network_adapter.rb +0 -12
- data/lib/fog/hyperv/requests/compute/get_cluster.rb +0 -11
- data/lib/fog/hyperv/requests/compute/get_cluster_node.rb +0 -19
- data/lib/fog/hyperv/requests/compute/get_vhd.rb +0 -34
- data/lib/fog/hyperv/requests/compute/get_vm.rb +0 -20
- data/lib/fog/hyperv/requests/compute/get_vm_bios.rb +0 -21
- data/lib/fog/hyperv/requests/compute/get_vm_dvd_drive.rb +0 -20
- data/lib/fog/hyperv/requests/compute/get_vm_firmware.rb +0 -19
- data/lib/fog/hyperv/requests/compute/get_vm_floppy_disk_drive.rb +0 -20
- data/lib/fog/hyperv/requests/compute/get_vm_group.rb +0 -23
- data/lib/fog/hyperv/requests/compute/get_vm_hard_disk_drive.rb +0 -20
- data/lib/fog/hyperv/requests/compute/get_vm_host.rb +0 -12
- data/lib/fog/hyperv/requests/compute/get_vm_host_cluster.rb +0 -25
- data/lib/fog/hyperv/requests/compute/get_vm_network_adapter.rb +0 -27
- data/lib/fog/hyperv/requests/compute/get_vm_switch.rb +0 -27
- data/lib/fog/hyperv/requests/compute/mock_files/get_vm.json +0 -1
- data/lib/fog/hyperv/requests/compute/new_vhd.rb +0 -12
- data/lib/fog/hyperv/requests/compute/new_vm.rb +0 -15
- data/lib/fog/hyperv/requests/compute/new_vm_switch.rb +0 -13
- data/lib/fog/hyperv/requests/compute/remove_item.rb +0 -13
- data/lib/fog/hyperv/requests/compute/remove_vm.rb +0 -15
- data/lib/fog/hyperv/requests/compute/remove_vm_dvd_drive.rb +0 -12
- data/lib/fog/hyperv/requests/compute/remove_vm_hard_disk_drive.rb +0 -12
- data/lib/fog/hyperv/requests/compute/remove_vm_network_adapter.rb +0 -12
- data/lib/fog/hyperv/requests/compute/restart_vm.rb +0 -15
- data/lib/fog/hyperv/requests/compute/set_vm.rb +0 -12
- data/lib/fog/hyperv/requests/compute/set_vm_bios.rb +0 -13
- data/lib/fog/hyperv/requests/compute/set_vm_dvd_drive.rb +0 -12
- data/lib/fog/hyperv/requests/compute/set_vm_firmware.rb +0 -13
- data/lib/fog/hyperv/requests/compute/set_vm_hard_disk_drive.rb +0 -12
- data/lib/fog/hyperv/requests/compute/set_vm_network_adapter.rb +0 -12
- data/lib/fog/hyperv/requests/compute/set_vm_network_adapter_vlan.rb +0 -12
- data/lib/fog/hyperv/requests/compute/set_vm_switch.rb +0 -13
- data/lib/fog/hyperv/requests/compute/start_vm.rb +0 -15
- data/lib/fog/hyperv/requests/compute/stop_vm.rb +0 -15
- data/lib/fog/model.rb +0 -91
- data/test/fog/hyperv_test.rb +0 -7
- data/test/test_helper.rb +0 -4
- /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_cluster.json +0 -0
- /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_cluster_node.json +0 -0
- /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_vhd.json +0 -0
- /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_vm_bios.json +0 -0
- /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_vm_dvd_drive.json +0 -0
- /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_vm_firmware.json +0 -0
- /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_vm_floppy_disk_drive.json +0 -0
- /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_vm_hard_disk_drive.json +0 -0
- /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_vm_host.json +0 -0
- /data/lib/fog/hyperv/{requests/compute → compute/requests}/mock_files/get_vm_network_adapter.json +0 -0
- /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:,
|
|
125
|
+
|
|
126
|
+
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:,
|
|
158
|
+
path:,
|
|
159
|
+
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:,
|
|
174
|
+
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:,
|
|
188
|
+
path:,
|
|
189
|
+
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:, **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:, **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,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:, **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:, **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:, **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:, **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,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:, **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
|