Skip to content
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
67 changes: 67 additions & 0 deletions examples/iaasalpha/attach_nic/attach_nic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package main

import (
"context"
"fmt"
"net/http"
"os"

"github.com/stackitcloud/stackit-sdk-go/core/config"
"github.com/stackitcloud/stackit-sdk-go/core/runtime"
"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"
serverId := "SERVER_ID"
nicId := "NIC_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)
}

// Attach an existing network interface to an existing server
var httpResp *http.Response
ctxWithHTTPResp := runtime.WithCaptureHTTPResponse(context.Background(), &httpResp)
err = iaasalphaClient.AddNICToServer(ctxWithHTTPResp, projectId, serverId, nicId).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `AddNICToServer`: %v\n", err)
} else {
fmt.Printf("[iaasalpha API] Triggered attachment of nic with ID %q.\n", nicId)
}
requestId := httpResp.Header[wait.XRequestIDHeader][0]

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

fmt.Printf("[iaasalpha API] Nic %q has been successfully attached to the server %s.\n", nicId, serverId)

err = iaasalphaClient.RemoveNICFromServer(ctxWithHTTPResp, projectId, serverId, nicId).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `RemoveNICFromServer`: %v\n", err)
} else {
fmt.Printf("[iaasalpha API] Triggered removal of attachment of nic with ID %q.\n", nicId)
}

requestId = httpResp.Header[wait.XRequestIDHeader][0]

// Wait for dettachment of the nic
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasalphaClient, projectId, requestId).WaitWithContext(context.Background())
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when waiting for removal of attachment of NIC: %v\n", err)
os.Exit(1)
}

fmt.Printf("[iaasalpha API] NIC %q has been successfully detacched from the server %s.\n", nicId, serverId)
}
67 changes: 67 additions & 0 deletions examples/iaasalpha/attach_public_ip/attach_public_ip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package main

import (
"context"
"fmt"
"net/http"
"os"

"github.com/stackitcloud/stackit-sdk-go/core/config"
"github.com/stackitcloud/stackit-sdk-go/core/runtime"
"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"
serverId := "SERVER_ID"
publicIpId := "PUBLIC_IP_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)
}

// Attach an existing network interface to an existing server
var httpResp *http.Response
ctxWithHTTPResp := runtime.WithCaptureHTTPResponse(context.Background(), &httpResp)
err = iaasalphaClient.AddPublicIpToServer(ctxWithHTTPResp, projectId, serverId, publicIpId).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `AddPublicIpToServer`: %v\n", err)
} else {
fmt.Printf("[iaasalpha API] Triggered attachment of public ip with ID %q.\n", publicIpId)
}
requestId := httpResp.Header[wait.XRequestIDHeader][0]

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

fmt.Printf("[iaasalpha API] Public IP %q has been successfully attached to the server %s.\n", publicIpId, serverId)

err = iaasalphaClient.RemovePublicIpFromServer(ctxWithHTTPResp, projectId, serverId, publicIpId).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `RemovePublicIpFromServer`: %v\n", err)
} else {
fmt.Printf("[iaasalpha API] Triggered removal of attachment of public ip with ID %q.\n", publicIpId)
}

requestId = httpResp.Header[wait.XRequestIDHeader][0]

// Wait for dettachment of the public ip
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasalphaClient, projectId, requestId).WaitWithContext(context.Background())
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when waiting for removal of attachment of PublicIp: %v\n", err)
os.Exit(1)
}

fmt.Printf("[iaasalpha API] PublicIp %q has been successfully detacched from the server %s.\n", publicIpId, serverId)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package main

import (
"context"
"fmt"
"net/http"
"os"

"github.com/stackitcloud/stackit-sdk-go/core/config"
"github.com/stackitcloud/stackit-sdk-go/core/runtime"
"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"
serverId := "SERVER_ID"
securityGroupId := "SECURITY_GROUP_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)
}

// Attach an existing network interface to an existing server
var httpResp *http.Response
ctxWithHTTPResp := runtime.WithCaptureHTTPResponse(context.Background(), &httpResp)
err = iaasalphaClient.AddSecurityGroupToServer(ctxWithHTTPResp, projectId, serverId, securityGroupId).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `AddSecurityGroupToServer`: %v\n", err)
} else {
fmt.Printf("[iaasalpha API] Triggered attachment of security group with ID %q.\n", securityGroupId)
}
requestId := httpResp.Header[wait.XRequestIDHeader][0]

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

