Skip to content

Commit 9654817

Browse files
committed
launchpad instance types
1 parent 7e786c2 commit 9654817

166 files changed

Lines changed: 25184 additions & 2378 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

internal/currency/currency.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package currency
2+
3+
import (
4+
"strconv"
5+
6+
"github.com/bojanz/currency"
7+
"github.com/brevdev/cloud/internal/errors"
8+
)
9+
10+
func NaNMaker(currencyCode string) (currency.Amount, error) {
11+
nan, err := currency.NewAmount("nan", currencyCode)
12+
if err != nil {
13+
return currency.Amount{}, errors.WrapAndTrace(err)
14+
}
15+
return nan, nil
16+
}
17+
18+
func NewAmount(amount string, currencyCode string) (currency.Amount, error) {
19+
a, err := currency.NewAmount(amount, currencyCode)
20+
if err != nil {
21+
return currency.Amount{}, errors.WrapAndTrace(err)
22+
}
23+
nan, err := NaNMaker(currencyCode)
24+
if err != nil {
25+
return currency.Amount{}, errors.WrapAndTrace(err)
26+
}
27+
if a.Equal(nan) {
28+
return currency.Amount{}, errors.WrapAndTrace(errors.New("invalid limit amount"))
29+
}
30+
return a, nil
31+
}
32+
33+
func MustAmount(amount string, currencyCode string) currency.Amount {
34+
a, err := currency.NewAmount(amount, currencyCode)
35+
if err != nil {
36+
panic(err)
37+
}
38+
return a
39+
}
40+
41+
// regular currency is causing issues
42+
type AmountJSON struct {
43+
Number string `json:"number"`
44+
CurrencyCode string `json:"currency"`
45+
}
46+
47+
func (a AmountJSON) ToAmount() (currency.Amount, error) {
48+
return NewAmount(a.Number, a.CurrencyCode)
49+
}
50+
51+
func FromAmount(a currency.Amount) AmountJSON {
52+
return AmountJSON{
53+
Number: a.Number(),
54+
CurrencyCode: a.CurrencyCode(),
55+
}
56+
}
57+
58+
func ToDollarsFloat(a currency.Amount) (float64, error) {
59+
amountInDollars, err := strconv.ParseFloat(a.Number(), 64)
60+
if err != nil {
61+
return 0, errors.WrapAndTrace(err)
62+
}
63+
return amountInDollars, nil
64+
}
65+
66+
func ToCentsInt(a currency.Amount) (int64, error) {
67+
c, err := a.Int64()
68+
if err != nil {
69+
return 0, errors.WrapAndTrace(err)
70+
}
71+
return c, nil
72+
}
73+
74+
func ToDollarsInt(a currency.Amount) (int64, error) {
75+
fd, err := ToDollarsFloat(a)
76+
if err != nil {
77+
return 0, errors.WrapAndTrace(err)
78+
}
79+
return int64(fd), nil
80+
}
81+
82+
var ZeroAmount = MustAmount("0", "USD")

