blob: d897f6a251a64ecd9e63df8df75e5cbd22f31d8a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
package digitalocean
import (
"context"
"golang.org/x/oauth2"
"github.com/digitalocean/godo"
"go.wit.com/log"
)
func (d *DigitalOcean) PowerOn(dropletID int) error {
tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: d.token})
oauthClient := oauth2.NewClient(context.Background(), tokenSource)
client := godo.NewClient(oauthClient)
ctx := context.TODO()
// Create a request to power on the droplet.
_, _, err := client.DropletActions.PowerOn(ctx, dropletID)
if err != nil {
return err
}
log.Printf("Power-on signal sent to droplet with ID: %d\n", dropletID)
return nil
}
func (d *DigitalOcean) PowerOff(dropletID int) error {
tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: d.token})
oauthClient := oauth2.NewClient(context.Background(), tokenSource)
client := godo.NewClient(oauthClient)
ctx := context.TODO()
// Create a request to power on the droplet.
_, _, err := client.DropletActions.PowerOff(ctx, dropletID)
if err != nil {
return err
}
log.Printf("Power-on signal sent to droplet with ID: %d\n", dropletID)
return nil
}
|