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.
- 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 +50 -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 +183 -0
- data/lib/fog/hyperv/compute/models/hard_drives.rb +28 -0
- data/lib/fog/hyperv/compute/models/host.rb +63 -0
- data/lib/fog/hyperv/compute/models/hosts.rb +13 -0
- data/lib/fog/hyperv/compute/models/network_adapter.rb +368 -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 +16 -0
- data/lib/fog/hyperv/compute/requests/resize_vhd.rb +16 -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 +53 -44
- metadata +187 -105
- data/.gitignore +0 -10
- data/.travis.yml +0 -11
- data/CHANGELOG.md +0 -52
- data/Gemfile +0 -4
- data/Rakefile +0 -10
- data/fog-hyperv.gemspec +0 -25
- 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
data/lib/fog/hyperv/compute.rb
CHANGED
|
@@ -1,425 +1,244 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
protected
|
|
104
|
-
|
|
105
|
-
def requires(opts, *args)
|
|
106
|
-
missing = args - opts.keys
|
|
107
|
-
return if missing.none?
|
|
108
|
-
|
|
109
|
-
method = caller[0][/`.*'/][1..-2]
|
|
110
|
-
if missing.length == 1
|
|
111
|
-
raise(ArgumentError, "#{missing.first} is required for #{method}")
|
|
112
|
-
elsif missing.any?
|
|
113
|
-
raise(ArgumentError, "#{missing[0...-1].join(', ')}, and #{missing[-1]} are required for #{method}")
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def requires_one(opts, *args)
|
|
118
|
-
missing = args - opts.keys
|
|
119
|
-
return if missing.length < args.length
|
|
120
|
-
|
|
121
|
-
method = caller[0][/`.*'/][1..-2]
|
|
122
|
-
raise(ArgumentError, "#{missing[0...-1].join(', ')}, or #{missing[-1]} are required for #{method}")
|
|
123
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Fog::Hyperv
|
|
4
|
+
class Compute < Fog::Service
|
|
5
|
+
requires :hyperv_username
|
|
6
|
+
recognizes :hyperv_endpoint, :hyperv_host,
|
|
7
|
+
:hyperv_password,
|
|
8
|
+
:hyperv_transport, :hyperv_realm,
|
|
9
|
+
:hyperv_debug
|
|
10
|
+
|
|
11
|
+
secrets :hyperv_password, :connection
|
|
12
|
+
|
|
13
|
+
model_path 'fog/hyperv/compute/models'
|
|
14
|
+
model :bios
|
|
15
|
+
model :cluster
|
|
16
|
+
collection :clusters
|
|
17
|
+
model :com_port
|
|
18
|
+
collection :com_ports
|
|
19
|
+
model :dvd_drive
|
|
20
|
+
collection :dvd_drives
|
|
21
|
+
model :firmware
|
|
22
|
+
model :floppy_drive
|
|
23
|
+
collection :floppy_drives
|
|
24
|
+
model :hard_drive
|
|
25
|
+
collection :hard_drives
|
|
26
|
+
model :host
|
|
27
|
+
collection :hosts
|
|
28
|
+
model :network_adapter
|
|
29
|
+
model :network_adapter_vlan
|
|
30
|
+
collection :network_adapters
|
|
31
|
+
model :security
|
|
32
|
+
model :server
|
|
33
|
+
collection :servers
|
|
34
|
+
model :switch
|
|
35
|
+
collection :switches
|
|
36
|
+
model :vhd
|
|
37
|
+
collection :vhds
|
|
38
|
+
|
|
39
|
+
request_path 'fog/hyperv/compute/requests'
|
|
40
|
+
request :add_vm_dvd_drive
|
|
41
|
+
request :add_vm_hard_disk_drive
|
|
42
|
+
request :add_vm_network_adapter
|
|
43
|
+
request :connect_vm_network_adapter
|
|
44
|
+
request :disable_vm_tpm
|
|
45
|
+
request :disconnect_vm_network_adapter
|
|
46
|
+
request :enable_vm_tpm
|
|
47
|
+
request :get_cluster
|
|
48
|
+
request :get_cluster_node
|
|
49
|
+
request :get_vhd
|
|
50
|
+
request :get_vm
|
|
51
|
+
request :get_vm_bios
|
|
52
|
+
request :get_vm_com_port
|
|
53
|
+
request :get_vm_dvd_drive
|
|
54
|
+
request :get_vm_firmware
|
|
55
|
+
request :get_vm_floppy_disk_drive
|
|
56
|
+
request :get_vm_group
|
|
57
|
+
request :get_vm_hard_disk_drive
|
|
58
|
+
request :get_vm_host
|
|
59
|
+
request :get_vm_host_cluster
|
|
60
|
+
request :get_vm_host_sbt
|
|
61
|
+
request :get_vm_key_protector
|
|
62
|
+
request :get_vm_network_adapter
|
|
63
|
+
request :get_vm_network_adapter_vlan
|
|
64
|
+
request :get_vm_security
|
|
65
|
+
request :get_vm_switch
|
|
66
|
+
request :new_vhd
|
|
67
|
+
request :new_vm
|
|
68
|
+
request :new_vm_switch
|
|
69
|
+
request :optimize_vhd
|
|
70
|
+
request :remove_item
|
|
71
|
+
request :remove_vm
|
|
72
|
+
request :remove_vm_dvd_drive
|
|
73
|
+
request :remove_vm_hard_disk_drive
|
|
74
|
+
request :remove_vm_network_adapter
|
|
75
|
+
request :remove_vm_switch
|
|
76
|
+
request :rename_vm
|
|
77
|
+
request :rename_vm_network_adapter
|
|
78
|
+
request :rename_vm_switch
|
|
79
|
+
request :resize_vhd
|
|
80
|
+
request :restart_vm
|
|
81
|
+
request :resume_vm
|
|
82
|
+
request :save_vm
|
|
83
|
+
request :set_vm
|
|
84
|
+
request :set_vm_bios
|
|
85
|
+
request :set_vm_com_port
|
|
86
|
+
request :set_vm_dvd_drive
|
|
87
|
+
request :set_vm_firmware
|
|
88
|
+
request :set_vm_floppy_disk_drive
|
|
89
|
+
request :set_vm_hard_disk_drive
|
|
90
|
+
request :set_vm_key_protector
|
|
91
|
+
request :set_vm_network_adapter
|
|
92
|
+
request :set_vm_network_adapter_vlan
|
|
93
|
+
request :set_vm_security
|
|
94
|
+
request :set_vm_switch
|
|
95
|
+
request :start_vm
|
|
96
|
+
request :stop_vm
|
|
97
|
+
request :suspend_vm
|
|
98
|
+
|
|
99
|
+
class Shared
|
|
100
|
+
def version
|
|
101
|
+
'0.0'
|
|
102
|
+
end
|
|
124
103
|
|
|
125
|
-
|
|
126
|
-
method = caller[0][/`.*'/][1..-2].split('_')
|
|
127
|
-
method = method[0].capitalize + "-" + Fog::Hyperv.camelize(method[1..-1].join('_'))
|
|
104
|
+
protected
|
|
128
105
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
106
|
+
def requires(opts, *args)
|
|
107
|
+
missing = args - opts.keys
|
|
108
|
+
return if missing.none?
|
|
132
109
|
|
|
110
|
+
method = caller[0][/`.*'/][1..-2]
|
|
111
|
+
raise(ArgumentError, "#{missing.first} is required for #{method}") if missing.length == 1
|
|
112
|
+
raise(ArgumentError, "#{missing[0...-1].join(', ')}, and #{missing[-1]} are required for #{method}") if missing.any?
|
|
133
113
|
end
|
|
134
114
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
attr_accessor :bake_optmap, :bake_json
|
|
139
|
-
|
|
140
|
-
def initialize(options = {})
|
|
141
|
-
# require 'ostruct'
|
|
142
|
-
require 'fog/json'
|
|
143
|
-
require 'logging'
|
|
144
|
-
|
|
145
|
-
@connections = {}
|
|
146
|
-
@hyperv_endpoint = options[:hyperv_endpoint]
|
|
147
|
-
@hyperv_endpoint = "http://#{options[:hyperv_host]}:5985/wsman" if !@hyperv_endpoint && options[:hyperv_host]
|
|
148
|
-
@hyperv_username = options[:hyperv_username]
|
|
149
|
-
@hyperv_password = options[:hyperv_password]
|
|
150
|
-
@hyperv_realm = options[:hyperv_realm]
|
|
151
|
-
@hyperv_transport = options[:hyperv_transport] || (@hyperv_realm ? :kerberos : :negotiate)
|
|
152
|
-
|
|
153
|
-
Logging.logger['WinRM::HTTP::HttpNegotiate'].level = :error
|
|
154
|
-
@logger = Logging.logger['hyper-v']
|
|
155
|
-
if options[:hyperv_debug]
|
|
156
|
-
logger.level = :debug
|
|
157
|
-
logger.add_appenders Logging.appenders.stdout
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
connect
|
|
161
|
-
end
|
|
115
|
+
def requires_one(opts, *args)
|
|
116
|
+
missing = args - opts.keys
|
|
117
|
+
return if missing.length < args.length
|
|
162
118
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
119
|
+
method = caller[0][/`.*'/][1..-2]
|
|
120
|
+
raise(ArgumentError, "#{missing[0...-1].join(', ')}, or #{missing[-1]} is required for #{method}")
|
|
121
|
+
end
|
|
166
122
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
else
|
|
171
|
-
run_wql('SELECT Name FROM Msvm_ComputerSystem WHERE Caption = "Hosting Computer System"')[:xml_fragment] && true
|
|
172
|
-
end
|
|
173
|
-
rescue => e
|
|
174
|
-
logger.debug "Validation failed with #{e.class}; #{e.message}"
|
|
175
|
-
false
|
|
176
|
-
end
|
|
123
|
+
def requires_version(required_version)
|
|
124
|
+
method = caller[0][/`.*'/][1..-2].split('_')
|
|
125
|
+
method = "#{method[0].capitalize}-#{Fog::Hyperv.camelize(method[1..].join('_'))}"
|
|
177
126
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
127
|
+
raise Fog::Hyperv::Errors::VersionError.new(required_version, version, method) \
|
|
128
|
+
unless Gem::Version.new(version) >= Gem::Version.new(required_version)
|
|
129
|
+
end
|
|
130
|
+
end
|
|
181
131
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
rescue => e
|
|
185
|
-
logger.debug "Cluster support checking failed with #{e.class}: #{e.message}"
|
|
186
|
-
false
|
|
187
|
-
end
|
|
132
|
+
class Real < Shared
|
|
133
|
+
include Fog::Hyperv::Utils::Winrm
|
|
188
134
|
|
|
189
|
-
|
|
190
|
-
@version ||= run_wql('SELECT Version FROM Win32_OperatingSystem', _namespace: 'root/cimv2/*')[:xml_fragment].first[:version] rescue \
|
|
191
|
-
run_shell("$VMMS = if ([environment]::Is64BitProcess) { \"$($env:SystemRoot)\\System32\\vmms.exe\" } else { \"$($env:SystemRoot)\\Sysnative\\vmms.exe\" }\n(Get-Item $VMMS).VersionInfo.ProductVersion", _skip_json: true).stdout.strip
|
|
192
|
-
end
|
|
135
|
+
attr_reader :logger
|
|
193
136
|
|
|
194
|
-
|
|
195
|
-
@ps_version ||= run_shell('$PSVersionTable.PSVersion', _bake_optmap: false, _bake_json: false)
|
|
196
|
-
end
|
|
137
|
+
attr_accessor :bake_optmap, :bake_json
|
|
197
138
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
bake_json = options.delete :_bake_json
|
|
202
|
-
if bake_json
|
|
203
|
-
if ps_version[:major] >= 6
|
|
204
|
-
"$Args = ConvertFrom-Json -AsHashtable '#{Fog::JSON.encode options}'"
|
|
205
|
-
else
|
|
206
|
-
<<-EOS
|
|
207
|
-
$JsonObject = '#{Fog::JSON.encode options}'
|
|
208
|
-
$JsonParameters = ConvertFrom-Json -InputObject $JsonObject
|
|
209
|
-
$Args = $JsonParameters.psobject.properties | foreach -begin {$h=@{}} -process {$h."$($_.Name)" = $_.Value} -end {$h}
|
|
210
|
-
EOS
|
|
211
|
-
end
|
|
212
|
-
else
|
|
213
|
-
args = options.reject { |k, v| v.nil? || v.is_a?(FalseClass) || k.to_s.start_with?('_') }.map do |k, v|
|
|
214
|
-
"'#{k}'=#{Fog::Hyperv.shell_quoted(v, true)}"
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
"$Args = @{#{args.join ';'}}"
|
|
218
|
-
end
|
|
219
|
-
end
|
|
139
|
+
def initialize(options = {}) # rubocop:disable Style/OptionHash, Lint/MissingSuper -- No super method
|
|
140
|
+
require 'fog/json'
|
|
141
|
+
require 'logging'
|
|
220
142
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
# $Result | select <return_fields> | ConvertTo-Json
|
|
225
|
-
end
|
|
143
|
+
# Transfer cmdlet parameters as JSON object
|
|
144
|
+
@bake_json = true
|
|
145
|
+
@bake_optmap = true
|
|
226
146
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
147
|
+
@connections = {}
|
|
148
|
+
@hyperv_endpoint = options[:hyperv_endpoint]
|
|
149
|
+
@hyperv_endpoint ||= "http://#{options[:hyperv_host]}:5985/wsman" if options[:hyperv_host]
|
|
150
|
+
@hyperv_username = options[:hyperv_username]
|
|
151
|
+
@hyperv_password = options[:hyperv_password]
|
|
152
|
+
@hyperv_realm = options[:hyperv_realm]
|
|
153
|
+
@hyperv_transport = options[:hyperv_transport] || (@hyperv_realm ? :kerberos : :negotiate)
|
|
230
154
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
"#{k} = #{(v.is_a?(String) || v.to_s =~ /\s/) && v.inspect || v}"
|
|
234
|
-
end
|
|
155
|
+
# Hide NEGOTIATE logging from WinRM to reduce log spam when debugging
|
|
156
|
+
Logging.logger['WinRM::HTTP::HttpNegotiate'].level = :error
|
|
235
157
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
else
|
|
241
|
-
logger.debug "WQL; #{namespace} >>> #{query}"
|
|
242
|
-
@connection.run_wql(query, namespace)
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
logger.debug "WQL; <<< #{data}"
|
|
246
|
-
data
|
|
158
|
+
@logger = Logging.logger[Fog::Hyperv]
|
|
159
|
+
if options[:hyperv_debug]
|
|
160
|
+
logger.level = :debug
|
|
161
|
+
logger.add_appenders Logging.appenders.stdout
|
|
247
162
|
end
|
|
248
163
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return_fields = options.delete :_return_fields
|
|
252
|
-
return_fields = "| select #{Fog::Hyperv.camelize([return_fields].flatten).join ','}" if return_fields
|
|
253
|
-
suffix = options.delete :_suffix
|
|
254
|
-
json_depth = options.delete :_json_depth
|
|
255
|
-
skip_json = options.delete :_skip_json
|
|
256
|
-
skip_camelize = options.delete :_skip_camelize
|
|
257
|
-
skip_uncamelize = options.delete :_skip_uncamelize
|
|
258
|
-
always_include = options.delete(:_always_include) {|_| []}
|
|
259
|
-
bake_optmap = options.delete(:_bake_optmap) {|_| @bake_optmap }
|
|
260
|
-
bake_json = options.delete(:_bake_json) {|_| @bake_json }
|
|
261
|
-
computer = options.delete(:_target_computer) || '.'
|
|
262
|
-
computers = [options.delete(:computer_name)].flatten.compact
|
|
263
|
-
options.delete_if { |o| o.to_s.start_with?('_') }
|
|
264
|
-
|
|
265
|
-
always_include = Fog::Hyperv.camelize(always_include) unless skip_camelize
|
|
266
|
-
options = Fog::Hyperv.camelize(options) unless skip_camelize
|
|
267
|
-
|
|
268
|
-
if supports_multihop?
|
|
269
|
-
options[:computer_name] = computers
|
|
270
|
-
computer = '.'
|
|
271
|
-
elsif computers.length > 1 || (computers.length == 1 && !['.','localhost'].include?(computers.first.downcase))
|
|
272
|
-
logger.debug "Executing multi-query for #{computers}"
|
|
273
|
-
ret = []
|
|
274
|
-
computers.each do |c|
|
|
275
|
-
out = run_shell(command, orig_opts.merge(computer_name: nil, _target_computer: c))
|
|
276
|
-
if out.is_a? Array
|
|
277
|
-
ret += out
|
|
278
|
-
else
|
|
279
|
-
ret << out
|
|
280
|
-
end
|
|
281
|
-
end
|
|
282
|
-
return ret.first if ret.length == 1
|
|
283
|
-
return ret
|
|
284
|
-
end
|
|
285
|
-
|
|
286
|
-
args = options.reject { |k, v| !always_include.include?(k) && (v.nil? || v.is_a?(FalseClass) || k.to_s.start_with?('_') || (v.is_a?(String) && v.empty?)) }.map do |k, v|
|
|
287
|
-
"-#{k} #{Fog::Hyperv.shell_quoted v if !v.is_a?(TrueClass) || always_include.include?(k)}"
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
if bake_optmap
|
|
291
|
-
command_args = "#{hash_to_optmap options.merge(_bake_json: bake_json)}\n#{command} @Args"
|
|
292
|
-
else
|
|
293
|
-
command_args = "#{command} #{args.join ' ' unless args.empty?}"
|
|
294
|
-
end
|
|
295
|
-
commandline = "#{command_args} #{suffix} #{return_fields} #{"| ConvertTo-Json -Compress #{"-Depth #{json_depth}" if json_depth}" unless skip_json}"
|
|
296
|
-
logger.debug "PS; >>> #{commandline}"
|
|
297
|
-
|
|
298
|
-
out = nil
|
|
299
|
-
if local?
|
|
300
|
-
commanddata = [
|
|
301
|
-
'powershell',
|
|
302
|
-
'-NoLogo',
|
|
303
|
-
'-NoProfile',
|
|
304
|
-
'-NonInteractive',
|
|
305
|
-
commandline
|
|
306
|
-
]
|
|
307
|
-
begin
|
|
308
|
-
out = OpenStruct.new stdout: '',
|
|
309
|
-
stderr: '',
|
|
310
|
-
exitcode: -1
|
|
311
|
-
out.stdout, out.stderr, out.exitcode = Open3.capture3(*commanddata)
|
|
312
|
-
out.exitcode = out.exitcode.exitstatus
|
|
313
|
-
rescue StandardError => ex
|
|
314
|
-
out.stderr = ex.inspect
|
|
315
|
-
out.exitcode = -1
|
|
316
|
-
end
|
|
317
|
-
else
|
|
318
|
-
connection(computer).shell(:powershell) do |shell|
|
|
319
|
-
# TODO: Reuse shell?
|
|
320
|
-
# XXX Multiple commands in one invokation?
|
|
321
|
-
out = shell.run(commandline)
|
|
322
|
-
end
|
|
323
|
-
end
|
|
324
|
-
|
|
325
|
-
# TODO: Map error codes in some manner?
|
|
326
|
-
raise Fog::Hyperv::Errors::ServiceError, "Failed to execute #{commandline}" unless out
|
|
327
|
-
raise Fog::Hyperv::Errors::PSError.new(out, "When executing #{command_args}") unless out.exitcode.zero?
|
|
328
|
-
|
|
329
|
-
logger.debug "PS; <<< OUT=[#{out.stdout.inspect}] ERR=[#{out.stderr.inspect}] EXIT=[#{out.exitcode}]"
|
|
164
|
+
connect
|
|
165
|
+
end
|
|
330
166
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
json = Fog::JSON.decode(out.stdout)
|
|
336
|
-
json = Fog::Hyperv.uncamelize(json) unless skip_uncamelize
|
|
337
|
-
json
|
|
338
|
-
end
|
|
339
|
-
end
|
|
167
|
+
# Is the provider communicating with a Hyper-V install on the local machine
|
|
168
|
+
def local?
|
|
169
|
+
false # @hyperv_endpoint.nil?
|
|
170
|
+
end
|
|
340
171
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
logger.debug "Creating WinRM connection with #{opts.merge password: '<REDACTED>'}"
|
|
355
|
-
connection = WinRM::Connection.new opts
|
|
356
|
-
connection.logger.level = :error
|
|
357
|
-
@connections[fqdn] = connection
|
|
358
|
-
|
|
359
|
-
if endpoint == @hyperv_endpoint
|
|
360
|
-
@connection = connection
|
|
361
|
-
@connections['.'] = connection
|
|
362
|
-
@connections['localhost'] = connection
|
|
363
|
-
end
|
|
364
|
-
connection
|
|
365
|
-
end
|
|
172
|
+
# Is the Hyper-V provider valid - i.e. can it communicate with a Hyper-V install
|
|
173
|
+
# @return [Boolean] is the endpoint running a working Hyper-V setup
|
|
174
|
+
def valid?
|
|
175
|
+
if local?
|
|
176
|
+
run_cmd('Get-VMHost', _return_fields: :name) && true
|
|
177
|
+
else
|
|
178
|
+
run_wql('SELECT Name FROM Msvm_ComputerSystem WHERE Caption = "Hosting Computer System"')[:xml_fragment] && true
|
|
179
|
+
end
|
|
180
|
+
rescue StandardError => e
|
|
181
|
+
logger.debug "Validation failed with #{e.class}; #{e.message}"
|
|
182
|
+
false
|
|
183
|
+
end
|
|
366
184
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
185
|
+
# Does the Hyper-V install support clusters - i.e. is the machine joined to a failover cluster
|
|
186
|
+
# @return [Boolean] is the Hyper-V setup possible to cluster
|
|
187
|
+
def supports_clusters?
|
|
188
|
+
run_wql('SELECT Name FROM MSCluster_ResourceGroup', _namespace: 'root/mscluster/*')[:xml_fragment] && true
|
|
189
|
+
rescue StandardError => e
|
|
190
|
+
logger.debug "Cluster support checking failed with #{e.class}: #{e.message}"
|
|
191
|
+
false
|
|
192
|
+
end
|
|
193
|
+
end
|
|
370
194
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
endpoint = "http://#{host}:5985/wsman"
|
|
195
|
+
# Mocked version of the provider for use in testing
|
|
196
|
+
class Mock < Shared
|
|
197
|
+
def initialize(_options = {}) # rubocop:disable Lint/MissingSuper -- No super method
|
|
198
|
+
require 'fog/json'
|
|
199
|
+
end
|
|
377
200
|
|
|
378
|
-
|
|
201
|
+
def method_missing(method, *args)
|
|
202
|
+
if requests.find { |_, k| k == method }
|
|
203
|
+
handle_mock_response((args.first || {}).merge(_method: method))
|
|
204
|
+
else
|
|
205
|
+
super
|
|
379
206
|
end
|
|
380
207
|
end
|
|
381
208
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
end
|
|
209
|
+
def respond_to_missing?(method, include_private = false)
|
|
210
|
+
requests.find { |_, k| k == method } || super
|
|
211
|
+
end
|
|
386
212
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
else
|
|
391
|
-
super
|
|
392
|
-
end
|
|
393
|
-
end
|
|
213
|
+
def self.method_defined?(method)
|
|
214
|
+
Fog::Hyperv::Compute.requests.find { |_, k| k == method } || super
|
|
215
|
+
end
|
|
394
216
|
|
|
395
|
-
|
|
396
|
-
requests.find { |_, k| k == method } || super
|
|
397
|
-
end
|
|
217
|
+
private
|
|
398
218
|
|
|
399
|
-
|
|
400
|
-
|
|
219
|
+
def handle_mock_response(_method: nil, **args)
|
|
220
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('4.0')
|
|
221
|
+
_method ||= caller[0][/'.*'/][1..-2].split('#').last
|
|
222
|
+
_method ||= caller[1][/'.*'/][1..-2].split('#').last
|
|
223
|
+
else
|
|
224
|
+
_method ||= caller[0][/`.*'/][1..-2]
|
|
225
|
+
_method ||= caller[1][/`.*'/][1..-2]
|
|
401
226
|
end
|
|
402
227
|
|
|
403
|
-
|
|
228
|
+
path = File.join File.dirname(__FILE__), 'compute', 'requests', 'mock_files', "#{_method}.json"
|
|
229
|
+
raise Fog::Errors::MockNotImplemented, "No mocked data for #{path}" unless File.exist? path
|
|
230
|
+
raise Fog::Errors::MockNotImplemented, 'Not implementing skipping of json' if args[:_skip_json]
|
|
231
|
+
raise Fog::Errors::MockNotImplemented, 'Not implementing skipping of uncamelize' if args[:_skip_uncamelize]
|
|
404
232
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
method ||= caller[0][/`.*'/][1..-2]
|
|
408
|
-
method ||= caller[1][/`.*'/][1..-2]
|
|
409
|
-
|
|
410
|
-
path = File.join File.dirname(__FILE__), 'requests', 'compute', 'mock_files', "#{method}.json"
|
|
411
|
-
Fog::Mock.not_implemented unless File.exist? path
|
|
412
|
-
raise Fog::Errors::MockNotImplemented, 'Not implementing skipping of json' if args[:_skip_json]
|
|
413
|
-
raise Fog::Errors::MockNotImplemented, 'Not implementing skipping of uncamelize' if args[:_skip_uncamelize]
|
|
414
|
-
|
|
415
|
-
ret = Fog::JSON.decode(open(path).read)
|
|
416
|
-
ret = Fog::Hyperv.uncamelize(ret)
|
|
233
|
+
ret = Fog::JSON.decode(File.read(path))
|
|
234
|
+
ret = Fog::Hyperv.uncamelize(ret)
|
|
417
235
|
|
|
236
|
+
if args[:_return_fields]
|
|
418
237
|
ret = ret.map do |obj|
|
|
419
|
-
obj.
|
|
420
|
-
end
|
|
421
|
-
ret
|
|
238
|
+
obj.slice(*args[:_return_fields])
|
|
239
|
+
end
|
|
422
240
|
end
|
|
241
|
+
ret
|
|
423
242
|
end
|
|
424
243
|
end
|
|
425
244
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Fog::Hyperv
|
|
4
|
+
# General GUID format matching the UUIDv4 specification
|
|
5
|
+
GUID = /[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}/i
|
|
6
|
+
|
|
7
|
+
# General enum for on/off toggles as used by Hyper-V
|
|
8
|
+
#
|
|
9
|
+
# @note Defined by Microsoft.HyperV.PowerShell.OnOffState
|
|
10
|
+
ON_OFF_STATE_ENUM_VALUES = %i[
|
|
11
|
+
On
|
|
12
|
+
Off
|
|
13
|
+
].freeze
|
|
14
|
+
|
|
15
|
+
# Possible boot devices
|
|
16
|
+
#
|
|
17
|
+
# A few values - +:VHD+ and +:IDE+, +:NetworkAdapter+ and +:LegacyNetworkAdapter+ - refer to the same actual value,
|
|
18
|
+
# but will be used depending on the generation of the VM.
|
|
19
|
+
#
|
|
20
|
+
# @note Defined by Microsoft.HyperV.PowerShell.BootDevice
|
|
21
|
+
BOOT_DEVICE_ENUM_VALUES = %i[
|
|
22
|
+
Floppy CD IDE LegacyNetworkAdapter NetworkAdapter VHD
|
|
23
|
+
].freeze
|
|
24
|
+
end
|