internal/currency/currency_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package currency
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"testing"
7+
8+
"github.com/bojanz/currency"
9+
"github.com/brevdev/dev-plane/pkg/collections"
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func Test_CurrencyConversion(t *testing.T) {
14+
bad := "$1.22"
15+
res, err := currency.NewAmount(bad, "USD")
16+
assert.Error(t, err)
17+
assert.Empty(t, res)
18+
19+
res, err = currency.NewAmount(bad, "EU")
20+
assert.Error(t, err)
21+
assert.Empty(t, res)
22+
23+
good := "1.22"
24+
res, err = currency.NewAmount(good, "USD")
25+
assert.NoError(t, err)
26+
assert.NotEmpty(t, res)
27+
28+
r, _ := json.Marshal(res)
29+
fmt.Println(string(r))
30+
_, _ = collections.FromJSON[currency.Amount](r)
31+
32+
nan := "nan"
33+
res, err = currency.NewAmount(nan, "USD")
34+
assert.NoError(t, err)
35+
assert.NotEmpty(t, res)
36+
37+
nanU := "NaN"
38+
res, err = currency.NewAmount(nanU, "USD")
39+
assert.NoError(t, err)
40+
assert.NotEmpty(t, res)
41+
42+
cents := 550
43+
res, err = currency.NewAmountFromInt64(int64(cents), "USD")
44+
assert.NoError(t, err)
45+
assert.NotEmpty(t, res)
46+
assert.Equal(t, "5.50 USD", res.String())
47+
}
48+
49+
func Test_Int(t *testing.T) {
50+
amount, err := currency.NewAmount("5.50", "USD")
51+
assert.NoError(t, err)
52+
i, err := amount.Int64()
53+
assert.NoError(t, err)
54+
assert.Equal(t, int64(550), i)
55+
}
56+
57+
func Test_DollarsInt(t *testing.T) {
58+
amount, err := currency.NewAmount("5.50", "USD")
59+
assert.NoError(t, err)
60+
d, err := ToDollarsInt(amount)
61+
assert.NoError(t, err)
62+
assert.Equal(t, int64(5), d)
63+
}
64+
65+
func Test_ToDollarsFloat(t *testing.T) {
66+
amount, err := currency.NewAmount("5.50", "USD")
67+
assert.NoError(t, err)
68+
d, err := ToDollarsFloat(amount)
69+
assert.NoError(t, err)
70+
assert.Equal(t, float64(5.5), d)
71+
}

v1/location.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package v1
33
import (
44
"context"
55
"fmt"
6+
"slices"
67
)
78

