GetNextID returns the next free VMID, optionally validating a requested one.
(requested int)
| 39 | |
| 40 | // GetNextID returns the next free VMID, optionally validating a requested one. |
| 41 | func (c *Client) GetNextID(requested int) (int, error) { |
| 42 | path := "/cluster/nextid" |
| 43 | if requested > 0 { |
| 44 | path += "?vmid=" + strconv.Itoa(requested) |
| 45 | } |
| 46 | |
| 47 | var res map[string]interface{} |
| 48 | if err := c.Get(path, &res); err != nil { |
| 49 | return 0, fmt.Errorf("failed to get next VMID: %w", err) |
| 50 | } |
| 51 | |
| 52 | nextID := getInt(res, "data") |
| 53 | if nextID <= 0 { |
| 54 | return 0, fmt.Errorf("invalid nextid response format") |
| 55 | } |
| 56 | |
| 57 | return nextID, nil |
| 58 | } |
| 59 | |
| 60 | // CreateVM creates a QEMU VM and returns the queued task UPID. |
| 61 | func (c *Client) CreateVM(nodeName string, options VMCreateOptions) (string, error) { |
no test coverage detected