Skip to content

Commit 808dcd1

Browse files
committed
Create cpi-hyperv.json
1 parent cf1728a commit 808dcd1

File tree

1 file changed

+378
-0
lines changed

1 file changed

+378
-0
lines changed

CPIs/cpi-hyperv.json

Lines changed: 378 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,378 @@
1+
{
2+
"name": "hyperv",
3+
"type": "command",
4+
"default_settings": {
5+
"hostname": "localhost",
6+
"output_format": "json"
7+
},
8+
"actions": {
9+
"test_install": {
10+
"target": {
11+
"Command": "powershell -Command \"Get-Command Get-VM -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Version | ConvertTo-Json\""
12+
},
13+
"parse_rules": {
14+
"type": "object",
15+
"patterns": {
16+
"version": {
17+
"regex": "(.*)",
18+
"group": 1
19+
}
20+
}
21+
}
22+
},
23+
"list_workers": {
24+
"target": {
25+
"Command": "powershell -Command \"Get-VM | Select-Object Name, State, CPUUsage, MemoryAssigned, Uptime, Status, Version, Path, Id | ConvertTo-Json -Depth 2\""
26+
},
27+
"parse_rules": {
28+
"type": "object",
29+
"patterns": {
30+
"vms": {
31+
"regex": "(.*)",
32+
"group": 1
33+
}
34+
}
35+
}
36+
},
37+
"get_worker": {
38+
"target": {
39+
"Command": "powershell -Command \"Get-VM -Name '{name}' | Select-Object Name, State, CPUUsage, MemoryAssigned, Uptime, Status, Version, Path, Id | ConvertTo-Json -Depth 2\""
40+
},
41+
"params": [
42+
"name"
43+
],
44+
"parse_rules": {
45+
"type": "object",
46+
"patterns": {
47+
"vm": {
48+
"regex": "(.*)",
49+
"group": 1
50+
}
51+
}
52+
}
53+
},
54+
"create_worker": {
55+
"target": {
56+
"Command": "powershell -Command \"New-VM -Name '{name}' -MemoryStartupBytes {memory_mb}MB -Generation {generation} -Path '{path}' -NewVHDPath '{path}\\{name}\\{name}.vhdx' -NewVHDSizeBytes {disk_size_gb}GB -SwitchName '{network}' | ConvertTo-Json\""
57+
},
58+
"params": [
59+
"name",
60+
"memory_mb",
61+
"path",
62+
"disk_size_gb",
63+
"network"
64+
],
65+
"default_settings": {
66+
"generation": "2",
67+
"memory_mb": "2048",
68+
"disk_size_gb": "40",
69+
"path": "C:\\VMs",
70+
"network": "Default Switch"
71+
},
72+
"parse_rules": {
73+
"type": "object",
74+
"patterns": {
75+
"vm_id": {
76+
"regex": "\"Id\":\\s*\"([^\"]+)\"",
77+
"group": 1
78+
}
79+
}
80+
}
81+
},
82+
"start_worker": {
83+
"target": {
84+
"Command": "powershell -Command \"Start-VM -Name '{name}' -PassThru | Select-Object Name, State | ConvertTo-Json\""
85+
},
86+
"params": [
87+
"name"
88+
],
89+
"parse_rules": {
90+
"type": "object",
91+
"patterns": {
92+
"result": {
93+
"regex": "(.*)",
94+
"group": 1
95+
}
96+
}
97+
}
98+
},
99+
"stop_worker": {
100+
"target": {
101+
"Command": "powershell -Command \"Stop-VM -Name '{name}' {force_param} -PassThru | Select-Object Name, State | ConvertTo-Json\""
102+
},
103+
"params": [
104+
"name"
105+
],
106+
"default_settings": {
107+
"force_param": ""
108+
},
109+
"parse_rules": {
110+
"type": "object",
111+
"patterns": {
112+
"result": {
113+
"regex": "(.*)",
114+
"group": 1
115+
}
116+
}
117+
}
118+
},
119+
"delete_worker": {
120+
"target": {
121+
"Command": "powershell -Command \"Remove-VM -Name '{name}' {force_param} -Confirm:$false -PassThru | Select-Object Name, Id | ConvertTo-Json\""
122+
},
123+
"params": [
124+
"name"
125+
],
126+
"default_settings": {
127+
"force_param": ""
128+
},
129+
"parse_rules": {
130+
"type": "object",
131+
"patterns": {
132+
"result": {
133+
"regex": "(.*)",
134+
"group": 1
135+
}
136+
}
137+
}
138+
},
139+
"set_worker_memory": {
140+
"target": {
141+
"Command": "powershell -Command \"Set-VMMemory -VMName '{name}' -StartupBytes {memory_mb}MB -Priority {memory_priority} -Buffer {memory_buffer}; Get-VM -Name '{name}' | Select-Object Name, MemoryAssigned | ConvertTo-Json\""
142+
},
143+
"params": [
144+
"name",
145+
"memory_mb"
146+
],
147+
"default_settings": {
148+
"memory_priority": "50",
149+
"memory_buffer": "20"
150+
},
151+
"parse_rules": {
152+
"type": "object",
153+
"patterns": {
154+
"result": {
155+
"regex": "(.*)",
156+
"group": 1
157+
}
158+
}
159+
}
160+
},
161+
"set_worker_cpu": {
162+
"target": {
163+
"Command": "powershell -Command \"Set-VMProcessor -VMName '{name}' -Count {vcpus} -Reserve {cpu_reserve} -Maximum {cpu_maximum} -RelativeWeight {cpu_weight}; Get-VM -Name '{name}' | Select-Object Name, ProcessorCount | ConvertTo-Json\""
164+
},
165+
"params": [
166+
"name",
167+
"vcpus"
168+
],
169+
"default_settings": {
170+
"cpu_reserve": "0",
171+
"cpu_maximum": "100",
172+
"cpu_weight": "100"
173+
},
174+
"parse_rules": {
175+
"type": "object",
176+
"patterns": {
177+
"result": {
178+
"regex": "(.*)",
179+
"group": 1
180+
}
181+
}
182+
}
183+
},
184+
"list_snapshots": {
185+
"target": {
186+
"Command": "powershell -Command \"Get-VMSnapshot -VMName '{name}' | Select-Object Name, CreationTime, ParentSnapshotName, SnapshotType, Id | ConvertTo-Json\""
187+
},
188+
"params": [
189+
"name"
190+
],
191+
"parse_rules": {
192+
"type": "object",
193+
"patterns": {
194+
"snapshots": {
195+
"regex": "(.*)",
196+
"group": 1
197+
}
198+
}
199+
}
200+
},
201+
"create_snapshot": {
202+
"target": {
203+
"Command": "powershell -Command \"Checkpoint-VM -Name '{name}' -SnapshotName '{snapshot_name}' -PassThru | Select-Object VMName, Name, Id | ConvertTo-Json\""
204+
},
205+
"params": [
206+
"name",
207+
"snapshot_name"
208+
],
209+
"parse_rules": {
210+
"type": "object",
211+
"patterns": {
212+
"snapshot": {
213+
"regex": "(.*)",
214+
"group": 1
215+
}
216+
}
217+
}
218+
},
219+
"restore_snapshot": {
220+
"target": {
221+
"Command": "powershell -Command \"Restore-VMSnapshot -VMName '{name}' -Name '{snapshot_name}' -Confirm:$false -PassThru | Select-Object VMName, Name, Id | ConvertTo-Json\""
222+
},
223+
"params": [
224+
"name",
225+
"snapshot_name"
226+
],
227+
"parse_rules": {
228+
"type": "object",
229+
"patterns": {
230+
"result": {
231+
"regex": "(.*)",
232+
"group": 1
233+
}
234+
}
235+
}
236+
},
237+
"remove_snapshot": {
238+
"target": {
239+
"Command": "powershell -Command \"Remove-VMSnapshot -VMName '{name}' -Name '{snapshot_name}' -Confirm:$false; Get-VM -Name '{name}' | Select-Object Name, Id | ConvertTo-Json\""
240+
},
241+
"params": [
242+
"name",
243+
"snapshot_name"
244+
],
245+
"parse_rules": {
246+
"type": "object",
247+
"patterns": {
248+
"result": {
249+
"regex": "(.*)",
250+
"group": 1
251+
}
252+
}
253+
}
254+
},
255+
"list_networks": {
256+
"target": {
257+
"Command": "powershell -Command \"Get-VMSwitch | Select-Object Name, SwitchType, NetAdapterInterfaceDescription, AllowManagementOS, Id | ConvertTo-Json\""
258+
},
259+
"parse_rules": {
260+
"type": "object",
261+
"patterns": {
262+
"switches": {
263+
"regex": "(.*)",
264+
"group": 1
265+
}
266+
}
267+
}
268+
},
269+
"create_network": {
270+
"target": {
271+
"Command": "powershell -Command \"New-VMSwitch -Name '{name}' -SwitchType {switch_type} {physical_adapter_param} -AllowManagementOS {allow_management_os} -Notes '{notes}' | Select-Object Name, SwitchType, Id | ConvertTo-Json\""
272+
},
273+
"params": [
274+
"name",
275+
"switch_type"
276+
],
277+
"default_settings": {
278+
"physical_adapter_param": "",
279+
"allow_management_os": "$true",
280+
"notes": "Created by CPI"
281+
},
282+
"parse_rules": {
283+
"type": "object",
284+
"patterns": {
285+
"switch": {
286+
"regex": "(.*)",
287+
"group": 1
288+
}
289+
}
290+
}
291+
},
292+
"list_disks": {
293+
"target": {
294+
"Command": "powershell -Command \"Get-VHD -Path '{path}\\*.vhdx' | Select-Object Path, VhdFormat, VhdType, Size, FileSize, FragmentationPercentage, ParentPath | ConvertTo-Json\""
295+
},
296+
"params": [
297+
"path"
298+
],
299+
"default_settings": {
300+
"path": "C:\\VMs"
301+
},
302+
"parse_rules": {
303+
"type": "object",
304+
"patterns": {
305+
"disks": {
306+
"regex": "(.*)",
307+
"group": 1
308+
}
309+
}
310+
}
311+
},
312+
"create_disk": {
313+
"target": {
314+
"Command": "powershell -Command \"New-VHD -Path '{path}\\{disk_name}.vhdx' -SizeBytes {size_gb}GB -Dynamic:{dynamic} | Select-Object Path, VhdFormat, VhdType, Size, FileSize | ConvertTo-Json\""
315+
},
316+
"params": [
317+
"path",
318+
"disk_name",
319+
"size_gb"
320+
],
321+
"default_settings": {
322+
"path": "C:\\VMs",
323+
"dynamic": "$true"
324+
},
325+
"parse_rules": {
326+
"type": "object",
327+
"patterns": {
328+
"disk": {
329+
"regex": "(.*)",
330+
"group": 1
331+
}
332+
}
333+
}
334+
},
335+
"attach_disk": {
336+
"target": {
337+
"Command": "powershell -Command \"Add-VMHardDiskDrive -VMName '{name}' -Path '{path}\\{disk_name}.vhdx' -ControllerType {controller_type} -ControllerNumber {controller_number} -ControllerLocation {controller_location}; Get-VMHardDiskDrive -VMName '{name}' | Select-Object VMName, Path, ControllerType, ControllerNumber, ControllerLocation | ConvertTo-Json\""
338+
},
339+
"params": [
340+
"name",
341+
"path",
342+
"disk_name"
343+
],
344+
"default_settings": {
345+
"path": "C:\\VMs",
346+
"controller_type": "SCSI",
347+
"controller_number": "0",
348+
"controller_location": "1"
349+
},
350+
"parse_rules": {
351+
"type": "object",
352+
"patterns": {
353+
"result": {
354+
"regex": "(.*)",
355+
"group": 1
356+
}
357+
}
358+
}
359+
},
360+
"get_worker_metrics": {
361+
"target": {
362+
"Command": "powershell -Command \"Get-VM -Name '{name}' | Select-Object Name, CPUUsage, MemoryAssigned, MemoryDemand, MemoryStatus, Status, Uptime | ConvertTo-Json\""
363+
},
364+
"params": [
365+
"name"
366+
],
367+
"parse_rules": {
368+
"type": "object",
369+
"patterns": {
370+
"metrics": {
371+
"regex": "(.*)",
372+
"group": 1
373+
}
374+
}
375+
}
376+
}
377+
}
378+
}

0 commit comments

Comments
 (0)