Skip to content

Commit

Permalink
fix sshHost, disk resize, and allow sparse mac, storage_type & qemu_o…
Browse files Browse the repository at this point in the history
…s-type parameters
  • Loading branch information
Grant Gongaware committed Jul 16, 2018
1 parent 27fba3b commit a14c33d
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions proxmox/resource_vm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package proxmox
import (
"fmt"
"log"
"math"
"path"
"regexp"
"strconv"
Expand Down Expand Up @@ -62,12 +63,24 @@ func resourceVmQemu() *schema.Resource {
"storage_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ForceNew: false,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if new == "" {
return true // empty template ok
}
return strings.TrimSpace(old) == strings.TrimSpace(new)
},
},
"qemu_os": {
Type: schema.TypeString,
Optional: true,
Default: "l26",
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old == "" {
return true // reading empty ok
}
return strings.TrimSpace(old) == strings.TrimSpace(new)
},
},
"memory": {
Type: schema.TypeInt,
Expand All @@ -84,6 +97,12 @@ func resourceVmQemu() *schema.Resource {
"disk_gb": {
Type: schema.TypeFloat,
Required: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
// bigger ok
oldf, _ := strconv.ParseFloat(old, 64)
newf, _ := strconv.ParseFloat(new, 64)
return oldf >= newf
},
},
"nic": {
Type: schema.TypeString,
Expand Down Expand Up @@ -132,8 +151,8 @@ func resourceVmQemu() *schema.Resource {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old == "" {
return false // macaddr auto-generates and its ok
if new == "" {
return true // macaddr auto-generates and its ok
}
return strings.TrimSpace(old) == strings.TrimSpace(new)
},
Expand Down Expand Up @@ -162,6 +181,9 @@ func resourceVmQemu() *schema.Resource {
"sshkeys": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return strings.TrimSpace(old) == strings.TrimSpace(new)
},
},
"ipconfig0": {
Type: schema.TypeString,
Expand Down Expand Up @@ -298,7 +320,8 @@ func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error {
if config.HasCloudInit() {
if d.Get("ssh_forward_ip") != nil {
sshHost = d.Get("ssh_forward_ip").(string)
} else {
}
if sshHost == "" {
// parse IP address out of ipconfig0
ipMatch := rxIPconfig.FindStringSubmatch(d.Get("ipconfig0").(string))
sshHost = ipMatch[1]
Expand Down Expand Up @@ -504,7 +527,8 @@ func prepareDiskSize(client *pxapi.Client, vmr *pxapi.VmRef, diskGB float64) err
}
if diskGB > clonedConfig.DiskSize {
log.Print("[DEBUG] resizing disk " + clonedConfig.StorageType)
_, err = client.ResizeQemuDisk(vmr, clonedConfig.StorageType+"0", int(diskGB-clonedConfig.DiskSize))
diffSize := int(math.Ceil(diskGB - clonedConfig.DiskSize))
_, err = client.ResizeQemuDisk(vmr, clonedConfig.StorageType+"0", diffSize)
if err != nil {
return err
}
Expand Down

0 comments on commit a14c33d

Please sign in to comment.