Skip to content

Commit

Permalink
Merge pull request #282 from sabuhigr/master
Browse files Browse the repository at this point in the history
Added Getting vm by id to client
  • Loading branch information
mleone87 committed Dec 6, 2023
2 parents 566d203 + 39376bf commit fc4fc66
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions proxmox/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,35 @@ func (c *Client) GetVmRefsByName(vmName string) (vmrs []*VmRef, err error) {
}
}

func (c *Client) GetVmRefById(vmId int) (vmr *VmRef, err error) {
var exist bool = false
vms, err := c.GetResourceList(resourceListGuest)
if err != nil {
return
}
for vmii := range vms {
vm := vms[vmii].(map[string]interface{})
if int(vm["vmid"].(float64)) != 0 && int(vm["vmid"].(float64)) == vmId {
vmr = NewVmRef(int(vm["vmid"].(float64)))
vmr.node = vm["node"].(string)
vmr.vmType = vm["type"].(string)
vmr.pool = ""
if vm["pool"] != nil {
vmr.pool = vm["pool"].(string)
}
if vm["hastate"] != nil {
vmr.haState = vm["hastate"].(string)
}
return
}
}
if !exist {
return nil, fmt.Errorf("vm 'id-%d' not found", vmId)
} else {
return
}
}

func (c *Client) GetVmState(vmr *VmRef) (vmState map[string]interface{}, err error) {
err = c.CheckVmRef(vmr)
if err != nil {
Expand Down

0 comments on commit fc4fc66

Please sign in to comment.