diff --git a/provider/cmd/pulumi-resource-esxi-native/schema.json b/provider/cmd/pulumi-resource-esxi-native/schema.json index c73644f..bf82c29 100644 --- a/provider/cmd/pulumi-resource-esxi-native/schema.json +++ b/provider/cmd/pulumi-resource-esxi-native/schema.json @@ -814,6 +814,112 @@ } } } + }, + "esxi-native:index:getVirtualMachineById": { + "inputs": { + "properties": { + "id": { + "type": "string", + "description": "Virtual Machine Id to get details of" + } + }, + "required": [ + "id" + ] + }, + "outputs": { + "properties": { + "id": { + "type": "string", + "description": "esxi vm id." + }, + "name": { + "type": "string", + "description": "esxi vm name." + }, + "bootFirmware": { + "type": "string", + "$ref": "#/types/esxi-native:index:BootFirmwareType", + "description": "Boot type('efi' is boot uefi mode)" + }, + "diskStore": { + "type": "string", + "description": "esxi diskstore for boot disk." + }, + "resourcePoolName": { + "type": "string", + "description": "Resource pool name to place vm." + }, + "bootDiskSize": { + "type": "string", + "description": "VM boot disk size. Will expand boot disk to this size." + }, + "bootDiskType": { + "type": "string", + "$ref": "#/types/esxi-native:index:DiskType", + "description": "VM boot disk type. thin, zeroedthick, eagerzeroedthick" + }, + "memSize": { + "type": "string", + "description": "VM memory size." + }, + "numVCpus": { + "type": "string", + "description": "VM number of virtual cpus." + }, + "virtualHWVer": { + "type": "string", + "description": "VM Virtual HW version." + }, + "os": { + "type": "string", + "description": "VM OS type." + }, + "networkInterfaces": { + "type": "array", + "description": "VM network interfaces.", + "items": { + "$ref": "#/types/esxi-native:index:NetworkInterface" + } + }, + "power": { + "type": "string", + "description": "VM power state." + }, + "ipAddress": { + "type": "string", + "description": "The IP address reported by VMWare tools." + }, + "startupTimeout": { + "type": "integer", + "description": "The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine.", + "default": 600 + }, + "shutdownTimeout": { + "type": "integer", + "description": "The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine.", + "default": 600 + }, + "virtualDisks": { + "type": "array", + "description": "VM virtual disks.", + "items": { + "$ref": "#/types/esxi-native:index:VMVirtualDisk" + } + }, + "notes": { + "type": "string", + "description": "VM memory size." + }, + "info": { + "type": "array", + "description": "pass data to VM", + "items": { + "$ref": "#/types/esxi-native:index:KeyValuePair" + } + } + } + } } }, "language": { diff --git a/provider/pkg/esxi/mapUtils.go b/provider/pkg/esxi/mapUtils.go index d34ba03..7caa28a 100644 --- a/provider/pkg/esxi/mapUtils.go +++ b/provider/pkg/esxi/mapUtils.go @@ -15,7 +15,7 @@ func (vm *VirtualMachine) toMap(keepId ...bool) map[string]interface{} { delete(outputs, "ovfProperties") delete(outputs, "ovfPropertiesTimer") - if vm.BootDiskType == "Unknown" || vm.BootDiskType == "" { + if vm.BootDiskType == "Unknown" || len(vm.BootDiskType) == 0 { delete(outputs, "bootDiskType") } @@ -24,12 +24,12 @@ func (vm *VirtualMachine) toMap(keepId ...bool) map[string]interface{} { } // Do network interfaces - if len(vm.NetworkInterfaces) == 0 || vm.NetworkInterfaces[0].VirtualNetwork == "" { + if len(vm.NetworkInterfaces) == 0 || len(vm.NetworkInterfaces[0].VirtualNetwork) == 0 { delete(outputs, "networkInterfaces") } // Do virtual disks - if len(vm.VirtualDisks) == 0 || vm.VirtualDisks[0].VirtualDiskId == "" { + if len(vm.VirtualDisks) == 0 || len(vm.VirtualDisks[0].VirtualDiskId) == 0 { delete(outputs, "virtualDisks") } diff --git a/provider/pkg/esxi/resourceService.go b/provider/pkg/esxi/resourceService.go index 1ef5d26..1f7aa78 100644 --- a/provider/pkg/esxi/resourceService.go +++ b/provider/pkg/esxi/resourceService.go @@ -36,6 +36,7 @@ func NewResourceService() *ResourceService { "esxi-native:index:VirtualMachine:Delete": functionMapper{VirtualMachineDeleteParser, VirtualMachineDelete}, "esxi-native:index:VirtualMachine:Read": functionMapper{VirtualMachineReadParser, VirtualMachineRead}, "esxi-native:index:getVirtualMachine": functionMapper{VirtualMachineGetParser, VirtualMachineGet}, + "esxi-native:index:getVirtualMachineById": functionMapper{VirtualMachineGetByIdParser, VirtualMachineGetById}, "esxi-native:index:VirtualSwitch:Create": functionMapper{VirtualSwitchCreateParser, VirtualSwitchCreate}, "esxi-native:index:VirtualSwitch:Update": functionMapper{VirtualSwitchUpdateParser, VirtualSwitchUpdate}, "esxi-native:index:VirtualSwitch:Delete": functionMapper{VirtualSwitchDeleteParser, VirtualSwitchDelete}, @@ -44,45 +45,53 @@ func NewResourceService() *ResourceService { } } -func (receiver *ResourceService) Create(token string, inputs resource.PropertyMap, esxi *Host) (rId string, result resource.PropertyMap, err error) { +func (receiver *ResourceService) Create(token string, inputs resource.PropertyMap, esxi *Host) (string, resource.PropertyMap, error) { token = fmt.Sprintf("%s:Create", token) return receiver.call(token, "", inputs, esxi) } -func (receiver *ResourceService) Update(token string, id string, inputs resource.PropertyMap, esxi *Host) (rId string, result resource.PropertyMap, err error) { +func (receiver *ResourceService) Update(token string, id string, inputs resource.PropertyMap, esxi *Host) (string, resource.PropertyMap, error) { token = fmt.Sprintf("%s:Update", token) return receiver.call(token, id, inputs, esxi) } -func (receiver *ResourceService) Delete(token string, id string, inputs resource.PropertyMap, esxi *Host) (rId string, result resource.PropertyMap, err error) { +func (receiver *ResourceService) Delete(token string, id string, inputs resource.PropertyMap, esxi *Host) (string, resource.PropertyMap, error) { token = fmt.Sprintf("%s:Delete", token) return receiver.call(token, id, inputs, esxi) } -func (receiver *ResourceService) Read(token string, id string, inputs resource.PropertyMap, esxi *Host) (rId string, result resource.PropertyMap, err error) { +func (receiver *ResourceService) Read(token string, id string, inputs resource.PropertyMap, esxi *Host) (string, resource.PropertyMap, error) { token = fmt.Sprintf("%s:Read", token) return receiver.call(token, id, inputs, esxi) } -func (receiver *ResourceService) Invoke(token string, inputs resource.PropertyMap, esxi *Host) (result resource.PropertyMap, err error) { - mapper := receiver.functions[token] +func (receiver *ResourceService) Invoke(token string, inputs resource.PropertyMap, esxi *Host) (resource.PropertyMap, error) { + mapper, ok := receiver.functions[token] + if !ok { + return nil, fmt.Errorf("unknown function '%s'", token) + } params := mapper.getParams("", inputs, esxi) functionHandler := reflect.ValueOf(mapper.handler) - var res []reflect.Value - res = functionHandler.Call(params) - result = res[0].Interface().(resource.PropertyMap) - return + var functionResult []reflect.Value + functionResult = functionHandler.Call(params) + result := functionResult[0].Interface().(resource.PropertyMap) + err := functionResult[1].Interface().(error) + return result, err } -func (receiver *ResourceService) call(token string, id string, inputs resource.PropertyMap, esxi *Host) (rId string, result resource.PropertyMap, err error) { - mapper := receiver.functions[token] +func (receiver *ResourceService) call(token string, id string, inputs resource.PropertyMap, esxi *Host) (string, resource.PropertyMap, error) { + mapper, ok := receiver.functions[token] + if !ok { + return "", nil, fmt.Errorf("unknown operation '%s'", token) + } params := mapper.getParams(id, inputs, esxi) functionHandler := reflect.ValueOf(mapper.handler) - var res []reflect.Value - res = functionHandler.Call(params) - rId = res[0].Interface().(string) - result = res[1].Interface().(resource.PropertyMap) - return + var functionResult []reflect.Value + functionResult = functionHandler.Call(params) + resourceId := functionResult[0].Interface().(string) + resourceData := functionResult[1].Interface().(resource.PropertyMap) + err := functionResult[2].Interface().(error) + return resourceId, resourceData, err } func (m *functionMapper) getParams(id string, inputs resource.PropertyMap, esxi *Host) []reflect.Value { diff --git a/provider/pkg/esxi/virtualMachineGet.go b/provider/pkg/esxi/virtualMachineGet.go index a83571f..34fe78e 100644 --- a/provider/pkg/esxi/virtualMachineGet.go +++ b/provider/pkg/esxi/virtualMachineGet.go @@ -1,6 +1,7 @@ package esxi import ( + "fmt" "github.com/pulumi/pulumi/sdk/v3/go/common/resource" ) @@ -9,17 +10,28 @@ func VirtualMachineGetParser(inputs resource.PropertyMap) string { } func VirtualMachineGet(name string, esxi *Host) (resource.PropertyMap, error) { - id, _ := esxi.getVirtualMachineId(name) + id, err := esxi.getVirtualMachineId(name) + if err != nil { + return nil, fmt.Errorf("unable to find a virtual machine corresponding to the name '%s'", name) + } + + return VirtualMachineGetById(id, esxi) +} + +func VirtualMachineGetByIdParser(inputs resource.PropertyMap) string { + return inputs["id"].StringValue() +} - vm, err := esxi.readVirtualMachine(VirtualMachine{ +func VirtualMachineGetById(id string, esxi *Host) (resource.PropertyMap, error) { + vm := esxi.readVirtualMachine(VirtualMachine{ Id: id, StartupTimeout: 1, }) - if err != nil || vm.Name == "" { - return nil, err + if len(vm.Name) == 0 { + return nil, fmt.Errorf("unable to find a virtual machine corresponding to the id '%s'", vm.Id) } result := vm.toMap(true) - return resource.NewPropertyMapFromMap(result), err + return resource.NewPropertyMapFromMap(result), nil } diff --git a/provider/pkg/esxi/virtualMachineRead.go b/provider/pkg/esxi/virtualMachineRead.go index ac1d3ef..6e7732a 100644 --- a/provider/pkg/esxi/virtualMachineRead.go +++ b/provider/pkg/esxi/virtualMachineRead.go @@ -21,17 +21,17 @@ func VirtualMachineReadParser(id string, inputs resource.PropertyMap) VirtualMac func VirtualMachineRead(vm VirtualMachine, esxi *Host) (string, resource.PropertyMap, error) { // read vm - vm, err := esxi.readVirtualMachine(vm) + vm = esxi.readVirtualMachine(vm) - if err != nil || vm.Name == "" { - return "", nil, err + if len(vm.Name) == 0 { + return "", nil, fmt.Errorf("unable to find a virtual machine corresponding to the id '%s'", vm.Id) } result := vm.toMap() - return vm.Id, resource.NewPropertyMapFromMap(result), err + return vm.Id, resource.NewPropertyMapFromMap(result), nil } -func (esxi *Host) readVirtualMachine(vm VirtualMachine) (VirtualMachine, error) { +func (esxi *Host) readVirtualMachine(vm VirtualMachine) VirtualMachine { command := fmt.Sprintf("vim-cmd vmsvc/get.summary %s", vm.Id) stdout, err := esxi.Execute(command, "Get Guest summary") @@ -54,7 +54,7 @@ func (esxi *Host) readVirtualMachine(vm VirtualMachine) (VirtualMachine, error) vm.Notes = "" vm.Info = nil - return vm, nil + return vm } r, _ := regexp.Compile("") @@ -261,5 +261,5 @@ func (esxi *Host) readVirtualMachine(vm VirtualMachine) (VirtualMachine, error) i++ } - return vm, nil + return vm } diff --git a/provider/pkg/esxi/virtualMacineUtils.go b/provider/pkg/esxi/virtualMacineUtils.go index 8189e48..7420318 100644 --- a/provider/pkg/esxi/virtualMacineUtils.go +++ b/provider/pkg/esxi/virtualMacineUtils.go @@ -235,7 +235,7 @@ func (esxi *Host) updateVmxContents(isNew bool, vm VirtualMachine) error { for i, ni := range vm.NetworkInterfaces { logging.V(9).Infof("updateVmxContents: ethernet%d", i) - if ni.VirtualNetwork == "" && strings.Contains(vmxContents, "ethernet"+strconv.Itoa(i)) == true { + if len(ni.VirtualNetwork) == 0 && strings.Contains(vmxContents, "ethernet"+strconv.Itoa(i)) == true { // This is Modify (Delete existing network configuration) logging.V(9).Infof("updateVmxContents: Modify ethernet%d - Delete existing.", i) regexReplacement = fmt.Sprintf("") @@ -293,7 +293,7 @@ func (esxi *Host) updateVmxContents(isNew bool, vm VirtualMachine) error { } // Set network type - if ni.NicType == "" { + if len(ni.NicType) == 0 { networkType = defaultNetworkType } else { networkType = ni.NicType diff --git a/provider/pkg/esxi/virtualSwitchCreate.go b/provider/pkg/esxi/virtualSwitchCreate.go index 1e9b111..f938a7a 100644 --- a/provider/pkg/esxi/virtualSwitchCreate.go +++ b/provider/pkg/esxi/virtualSwitchCreate.go @@ -37,7 +37,7 @@ func VirtualSwitchCreate(inputs resource.PropertyMap, esxi *Host) (resource.Prop // mtu = 1500 //} // - //if linkDiscoveryMode == "" { + //if len(linkDiscoveryMode) == 0 { // linkDiscoveryMode = "listen" //} // diff --git a/provider/pkg/provider/provider.go b/provider/pkg/provider/provider.go index 0d8439a..667e89a 100644 --- a/provider/pkg/provider/provider.go +++ b/provider/pkg/provider/provider.go @@ -279,7 +279,7 @@ func (p *esxiProvider) Create(ctx context.Context, req *pulumirpc.CreateRequest) // Process Create call. var result resource.PropertyMap id, result, err := p.resourceService.Create(token, inputs, p.esxi) - if err != nil || len(id) == 0 || result == nil { + if err != nil { return nil, err } diff --git a/sdk/dotnet/GetVirtualMachineById.cs b/sdk/dotnet/GetVirtualMachineById.cs new file mode 100644 index 0000000..91c60fe --- /dev/null +++ b/sdk/dotnet/GetVirtualMachineById.cs @@ -0,0 +1,190 @@ +// *** WARNING: this file was generated by pulumigen. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Threading.Tasks; +using Pulumi.Serialization; + +namespace Pulumi.EsxiNative +{ + public static class GetVirtualMachineById + { + public static Task InvokeAsync(GetVirtualMachineByIdArgs args, InvokeOptions? options = null) + => Pulumi.Deployment.Instance.InvokeAsync("esxi-native:index:getVirtualMachineById", args ?? new GetVirtualMachineByIdArgs(), options.WithDefaults()); + + public static Output Invoke(GetVirtualMachineByIdInvokeArgs args, InvokeOptions? options = null) + => Pulumi.Deployment.Instance.Invoke("esxi-native:index:getVirtualMachineById", args ?? new GetVirtualMachineByIdInvokeArgs(), options.WithDefaults()); + } + + + public sealed class GetVirtualMachineByIdArgs : Pulumi.InvokeArgs + { + /// + /// Virtual Machine Id to get details of + /// + [Input("id", required: true)] + public string Id { get; set; } = null!; + + public GetVirtualMachineByIdArgs() + { + } + } + + public sealed class GetVirtualMachineByIdInvokeArgs : Pulumi.InvokeArgs + { + /// + /// Virtual Machine Id to get details of + /// + [Input("id", required: true)] + public Input Id { get; set; } = null!; + + public GetVirtualMachineByIdInvokeArgs() + { + } + } + + + [OutputType] + public sealed class GetVirtualMachineByIdResult + { + /// + /// VM boot disk size. Will expand boot disk to this size. + /// + public readonly string? BootDiskSize; + /// + /// VM boot disk type. thin, zeroedthick, eagerzeroedthick + /// + public readonly Pulumi.EsxiNative.DiskType? BootDiskType; + /// + /// Boot type('efi' is boot uefi mode) + /// + public readonly Pulumi.EsxiNative.BootFirmwareType? BootFirmware; + /// + /// esxi diskstore for boot disk. + /// + public readonly string? DiskStore; + /// + /// esxi vm id. + /// + public readonly string? Id; + /// + /// pass data to VM + /// + public readonly ImmutableArray Info; + /// + /// The IP address reported by VMWare tools. + /// + public readonly string? IpAddress; + /// + /// VM memory size. + /// + public readonly string? MemSize; + /// + /// esxi vm name. + /// + public readonly string? Name; + /// + /// VM network interfaces. + /// + public readonly ImmutableArray NetworkInterfaces; + /// + /// VM memory size. + /// + public readonly string? Notes; + /// + /// VM number of virtual cpus. + /// + public readonly string? NumVCpus; + /// + /// VM OS type. + /// + public readonly string? Os; + /// + /// VM power state. + /// + public readonly string? Power; + /// + /// Resource pool name to place vm. + /// + public readonly string? ResourcePoolName; + /// + /// The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. + /// + public readonly int? ShutdownTimeout; + /// + /// The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. + /// + public readonly int? StartupTimeout; + /// + /// VM virtual disks. + /// + public readonly ImmutableArray VirtualDisks; + /// + /// VM Virtual HW version. + /// + public readonly string? VirtualHWVer; + + [OutputConstructor] + private GetVirtualMachineByIdResult( + string? bootDiskSize, + + Pulumi.EsxiNative.DiskType? bootDiskType, + + Pulumi.EsxiNative.BootFirmwareType? bootFirmware, + + string? diskStore, + + string? id, + + ImmutableArray info, + + string? ipAddress, + + string? memSize, + + string? name, + + ImmutableArray networkInterfaces, + + string? notes, + + string? numVCpus, + + string? os, + + string? power, + + string? resourcePoolName, + + int? shutdownTimeout, + + int? startupTimeout, + + ImmutableArray virtualDisks, + + string? virtualHWVer) + { + BootDiskSize = bootDiskSize; + BootDiskType = bootDiskType; + BootFirmware = bootFirmware; + DiskStore = diskStore; + Id = id; + Info = info; + IpAddress = ipAddress; + MemSize = memSize; + Name = name; + NetworkInterfaces = networkInterfaces; + Notes = notes; + NumVCpus = numVCpus; + Os = os; + Power = power; + ResourcePoolName = resourcePoolName; + ShutdownTimeout = shutdownTimeout; + StartupTimeout = startupTimeout; + VirtualDisks = virtualDisks; + VirtualHWVer = virtualHWVer; + } + } +} diff --git a/sdk/dotnet/version.txt b/sdk/dotnet/version.txt index 1da299e..3d0b811 100644 --- a/sdk/dotnet/version.txt +++ b/sdk/dotnet/version.txt @@ -1 +1 @@ -0.0.2-alpha.1688086423+4f3ff12d.dirty +0.0.2-alpha.1688123515+53c046da.dirty diff --git a/sdk/go/esxi/getVirtualMachineById.go b/sdk/go/esxi/getVirtualMachineById.go new file mode 100644 index 0000000..b88aebb --- /dev/null +++ b/sdk/go/esxi/getVirtualMachineById.go @@ -0,0 +1,218 @@ +// Code generated by pulumigen DO NOT EDIT. +// *** WARNING: Do not edit by hand unless you're certain you know what you are doing! *** + +package esxi + +import ( + "context" + "reflect" + + "github.com/pulumi/pulumi/sdk/v3/go/pulumi" +) + +func GetVirtualMachineById(ctx *pulumi.Context, args *GetVirtualMachineByIdArgs, opts ...pulumi.InvokeOption) (*GetVirtualMachineByIdResult, error) { + var rv GetVirtualMachineByIdResult + err := ctx.Invoke("esxi-native:index:getVirtualMachineById", args, &rv, opts...) + if err != nil { + return nil, err + } + return rv.Defaults(), nil +} + +type GetVirtualMachineByIdArgs struct { + // Virtual Machine Id to get details of + Id string `pulumi:"id"` +} + +type GetVirtualMachineByIdResult struct { + // VM boot disk size. Will expand boot disk to this size. + BootDiskSize *string `pulumi:"bootDiskSize"` + // VM boot disk type. thin, zeroedthick, eagerzeroedthick + BootDiskType *DiskType `pulumi:"bootDiskType"` + // Boot type('efi' is boot uefi mode) + BootFirmware *BootFirmwareType `pulumi:"bootFirmware"` + // esxi diskstore for boot disk. + DiskStore *string `pulumi:"diskStore"` + // esxi vm id. + Id *string `pulumi:"id"` + // pass data to VM + Info []KeyValuePair `pulumi:"info"` + // The IP address reported by VMWare tools. + IpAddress *string `pulumi:"ipAddress"` + // VM memory size. + MemSize *string `pulumi:"memSize"` + // esxi vm name. + Name *string `pulumi:"name"` + // VM network interfaces. + NetworkInterfaces []NetworkInterface `pulumi:"networkInterfaces"` + // VM memory size. + Notes *string `pulumi:"notes"` + // VM number of virtual cpus. + NumVCpus *string `pulumi:"numVCpus"` + // VM OS type. + Os *string `pulumi:"os"` + // VM power state. + Power *string `pulumi:"power"` + // Resource pool name to place vm. + ResourcePoolName *string `pulumi:"resourcePoolName"` + // The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. + ShutdownTimeout *int `pulumi:"shutdownTimeout"` + // The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. + StartupTimeout *int `pulumi:"startupTimeout"` + // VM virtual disks. + VirtualDisks []VMVirtualDisk `pulumi:"virtualDisks"` + // VM Virtual HW version. + VirtualHWVer *string `pulumi:"virtualHWVer"` +} + +// Defaults sets the appropriate defaults for GetVirtualMachineByIdResult +func (val *GetVirtualMachineByIdResult) Defaults() *GetVirtualMachineByIdResult { + if val == nil { + return nil + } + tmp := *val + if isZero(tmp.ShutdownTimeout) { + shutdownTimeout_ := 600 + tmp.ShutdownTimeout = &shutdownTimeout_ + } + if isZero(tmp.StartupTimeout) { + startupTimeout_ := 600 + tmp.StartupTimeout = &startupTimeout_ + } + return &tmp +} + +func GetVirtualMachineByIdOutput(ctx *pulumi.Context, args GetVirtualMachineByIdOutputArgs, opts ...pulumi.InvokeOption) GetVirtualMachineByIdResultOutput { + return pulumi.ToOutputWithContext(context.Background(), args). + ApplyT(func(v interface{}) (GetVirtualMachineByIdResult, error) { + args := v.(GetVirtualMachineByIdArgs) + r, err := GetVirtualMachineById(ctx, &args, opts...) + var s GetVirtualMachineByIdResult + if r != nil { + s = *r + } + return s, err + }).(GetVirtualMachineByIdResultOutput) +} + +type GetVirtualMachineByIdOutputArgs struct { + // Virtual Machine Id to get details of + Id pulumi.StringInput `pulumi:"id"` +} + +func (GetVirtualMachineByIdOutputArgs) ElementType() reflect.Type { + return reflect.TypeOf((*GetVirtualMachineByIdArgs)(nil)).Elem() +} + +type GetVirtualMachineByIdResultOutput struct{ *pulumi.OutputState } + +func (GetVirtualMachineByIdResultOutput) ElementType() reflect.Type { + return reflect.TypeOf((*GetVirtualMachineByIdResult)(nil)).Elem() +} + +func (o GetVirtualMachineByIdResultOutput) ToGetVirtualMachineByIdResultOutput() GetVirtualMachineByIdResultOutput { + return o +} + +func (o GetVirtualMachineByIdResultOutput) ToGetVirtualMachineByIdResultOutputWithContext(ctx context.Context) GetVirtualMachineByIdResultOutput { + return o +} + +// VM boot disk size. Will expand boot disk to this size. +func (o GetVirtualMachineByIdResultOutput) BootDiskSize() pulumi.StringPtrOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) *string { return v.BootDiskSize }).(pulumi.StringPtrOutput) +} + +// VM boot disk type. thin, zeroedthick, eagerzeroedthick +func (o GetVirtualMachineByIdResultOutput) BootDiskType() DiskTypePtrOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) *DiskType { return v.BootDiskType }).(DiskTypePtrOutput) +} + +// Boot type('efi' is boot uefi mode) +func (o GetVirtualMachineByIdResultOutput) BootFirmware() BootFirmwareTypePtrOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) *BootFirmwareType { return v.BootFirmware }).(BootFirmwareTypePtrOutput) +} + +// esxi diskstore for boot disk. +func (o GetVirtualMachineByIdResultOutput) DiskStore() pulumi.StringPtrOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) *string { return v.DiskStore }).(pulumi.StringPtrOutput) +} + +// esxi vm id. +func (o GetVirtualMachineByIdResultOutput) Id() pulumi.StringPtrOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) *string { return v.Id }).(pulumi.StringPtrOutput) +} + +// pass data to VM +func (o GetVirtualMachineByIdResultOutput) Info() KeyValuePairArrayOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) []KeyValuePair { return v.Info }).(KeyValuePairArrayOutput) +} + +// The IP address reported by VMWare tools. +func (o GetVirtualMachineByIdResultOutput) IpAddress() pulumi.StringPtrOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) *string { return v.IpAddress }).(pulumi.StringPtrOutput) +} + +// VM memory size. +func (o GetVirtualMachineByIdResultOutput) MemSize() pulumi.StringPtrOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) *string { return v.MemSize }).(pulumi.StringPtrOutput) +} + +// esxi vm name. +func (o GetVirtualMachineByIdResultOutput) Name() pulumi.StringPtrOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) *string { return v.Name }).(pulumi.StringPtrOutput) +} + +// VM network interfaces. +func (o GetVirtualMachineByIdResultOutput) NetworkInterfaces() NetworkInterfaceArrayOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) []NetworkInterface { return v.NetworkInterfaces }).(NetworkInterfaceArrayOutput) +} + +// VM memory size. +func (o GetVirtualMachineByIdResultOutput) Notes() pulumi.StringPtrOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) *string { return v.Notes }).(pulumi.StringPtrOutput) +} + +// VM number of virtual cpus. +func (o GetVirtualMachineByIdResultOutput) NumVCpus() pulumi.StringPtrOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) *string { return v.NumVCpus }).(pulumi.StringPtrOutput) +} + +// VM OS type. +func (o GetVirtualMachineByIdResultOutput) Os() pulumi.StringPtrOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) *string { return v.Os }).(pulumi.StringPtrOutput) +} + +// VM power state. +func (o GetVirtualMachineByIdResultOutput) Power() pulumi.StringPtrOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) *string { return v.Power }).(pulumi.StringPtrOutput) +} + +// Resource pool name to place vm. +func (o GetVirtualMachineByIdResultOutput) ResourcePoolName() pulumi.StringPtrOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) *string { return v.ResourcePoolName }).(pulumi.StringPtrOutput) +} + +// The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. +func (o GetVirtualMachineByIdResultOutput) ShutdownTimeout() pulumi.IntPtrOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) *int { return v.ShutdownTimeout }).(pulumi.IntPtrOutput) +} + +// The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. +func (o GetVirtualMachineByIdResultOutput) StartupTimeout() pulumi.IntPtrOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) *int { return v.StartupTimeout }).(pulumi.IntPtrOutput) +} + +// VM virtual disks. +func (o GetVirtualMachineByIdResultOutput) VirtualDisks() VMVirtualDiskArrayOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) []VMVirtualDisk { return v.VirtualDisks }).(VMVirtualDiskArrayOutput) +} + +// VM Virtual HW version. +func (o GetVirtualMachineByIdResultOutput) VirtualHWVer() pulumi.StringPtrOutput { + return o.ApplyT(func(v GetVirtualMachineByIdResult) *string { return v.VirtualHWVer }).(pulumi.StringPtrOutput) +} + +func init() { + pulumi.RegisterOutputType(GetVirtualMachineByIdResultOutput{}) +} diff --git a/sdk/nodejs/getVirtualMachineById.ts b/sdk/nodejs/getVirtualMachineById.ts new file mode 100644 index 0000000..c4e24fd --- /dev/null +++ b/sdk/nodejs/getVirtualMachineById.ts @@ -0,0 +1,114 @@ +// *** WARNING: this file was generated by pulumigen. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +import * as pulumi from "@pulumi/pulumi"; +import { input as inputs, output as outputs, enums } from "./types"; +import * as utilities from "./utilities"; + +export function getVirtualMachineById(args: GetVirtualMachineByIdArgs, opts?: pulumi.InvokeOptions): Promise { + if (!opts) { + opts = {} + } + + opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); + return pulumi.runtime.invoke("esxi-native:index:getVirtualMachineById", { + "id": args.id, + }, opts); +} + +export interface GetVirtualMachineByIdArgs { + /** + * Virtual Machine Id to get details of + */ + id: string; +} + +export interface GetVirtualMachineByIdResult { + /** + * VM boot disk size. Will expand boot disk to this size. + */ + readonly bootDiskSize?: string; + /** + * VM boot disk type. thin, zeroedthick, eagerzeroedthick + */ + readonly bootDiskType?: enums.DiskType; + /** + * Boot type('efi' is boot uefi mode) + */ + readonly bootFirmware?: enums.BootFirmwareType; + /** + * esxi diskstore for boot disk. + */ + readonly diskStore?: string; + /** + * esxi vm id. + */ + readonly id?: string; + /** + * pass data to VM + */ + readonly info?: outputs.KeyValuePair[]; + /** + * The IP address reported by VMWare tools. + */ + readonly ipAddress?: string; + /** + * VM memory size. + */ + readonly memSize?: string; + /** + * esxi vm name. + */ + readonly name?: string; + /** + * VM network interfaces. + */ + readonly networkInterfaces?: outputs.NetworkInterface[]; + /** + * VM memory size. + */ + readonly notes?: string; + /** + * VM number of virtual cpus. + */ + readonly numVCpus?: string; + /** + * VM OS type. + */ + readonly os?: string; + /** + * VM power state. + */ + readonly power?: string; + /** + * Resource pool name to place vm. + */ + readonly resourcePoolName?: string; + /** + * The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. + */ + readonly shutdownTimeout?: number; + /** + * The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. + */ + readonly startupTimeout?: number; + /** + * VM virtual disks. + */ + readonly virtualDisks?: outputs.VMVirtualDisk[]; + /** + * VM Virtual HW version. + */ + readonly virtualHWVer?: string; +} + +export function getVirtualMachineByIdOutput(args: GetVirtualMachineByIdOutputArgs, opts?: pulumi.InvokeOptions): pulumi.Output { + return pulumi.output(args).apply(a => getVirtualMachineById(a, opts)) +} + +export interface GetVirtualMachineByIdOutputArgs { + /** + * Virtual Machine Id to get details of + */ + id: pulumi.Input; +} diff --git a/sdk/nodejs/index.ts b/sdk/nodejs/index.ts index 660ca90..f882e63 100644 --- a/sdk/nodejs/index.ts +++ b/sdk/nodejs/index.ts @@ -6,6 +6,7 @@ import * as utilities from "./utilities"; // Export members: export * from "./getVirtualMachine"; +export * from "./getVirtualMachineById"; export * from "./portGroup"; export * from "./provider"; export * from "./resourcePool"; diff --git a/sdk/nodejs/tsconfig.json b/sdk/nodejs/tsconfig.json index 5e4f2a3..b216288 100644 --- a/sdk/nodejs/tsconfig.json +++ b/sdk/nodejs/tsconfig.json @@ -16,6 +16,7 @@ "config/index.ts", "config/vars.ts", "getVirtualMachine.ts", + "getVirtualMachineById.ts", "index.ts", "portGroup.ts", "provider.ts", diff --git a/sdk/python/pulumi_esxi_native/__init__.py b/sdk/python/pulumi_esxi_native/__init__.py index 0dff0ba..a3b5f11 100644 --- a/sdk/python/pulumi_esxi_native/__init__.py +++ b/sdk/python/pulumi_esxi_native/__init__.py @@ -7,6 +7,7 @@ # Export this package's modules as members: from ._enums import * from .get_virtual_machine import * +from .get_virtual_machine_by_id import * from .port_group import * from .provider import * from .resource_pool import * diff --git a/sdk/python/pulumi_esxi_native/get_virtual_machine_by_id.py b/sdk/python/pulumi_esxi_native/get_virtual_machine_by_id.py new file mode 100644 index 0000000..7bbeb9e --- /dev/null +++ b/sdk/python/pulumi_esxi_native/get_virtual_machine_by_id.py @@ -0,0 +1,307 @@ +# coding=utf-8 +# *** WARNING: this file was generated by pulumigen. *** +# *** Do not edit by hand unless you're certain you know what you are doing! *** + +import copy +import warnings +import pulumi +import pulumi.runtime +from typing import Any, Mapping, Optional, Sequence, Union, overload +from . import _utilities +from . import outputs +from ._enums import * + +__all__ = [ + 'GetVirtualMachineByIdResult', + 'AwaitableGetVirtualMachineByIdResult', + 'get_virtual_machine_by_id', + 'get_virtual_machine_by_id_output', +] + +@pulumi.output_type +class GetVirtualMachineByIdResult: + def __init__(__self__, boot_disk_size=None, boot_disk_type=None, boot_firmware=None, disk_store=None, id=None, info=None, ip_address=None, mem_size=None, name=None, network_interfaces=None, notes=None, num_v_cpus=None, os=None, power=None, resource_pool_name=None, shutdown_timeout=None, startup_timeout=None, virtual_disks=None, virtual_hw_ver=None): + if boot_disk_size and not isinstance(boot_disk_size, str): + raise TypeError("Expected argument 'boot_disk_size' to be a str") + pulumi.set(__self__, "boot_disk_size", boot_disk_size) + if boot_disk_type and not isinstance(boot_disk_type, str): + raise TypeError("Expected argument 'boot_disk_type' to be a str") + pulumi.set(__self__, "boot_disk_type", boot_disk_type) + if boot_firmware and not isinstance(boot_firmware, str): + raise TypeError("Expected argument 'boot_firmware' to be a str") + pulumi.set(__self__, "boot_firmware", boot_firmware) + if disk_store and not isinstance(disk_store, str): + raise TypeError("Expected argument 'disk_store' to be a str") + pulumi.set(__self__, "disk_store", disk_store) + if id and not isinstance(id, str): + raise TypeError("Expected argument 'id' to be a str") + pulumi.set(__self__, "id", id) + if info and not isinstance(info, list): + raise TypeError("Expected argument 'info' to be a list") + pulumi.set(__self__, "info", info) + if ip_address and not isinstance(ip_address, str): + raise TypeError("Expected argument 'ip_address' to be a str") + pulumi.set(__self__, "ip_address", ip_address) + if mem_size and not isinstance(mem_size, str): + raise TypeError("Expected argument 'mem_size' to be a str") + pulumi.set(__self__, "mem_size", mem_size) + if name and not isinstance(name, str): + raise TypeError("Expected argument 'name' to be a str") + pulumi.set(__self__, "name", name) + if network_interfaces and not isinstance(network_interfaces, list): + raise TypeError("Expected argument 'network_interfaces' to be a list") + pulumi.set(__self__, "network_interfaces", network_interfaces) + if notes and not isinstance(notes, str): + raise TypeError("Expected argument 'notes' to be a str") + pulumi.set(__self__, "notes", notes) + if num_v_cpus and not isinstance(num_v_cpus, str): + raise TypeError("Expected argument 'num_v_cpus' to be a str") + pulumi.set(__self__, "num_v_cpus", num_v_cpus) + if os and not isinstance(os, str): + raise TypeError("Expected argument 'os' to be a str") + pulumi.set(__self__, "os", os) + if power and not isinstance(power, str): + raise TypeError("Expected argument 'power' to be a str") + pulumi.set(__self__, "power", power) + if resource_pool_name and not isinstance(resource_pool_name, str): + raise TypeError("Expected argument 'resource_pool_name' to be a str") + pulumi.set(__self__, "resource_pool_name", resource_pool_name) + if shutdown_timeout and not isinstance(shutdown_timeout, int): + raise TypeError("Expected argument 'shutdown_timeout' to be a int") + pulumi.set(__self__, "shutdown_timeout", shutdown_timeout) + if startup_timeout and not isinstance(startup_timeout, int): + raise TypeError("Expected argument 'startup_timeout' to be a int") + pulumi.set(__self__, "startup_timeout", startup_timeout) + if virtual_disks and not isinstance(virtual_disks, list): + raise TypeError("Expected argument 'virtual_disks' to be a list") + pulumi.set(__self__, "virtual_disks", virtual_disks) + if virtual_hw_ver and not isinstance(virtual_hw_ver, str): + raise TypeError("Expected argument 'virtual_hw_ver' to be a str") + pulumi.set(__self__, "virtual_hw_ver", virtual_hw_ver) + + @property + @pulumi.getter(name="bootDiskSize") + def boot_disk_size(self) -> Optional[str]: + """ + VM boot disk size. Will expand boot disk to this size. + """ + return pulumi.get(self, "boot_disk_size") + + @property + @pulumi.getter(name="bootDiskType") + def boot_disk_type(self) -> Optional['DiskType']: + """ + VM boot disk type. thin, zeroedthick, eagerzeroedthick + """ + return pulumi.get(self, "boot_disk_type") + + @property + @pulumi.getter(name="bootFirmware") + def boot_firmware(self) -> Optional['BootFirmwareType']: + """ + Boot type('efi' is boot uefi mode) + """ + return pulumi.get(self, "boot_firmware") + + @property + @pulumi.getter(name="diskStore") + def disk_store(self) -> Optional[str]: + """ + esxi diskstore for boot disk. + """ + return pulumi.get(self, "disk_store") + + @property + @pulumi.getter + def id(self) -> Optional[str]: + """ + esxi vm id. + """ + return pulumi.get(self, "id") + + @property + @pulumi.getter + def info(self) -> Optional[Sequence['outputs.KeyValuePair']]: + """ + pass data to VM + """ + return pulumi.get(self, "info") + + @property + @pulumi.getter(name="ipAddress") + def ip_address(self) -> Optional[str]: + """ + The IP address reported by VMWare tools. + """ + return pulumi.get(self, "ip_address") + + @property + @pulumi.getter(name="memSize") + def mem_size(self) -> Optional[str]: + """ + VM memory size. + """ + return pulumi.get(self, "mem_size") + + @property + @pulumi.getter + def name(self) -> Optional[str]: + """ + esxi vm name. + """ + return pulumi.get(self, "name") + + @property + @pulumi.getter(name="networkInterfaces") + def network_interfaces(self) -> Optional[Sequence['outputs.NetworkInterface']]: + """ + VM network interfaces. + """ + return pulumi.get(self, "network_interfaces") + + @property + @pulumi.getter + def notes(self) -> Optional[str]: + """ + VM memory size. + """ + return pulumi.get(self, "notes") + + @property + @pulumi.getter(name="numVCpus") + def num_v_cpus(self) -> Optional[str]: + """ + VM number of virtual cpus. + """ + return pulumi.get(self, "num_v_cpus") + + @property + @pulumi.getter + def os(self) -> Optional[str]: + """ + VM OS type. + """ + return pulumi.get(self, "os") + + @property + @pulumi.getter + def power(self) -> Optional[str]: + """ + VM power state. + """ + return pulumi.get(self, "power") + + @property + @pulumi.getter(name="resourcePoolName") + def resource_pool_name(self) -> Optional[str]: + """ + Resource pool name to place vm. + """ + return pulumi.get(self, "resource_pool_name") + + @property + @pulumi.getter(name="shutdownTimeout") + def shutdown_timeout(self) -> Optional[int]: + """ + The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. + """ + return pulumi.get(self, "shutdown_timeout") + + @property + @pulumi.getter(name="startupTimeout") + def startup_timeout(self) -> Optional[int]: + """ + The amount of vm uptime, in seconds, to wait for an available IP address on this virtual machine. + """ + return pulumi.get(self, "startup_timeout") + + @property + @pulumi.getter(name="virtualDisks") + def virtual_disks(self) -> Optional[Sequence['outputs.VMVirtualDisk']]: + """ + VM virtual disks. + """ + return pulumi.get(self, "virtual_disks") + + @property + @pulumi.getter(name="virtualHWVer") + def virtual_hw_ver(self) -> Optional[str]: + """ + VM Virtual HW version. + """ + return pulumi.get(self, "virtual_hw_ver") + + +class AwaitableGetVirtualMachineByIdResult(GetVirtualMachineByIdResult): + # pylint: disable=using-constant-test + def __await__(self): + if False: + yield self + return GetVirtualMachineByIdResult( + boot_disk_size=self.boot_disk_size, + boot_disk_type=self.boot_disk_type, + boot_firmware=self.boot_firmware, + disk_store=self.disk_store, + id=self.id, + info=self.info, + ip_address=self.ip_address, + mem_size=self.mem_size, + name=self.name, + network_interfaces=self.network_interfaces, + notes=self.notes, + num_v_cpus=self.num_v_cpus, + os=self.os, + power=self.power, + resource_pool_name=self.resource_pool_name, + shutdown_timeout=self.shutdown_timeout, + startup_timeout=self.startup_timeout, + virtual_disks=self.virtual_disks, + virtual_hw_ver=self.virtual_hw_ver) + + +def get_virtual_machine_by_id(id: Optional[str] = None, + opts: Optional[pulumi.InvokeOptions] = None) -> AwaitableGetVirtualMachineByIdResult: + """ + Use this data source to access information about an existing resource. + + :param str id: Virtual Machine Id to get details of + """ + __args__ = dict() + __args__['id'] = id + if opts is None: + opts = pulumi.InvokeOptions() + if opts.version is None: + opts.version = _utilities.get_version() + __ret__ = pulumi.runtime.invoke('esxi-native:index:getVirtualMachineById', __args__, opts=opts, typ=GetVirtualMachineByIdResult).value + + return AwaitableGetVirtualMachineByIdResult( + boot_disk_size=__ret__.boot_disk_size, + boot_disk_type=__ret__.boot_disk_type, + boot_firmware=__ret__.boot_firmware, + disk_store=__ret__.disk_store, + id=__ret__.id, + info=__ret__.info, + ip_address=__ret__.ip_address, + mem_size=__ret__.mem_size, + name=__ret__.name, + network_interfaces=__ret__.network_interfaces, + notes=__ret__.notes, + num_v_cpus=__ret__.num_v_cpus, + os=__ret__.os, + power=__ret__.power, + resource_pool_name=__ret__.resource_pool_name, + shutdown_timeout=__ret__.shutdown_timeout, + startup_timeout=__ret__.startup_timeout, + virtual_disks=__ret__.virtual_disks, + virtual_hw_ver=__ret__.virtual_hw_ver) + + +@_utilities.lift_output_func(get_virtual_machine_by_id) +def get_virtual_machine_by_id_output(id: Optional[pulumi.Input[str]] = None, + opts: Optional[pulumi.InvokeOptions] = None) -> pulumi.Output[GetVirtualMachineByIdResult]: + """ + Use this data source to access information about an existing resource. + + :param str id: Virtual Machine Id to get details of + """ + ...