fmt.Printf("[iaasalpha API] Security group %q has been successfully attached to the server %s.\n", securityGroupId, serverId)

err = iaasalphaClient.RemoveSecurityGroupFromServer(ctxWithHTTPResp, projectId, serverId, securityGroupId).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `RemoveSecurityGroupFromServer`: %v\n", err)
} else {
fmt.Printf("[iaasalpha API] Triggered removal of attachment of security group with ID %q.\n", securityGroupId)
}

requestId = httpResp.Header[wait.XRequestIDHeader][0]

// Wait for dettachment of the security group
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasalphaClient, projectId, requestId).WaitWithContext(context.Background())
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when waiting for removal of attachment of SecurityGroup: %v\n", err)
os.Exit(1)
}

fmt.Printf("[iaasalpha API] SecurityGroup %q has been successfully detacched from the server %s.\n", securityGroupId, serverId)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package main

import (
"context"
"fmt"
"net/http"
"os"

"github.com/stackitcloud/stackit-sdk-go/core/config"
"github.com/stackitcloud/stackit-sdk-go/core/runtime"
"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"
serverId := "SERVER_ID"
serviceAccountMail := "SERVICE_ACCOUNT_MAIL"

// 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)
}

// Attach an existing service account to an existing server
var httpResp *http.Response
ctxWithHTTPResp := runtime.WithCaptureHTTPResponse(context.Background(), &httpResp)
_, err = iaasalphaClient.AddServiceAccountToServer(ctxWithHTTPResp, projectId, serverId, serviceAccountMail).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `AddServiceAccountToServer`: %v\n", err)
} else {
fmt.Printf("[iaasalpha API] Triggered attachment of service account with mail %q.\n", serviceAccountMail)
}
requestId := httpResp.Header[wait.XRequestIDHeader][0]

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

fmt.Printf("[iaasalpha API] Service account %q has been successfully attached to the server %s.\n", serviceAccountMail, serverId)

_, err = iaasalphaClient.RemoveServiceAccountFromServer(ctxWithHTTPResp, projectId, serverId, serviceAccountMail).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `RemoveServiceAccountFromServer`: %v\n", err)
} else {
fmt.Printf("[iaasalpha API] Triggered removal of attachment of service account with mail %q.\n", serviceAccountMail)
}

requestId = httpResp.Header[wait.XRequestIDHeader][0]

// Wait for dettachment of the service account
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasalphaClient, projectId, requestId).WaitWithContext(context.Background())
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when waiting for removal of attachment of service account: %v\n", err)
os.Exit(1)
}

fmt.Printf("[iaasalpha API] Service account %q has been successfully detacched from the server %s.\n", serviceAccountMail, serverId)
}
60 changes: 60 additions & 0 deletions examples/iaasalpha/attach_volume/attach_volume.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package main

import (
"context"
"fmt"
"os"

"github.com/stackitcloud/stackit-sdk-go/core/config"
"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"
serverId := "SERVER_ID"
volumeId := "VOLUME_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)
}

payload := iaasalpha.AddVolumeToServerPayload{}
_, err = iaasalphaClient.AddVolumeToServer(context.Background(), projectId, serverId, volumeId).AddVolumeToServerPayload(payload).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `AddVolumeToServer`: %v\n", err)
} else {
fmt.Printf("[iaasalpha API] Triggered attachment of volume with ID %q.\n", volumeId)
}

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

fmt.Printf("[iaasalpha API] Volume %q has been successfully attached to the server %s.\n", volumeId, serverId)

err = iaasalphaClient.RemoveVolumeFromServer(context.Background(), projectId, serverId, volumeId).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[iaasalpha API] Error when calling `RemoveVolumeFromServer`: %v\n", err)
} else {
fmt.Printf("[iaasalpha API] Triggered removal of attachment of volume with ID %q.\n", volumeId)
}

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

fmt.Printf("[iaasalpha API] Volume %q has been successfully detacched from the server %s.\n", volumeId, serverId)
}
2 changes: 1 addition & 1 deletion examples/iaasalpha/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/stackitcloud/stackit-sdk-go/core v0.14.0
github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.8-alpha
github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.11-alpha
)

require (
Expand Down
4 changes: 2 additions & 2 deletions examples/iaasalpha/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ 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=
github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.8-alpha h1:s7HprLITChqzYk1sO605q0Ivhge7oNmZ4sVBfySlgw8=
github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.8-alpha/go.mod h1:b4KR6r+yWS2hsDkz6ebRqxgadB+ZsAZcG0oDfv5jeaY=
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=
Loading