mirror of
https://github.com/letic/terraform-provider-proxmox.git
synced 2024-07-03 16:12:38 +00:00
fix parallel VMID grabbing
This commit is contained in:
parent
624169e7b7
commit
679fd58542
|
@ -3,6 +3,7 @@ package proxmox
|
|||
import (
|
||||
pxapi "github.com/Telmate/proxmox-api-go/proxmox"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type providerConfiguration struct {
|
||||
|
@ -54,3 +55,20 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|||
Client: client,
|
||||
}, nil
|
||||
}
|
||||
|
||||
var mutex = &sync.Mutex{}
|
||||
var maxVmId = 0
|
||||
|
||||
func nextVmId(client *pxapi.Client) (nextId int, err error) {
|
||||
mutex.Lock()
|
||||
if maxVmId == 0 {
|
||||
maxVmId, err = pxapi.MaxVmId(client)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
maxVmId++
|
||||
nextId = maxVmId
|
||||
mutex.Unlock()
|
||||
return nextId, nil
|
||||
}
|
||||
|
|
|
@ -127,11 +127,11 @@ func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
// get unique id
|
||||
maxid, err := pxapi.MaxVmId(client)
|
||||
nextid, err := nextVmId(client)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
vmr := pxapi.NewVmRef(maxid + 1)
|
||||
vmr := pxapi.NewVmRef(nextid)
|
||||
vmr.SetNode(d.Get("target_node").(string))
|
||||
|
||||
// check if ISO or clone
|
||||
|
|
Loading…
Reference in New Issue
Block a user