From 9d8bfb6c9d9a85b38b218caf7e2cbab177b811ec Mon Sep 17 00:00:00 2001 From: Sharad Kesarwani <108344822+sharadkesarwani@users.noreply.github.com> Date: Fri, 6 Oct 2023 14:57:56 +0530 Subject: [PATCH] added support for "instanceTypesFilters" in AWS ocean launchSpec. (#266) --- .../providers/aws/launchSpec/create/main.go | 69 ++++++++ service/ocean/providers/aws/launchspec.go | 167 ++++++++++++++++++ 2 files changed, 236 insertions(+) create mode 100644 examples/service/ocean/providers/aws/launchSpec/create/main.go diff --git a/examples/service/ocean/providers/aws/launchSpec/create/main.go b/examples/service/ocean/providers/aws/launchSpec/create/main.go new file mode 100644 index 00000000..618d495c --- /dev/null +++ b/examples/service/ocean/providers/aws/launchSpec/create/main.go @@ -0,0 +1,69 @@ +package main + +import ( + "context" + "github.com/spotinst/spotinst-sdk-go/service/ocean" + "github.com/spotinst/spotinst-sdk-go/service/ocean/providers/aws" + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" + "log" +) + +func main() { + // All clients require a Session. The Session provides the client with + // shared configuration such as account and credentials. + // A Session should be shared where possible to take advantage of + // configuration and credential caching. See the session package for + // more information. + sess := session.New() + + // Create a new instance of the service's client with a Session. + // Optional spotinst.Config values can also be provided as variadic + // arguments to the New function. This option allows you to provide + // service specific configuration. + svc := ocean.New(sess) + + // Create a new context. + ctx := context.Background() + + // Create a new launch spec. + out, err := svc.CloudProviderAWS().CreateLaunchSpec(ctx, &aws.CreateLaunchSpecInput{ + LaunchSpec: &aws.LaunchSpec{ + Name: spotinst.String("test-vng"), + OceanID: spotinst.String("o-abcd123456"), + ImageID: spotinst.String("ami-abcd123456"), + SecurityGroupIDs: []string{"sg-123456"}, + SubnetIDs: []string{"subnet-12345", "subnet-67890"}, + InstanceTypesFilters: &aws.InstanceTypesFilters{ + DiskTypes: []string{"EBS", "SSD"}, + MinVcpu: spotinst.Int(2), + MaxVcpu: spotinst.Int(80), + MinGpu: spotinst.Int(0), + MaxGpu: spotinst.Int(5), + IncludeFamilies: []string{"c*", "t*"}, + ExcludeFamilies: []string{"m*"}, + ExcludeMetal: spotinst.Bool(true), + Categories: []string{"General_purpose", "Compute_optimized"}, + Hypervisor: []string{"nitro", "xen"}, + IsEnaSupported: spotinst.Bool(true), + MaxMemoryGiB: spotinst.Float64(16), + MinMemoryGiB: spotinst.Float64(8), + MinEnis: spotinst.Int(2), + VirtualizationTypes: []string{"hvm"}, + RootDeviceTypes: []string{"ebs"}, + MaxNetworkPerformance: spotinst.Int(20), + MinNetworkPerformance: spotinst.Int(2), + }}, + }) + if err != nil { + log.Fatalf("spotinst: failed to create launch spec: %v", err) + } + + // Output. + if out.LaunchSpec != nil { + log.Printf("LaunchSpec %q: %s", + spotinst.StringValue(out.LaunchSpec.ID), + stringutil.Stringify(out.LaunchSpec)) + } +} diff --git a/service/ocean/providers/aws/launchspec.go b/service/ocean/providers/aws/launchspec.go index 8cc9996f..4d197b71 100644 --- a/service/ocean/providers/aws/launchspec.go +++ b/service/ocean/providers/aws/launchspec.go @@ -39,6 +39,7 @@ type LaunchSpec struct { LaunchSpecScheduling *LaunchSpecScheduling `json:"scheduling,omitempty"` InstanceMetadataOptions *LaunchspecInstanceMetadataOptions `json:"instanceMetadataOptions,omitempty"` Images []*Images `json:"images,omitempty"` + InstanceTypesFilters *InstanceTypesFilters `json:"instanceTypesFilters,omitempty"` // Read-only fields. CreatedAt *time.Time `json:"createdAt,omitempty"` @@ -274,6 +275,30 @@ type Images struct { nullFields []string } +type InstanceTypesFilters struct { + Categories []string `json:"categories,omitempty"` + DiskTypes []string `json:"diskTypes,omitempty"` + ExcludeFamilies []string `json:"excludeFamilies,omitempty"` + ExcludeMetal *bool `json:"excludeMetal,omitempty"` + Hypervisor []string `json:"hypervisor,omitempty"` + IncludeFamilies []string `json:"includeFamilies,omitempty"` + IsEnaSupported *bool `json:"isEnaSupported,omitempty"` + MaxGpu *int `json:"maxGpu,omitempty"` + MaxMemoryGiB *float64 `json:"maxMemoryGiB,omitempty"` + MaxNetworkPerformance *int `json:"maxNetworkPerformance,omitempty"` + MaxVcpu *int `json:"maxVcpu,omitempty"` + MinEnis *int `json:"minEnis,omitempty"` + MinGpu *int `json:"minGpu,omitempty"` + MinMemoryGiB *float64 `json:"minMemoryGiB,omitempty"` + MinNetworkPerformance *int `json:"minNetworkPerformance,omitempty"` + MinVcpu *int `json:"minVcpu,omitempty"` + RootDeviceTypes []string `json:"rootDeviceTypes,omitempty"` + VirtualizationTypes []string `json:"virtualizationTypes,omitempty"` + + forceSendFields []string + nullFields []string +} + type ListLaunchSpecsInput struct { OceanID *string `json:"oceanId,omitempty"` } @@ -648,6 +673,12 @@ func (o *LaunchSpec) SetScheduling(v *LaunchSpecScheduling) *LaunchSpec { } return o } +func (o *LaunchSpec) SetInstanceTypesFilters(v *InstanceTypesFilters) *LaunchSpec { + if o.InstanceTypesFilters = v; o.InstanceTypesFilters == nil { + o.nullFields = append(o.nullFields, "InstanceTypesFilters") + } + return o +} // endregion @@ -1150,3 +1181,139 @@ func (o *Images) SetImageId(v *string) *Images { } // endregion + +// region InstanceTypesFilters + +func (o InstanceTypesFilters) MarshalJSON() ([]byte, error) { + type noMethod InstanceTypesFilters + raw := noMethod(o) + return jsonutil.MarshalJSON(raw, o.forceSendFields, o.nullFields) +} + +func (o *InstanceTypesFilters) SetCategories(v []string) *InstanceTypesFilters { + if o.Categories = v; o.Categories == nil { + o.nullFields = append(o.nullFields, "Categories") + } + return o +} + +func (o *InstanceTypesFilters) SetDiskTypes(v []string) *InstanceTypesFilters { + if o.DiskTypes = v; o.DiskTypes == nil { + o.nullFields = append(o.nullFields, "DiskTypes") + } + return o +} + +func (o *InstanceTypesFilters) SetExcludeFamilies(v []string) *InstanceTypesFilters { + if o.ExcludeFamilies = v; o.ExcludeFamilies == nil { + o.nullFields = append(o.nullFields, "ExcludeFamilies") + } + return o +} + +func (o *InstanceTypesFilters) SetExcludeMetal(v *bool) *InstanceTypesFilters { + if o.ExcludeMetal = v; o.ExcludeMetal == nil { + o.nullFields = append(o.nullFields, "ExcludeMetal") + } + return o +} + +func (o *InstanceTypesFilters) SetHypervisor(v []string) *InstanceTypesFilters { + if o.Hypervisor = v; o.Hypervisor == nil { + o.nullFields = append(o.nullFields, "Hypervisor") + } + return o +} + +func (o *InstanceTypesFilters) SetIncludeFamilies(v []string) *InstanceTypesFilters { + if o.IncludeFamilies = v; o.IncludeFamilies == nil { + o.nullFields = append(o.nullFields, "IncludeFamilies") + } + return o +} + +func (o *InstanceTypesFilters) SetIsEnaSupported(v *bool) *InstanceTypesFilters { + if o.IsEnaSupported = v; o.IsEnaSupported == nil { + o.nullFields = append(o.nullFields, "IsEnaSupported") + } + return o +} + +func (o *InstanceTypesFilters) SetMaxGpu(v *int) *InstanceTypesFilters { + if o.MaxGpu = v; o.MaxGpu == nil { + o.nullFields = append(o.nullFields, "MaxGpu") + } + return o +} + +func (o *InstanceTypesFilters) SetMaxMemoryGiB(v *float64) *InstanceTypesFilters { + if o.MaxMemoryGiB = v; o.MaxMemoryGiB == nil { + o.nullFields = append(o.nullFields, "MaxMemoryGiB") + } + return o +} + +func (o *InstanceTypesFilters) SetMaxNetworkPerformance(v *int) *InstanceTypesFilters { + if o.MaxNetworkPerformance = v; o.MaxNetworkPerformance == nil { + o.nullFields = append(o.nullFields, "MaxNetworkPerformance") + } + return o +} + +func (o *InstanceTypesFilters) SetMaxVcpu(v *int) *InstanceTypesFilters { + if o.MaxVcpu = v; o.MaxVcpu == nil { + o.nullFields = append(o.nullFields, "MaxVcpu") + } + return o +} + +func (o *InstanceTypesFilters) SetMinEnis(v *int) *InstanceTypesFilters { + if o.MinEnis = v; o.MinEnis == nil { + o.nullFields = append(o.nullFields, "MinEnis") + } + return o +} + +func (o *InstanceTypesFilters) SetMinGpu(v *int) *InstanceTypesFilters { + if o.MinGpu = v; o.MinGpu == nil { + o.nullFields = append(o.nullFields, "MinGpu") + } + return o +} + +func (o *InstanceTypesFilters) SetMinMemoryGiB(v *float64) *InstanceTypesFilters { + if o.MinMemoryGiB = v; o.MinMemoryGiB == nil { + o.nullFields = append(o.nullFields, "MinMemoryGiB") + } + return o +} + +func (o *InstanceTypesFilters) SetMinNetworkPerformance(v *int) *InstanceTypesFilters { + if o.MinNetworkPerformance = v; o.MinNetworkPerformance == nil { + o.nullFields = append(o.nullFields, "MinNetworkPerformance") + } + return o +} + +func (o *InstanceTypesFilters) SetMinVcpu(v *int) *InstanceTypesFilters { + if o.MinVcpu = v; o.MinVcpu == nil { + o.nullFields = append(o.nullFields, "MinVcpu") + } + return o +} + +func (o *InstanceTypesFilters) SetRootDeviceTypes(v []string) *InstanceTypesFilters { + if o.RootDeviceTypes = v; o.RootDeviceTypes == nil { + o.nullFields = append(o.nullFields, "RootDeviceTypes") + } + return o +} + +func (o *InstanceTypesFilters) SetVirtualizationTypes(v []string) *InstanceTypesFilters { + if o.VirtualizationTypes = v; o.VirtualizationTypes == nil { + o.nullFields = append(o.nullFields, "VirtualizationTypes") + } + return o +} + +// endregion