From 5712c9bfbab060075cf4330e6000c25634261c9c Mon Sep 17 00:00:00 2001 From: edmondshtogu Date: Thu, 3 Aug 2023 14:37:51 +0200 Subject: [PATCH] Fixing lint issues.. --- .../pulumi-resource-esxi-native/schema.json | 30 ++- provider/pkg/schema/validation.go | 185 +++++++++--------- sdk/dotnet/ResourcePool.cs | 6 + sdk/dotnet/VirtualMachine.cs | 16 +- sdk/dotnet/version.txt | 2 +- sdk/go/esxi/resourcePool.go | 18 ++ sdk/go/esxi/virtualMachine.go | 24 +-- sdk/nodejs/resourcePool.ts | 12 +- sdk/nodejs/virtualMachine.ts | 20 +- .../resource_pool.py | 24 +++ .../virtual_machine.py | 148 +++++++------- 11 files changed, 277 insertions(+), 208 deletions(-) diff --git a/provider/cmd/pulumi-resource-esxi-native/schema.json b/provider/cmd/pulumi-resource-esxi-native/schema.json index c5833dd..f240923 100644 --- a/provider/cmd/pulumi-resource-esxi-native/schema.json +++ b/provider/cmd/pulumi-resource-esxi-native/schema.json @@ -219,7 +219,8 @@ }, "vSwitch": { "type": "string", - "description": "Virtual Switch Name." + "description": "Virtual Switch Name.", + "willReplaceOnChanges": true }, "vlan": { "type": "integer", @@ -291,15 +292,18 @@ "inputProperties": { "name": { "type": "string", - "description": "Resource Pool Name" + "description": "Resource Pool Name", + "willReplaceOnChanges": true }, "cpuMin": { "type": "integer", - "description": "CPU minimum (in MHz)." + "description": "CPU minimum (in MHz).", + "default": 100 }, "cpuMinExpandable": { "type": "string", - "description": "Can pool borrow CPU resources from parent?" + "description": "Can pool borrow CPU resources from parent?", + "default": "true" }, "cpuMax": { "type": "integer", @@ -307,15 +311,18 @@ }, "cpuShares": { "type": "string", - "description": "CPU shares (low/normal/high/)." + "description": "CPU shares (low/normal/high/).", + "default": "normal" }, "memMin": { "type": "integer", - "description": "Memory minimum (in MB)." + "description": "Memory minimum (in MB).", + "default": 200 }, "memMinExpandable": { "type": "string", - "description": "Can pool borrow memory resources from parent?" + "description": "Can pool borrow memory resources from parent?", + "default": "true" }, "memMax": { "type": "integer", @@ -323,7 +330,8 @@ }, "memShares": { "type": "string", - "description": "Memory shares (low/normal/high/)." + "description": "Memory shares (low/normal/high/).", + "default": "normal" } } }, @@ -489,7 +497,11 @@ } }, "requiredInputs": [ - "diskStore" + "diskStore", + "resourcePoolName", + "memSize", + "numVCpus", + "os" ], "inputProperties": { "name": { diff --git a/provider/pkg/schema/validation.go b/provider/pkg/schema/validation.go index 5095409..557705a 100644 --- a/provider/pkg/schema/validation.go +++ b/provider/pkg/schema/validation.go @@ -18,6 +18,9 @@ const ( maxStartupTimeout = 600 maxOvfProperties = 6000 + maxVlanId = 4095 + maxDiskSize = 62000 + // Maximum values for VirtualMachine properties. maxNetworkInterfaces = 10 maxVirtualDisks = 59 @@ -29,12 +32,8 @@ func ValidatePortGroup(resourceToken string, inputs resource.PropertyMap) []*pul failures := make(map[string]string) // Validate required properties. - if _, has := inputs["name"]; !has { - failures["name"] = fmt.Sprintf(propertyRequired, "name") - } - if _, has := inputs["vSwitch"]; !has { - failures["vSwitch"] = fmt.Sprintf(propertyRequired, "vSwitch") - } + checkRequiredProperty("name", inputs, &failures) + checkRequiredProperty("vSwitch", inputs, &failures) // Validate boolean properties. booleanProps := []string{"forgedTransmits", "promiscuousMode", "macChanges"} @@ -47,6 +46,8 @@ func ValidatePortGroup(resourceToken string, inputs resource.PropertyMap) []*pul } } + validatePropertyValueInBetween("vlan", 0, maxVlanId, inputs, &failures) + return validateResource(resourceToken, failures) } @@ -61,6 +62,10 @@ func ValidateResourcePool(resourceToken string, inputs resource.PropertyMap) []* failures["name"] = "The property 'name' cannot start with '/'!" } + // Validate "cpuShares" and "memShares". + validateCPUShares("cpuShares", inputs, &failures) + validateCPUShares("memShares", inputs, &failures) + // Validate boolean properties. booleanProps := []string{"cpuMinExpandable", "memMinExpandable"} for _, key := range booleanProps { @@ -72,89 +77,89 @@ func ValidateResourcePool(resourceToken string, inputs resource.PropertyMap) []* } } - // Validate "cpuShares" and "memShares". - validateShares := func(key string) { - if value, has := inputs[resource.PropertyKey(key)]; has { - strVal := value.StringValue() - if _, err := strconv.Atoi(strVal); err != nil { - failures[key] = fmt.Sprintf(invalidFormat, key, fmt.Sprintf("must be low/normal/high/ (%s)", err)) - } - } - } - validateShares("cpuShares") - validateShares("memShares") - return validateResource(resourceToken, failures) } func ValidateVirtualDisk(resourceToken string, inputs resource.PropertyMap) []*pulumirpc.CheckFailure { failures := map[string]string{} - checkRequiredProperty("name", inputs, &failures) - checkRequiredProperty("diskStore", inputs, &failures) - checkRequiredProperty("directory", inputs, &failures) - checkRequiredProperty("diskType", inputs, &failures) + requiredProps := []string{"name", "diskStore", "directory", "diskType"} + for _, key := range requiredProps { + checkRequiredProperty(key, inputs, &failures) + } - validateDiskType(inputs, &failures) + validateDiskType("diskType", inputs, &failures) return validateResource(resourceToken, failures) } -func checkRequiredProperty(property string, inputs resource.PropertyMap, failures *map[string]string) { - if _, has := inputs[resource.PropertyKey(property)]; !has { - (*failures)[property] = fmt.Sprintf(propertyRequired, property) - } -} - -func validateDiskType(inputs resource.PropertyMap, failures *map[string]string) { - key := "diskType" - if prop, has := inputs[resource.PropertyKey(key)]; has { - value := prop.StringValue() - if _, err := strconv.Atoi(value); !contains([]string{"thin", "zeroedthick", "eagerzeroedthick"}, value) && err != nil { - (*failures)[key] = fmt.Sprintf(invalidFormat, key, fmt.Sprintf("must be one of the thin, zeroedthick, or eagerzeroedthick (%s)", err)) - } - } -} - // ValidateVirtualMachine validates a virtual machine resource. func ValidateVirtualMachine(resourceToken string, inputs resource.PropertyMap) []*pulumirpc.CheckFailure { failures := map[string]string{} - validateBootDiskType(inputs, &failures) - validateBootDiskSize(inputs, &failures) - validateTimeoutProperty("shutdownTimeout", 0, maxShutdownTimeout, inputs, &failures) - validateTimeoutProperty("startupTimeout", 0, maxStartupTimeout, inputs, &failures) - validateTimeoutProperty("ovfPropertiesTimer", 0, maxOvfProperties, inputs, &failures) + // Validate required properties. + requiredProps := []string{"name", "diskStore", "resourcePoolName", "memSize", "numVCpus", "os"} + for _, key := range requiredProps { + checkRequiredProperty(key, inputs, &failures) + } + + validateDiskType("bootDiskType", inputs, &failures) + validatePropertyValueInBetween("bootDiskSize", 0, maxDiskSize, inputs, &failures) + validatePropertyValueInBetween("shutdownTimeout", 0, maxShutdownTimeout, inputs, &failures) + validatePropertyValueInBetween("startupTimeout", 0, maxStartupTimeout, inputs, &failures) + validatePropertyValueInBetween("ovfPropertiesTimer", 0, maxOvfProperties, inputs, &failures) + validateKeyValuePairsProperty("ovfProperties", inputs, &failures) + validateKeyValuePairsProperty("info", inputs, &failures) validateVirtualMachineOs(inputs, &failures) validateNetworkInterfaces(inputs, &failures) - validateOvfProperties(inputs, &failures) validateVirtualDisks(inputs, &failures) - // Validate required properties. + // TODO: recheck if it is okay + // "virtualHWVer": + // if contains([]string{"0","4","7","8","9","10","11","12","13","14"}, property.StringValue()) { + // failures[key] = fmt.Sprintf(invalidFormat, key, "4,7,8,9,10,11,12,13 or 14") + // } + + return validateResource(resourceToken, failures) +} + +func ValidateVirtualSwitch(resourceToken string, inputs resource.PropertyMap) []*pulumirpc.CheckFailure { + failures := map[string]string{} + checkRequiredProperty("name", inputs, &failures) - checkRequiredProperty("diskStore", inputs, &failures) + validateLinkDiscoveryMode(inputs, &failures) + validateUplinks(inputs, &failures) return validateResource(resourceToken, failures) } -func validateBootDiskType(inputs resource.PropertyMap, failures *map[string]string) { - key := "bootDiskType" - value := inputs[resource.PropertyKey(key)].StringValue() - if _, err := strconv.Atoi(value); !contains([]string{"thin", "zeroedthick", "eagerzeroedthick"}, value) && err != nil { - (*failures)[key] = fmt.Sprintf(invalidFormat, key, fmt.Sprintf("must be one of the thin, zeroedthick, or eagerzeroedthick (%s)", err)) +func checkRequiredProperty(property string, inputs resource.PropertyMap, failures *map[string]string) { + if _, has := inputs[resource.PropertyKey(property)]; !has { + (*failures)[property] = fmt.Sprintf(propertyRequired, property) } } -func validateBootDiskSize(inputs resource.PropertyMap, failures *map[string]string) { - key := "bootDiskSize" - if val := inputs[resource.PropertyKey(key)].NumberValue(); val < 1 || val > 62000 { - (*failures)[key] = fmt.Sprintf(invalidFormat, key, "should be between 1 and 62000") +func validatePropertyValueInBetween(key string, min, max float64, inputs resource.PropertyMap, failures *map[string]string) { + if val, has := inputs[resource.PropertyKey(key)]; has && val.NumberValue() < min || val.NumberValue() > max { + (*failures)[key] = fmt.Sprintf(invalidFormat, key, fmt.Sprintf("expected to be in the range (%f - %f), got %f", min, max, val.NumberValue())) } } -func validateTimeoutProperty(key string, min, max float64, inputs resource.PropertyMap, failures *map[string]string) { - if val := inputs[resource.PropertyKey(key)].NumberValue(); val < min || val > max { - (*failures)[key] = fmt.Sprintf(invalidFormat, key, fmt.Sprintf("should be between %f and %f", min, max)) +func validateCPUShares(key string, inputs resource.PropertyMap, failures *map[string]string) { + if value, has := inputs[resource.PropertyKey(key)]; has { + strVal := value.StringValue() + if _, err := strconv.Atoi(strVal); !contains([]string{"low", "normal", "high"}, strVal) || err != nil { + (*failures)[key] = fmt.Sprintf(invalidFormat, key, fmt.Sprintf("must be low/normal/high/ (%s)", err)) + } + } +} + +func validateDiskType(key string, inputs resource.PropertyMap, failures *map[string]string) { + if prop, has := inputs[resource.PropertyKey(key)]; has { + value := prop.StringValue() + if _, err := strconv.Atoi(value); !contains([]string{"thin", "zeroedthick", "eagerzeroedthick"}, value) && err != nil { + (*failures)[key] = fmt.Sprintf(invalidFormat, key, fmt.Sprintf("must be one of the thin, zeroedthick, or eagerzeroedthick (%s)", err)) + } } } @@ -189,16 +194,15 @@ func validateNetworkInterfaces(inputs resource.PropertyMap, failures *map[string } } -func validateOvfProperties(inputs resource.PropertyMap, failures *map[string]string) { - key := "ovfProperties" +func validateKeyValuePairsProperty(key string, inputs resource.PropertyMap, failures *map[string]string) { property, hasProperty := inputs[resource.PropertyKey(key)] if hasProperty && len(property.ArrayValue()) > 0 { - for i, ovfProperty := range property.ArrayValue() { - if _, has := ovfProperty.ObjectValue()["key"]; !has { + for i, item := range property.ArrayValue() { + if _, has := item.ObjectValue()["key"]; !has { itemKey := fmt.Sprintf("%s[%d].key", key, i) (*failures)[itemKey] = fmt.Sprintf(propertyRequired, itemKey) } - if _, has := ovfProperty.ObjectValue()["value"]; !has { + if _, has := item.ObjectValue()["value"]; !has { itemKey := fmt.Sprintf("%s[%d].value", key, i) (*failures)[itemKey] = fmt.Sprintf(propertyRequired, itemKey) } @@ -217,10 +221,9 @@ func validateVirtualDisks(inputs resource.PropertyMap, failures *map[string]stri } if len(property.ArrayValue()) > 0 { for i, ovfProperty := range property.ArrayValue() { - itemErrorFormat := "The property '%s' is required!" if _, has := ovfProperty.ObjectValue()["virtualDiskId"]; !has { itemKey := fmt.Sprintf("%s[%d].virtualDiskId", key, i) - (*failures)[itemKey] = fmt.Sprintf(itemErrorFormat, itemKey) + (*failures)[itemKey] = fmt.Sprintf(propertyRequired, itemKey) } if slot, has := ovfProperty.ObjectValue()["slot"]; has { check := validateVirtualDiskSlot(slot.StringValue()) @@ -233,16 +236,6 @@ func validateVirtualDisks(inputs resource.PropertyMap, failures *map[string]stri } } -func ValidateVirtualSwitch(resourceToken string, inputs resource.PropertyMap) []*pulumirpc.CheckFailure { - failures := map[string]string{} - - checkRequiredProperty("name", inputs, &failures) - validateLinkDiscoveryMode(inputs, &failures) - validateUplinks(inputs, &failures) - - return validateResource(resourceToken, failures) -} - func validateLinkDiscoveryMode(inputs resource.PropertyMap, failures *map[string]string) { key := "linkDiscoveryMode" if prop, has := inputs[resource.PropertyKey(key)]; has { @@ -269,26 +262,6 @@ func validateUplinks(inputs resource.PropertyMap, failures *map[string]string) { } } -// validateResource checks for failures and generates CheckFailure messages. -func validateResource(resourceToken string, failures map[string]string) []*pulumirpc.CheckFailure { - checkFailures := make([]*pulumirpc.CheckFailure, 0, len(failures)) - for property, reason := range failures { - path := fmt.Sprintf("%s.%s", resourceToken, property) - checkFailures = append(checkFailures, &pulumirpc.CheckFailure{Property: path, Reason: reason}) - } - return checkFailures -} - -// contains checks if an item is present in a collection. -func contains[T comparable](collection []T, value T) bool { - for _, item := range collection { - if item == value { - return true - } - } - return false -} - // validateVirtualMachineOsType checks if the OS type is valid. func validateVirtualMachineOsType(os string) bool { // All valid Guest OS's @@ -410,3 +383,23 @@ func validateVirtualDiskSlot(slot string) string { return result } + +// validateResource checks for failures and generates CheckFailure messages. +func validateResource(resourceToken string, failures map[string]string) []*pulumirpc.CheckFailure { + checkFailures := make([]*pulumirpc.CheckFailure, 0, len(failures)) + for property, reason := range failures { + path := fmt.Sprintf("%s.%s", resourceToken, property) + checkFailures = append(checkFailures, &pulumirpc.CheckFailure{Property: path, Reason: reason}) + } + return checkFailures +} + +// contains checks if an item is present in a collection. +func contains[T comparable](collection []T, value T) bool { + for _, item := range collection { + if item == value { + return true + } + } + return false +} diff --git a/sdk/dotnet/ResourcePool.cs b/sdk/dotnet/ResourcePool.cs index 1260962..91feb6a 100644 --- a/sdk/dotnet/ResourcePool.cs +++ b/sdk/dotnet/ResourcePool.cs @@ -169,6 +169,12 @@ public sealed class ResourcePoolArgs : global::Pulumi.ResourceArgs public ResourcePoolArgs() { + CpuMin = 100; + CpuMinExpandable = "true"; + CpuShares = "normal"; + MemMin = 200; + MemMinExpandable = "true"; + MemShares = "normal"; } public static new ResourcePoolArgs Empty => new ResourcePoolArgs(); } diff --git a/sdk/dotnet/VirtualMachine.cs b/sdk/dotnet/VirtualMachine.cs index aad472d..cddd994 100644 --- a/sdk/dotnet/VirtualMachine.cs +++ b/sdk/dotnet/VirtualMachine.cs @@ -212,8 +212,8 @@ public InputList Info /// /// VM memory size. /// - [Input("memSize")] - public Input? MemSize { get; set; } + [Input("memSize", required: true)] + public Input MemSize { get; set; } = null!; /// /// esxi vm name. @@ -242,14 +242,14 @@ public InputList NetworkInterfaces /// /// VM number of virtual cpus. /// - [Input("numVCpus")] - public Input? NumVCpus { get; set; } + [Input("numVCpus", required: true)] + public Input NumVCpus { get; set; } = null!; /// /// VM OS type. /// - [Input("os")] - public Input? Os { get; set; } + [Input("os", required: true)] + public Input Os { get; set; } = null!; [Input("ovfProperties")] private InputList? _ovfProperties; @@ -284,8 +284,8 @@ public InputList OvfProperties /// /// Resource pool name to place vm. /// - [Input("resourcePoolName")] - public Input? ResourcePoolName { get; set; } + [Input("resourcePoolName", required: true)] + public Input ResourcePoolName { get; set; } = null!; /// /// The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. (0-600) diff --git a/sdk/dotnet/version.txt b/sdk/dotnet/version.txt index f880671..31113bb 100644 --- a/sdk/dotnet/version.txt +++ b/sdk/dotnet/version.txt @@ -1 +1 @@ -0.0.2-alpha.1691011300+827cdc46 +0.0.2-alpha.1691017321+eb2aa746.dirty diff --git a/sdk/go/esxi/resourcePool.go b/sdk/go/esxi/resourcePool.go index 12ae546..d944b83 100644 --- a/sdk/go/esxi/resourcePool.go +++ b/sdk/go/esxi/resourcePool.go @@ -41,6 +41,24 @@ func NewResourcePool(ctx *pulumi.Context, args = &ResourcePoolArgs{} } + if args.CpuMin == nil { + args.CpuMin = pulumi.IntPtr(100) + } + if args.CpuMinExpandable == nil { + args.CpuMinExpandable = pulumi.StringPtr("true") + } + if args.CpuShares == nil { + args.CpuShares = pulumi.StringPtr("normal") + } + if args.MemMin == nil { + args.MemMin = pulumi.IntPtr(200) + } + if args.MemMinExpandable == nil { + args.MemMinExpandable = pulumi.StringPtr("true") + } + if args.MemShares == nil { + args.MemShares = pulumi.StringPtr("normal") + } opts = internal.PkgResourceDefaultOpts(opts) var resource ResourcePool err := ctx.RegisterResource("esxi-native:index:ResourcePool", name, args, &resource, opts...) diff --git a/sdk/go/esxi/virtualMachine.go b/sdk/go/esxi/virtualMachine.go index 33fd1d7..bab4a60 100644 --- a/sdk/go/esxi/virtualMachine.go +++ b/sdk/go/esxi/virtualMachine.go @@ -73,19 +73,19 @@ func NewVirtualMachine(ctx *pulumi.Context, args.BootFirmware = BootFirmwareType("bios") } if args.MemSize == nil { - args.MemSize = pulumi.IntPtr(512) + args.MemSize = pulumi.Int(512) } if args.NumVCpus == nil { - args.NumVCpus = pulumi.IntPtr(1) + args.NumVCpus = pulumi.Int(1) } if args.Os == nil { - args.Os = pulumi.StringPtr("centos") + args.Os = pulumi.String("centos") } if args.OvfPropertiesTimer == nil { args.OvfPropertiesTimer = pulumi.IntPtr(6000) } if args.ResourcePoolName == nil { - args.ResourcePoolName = pulumi.StringPtr("/") + args.ResourcePoolName = pulumi.String("/") } if args.ShutdownTimeout == nil { args.ShutdownTimeout = pulumi.IntPtr(600) @@ -142,7 +142,7 @@ type virtualMachineArgs struct { // pass data to VM Info []KeyValuePair `pulumi:"info"` // VM memory size. - MemSize *int `pulumi:"memSize"` + MemSize int `pulumi:"memSize"` // esxi vm name. Name *string `pulumi:"name"` // VM network interfaces. @@ -150,9 +150,9 @@ type virtualMachineArgs struct { // VM memory size. Notes *string `pulumi:"notes"` // VM number of virtual cpus. - NumVCpus *int `pulumi:"numVCpus"` + NumVCpus int `pulumi:"numVCpus"` // VM OS type. - Os *string `pulumi:"os"` + Os string `pulumi:"os"` // VM OVF properties. OvfProperties []KeyValuePair `pulumi:"ovfProperties"` // The amount of time, in seconds, to wait for the guest to boot and run ovfProperties. (0-6000) @@ -162,7 +162,7 @@ type virtualMachineArgs struct { // VM power state. Power *string `pulumi:"power"` // Resource pool name to place vm. - ResourcePoolName *string `pulumi:"resourcePoolName"` + ResourcePoolName string `pulumi:"resourcePoolName"` // The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. (0-600) ShutdownTimeout *int `pulumi:"shutdownTimeout"` // The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. (0-600) @@ -188,7 +188,7 @@ type VirtualMachineArgs struct { // pass data to VM Info KeyValuePairArrayInput // VM memory size. - MemSize pulumi.IntPtrInput + MemSize pulumi.IntInput // esxi vm name. Name pulumi.StringPtrInput // VM network interfaces. @@ -196,9 +196,9 @@ type VirtualMachineArgs struct { // VM memory size. Notes pulumi.StringPtrInput // VM number of virtual cpus. - NumVCpus pulumi.IntPtrInput + NumVCpus pulumi.IntInput // VM OS type. - Os pulumi.StringPtrInput + Os pulumi.StringInput // VM OVF properties. OvfProperties KeyValuePairArrayInput // The amount of time, in seconds, to wait for the guest to boot and run ovfProperties. (0-6000) @@ -208,7 +208,7 @@ type VirtualMachineArgs struct { // VM power state. Power pulumi.StringPtrInput // Resource pool name to place vm. - ResourcePoolName pulumi.StringPtrInput + ResourcePoolName pulumi.StringInput // The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. (0-600) ShutdownTimeout pulumi.IntPtrInput // The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. (0-600) diff --git a/sdk/nodejs/resourcePool.ts b/sdk/nodejs/resourcePool.ts index 2cb1b82..ae0902b 100644 --- a/sdk/nodejs/resourcePool.ts +++ b/sdk/nodejs/resourcePool.ts @@ -80,13 +80,13 @@ export class ResourcePool extends pulumi.CustomResource { opts = opts || {}; if (!opts.id) { resourceInputs["cpuMax"] = args ? args.cpuMax : undefined; - resourceInputs["cpuMin"] = args ? args.cpuMin : undefined; - resourceInputs["cpuMinExpandable"] = args ? args.cpuMinExpandable : undefined; - resourceInputs["cpuShares"] = args ? args.cpuShares : undefined; + resourceInputs["cpuMin"] = (args ? args.cpuMin : undefined) ?? 100; + resourceInputs["cpuMinExpandable"] = (args ? args.cpuMinExpandable : undefined) ?? "true"; + resourceInputs["cpuShares"] = (args ? args.cpuShares : undefined) ?? "normal"; resourceInputs["memMax"] = args ? args.memMax : undefined; - resourceInputs["memMin"] = args ? args.memMin : undefined; - resourceInputs["memMinExpandable"] = args ? args.memMinExpandable : undefined; - resourceInputs["memShares"] = args ? args.memShares : undefined; + resourceInputs["memMin"] = (args ? args.memMin : undefined) ?? 200; + resourceInputs["memMinExpandable"] = (args ? args.memMinExpandable : undefined) ?? "true"; + resourceInputs["memShares"] = (args ? args.memShares : undefined) ?? "normal"; resourceInputs["name"] = args ? args.name : undefined; } else { resourceInputs["cpuMax"] = undefined /*out*/; diff --git a/sdk/nodejs/virtualMachine.ts b/sdk/nodejs/virtualMachine.ts index 74dd32b..3fcf542 100644 --- a/sdk/nodejs/virtualMachine.ts +++ b/sdk/nodejs/virtualMachine.ts @@ -121,6 +121,18 @@ export class VirtualMachine extends pulumi.CustomResource { if ((!args || args.diskStore === undefined) && !opts.urn) { throw new Error("Missing required property 'diskStore'"); } + if ((!args || args.memSize === undefined) && !opts.urn) { + throw new Error("Missing required property 'memSize'"); + } + if ((!args || args.numVCpus === undefined) && !opts.urn) { + throw new Error("Missing required property 'numVCpus'"); + } + if ((!args || args.os === undefined) && !opts.urn) { + throw new Error("Missing required property 'os'"); + } + if ((!args || args.resourcePoolName === undefined) && !opts.urn) { + throw new Error("Missing required property 'resourcePoolName'"); + } resourceInputs["bootDiskSize"] = (args ? args.bootDiskSize : undefined) ?? 16; resourceInputs["bootDiskType"] = (args ? args.bootDiskType : undefined) ?? "thin"; resourceInputs["bootFirmware"] = (args ? args.bootFirmware : undefined) ?? "bios"; @@ -199,7 +211,7 @@ export interface VirtualMachineArgs { /** * VM memory size. */ - memSize?: pulumi.Input; + memSize: pulumi.Input; /** * esxi vm name. */ @@ -215,11 +227,11 @@ export interface VirtualMachineArgs { /** * VM number of virtual cpus. */ - numVCpus?: pulumi.Input; + numVCpus: pulumi.Input; /** * VM OS type. */ - os?: pulumi.Input; + os: pulumi.Input; /** * VM OVF properties. */ @@ -239,7 +251,7 @@ export interface VirtualMachineArgs { /** * Resource pool name to place vm. */ - resourcePoolName?: pulumi.Input; + resourcePoolName: pulumi.Input; /** * The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. (0-600) */ diff --git a/sdk/python/pulumiverse_pulumi-esxi-native/resource_pool.py b/sdk/python/pulumiverse_pulumi-esxi-native/resource_pool.py index 0ffb86f..8b7b9d9 100644 --- a/sdk/python/pulumiverse_pulumi-esxi-native/resource_pool.py +++ b/sdk/python/pulumiverse_pulumi-esxi-native/resource_pool.py @@ -37,18 +37,30 @@ def __init__(__self__, *, """ if cpu_max is not None: pulumi.set(__self__, "cpu_max", cpu_max) + if cpu_min is None: + cpu_min = 100 if cpu_min is not None: pulumi.set(__self__, "cpu_min", cpu_min) + if cpu_min_expandable is None: + cpu_min_expandable = 'true' if cpu_min_expandable is not None: pulumi.set(__self__, "cpu_min_expandable", cpu_min_expandable) + if cpu_shares is None: + cpu_shares = 'normal' if cpu_shares is not None: pulumi.set(__self__, "cpu_shares", cpu_shares) if mem_max is not None: pulumi.set(__self__, "mem_max", mem_max) + if mem_min is None: + mem_min = 200 if mem_min is not None: pulumi.set(__self__, "mem_min", mem_min) + if mem_min_expandable is None: + mem_min_expandable = 'true' if mem_min_expandable is not None: pulumi.set(__self__, "mem_min_expandable", mem_min_expandable) + if mem_shares is None: + mem_shares = 'normal' if mem_shares is not None: pulumi.set(__self__, "mem_shares", mem_shares) if name is not None: @@ -234,12 +246,24 @@ def _internal_init(__self__, __props__ = ResourcePoolArgs.__new__(ResourcePoolArgs) __props__.__dict__["cpu_max"] = cpu_max + if cpu_min is None: + cpu_min = 100 __props__.__dict__["cpu_min"] = cpu_min + if cpu_min_expandable is None: + cpu_min_expandable = 'true' __props__.__dict__["cpu_min_expandable"] = cpu_min_expandable + if cpu_shares is None: + cpu_shares = 'normal' __props__.__dict__["cpu_shares"] = cpu_shares __props__.__dict__["mem_max"] = mem_max + if mem_min is None: + mem_min = 200 __props__.__dict__["mem_min"] = mem_min + if mem_min_expandable is None: + mem_min_expandable = 'true' __props__.__dict__["mem_min_expandable"] = mem_min_expandable + if mem_shares is None: + mem_shares = 'normal' __props__.__dict__["mem_shares"] = mem_shares __props__.__dict__["name"] = name super(ResourcePool, __self__).__init__( diff --git a/sdk/python/pulumiverse_pulumi-esxi-native/virtual_machine.py b/sdk/python/pulumiverse_pulumi-esxi-native/virtual_machine.py index 59b5167..027a296 100644 --- a/sdk/python/pulumiverse_pulumi-esxi-native/virtual_machine.py +++ b/sdk/python/pulumiverse_pulumi-esxi-native/virtual_machine.py @@ -18,22 +18,22 @@ class VirtualMachineArgs: def __init__(__self__, *, disk_store: pulumi.Input[str], + mem_size: pulumi.Input[int], + num_v_cpus: pulumi.Input[int], + os: pulumi.Input[str], + resource_pool_name: pulumi.Input[str], boot_disk_size: Optional[pulumi.Input[int]] = None, boot_disk_type: Optional[pulumi.Input['DiskType']] = None, boot_firmware: Optional[pulumi.Input['BootFirmwareType']] = None, clone_from_virtual_machine: Optional[pulumi.Input[str]] = None, info: Optional[pulumi.Input[Sequence[pulumi.Input['KeyValuePairArgs']]]] = None, - mem_size: Optional[pulumi.Input[int]] = None, name: Optional[pulumi.Input[str]] = None, network_interfaces: Optional[pulumi.Input[Sequence[pulumi.Input['NetworkInterfaceArgs']]]] = None, notes: Optional[pulumi.Input[str]] = None, - num_v_cpus: Optional[pulumi.Input[int]] = None, - os: Optional[pulumi.Input[str]] = None, ovf_properties: Optional[pulumi.Input[Sequence[pulumi.Input['KeyValuePairArgs']]]] = None, ovf_properties_timer: Optional[pulumi.Input[int]] = None, ovf_source: Optional[pulumi.Input[str]] = None, power: Optional[pulumi.Input[str]] = None, - resource_pool_name: Optional[pulumi.Input[str]] = None, shutdown_timeout: Optional[pulumi.Input[int]] = None, startup_timeout: Optional[pulumi.Input[int]] = None, virtual_disks: Optional[pulumi.Input[Sequence[pulumi.Input['VMVirtualDiskArgs']]]] = None, @@ -41,28 +41,40 @@ def __init__(__self__, *, """ The set of arguments for constructing a VirtualMachine resource. :param pulumi.Input[str] disk_store: esxi diskstore for boot disk. + :param pulumi.Input[int] mem_size: VM memory size. + :param pulumi.Input[int] num_v_cpus: VM number of virtual cpus. + :param pulumi.Input[str] os: VM OS type. + :param pulumi.Input[str] resource_pool_name: Resource pool name to place vm. :param pulumi.Input[int] boot_disk_size: VM boot disk size. Will expand boot disk to this size. :param pulumi.Input['DiskType'] boot_disk_type: VM boot disk type. thin, zeroedthick, eagerzeroedthick :param pulumi.Input['BootFirmwareType'] boot_firmware: Boot type('efi' is boot uefi mode) :param pulumi.Input[str] clone_from_virtual_machine: Source vm path on esxi host to clone. :param pulumi.Input[Sequence[pulumi.Input['KeyValuePairArgs']]] info: pass data to VM - :param pulumi.Input[int] mem_size: VM memory size. :param pulumi.Input[str] name: esxi vm name. :param pulumi.Input[Sequence[pulumi.Input['NetworkInterfaceArgs']]] network_interfaces: VM network interfaces. :param pulumi.Input[str] notes: VM memory size. - :param pulumi.Input[int] num_v_cpus: VM number of virtual cpus. - :param pulumi.Input[str] os: VM OS type. :param pulumi.Input[Sequence[pulumi.Input['KeyValuePairArgs']]] ovf_properties: VM OVF properties. :param pulumi.Input[int] ovf_properties_timer: The amount of time, in seconds, to wait for the guest to boot and run ovfProperties. (0-6000) :param pulumi.Input[str] ovf_source: Path or URL of ovf file source. :param pulumi.Input[str] power: VM power state. - :param pulumi.Input[str] resource_pool_name: Resource pool name to place vm. :param pulumi.Input[int] shutdown_timeout: The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. (0-600) :param pulumi.Input[int] startup_timeout: The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. (0-600) :param pulumi.Input[Sequence[pulumi.Input['VMVirtualDiskArgs']]] virtual_disks: VM virtual disks. :param pulumi.Input[int] virtual_hw_ver: VM Virtual HW version. """ pulumi.set(__self__, "disk_store", disk_store) + if mem_size is None: + mem_size = 512 + pulumi.set(__self__, "mem_size", mem_size) + if num_v_cpus is None: + num_v_cpus = 1 + pulumi.set(__self__, "num_v_cpus", num_v_cpus) + if os is None: + os = 'centos' + pulumi.set(__self__, "os", os) + if resource_pool_name is None: + resource_pool_name = '/' + pulumi.set(__self__, "resource_pool_name", resource_pool_name) if boot_disk_size is None: boot_disk_size = 16 if boot_disk_size is not None: @@ -79,24 +91,12 @@ def __init__(__self__, *, pulumi.set(__self__, "clone_from_virtual_machine", clone_from_virtual_machine) if info is not None: pulumi.set(__self__, "info", info) - if mem_size is None: - mem_size = 512 - if mem_size is not None: - pulumi.set(__self__, "mem_size", mem_size) if name is not None: pulumi.set(__self__, "name", name) if network_interfaces is not None: pulumi.set(__self__, "network_interfaces", network_interfaces) if notes is not None: pulumi.set(__self__, "notes", notes) - if num_v_cpus is None: - num_v_cpus = 1 - if num_v_cpus is not None: - pulumi.set(__self__, "num_v_cpus", num_v_cpus) - if os is None: - os = 'centos' - if os is not None: - pulumi.set(__self__, "os", os) if ovf_properties is not None: pulumi.set(__self__, "ovf_properties", ovf_properties) if ovf_properties_timer is None: @@ -107,10 +107,6 @@ def __init__(__self__, *, pulumi.set(__self__, "ovf_source", ovf_source) if power is not None: pulumi.set(__self__, "power", power) - if resource_pool_name is None: - resource_pool_name = '/' - if resource_pool_name is not None: - pulumi.set(__self__, "resource_pool_name", resource_pool_name) if shutdown_timeout is None: shutdown_timeout = 600 if shutdown_timeout is not None: @@ -138,6 +134,54 @@ def disk_store(self) -> pulumi.Input[str]: def disk_store(self, value: pulumi.Input[str]): pulumi.set(self, "disk_store", value) + @property + @pulumi.getter(name="memSize") + def mem_size(self) -> pulumi.Input[int]: + """ + VM memory size. + """ + return pulumi.get(self, "mem_size") + + @mem_size.setter + def mem_size(self, value: pulumi.Input[int]): + pulumi.set(self, "mem_size", value) + + @property + @pulumi.getter(name="numVCpus") + def num_v_cpus(self) -> pulumi.Input[int]: + """ + VM number of virtual cpus. + """ + return pulumi.get(self, "num_v_cpus") + + @num_v_cpus.setter + def num_v_cpus(self, value: pulumi.Input[int]): + pulumi.set(self, "num_v_cpus", value) + + @property + @pulumi.getter + def os(self) -> pulumi.Input[str]: + """ + VM OS type. + """ + return pulumi.get(self, "os") + + @os.setter + def os(self, value: pulumi.Input[str]): + pulumi.set(self, "os", value) + + @property + @pulumi.getter(name="resourcePoolName") + def resource_pool_name(self) -> pulumi.Input[str]: + """ + Resource pool name to place vm. + """ + return pulumi.get(self, "resource_pool_name") + + @resource_pool_name.setter + def resource_pool_name(self, value: pulumi.Input[str]): + pulumi.set(self, "resource_pool_name", value) + @property @pulumi.getter(name="bootDiskSize") def boot_disk_size(self) -> Optional[pulumi.Input[int]]: @@ -198,18 +242,6 @@ def info(self) -> Optional[pulumi.Input[Sequence[pulumi.Input['KeyValuePairArgs' def info(self, value: Optional[pulumi.Input[Sequence[pulumi.Input['KeyValuePairArgs']]]]): pulumi.set(self, "info", value) - @property - @pulumi.getter(name="memSize") - def mem_size(self) -> Optional[pulumi.Input[int]]: - """ - VM memory size. - """ - return pulumi.get(self, "mem_size") - - @mem_size.setter - def mem_size(self, value: Optional[pulumi.Input[int]]): - pulumi.set(self, "mem_size", value) - @property @pulumi.getter def name(self) -> Optional[pulumi.Input[str]]: @@ -246,30 +278,6 @@ def notes(self) -> Optional[pulumi.Input[str]]: def notes(self, value: Optional[pulumi.Input[str]]): pulumi.set(self, "notes", value) - @property - @pulumi.getter(name="numVCpus") - def num_v_cpus(self) -> Optional[pulumi.Input[int]]: - """ - VM number of virtual cpus. - """ - return pulumi.get(self, "num_v_cpus") - - @num_v_cpus.setter - def num_v_cpus(self, value: Optional[pulumi.Input[int]]): - pulumi.set(self, "num_v_cpus", value) - - @property - @pulumi.getter - def os(self) -> Optional[pulumi.Input[str]]: - """ - VM OS type. - """ - return pulumi.get(self, "os") - - @os.setter - def os(self, value: Optional[pulumi.Input[str]]): - pulumi.set(self, "os", value) - @property @pulumi.getter(name="ovfProperties") def ovf_properties(self) -> Optional[pulumi.Input[Sequence[pulumi.Input['KeyValuePairArgs']]]]: @@ -318,18 +326,6 @@ def power(self) -> Optional[pulumi.Input[str]]: def power(self, value: Optional[pulumi.Input[str]]): pulumi.set(self, "power", value) - @property - @pulumi.getter(name="resourcePoolName") - def resource_pool_name(self) -> Optional[pulumi.Input[str]]: - """ - Resource pool name to place vm. - """ - return pulumi.get(self, "resource_pool_name") - - @resource_pool_name.setter - def resource_pool_name(self, value: Optional[pulumi.Input[str]]): - pulumi.set(self, "resource_pool_name", value) - @property @pulumi.getter(name="shutdownTimeout") def shutdown_timeout(self) -> Optional[pulumi.Input[int]]: @@ -501,15 +497,21 @@ def _internal_init(__self__, __props__.__dict__["info"] = info if mem_size is None: mem_size = 512 + if mem_size is None and not opts.urn: + raise TypeError("Missing required property 'mem_size'") __props__.__dict__["mem_size"] = mem_size __props__.__dict__["name"] = name __props__.__dict__["network_interfaces"] = network_interfaces __props__.__dict__["notes"] = notes if num_v_cpus is None: num_v_cpus = 1 + if num_v_cpus is None and not opts.urn: + raise TypeError("Missing required property 'num_v_cpus'") __props__.__dict__["num_v_cpus"] = num_v_cpus if os is None: os = 'centos' + if os is None and not opts.urn: + raise TypeError("Missing required property 'os'") __props__.__dict__["os"] = os __props__.__dict__["ovf_properties"] = ovf_properties if ovf_properties_timer is None: @@ -519,6 +521,8 @@ def _internal_init(__self__, __props__.__dict__["power"] = power if resource_pool_name is None: resource_pool_name = '/' + if resource_pool_name is None and not opts.urn: + raise TypeError("Missing required property 'resource_pool_name'") __props__.__dict__["resource_pool_name"] = resource_pool_name if shutdown_timeout is None: shutdown_timeout = 600