Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for iaasalpha #856

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/iaasalpha/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module github.com/stackitcloud/stackit-sdk-go/examples/iaasalpha

go 1.18

require (
github.com/stackitcloud/stackit-sdk-go/core v0.13.0
github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.3-alpha
)

require (
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/google/uuid v1.6.0 // indirect
)
9 changes: 9 additions & 0 deletions examples/iaasalpha/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/stackitcloud/stackit-sdk-go/core v0.13.0 h1:BtJT2WXqZdexPPQi/HPUIr8g4JUPOCheh6J9dxiCQ4Q=
github.com/stackitcloud/stackit-sdk-go/core v0.13.0/go.mod h1:mDX1mSTsB3mP+tNBGcFNx6gH1mGBN4T+dVt+lcw7nlw=
github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.3-alpha h1:cwNZwtvb7diYJhjNmxuX8IxaqOq1BNDSjtG3c9Ne1ig=
github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.3-alpha/go.mod h1:b4KR6r+yWS2hsDkz6ebRqxgadB+ZsAZcG0oDfv5jeaY=
95 changes: 95 additions & 0 deletions examples/iaasalpha/iaas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package main

import (
"context"
"fmt"
"os"

"github.com/stackitcloud/stackit-sdk-go/core/config"
"github.com/stackitcloud/stackit-sdk-go/core/utils"
"github.com/stackitcloud/stackit-sdk-go/services/iaasalpha"
"github.com/stackitcloud/stackit-sdk-go/services/iaasalpha/wait"
)

func main() {
// Specify the organization ID and project ID
projectId := "PROJECT_ID"

// Create a new API client, that uses default authentication and configuration
iaasalphaClient, err := iaasalpha.NewAPIClient(
config.WithRegion("eu01"),
)
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Creating API client: %v\n", err)
os.Exit(1)
}

volumes, err := iaasalphaClient.ListVolumes(context.Background(), projectId).Execute()

if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `ListVolumes`: %v\n", err)
} else {
fmt.Printf("[iaasalpha API] Number of volumes: %v\n", len(*volumes.Items))
}

// Create a volume
createVolumePayload := iaasalpha.CreateVolumePayload{
Name: utils.Ptr("example-volume"),
AvailabilityZone: utils.Ptr("eu01-1"),
Size: utils.Ptr(int64(10)),
}
volume, err := iaasalphaClient.CreateVolume(context.Background(), projectId).CreateVolumePayload(createVolumePayload).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `CreateVolume`: %v\n", err)
} else {
fmt.Printf("[iaasalpha API] Triggered creation of volume with ID %q.\n", *volume.Id)
}

// Wait for creation of the volume
volume, err = wait.CreateVolumeWaitHandler(context.Background(), iaasalphaClient, projectId, *volume.Id).WaitWithContext(context.Background())
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when waiting for creation: %v\n", err)
os.Exit(1)
}

fmt.Printf("[iaasalpha API] Network volume %q has been successfully created.\n", *volume.Id)

// Update a volume
updateVolumePayload := iaasalpha.UpdateVolumePayload{
Name: utils.Ptr("renamed"),
}
volume, err = iaasalphaClient.UpdateVolume(context.Background(), projectId, *volume.Id).UpdateVolumePayload(updateVolumePayload).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `UpdateVolume`: %v\n", err)
}

fmt.Printf("[iaasalpha API] Network volume %q has been successfully updated.\n", *volume.Id)

// Resize a volume
resizeVolumePayload := iaasalpha.ResizeVolumePayload{
Size: utils.Ptr(int64(130)),
}
err = iaasalphaClient.ResizeVolume(context.Background(), projectId, *volume.Id).ResizeVolumePayload(resizeVolumePayload).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `ResizeVolume`: %v\n", err)
}

fmt.Printf("[iaasalpha API] Network volume %q has been successfully resized.\n", *volume.Id)

// Delete a volume
err = iaasalphaClient.DeleteVolume(context.Background(), projectId, *volume.Id).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `DeleteVolume`: %v\n", err)
} else {
fmt.Printf("[iaasalpha API] Triggered deletion of volume with ID %q.\n", *volume.Id)
}

// Wait for deletion of the volume
_, err = wait.DeleteVolumeWaitHandler(context.Background(), iaasalphaClient, projectId, *volume.Id).WaitWithContext(context.Background())
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when waiting for deletion: %v\n", err)
os.Exit(1)
}

fmt.Printf("[iaasalpha API] Network volume %q has been successfully deleted.\n", *volume.Id)
}
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use (
./examples/dns
./examples/errorhandling
./examples/iaas
./examples/iaasalpha
./examples/loadbalancer
./examples/logme
./examples/mariadb
Expand Down
Loading