89
type CloudLocation interface {
@@ -35,6 +36,13 @@ func (l LocationsFilter) IsAll() bool {
3536
return false
3637
}
3738

39+
func (f LocationsFilter) IsAllowed(location string) bool {
40+
if f.IsAll() {
41+
return true
42+
}
43+
return slices.Contains(f, location)
44+
}
45+
3846
// ValidateGetLocations validates that the CloudLocation implementation returns at least one available location without error.
3947
func ValidateGetLocations(ctx context.Context, client CloudLocation) error {
4048
locs, err := client.GetLocations(ctx, GetLocationsArgs{})

v1/log.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package v1
2+
3+
import "context"
4+
5+
type Logger interface {
6+
Debug(ctx context.Context, msg string, args ...any)
7+
Info(ctx context.Context, msg string, args ...any)
8+
Warn(ctx context.Context, msg string, args ...any)
9+
Error(ctx context.Context, msg string, args ...any)
10+
}
11+
12+
type NoopLogger struct{}
13+
14+
func (l *NoopLogger) Debug(ctx context.Context, msg string, args ...any) {}
15+
func (l *NoopLogger) Info(ctx context.Context, msg string, args ...any) {}
16+
func (l *NoopLogger) Warn(ctx context.Context, msg string, args ...any) {}
17+
func (l *NoopLogger) Error(ctx context.Context, msg string, args ...any) {}
18+
19+
var _ Logger = &NoopLogger{}

v1/providers/launchpad/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SPEC_VERSION ?= v2.34.2
1+
SPEC_VERSION ?= v2.35.4
22
SPEC_FILE ?= /local/swagger-${SPEC_VERSION}.yaml
33
OUTPUT_DIR ?= launchpad
44
# To understand disallowAdditionalPropertiesIfNotPresent=false

v1/providers/launchpad/client.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,25 @@ import (
1010
"github.com/pkg/errors"
1111
)
1212

13-
1413
type LaunchpadClient struct {
1514
v1.NotImplCloudClient
1615
refID string
1716
apiKey string
1817
client *openapi.APIClient
18+
logger v1.Logger
1919
}
2020

2121
var _ v1.CloudClient = &LaunchpadClient{}
2222

23-
func NewLaunchpadClient(launchpadCredential LaunchpadCredential) (*LaunchpadClient, error) {
23+
type LaunchpadClientOption func(c *LaunchpadClient)
24+
25+
func WithLogger(logger v1.Logger) LaunchpadClientOption {
26+
return func(c *LaunchpadClient) {
27+
c.logger = logger
28+
}
29+
}
30+
31+
func NewLaunchpadClient(launchpadCredential LaunchpadCredential, opts ...LaunchpadClientOption) (*LaunchpadClient, error) {
2432
launchpadCredential.SetDefaults()
2533
err := launchpadCredential.Validate()
2634
if err != nil {
@@ -37,11 +45,18 @@ func NewLaunchpadClient(launchpadCredential LaunchpadCredential) (*LaunchpadClie
3745
}
3846
client := openapi.NewAPIClient(conf)
3947

40-
return &LaunchpadClient{
48+
launchpadClient := &LaunchpadClient{
4149
refID: launchpadCredential.RefID,
4250
apiKey: launchpadCredential.APIToken,
4351
client: client,
44-
}, nil
52+
logger: &v1.NoopLogger{},
53+
}
54+
55+
for _, opt := range opts {
56+
opt(launchpadClient)
57+
}
58+
59+
return launchpadClient, nil
4560
}
4661

4762
func (c *LaunchpadClient) makeAuthContext(ctx context.Context) context.Context {

v1/providers/launchpad/credential.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,13 @@ func (c *LaunchpadCredential) GetTenantID() (string, error) {
7171
return fmt.Sprintf("launchpad-%s", hAPIKey), nil
7272
}
7373

74+
func (c *LaunchpadCredential) MakeClientWithOptions(_ context.Context, _ string, opts ...LaunchpadClientOption) (v1.CloudClient, error) {
75+
return NewLaunchpadClient(*c, opts...)
76+
}
77+
7478
// MakeClient implements v1.CloudCredential.
75-
func (c *LaunchpadCredential) MakeClient(_ context.Context, _ string) (v1.CloudClient, error) {
76-
return NewLaunchpadClient(*c)
79+
func (c *LaunchpadCredential) MakeClient(ctx context.Context, location string) (v1.CloudClient, error) {
80+
return c.MakeClientWithOptions(ctx, location)
7781
}
7882

7983
func (c *LaunchpadCredential) GetInstancePollTime() time.Duration {

v1/providers/launchpad/gen/launchpad/.openapi-generator/FILES

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ api_auth.go
77
api_catalog_deployments.go
88
api_catalog_experiences.go
99
api_catalog_gpu_os_choices.go
10+
api_catalog_instance_types.go
1011
api_catalog_persona_choices.go
1112
api_identity_profile.go
1213
api_inventory_clusters.go
@@ -26,6 +27,7 @@ docs/BlankEnum.md
2627
docs/CatalogDeploymentsAPI.md
2728
docs/CatalogExperiencesAPI.md
2829
docs/CatalogGpuOsChoicesAPI.md
30+
docs/CatalogInstanceTypesAPI.md
2931
docs/CatalogPersonaChoicesAPI.md
3032
docs/CategoryEnum.md
3133
docs/Cluster.md
@@ -41,6 +43,7 @@ docs/DeploymentCluster.md
4143
docs/DeploymentExperience.md
4244
docs/DeploymentInstance.md
4345
docs/DeploymentKey.md
46+
docs/DeploymentNote.md
4447
docs/DeploymentPipeline.md
4548
docs/DeploymentPipelineActionEnum.md
4649
docs/DeploymentService.md
@@ -52,6 +55,7 @@ docs/DocDeploymentDelete.md
5255
docs/Experience.md
5356
docs/ExperienceBulk.md
5457
docs/ExperienceBulkUpdate.md
58+
docs/ExperienceNote.md
5559
docs/FcPlatformEnum.md
5660
docs/FormFactorEnum.md
5761
docs/Gpu.md
@@ -62,6 +66,11 @@ docs/IdentityProfileAPI.md
6266
docs/Instance.md
6367
docs/InstanceBulkUpdate.md
6468
docs/InstanceState.md
69+
docs/InstanceType.md
70+
docs/InstanceTypeGpu.md
71+
docs/InstanceTypePrice.md
72+
docs/InstanceTypeStorage.md
73+
docs/InterconnectionTypeEnum.md
6574
docs/InventoryClustersAPI.md
6675
docs/InventoryGpusAPI.md
6776
docs/InventoryInstancesAPI.md
@@ -86,13 +95,16 @@ docs/PaginatedClusterList.md
8695
docs/PaginatedDeploymentInstanceList.md
8796
docs/PaginatedDeploymentKeyList.md
8897
docs/PaginatedDeploymentList.md
98+
docs/PaginatedDeploymentNoteList.md
8999
docs/PaginatedDeploymentPipelineList.md
90100
docs/PaginatedDeploymentServiceList.md
91101
docs/PaginatedDeploymentTaskList.md
92102
docs/PaginatedExperienceList.md
103+
docs/PaginatedExperienceNoteList.md
93104
docs/PaginatedGpuList.md
94105
docs/PaginatedGpuOsChoiceList.md
95106
docs/PaginatedInstanceList.md
107+
docs/PaginatedInstanceTypeList.md
96108
docs/PaginatedLocationList.md
97109
docs/PaginatedModelChangeList.md
98110
docs/PaginatedNodeList.md
@@ -135,6 +147,7 @@ model_deployment_cluster.go
135147
model_deployment_experience.go
136148
model_deployment_instance.go
137149
model_deployment_key.go
150+
model_deployment_note.go
138151
model_deployment_pipeline.go
139152
model_deployment_pipeline_action_enum.go
140153
model_deployment_service.go
@@ -146,6 +159,7 @@ model_doc_deployment_delete.go
146159
model_experience.go
147160
model_experience_bulk.go
148161
model_experience_bulk_update.go
162+
model_experience_note.go
149163
model_fc_platform_enum.go
150164
model_form_factor_enum.go
151165
model_gpu.go
@@ -155,6 +169,11 @@ model_gpu_os_choice.go
155169
model_instance.go
156170
model_instance_bulk_update.go
157171
model_instance_state.go
172+
model_instance_type.go
173+
model_instance_type_gpu.go
174+
model_instance_type_price.go
175+
model_instance_type_storage.go
176+
model_interconnection_type_enum.go
158177
model_location.go
159178
model_location_provider.go
160179
model_logout.go
@@ -172,13 +191,16 @@ model_paginated_cluster_list.go
172191
model_paginated_deployment_instance_list.go
173192
model_paginated_deployment_key_list.go
174193
model_paginated_deployment_list.go
194+
model_paginated_deployment_note_list.go
175195
model_paginated_deployment_pipeline_list.go
176196
model_paginated_deployment_service_list.go
177197
model_paginated_deployment_task_list.go
178198
model_paginated_experience_list.go
199+
model_paginated_experience_note_list.go
179200
model_paginated_gpu_list.go
180201
model_paginated_gpu_os_choice_list.go
181202
model_paginated_instance_list.go
203+
model_paginated_instance_type_list.go
182204
model_paginated_location_list.go
183205
model_paginated_model_change_list.go
184206
model_paginated_node_list.go
@@ -205,6 +227,7 @@ test/api_auth_test.go
205227
test/api_catalog_deployments_test.go
206228
test/api_catalog_experiences_test.go
207229
test/api_catalog_gpu_os_choices_test.go
230+
test/api_catalog_instance_types_test.go
208231
test/api_catalog_persona_choices_test.go
209232
test/api_identity_profile_test.go
210233
test/api_inventory_clusters_test.go

0 commit comments

Comments
 (0)