From 16f706ce98630b4d60290f309d83a20120cf7da8 Mon Sep 17 00:00:00 2001 From: Christophe Jauffret Date: Fri, 29 Jul 2022 13:43:34 +0200 Subject: [PATCH] add CPU support --- builder/nutanix/config.go | 7 ++++++- builder/nutanix/config.hcl2spec.go | 4 ++-- builder/nutanix/driver.go | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/builder/nutanix/config.go b/builder/nutanix/config.go index 6b62735..2ff1405 100644 --- a/builder/nutanix/config.go +++ b/builder/nutanix/config.go @@ -57,7 +57,7 @@ type VmConfig struct { ImageName string `mapstructure:"image_name" json:"image_name" required:"false"` ClusterUUID string `mapstructure:"cluster_uuid" json:"cluster_uuid" required:"false"` ClusterName string `mapstructure:"cluster_name" json:"cluster_name" required:"false"` - CPU int32 `mapstructure:"cpu" json:"cpu" required:"false"` + CPU int64 `mapstructure:"cpu" json:"cpu" required:"false"` MemoryMB int64 `mapstructure:"memory_mb" json:"memory_mb" required:"false"` UserData string `mapstructure:"user_data" json:"user_data" required:"false"` } @@ -95,6 +95,11 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) { } } + if c.CPU == 0 { + log.Println("No CPU configured, defaulting to '1'") + c.CPU = 1 + } + if c.MemoryMB == 0 { log.Println("No VM Memory configured, defaulting to '4096'") c.MemoryMB = 4096 diff --git a/builder/nutanix/config.hcl2spec.go b/builder/nutanix/config.hcl2spec.go index 0043e1e..5579587 100644 --- a/builder/nutanix/config.hcl2spec.go +++ b/builder/nutanix/config.hcl2spec.go @@ -115,7 +115,7 @@ type FlatConfig struct { ImageName *string `mapstructure:"image_name" json:"image_name" required:"false" cty:"image_name" hcl:"image_name"` ClusterUUID *string `mapstructure:"cluster_uuid" json:"cluster_uuid" required:"false" cty:"cluster_uuid" hcl:"cluster_uuid"` ClusterName *string `mapstructure:"cluster_name" json:"cluster_name" required:"false" cty:"cluster_name" hcl:"cluster_name"` - CPU *int32 `mapstructure:"cpu" json:"cpu" required:"false" cty:"cpu" hcl:"cpu"` + CPU *int64 `mapstructure:"cpu" json:"cpu" required:"false" cty:"cpu" hcl:"cpu"` MemoryMB *int64 `mapstructure:"memory_mb" json:"memory_mb" required:"false" cty:"memory_mb" hcl:"memory_mb"` UserData *string `mapstructure:"user_data" json:"user_data" required:"false" cty:"user_data" hcl:"user_data"` } @@ -223,7 +223,7 @@ type FlatVmConfig struct { ImageName *string `mapstructure:"image_name" json:"image_name" required:"false" cty:"image_name" hcl:"image_name"` ClusterUUID *string `mapstructure:"cluster_uuid" json:"cluster_uuid" required:"false" cty:"cluster_uuid" hcl:"cluster_uuid"` ClusterName *string `mapstructure:"cluster_name" json:"cluster_name" required:"false" cty:"cluster_name" hcl:"cluster_name"` - CPU *int32 `mapstructure:"cpu" json:"cpu" required:"false" cty:"cpu" hcl:"cpu"` + CPU *int64 `mapstructure:"cpu" json:"cpu" required:"false" cty:"cpu" hcl:"cpu"` MemoryMB *int64 `mapstructure:"memory_mb" json:"memory_mb" required:"false" cty:"memory_mb" hcl:"memory_mb"` UserData *string `mapstructure:"user_data" json:"user_data" required:"false" cty:"user_data" hcl:"user_data"` } diff --git a/builder/nutanix/driver.go b/builder/nutanix/driver.go index a818ad3..c6bcda8 100644 --- a/builder/nutanix/driver.go +++ b/builder/nutanix/driver.go @@ -330,6 +330,7 @@ func (d *NutanixDriver) CreateRequest(vm VmConfig) (*v3.VMIntentInput, error) { Name: &vm.VMName, Resources: &v3.VMResources{ GuestCustomization: guestCustomization, + NumSockets: &vm.CPU, MemorySizeMib: &vm.MemoryMB, PowerState: &PowerStateOn, DiskList: DiskList,