@@ -2,6 +2,7 @@ package scalewaysdkgo
22
33import (
44 "fmt"
5+ "time"
56
67 "github.com/scaleway/scaleway-sdk-go/api/instance/v1"
78 "github.com/scaleway/scaleway-sdk-go/api/lb/v1"
@@ -84,6 +85,43 @@ func Example_listServers() {
8485 fmt .Println (response )
8586}
8687
88+ func Example_rebootAllServers () {
89+
90+ // Create a Scaleway client
91+ client , err := scw .NewClient (
92+ scw .WithAuth ("ACCESS_KEY" , "SECRET_KEY" ), // Get your credentials at https://console.scaleway.com/account/credentials
93+ scw .WithDefaultZone (scw .ZoneFrPar1 ),
94+ )
95+ if err != nil {
96+ panic (err )
97+ }
98+
99+ // Create SDK objects for Scaleway Instance product
100+ instanceAPI := instance .NewAPI (client )
101+
102+ // Call the ListServers method of the Instance SDK
103+ response , err := instanceAPI .ListServers (& instance.ListServersRequest {})
104+ if err != nil {
105+ panic (err )
106+ }
107+
108+ // For each server if they are running we reboot them using ServerActionAndWait
109+ for _ , server := range response .Servers {
110+ if server .State == instance .ServerStateRunning {
111+ fmt .Println ("Rebooting server with ID" , server .ID )
112+ err = instanceAPI .ServerActionAndWait (& instance.ServerActionAndWaitRequest {
113+ ServerID : server .ID ,
114+ Action : instance .ServerActionReboot ,
115+ Timeout : 5 * time .Minute ,
116+ })
117+ if err != nil {
118+ panic (err )
119+ }
120+ }
121+ }
122+ fmt .Println ("All servers were successfully rebooted" )
123+ }
124+
87125func Example_createLoadBalancer () {
88126
89127 // Create a Scaleway client
0 commit comments