mirror of
https://github.com/letic/terraform-provider-proxmox.git
synced 2024-10-05 02:01:04 +00:00
fix parallel VMID grabbing
This commit is contained in:
parent
624169e7b7
commit
679fd58542
@ -3,6 +3,7 @@ package proxmox
|
|||||||
import (
|
import (
|
||||||
pxapi "github.com/Telmate/proxmox-api-go/proxmox"
|
pxapi "github.com/Telmate/proxmox-api-go/proxmox"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type providerConfiguration struct {
|
type providerConfiguration struct {
|
||||||
@ -54,3 +55,20 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|||||||
Client: client,
|
Client: client,
|
||||||
}, nil
|
}, 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
|
// get unique id
|
||||||
maxid, err := pxapi.MaxVmId(client)
|
nextid, err := nextVmId(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
vmr := pxapi.NewVmRef(maxid + 1)
|
vmr := pxapi.NewVmRef(nextid)
|
||||||
vmr.SetNode(d.Get("target_node").(string))
|
vmr.SetNode(d.Get("target_node").(string))
|
||||||
|
|
||||||
// check if ISO or clone
|
// check if ISO or clone
|
||||||
|
Loading…
Reference in New Issue
Block a user