From 5b8eabcbbad6b8c347add74d37c6f214ddd513c2 Mon Sep 17 00:00:00 2001 From: Vicente Pinto Date: Thu, 10 Oct 2024 17:32:34 +0100 Subject: [PATCH 1/3] Add Public Ip example --- examples/iaasalpha/publicip/publicIp.go | 68 +++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 examples/iaasalpha/publicip/publicIp.go diff --git a/examples/iaasalpha/publicip/publicIp.go b/examples/iaasalpha/publicip/publicIp.go new file mode 100644 index 000000000..8ee3abedb --- /dev/null +++ b/examples/iaasalpha/publicip/publicIp.go @@ -0,0 +1,68 @@ +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" +) + +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) + } + + publicIps, err := iaasalphaClient.ListPublicIPs(context.Background(), projectId).Execute() + + if err != nil { + fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `ListPublicIPs`: %v\n", err) + } else { + fmt.Printf("[iaasalpha API] Number of Public IPs: %v\n", len(*publicIps.Items)) + } + + // Create a publicIp + createpublicIpPayload := iaasalpha.CreatePublicIPPayload{ + NetworkInterface: iaasalpha.NewNullableString(utils.Ptr("NIC_ID")), + } + publicIp, err := iaasalphaClient.CreatePublicIP(context.Background(), projectId).CreatePublicIPPayload(createpublicIpPayload).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `CreatePublicIP`: %v\n", err) + } else { + fmt.Printf("[iaasalpha API] public IP %q has been successfully created.\n", *publicIp.Id) + } + + // Update a publicIp + updatepublicIpPayload := iaasalpha.UpdatePublicIPPayload{ + NetworkInterface: iaasalpha.NewNullableString(nil), + } + publicIp, err = iaasalphaClient.UpdatePublicIP(context.Background(), projectId, *publicIp.Id).UpdatePublicIPPayload(updatepublicIpPayload).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `UpdatePublicIP`: %v\n", err) + } + + fmt.Printf("[iaasalpha API] public IP %q has been successfully updated.\n", *publicIp.Id) + if publicIp.NetworkInterface == nil { + fmt.Printf("[iaasalpha API] Public IP network interface has been successfully removed.\n") + } else { + fmt.Fprintf(os.Stderr, "[iaasalpha API] Public IP network interface has not been removed.\n") + } + + // Delete a public IP + err = iaasalphaClient.DeletePublicIP(context.Background(), projectId, *publicIp.Id).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `DeletepublicIp`: %v\n", err) + } else { + fmt.Printf("[iaasalpha API] public IP %q has been successfully deleted.\n", *publicIp.Id) + } +} From cfaedff5b55824531894ff7c357e3c3bcf25f371 Mon Sep 17 00:00:00 2001 From: Vicente Pinto Date: Fri, 11 Oct 2024 19:11:55 +0100 Subject: [PATCH 2/3] Update iaasalpha module --- examples/iaasalpha/go.mod | 4 ++-- examples/iaasalpha/go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/iaasalpha/go.mod b/examples/iaasalpha/go.mod index 05da82a7d..6f3b4dae9 100644 --- a/examples/iaasalpha/go.mod +++ b/examples/iaasalpha/go.mod @@ -3,8 +3,8 @@ 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.6-alpha + github.com/stackitcloud/stackit-sdk-go/core v0.14.0 + github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.10-alpha ) require ( diff --git a/examples/iaasalpha/go.sum b/examples/iaasalpha/go.sum index f7580a342..bd892927d 100644 --- a/examples/iaasalpha/go.sum +++ b/examples/iaasalpha/go.sum @@ -3,7 +3,7 @@ github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVI 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.6-alpha h1:XUYncbRKaqbG76OzoSugfvPHp6+0A86JJxW2T3CLT2E= -github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.6-alpha/go.mod h1:b4KR6r+yWS2hsDkz6ebRqxgadB+ZsAZcG0oDfv5jeaY= +github.com/stackitcloud/stackit-sdk-go/core v0.14.0 h1:oBwwzrEHDTlZpRoQwmMQpNA8bWciTrtGkiN29nx14Z0= +github.com/stackitcloud/stackit-sdk-go/core v0.14.0/go.mod h1:mDX1mSTsB3mP+tNBGcFNx6gH1mGBN4T+dVt+lcw7nlw= +github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.10-alpha h1:kHFq/7lJ6eS8m27zzAhTANttk6dZ2Jp4fb36D3Dsu+M= +github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.10-alpha/go.mod h1:nW/6vvumUHA7o1/JOOqsrEOBNrRHombEKB1U4jmg2wU= From d144020e2d28f73773ae66a329fe38fe4b933772 Mon Sep 17 00:00:00 2001 From: Vicente Pinto Date: Mon, 14 Oct 2024 16:12:47 +0100 Subject: [PATCH 3/3] Fix go.sum --- examples/iaasalpha/go.sum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/iaasalpha/go.sum b/examples/iaasalpha/go.sum index 2c7f90c9a..0f5e5a461 100644 --- a/examples/iaasalpha/go.sum +++ b/examples/iaasalpha/go.sum @@ -4,6 +4,6 @@ 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.14.0 h1:oBwwzrEHDTlZpRoQwmMQpNA8bWciTrtGkiN29nx14Z0= -github.com/stackitcloud/stackit-sdk-go/core v0.14.0/go.mod h1:mDX1mSTsB3mP+tNBGcFNx6gH1mGBN4T+dVt+lcw7nlw=ackitcloud/stackit-sdk-go/services/iaasalpha v0.1.10-alpha/go.mod h1:nW/6vvumUHA7o1/JOOqsrEOBNrRHombEKB1U4jmg2wU= +github.com/stackitcloud/stackit-sdk-go/core v0.14.0/go.mod h1:mDX1mSTsB3mP+tNBGcFNx6gH1mGBN4T+dVt+lcw7nlw= github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.11-alpha h1:uYslPwq0euGkuH6kHIhoXUaB9w+yrrDKLd80eo/5GZU= github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.11-alpha/go.mod h1:nW/6vvumUHA7o1/JOOqsrEOBNrRHombEKB1U4jmg2wU=