-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirtmachines.go
94 lines (73 loc) · 1.57 KB
/
virtmachines.go
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
package main
import (
"context"
"strings"
"github.com/luthermonson/go-proxmox"
)
var activeVMids = []uint64{}
// VirtualMachine struct
type VirtualMachine struct {
proxmox.VirtualMachine
vm_type string
tags []string
}
func getVirtualMachines(node proxmox.Node) []VirtualMachine {
vms, err := node.VirtualMachines(context.Background())
if err != nil {
logger.Fatal("Error fetching VMs for node: ", node.Name)
}
vmArray := []VirtualMachine{}
for _, vm := range vms {
tags := strings.Split(vm.Tags, ";")
vmType := "VM"
if vm.Template {
vmType = "Template"
}
vmArray = append(vmArray, VirtualMachine{
*vm,
vmType,
tags,
})
activeVMids = append(activeVMids, uint64(vm.VMID))
}
return vmArray
}
func getTemplates() []VirtualMachine {
// update nodes
updateNodes()
templates := []VirtualMachine{}
for _, node := range nodes {
for _, vm := range node.VirtualMachines {
if vm.vm_type == "Template" {
templates = append(templates, vm)
}
}
}
return templates
}
func getTemplate(source uint64) VirtualMachine {
// update nodes
updateNodes()
for _, node := range nodes {
for _, vm := range node.VirtualMachines {
if uint64(vm.VMID) == source {
return vm
}
}
}
logger.Fatal("Template not found")
return VirtualMachine{}
}
func getVMbyID(source uint64) VirtualMachine {
// update nodes
updateNodes()
for _, node := range nodes {
for _, vm := range node.VirtualMachines {
if uint64(vm.VMID) == source {
return vm
}
}
}
logger.Fatal("VM with id ", source, " not found")
return VirtualMachine{}
}