Skip to content

Commit 432afcb

Browse files
committed
adjust waiter and examples
- add routing table example
1 parent cb1d6ca commit 432afcb

File tree

13 files changed

+607
-451
lines changed

13 files changed

+607
-451
lines changed

examples/iaas/attach_nic/attach_nic.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@ import (
66
"net/http"
77
"os"
88

9-
"github.com/stackitcloud/stackit-sdk-go/core/config"
109
"github.com/stackitcloud/stackit-sdk-go/core/runtime"
1110
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1211
"github.com/stackitcloud/stackit-sdk-go/services/iaas/wait"
1312
)
1413

1514
func main() {
16-
// Specify the organization ID and project ID
15+
// Specify the project ID, server ID, nic ID and region
1716
projectId := "PROJECT_ID" // the uuid of your STACKIT project
1817
serverId := "SERVER_ID"
1918
nicId := "NIC_ID"
19+
region := "eu01"
2020

2121
// Create a new API client, that uses default authentication and configuration
22-
iaasClient, err := iaas.NewAPIClient(
23-
config.WithRegion("eu01"),
24-
)
22+
iaasClient, err := iaas.NewAPIClient()
2523
if err != nil {
2624
fmt.Fprintf(os.Stderr, "[iaas API] Creating API client: %v\n", err)
2725
os.Exit(1)
@@ -30,7 +28,7 @@ func main() {
3028
// Attach an existing network interface to an existing server
3129
var httpResp *http.Response
3230
ctxWithHTTPResp := runtime.WithCaptureHTTPResponse(context.Background(), &httpResp)
33-
err = iaasClient.AddNicToServer(ctxWithHTTPResp, projectId, serverId, nicId).Execute()
31+
err = iaasClient.AddNicToServer(ctxWithHTTPResp, projectId, region, serverId, nicId).Execute()
3432
if err != nil {
3533
fmt.Fprintf(os.Stderr, "[iaas API] Error when calling `AddNICToServer`: %v\n", err)
3634
} else {
@@ -39,15 +37,15 @@ func main() {
3937
requestId := httpResp.Header[wait.XRequestIDHeader][0]
4038

4139
// Wait for attachment of the nic
42-
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasClient, projectId, requestId).WaitWithContext(context.Background())
40+
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasClient, projectId, region, requestId).WaitWithContext(context.Background())
4341
if err != nil {
4442
fmt.Fprintf(os.Stderr, "[iaas API] Error when waiting for attachment: %v\n", err)
4543
os.Exit(1)
4644
}
4745

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

50-
err = iaasClient.RemoveNicFromServer(ctxWithHTTPResp, projectId, serverId, nicId).Execute()
48+
err = iaasClient.RemoveNicFromServer(ctxWithHTTPResp, projectId, region, serverId, nicId).Execute()
5149
if err != nil {
5250
fmt.Fprintf(os.Stderr, "[iaas API] Error when calling `RemoveNICFromServer`: %v\n", err)
5351
} else {
@@ -57,7 +55,7 @@ func main() {
5755
requestId = httpResp.Header[wait.XRequestIDHeader][0]
5856

5957
// Wait for dettachment of the nic
60-
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasClient, projectId, requestId).WaitWithContext(context.Background())
58+
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasClient, projectId, region, requestId).WaitWithContext(context.Background())
6159
if err != nil {
6260
fmt.Fprintf(os.Stderr, "[iaas API] Error when waiting for removal of attachment of NIC: %v\n", err)
6361
os.Exit(1)

examples/iaas/attach_public_ip/attach_public_ip.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@ import (
66
"net/http"
77
"os"
88

9-
"github.com/stackitcloud/stackit-sdk-go/core/config"
109
"github.com/stackitcloud/stackit-sdk-go/core/runtime"
1110
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1211
"github.com/stackitcloud/stackit-sdk-go/services/iaas/wait"
1312
)
1413

1514
func main() {
16-
// Specify the organization ID and project ID
15+
// Specify the project ID, server ID, public ip ID and region
1716
projectId := "PROJECT_ID" // the uuid of your STACKIT project
1817
serverId := "SERVER_ID"
1918
publicIpId := "PUBLIC_IP_ID"
19+
region := "eu01"
2020

2121
// Create a new API client, that uses default authentication and configuration
22-
iaasClient, err := iaas.NewAPIClient(
23-
config.WithRegion("eu01"),
24-
)
22+
iaasClient, err := iaas.NewAPIClient()
2523
if err != nil {
2624
fmt.Fprintf(os.Stderr, "[iaas API] Creating API client: %v\n", err)
2725
os.Exit(1)
@@ -30,7 +28,7 @@ func main() {
3028
// Attach an existing network interface to an existing server
3129
var httpResp *http.Response
3230
ctxWithHTTPResp := runtime.WithCaptureHTTPResponse(context.Background(), &httpResp)
33-
err = iaasClient.AddPublicIpToServer(ctxWithHTTPResp, projectId, serverId, publicIpId).Execute()
31+
err = iaasClient.AddPublicIpToServer(ctxWithHTTPResp, projectId, region, serverId, publicIpId).Execute()
3432
if err != nil {
3533
fmt.Fprintf(os.Stderr, "[iaas API] Error when calling `AddPublicIpToServer`: %v\n", err)
3634
} else {
@@ -39,15 +37,15 @@ func main() {
3937
requestId := httpResp.Header[wait.XRequestIDHeader][0]
4038

4139
// Wait for attachment of the public ip
42-
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasClient, projectId, requestId).WaitWithContext(context.Background())
40+
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasClient, projectId, region, requestId).WaitWithContext(context.Background())
4341
if err != nil {
4442
fmt.Fprintf(os.Stderr, "[iaas API] Error when waiting for attachment: %v\n", err)
4543
os.Exit(1)
4644
}
4745

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

50-
err = iaasClient.RemovePublicIpFromServer(ctxWithHTTPResp, projectId, serverId, publicIpId).Execute()
48+
err = iaasClient.RemovePublicIpFromServer(ctxWithHTTPResp, projectId, region, serverId, publicIpId).Execute()
5149
if err != nil {
5250
fmt.Fprintf(os.Stderr, "[iaas API] Error when calling `RemovePublicIpFromServer`: %v\n", err)
5351
} else {
@@ -57,7 +55,7 @@ func main() {
5755
requestId = httpResp.Header[wait.XRequestIDHeader][0]
5856

5957
// Wait for dettachment of the public ip
60-
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasClient, projectId, requestId).WaitWithContext(context.Background())
58+
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasClient, projectId, region, requestId).WaitWithContext(context.Background())
6159
if err != nil {
6260
fmt.Fprintf(os.Stderr, "[iaas API] Error when waiting for removal of attachment of PublicIp: %v\n", err)
6361
os.Exit(1)

examples/iaas/attach_security_group/attach_security_group.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@ import (
66
"net/http"
77
"os"
88

9-
"github.com/stackitcloud/stackit-sdk-go/core/config"
109
"github.com/stackitcloud/stackit-sdk-go/core/runtime"
1110
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1211
"github.com/stackitcloud/stackit-sdk-go/services/iaas/wait"
1312
)
1413

1514
func main() {
16-
// Specify the organization ID and project ID
15+
// Specify the project ID, server ID, security group ID and region
1716
projectId := "PROJECT_ID" // the uuid of your STACKIT project
1817
serverId := "SERVER_ID"
1918
securityGroupId := "SECURITY_GROUP_ID"
19+
region := "eu01"
2020

2121
// Create a new API client, that uses default authentication and configuration
22-
iaasClient, err := iaas.NewAPIClient(
23-
config.WithRegion("eu01"),
24-
)
22+
iaasClient, err := iaas.NewAPIClient()
2523
if err != nil {
2624
fmt.Fprintf(os.Stderr, "[iaas API] Creating API client: %v\n", err)
2725
os.Exit(1)
@@ -30,7 +28,7 @@ func main() {
3028
// Attach an existing network interface to an existing server
3129
var httpResp *http.Response
3230
ctxWithHTTPResp := runtime.WithCaptureHTTPResponse(context.Background(), &httpResp)
33-
err = iaasClient.AddSecurityGroupToServer(ctxWithHTTPResp, projectId, serverId, securityGroupId).Execute()
31+
err = iaasClient.AddSecurityGroupToServer(ctxWithHTTPResp, projectId, region, serverId, securityGroupId).Execute()
3432
if err != nil {
3533
fmt.Fprintf(os.Stderr, "[iaas API] Error when calling `AddSecurityGroupToServer`: %v\n", err)
3634
} else {
@@ -39,15 +37,15 @@ func main() {
3937
requestId := httpResp.Header[wait.XRequestIDHeader][0]
4038

4139
// Wait for attachment of the security group
42-
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasClient, projectId, requestId).WaitWithContext(context.Background())
40+
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasClient, projectId, region, requestId).WaitWithContext(context.Background())
4341
if err != nil {
4442
fmt.Fprintf(os.Stderr, "[iaas API] Error when waiting for attachment: %v\n", err)
4543
os.Exit(1)
4644
}
4745

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

50-
err = iaasClient.RemoveSecurityGroupFromServer(ctxWithHTTPResp, projectId, serverId, securityGroupId).Execute()
48+
err = iaasClient.RemoveSecurityGroupFromServer(ctxWithHTTPResp, projectId, region, serverId, securityGroupId).Execute()
5149
if err != nil {
5250
fmt.Fprintf(os.Stderr, "[iaas API] Error when calling `RemoveSecurityGroupFromServer`: %v\n", err)
5351
} else {
@@ -57,7 +55,7 @@ func main() {
5755
requestId = httpResp.Header[wait.XRequestIDHeader][0]
5856

5957
// Wait for dettachment of the security group
60-
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasClient, projectId, requestId).WaitWithContext(context.Background())
58+
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasClient, projectId, region, requestId).WaitWithContext(context.Background())
6159
if err != nil {
6260
fmt.Fprintf(os.Stderr, "[iaas API] Error when waiting for removal of attachment of SecurityGroup: %v\n", err)
6361
os.Exit(1)

examples/iaas/attach_service_account/attach_service_account.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@ import (
66
"net/http"
77
"os"
88

9-
"github.com/stackitcloud/stackit-sdk-go/core/config"
109
"github.com/stackitcloud/stackit-sdk-go/core/runtime"
1110
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1211
"github.com/stackitcloud/stackit-sdk-go/services/iaas/wait"
1312
)
1413

1514
func main() {
16-
// Specify the organization ID and project ID
15+
// Specify the project ID, server ID, service account mail and region
1716
projectId := "PROJECT_ID" // the uuid of your STACKIT project
1817
serverId := "SERVER_ID"
1918
serviceAccountMail := "SERVICE_ACCOUNT_MAIL"
19+
region := "eu01"
2020

2121
// Create a new API client, that uses default authentication and configuration
22-
iaasClient, err := iaas.NewAPIClient(
23-
config.WithRegion("eu01"),
24-
)
22+
iaasClient, err := iaas.NewAPIClient()
2523
if err != nil {
2624
fmt.Fprintf(os.Stderr, "[iaas API] Creating API client: %v\n", err)
2725
os.Exit(1)
@@ -30,7 +28,7 @@ func main() {
3028
// Attach an existing service account to an existing server
3129
var httpResp *http.Response
3230
ctxWithHTTPResp := runtime.WithCaptureHTTPResponse(context.Background(), &httpResp)
33-
_, err = iaasClient.AddServiceAccountToServer(ctxWithHTTPResp, projectId, serverId, serviceAccountMail).Execute()
31+
_, err = iaasClient.AddServiceAccountToServer(ctxWithHTTPResp, projectId, region, serverId, serviceAccountMail).Execute()
3432
if err != nil {
3533
fmt.Fprintf(os.Stderr, "[iaas API] Error when calling `AddServiceAccountToServer`: %v\n", err)
3634
} else {
@@ -39,15 +37,15 @@ func main() {
3937
requestId := httpResp.Header[wait.XRequestIDHeader][0]
4038

4139
// Wait for attachment of the service account
42-
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasClient, projectId, requestId).WaitWithContext(context.Background())
40+
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasClient, projectId, region, requestId).WaitWithContext(context.Background())
4341
if err != nil {
4442
fmt.Fprintf(os.Stderr, "[iaas API] Error when waiting for attachment: %v\n", err)
4543
os.Exit(1)
4644
}
4745

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

50-
_, err = iaasClient.RemoveServiceAccountFromServer(ctxWithHTTPResp, projectId, serverId, serviceAccountMail).Execute()
48+
_, err = iaasClient.RemoveServiceAccountFromServer(ctxWithHTTPResp, projectId, region, serverId, serviceAccountMail).Execute()
5149
if err != nil {
5250
fmt.Fprintf(os.Stderr, "[iaas API] Error when calling `RemoveServiceAccountFromServer`: %v\n", err)
5351
} else {
@@ -57,7 +55,7 @@ func main() {
5755
requestId = httpResp.Header[wait.XRequestIDHeader][0]
5856

5957
// Wait for dettachment of the service account
60-
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasClient, projectId, requestId).WaitWithContext(context.Background())
58+
_, err = wait.ProjectRequestWaitHandler(context.Background(), iaasClient, projectId, region, requestId).WaitWithContext(context.Background())
6159
if err != nil {
6260
fmt.Fprintf(os.Stderr, "[iaas API] Error when waiting for removal of attachment of service account: %v\n", err)
6361
os.Exit(1)

examples/iaas/attach_volume/attach_volume.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,50 @@ import (
55
"fmt"
66
"os"
77

8-
"github.com/stackitcloud/stackit-sdk-go/core/config"
98
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
109
"github.com/stackitcloud/stackit-sdk-go/services/iaas/wait"
1110
)
1211

1312
func main() {
14-
// Specify the organization ID and project ID
13+
// Specify the project ID, server ID, volume ID and region
1514
projectId := "PROJECT_ID" // the uuid of your STACKIT project
1615
serverId := "SERVER_ID"
1716
volumeId := "VOLUME_ID"
17+
region := "eu01"
1818

1919
// Create a new API client, that uses default authentication and configuration
20-
iaasClient, err := iaas.NewAPIClient(
21-
config.WithRegion("eu01"),
22-
)
20+
iaasClient, err := iaas.NewAPIClient()
2321
if err != nil {
2422
fmt.Fprintf(os.Stderr, "[iaas API] Creating API client: %v\n", err)
2523
os.Exit(1)
2624
}
2725

2826
payload := iaas.AddVolumeToServerPayload{}
29-
_, err = iaasClient.AddVolumeToServer(context.Background(), projectId, serverId, volumeId).AddVolumeToServerPayload(payload).Execute()
27+
_, err = iaasClient.AddVolumeToServer(context.Background(), projectId, region, serverId, volumeId).AddVolumeToServerPayload(payload).Execute()
3028
if err != nil {
3129
fmt.Fprintf(os.Stderr, "[iaas API] Error when calling `AddVolumeToServer`: %v\n", err)
3230
} else {
3331
fmt.Printf("[iaas API] Triggered attachment of volume with ID %q.\n", volumeId)
3432
}
3533

3634
// Wait for attachment of the volume
37-
_, err = wait.AddVolumeToServerWaitHandler(context.Background(), iaasClient, projectId, serverId, volumeId).WaitWithContext(context.Background())
35+
_, err = wait.AddVolumeToServerWaitHandler(context.Background(), iaasClient, projectId, region, serverId, volumeId).WaitWithContext(context.Background())
3836
if err != nil {
3937
fmt.Fprintf(os.Stderr, "[iaas API] Error when waiting for attachment: %v\n", err)
4038
os.Exit(1)
4139
}
4240

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

45-
err = iaasClient.RemoveVolumeFromServer(context.Background(), projectId, serverId, volumeId).Execute()
43+
err = iaasClient.RemoveVolumeFromServer(context.Background(), projectId, region, serverId, volumeId).Execute()
4644
if err != nil {
4745
fmt.Fprintf(os.Stderr, "[iaas API] Error when calling `RemoveVolumeFromServer`: %v\n", err)
4846
} else {
4947
fmt.Printf("[iaas API] Triggered removal of attachment of volume with ID %q.\n", volumeId)
5048
}
5149

5250
// Wait for dettachment of the volume
53-
_, err = wait.RemoveVolumeFromServerWaitHandler(context.Background(), iaasClient, projectId, serverId, volumeId).WaitWithContext(context.Background())
51+
_, err = wait.RemoveVolumeFromServerWaitHandler(context.Background(), iaasClient, projectId, region, serverId, volumeId).WaitWithContext(context.Background())
5452
if err != nil {
5553
fmt.Fprintf(os.Stderr, "[iaas API] Error when waiting for removal of attachment of volume: %v\n", err)
5654
os.Exit(1)

examples/iaas/network/network.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@ import (
55
"fmt"
66
"os"
77

8-
"github.com/stackitcloud/stackit-sdk-go/core/config"
98
"github.com/stackitcloud/stackit-sdk-go/core/utils"
109
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1110
"github.com/stackitcloud/stackit-sdk-go/services/iaas/wait"
1211
)
1312

1413
func main() {
15-
// Specify the organization ID and project ID
14+
// Specify the project ID and region
1615
projectId := "PROJECT_ID" // the uuid of your STACKIT project
16+
region := "eu01"
1717

1818
// Create a new API client, that uses default authentication and configuration
19-
iaasClient, err := iaas.NewAPIClient(
20-
config.WithRegion("eu01"),
21-
)
19+
iaasClient, err := iaas.NewAPIClient()
2220
if err != nil {
2321
fmt.Fprintf(os.Stderr, "[IaaS API] Creating API client: %v\n", err)
2422
os.Exit(1)
@@ -27,25 +25,25 @@ func main() {
2725
// Create a network
2826
createNetworkPayload := iaas.CreateNetworkPayload{
2927
Name: utils.Ptr("example-network"),
30-
AddressFamily: &iaas.CreateNetworkAddressFamily{
31-
Ipv4: &iaas.CreateNetworkIPv4Body{
32-
PrefixLength: utils.Ptr(int64(24)),
28+
Ipv4: &iaas.CreateNetworkIPv4{
29+
CreateNetworkIPv4WithPrefixLength: &iaas.CreateNetworkIPv4WithPrefixLength{
3330
Nameservers: &[]string{"1.2.3.4"},
31+
PrefixLength: utils.Ptr(int64(24)),
3432
},
3533
},
3634
}
3735

38-
network, err := iaasClient.CreateNetwork(context.Background(), projectId).CreateNetworkPayload(createNetworkPayload).Execute()
36+
network, err := iaasClient.CreateNetwork(context.Background(), projectId, region).CreateNetworkPayload(createNetworkPayload).Execute()
3937
if err != nil {
4038
fmt.Fprintf(os.Stderr, "[IaaS API] Error when calling `CreateNetwork`: %v\n", err)
4139
os.Exit(1)
4240
}
4341

44-
fmt.Printf("[IaaS API] Triggered creation of network with ID %q.\n", *network.NetworkId)
45-
fmt.Printf("[Iaas API] Current state of the network: %q\n", *network.State)
42+
fmt.Printf("[IaaS API] Triggered creation of network with ID %q.\n", *network.Id)
43+
fmt.Printf("[Iaas API] Current state of the network: %q\n", *network.Status)
4644
fmt.Println("[Iaas API] Waiting for network to be created...")
4745

48-
network, err = wait.CreateNetworkWaitHandler(context.Background(), iaasClient, projectId, *network.NetworkId).WaitWithContext(context.Background())
46+
network, err = wait.CreateNetworkWaitHandler(context.Background(), iaasClient, projectId, region, *network.Id).WaitWithContext(context.Background())
4947
if err != nil {
5048
fmt.Fprintf(os.Stderr, "[IaaS API] Error when waiting for creation: %v\n", err)
5149
os.Exit(1)
@@ -58,13 +56,13 @@ func main() {
5856
Name: utils.Ptr("example-network-test-renamed"),
5957
}
6058

61-
err = iaasClient.PartialUpdateNetwork(context.Background(), projectId, *network.NetworkId).PartialUpdateNetworkPayload(updateNetworkPayload).Execute()
59+
err = iaasClient.PartialUpdateNetwork(context.Background(), projectId, region, *network.Id).PartialUpdateNetworkPayload(updateNetworkPayload).Execute()
6260
if err != nil {
6361
fmt.Fprintf(os.Stderr, "[IaaS API] Error when calling `PartialUpdateNetwork`: %v\n", err)
6462
os.Exit(1)
6563
}
6664

67-
_, err = wait.UpdateNetworkWaitHandler(context.Background(), iaasClient, projectId, *network.NetworkId).WaitWithContext(context.Background())
65+
_, err = wait.UpdateNetworkWaitHandler(context.Background(), iaasClient, projectId, region, *network.Id).WaitWithContext(context.Background())
6866
if err != nil {
6967
fmt.Fprintf(os.Stderr, "[IaaS API] Error when waiting for update: %v\n", err)
7068
os.Exit(1)
@@ -73,13 +71,13 @@ func main() {
7371
fmt.Printf("[IaaS API] Network has been successfully updated.\n")
7472

7573
// Delete a network
76-
err = iaasClient.DeleteNetwork(context.Background(), projectId, *network.NetworkId).Execute()
74+
err = iaasClient.DeleteNetwork(context.Background(), projectId, region, *network.Id).Execute()
7775
if err != nil {
7876
fmt.Fprintf(os.Stderr, "[IaaS API] Error when calling `DeleteNetwork`: %v\n", err)
7977
os.Exit(1)
8078
}
8179

82-
_, err = wait.DeleteNetworkWaitHandler(context.Background(), iaasClient, projectId, *network.NetworkId).WaitWithContext(context.Background())
80+
_, err = wait.DeleteNetworkWaitHandler(context.Background(), iaasClient, projectId, region, *network.Id).WaitWithContext(context.Background())
8381
if err != nil {
8482
fmt.Fprintf(os.Stderr, "[IaaS API] Error when waiting for deletion: %v\n", err)
8583
os.Exit(1)

0 commit comments

Comments
 (0)