-
Notifications
You must be signed in to change notification settings - Fork 7
/
ip.go
90 lines (80 loc) · 2.51 KB
/
ip.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"bufio"
"context"
"os"
"github.com/gridscale/gsclient-go/v3"
log "github.com/sirupsen/logrus"
)
var emptyCtx = context.Background()
func main() {
uuid := os.Getenv("GRIDSCALE_UUID")
token := os.Getenv("GRIDSCALE_TOKEN")
config := gsclient.DefaultConfiguration(uuid, token)
client := gsclient.NewClient(config)
log.Info("gridscale client configured")
log.Info("Create IP address: Press 'Enter' to continue...")
bufio.NewReader(os.Stdin).ReadBytes('\n')
ipRequest := gsclient.IPCreateRequest{
Name: "go-client-ip",
Family: gsclient.IPv4Type,
}
// Create new IP
ipc, err := client.CreateIP(emptyCtx, ipRequest)
if err != nil {
log.Error("Create IP address has failed with error", err)
return
}
log.WithFields(log.Fields{"ip_uuid": ipc.ObjectUUID}).Info("IP address successfully created")
defer func() {
err := client.DeleteIP(emptyCtx, ipc.ObjectUUID)
if err != nil {
log.Error("Delete IP address has failed with error", err)
return
}
log.Info("Delete IP address successfully")
log.Info("Get deleted IP address: Press 'Enter' to continue...")
bufio.NewReader(os.Stdin).ReadBytes('\n')
ips, err := client.GetDeletedIPs(emptyCtx)
if err != nil {
log.Error("Get delete IP address has failed with error", err)
return
}
log.WithFields(log.Fields{
"ips": ips,
}).Info("Retrieved deleted IP successfully")
}()
log.Info("Update IP address: Press 'Enter' to continue...")
bufio.NewReader(os.Stdin).ReadBytes('\n')
// Get IP to update
ip, err := client.GetIP(emptyCtx, ipc.ObjectUUID)
if err != nil {
log.Error("Get IP address has failed with error", err)
return
}
updateRequest := gsclient.IPUpdateRequest{
Name: "Updated IP address",
Failover: ip.Properties.Failover,
ReverseDNS: ip.Properties.ReverseDNS,
Labels: &ip.Properties.Labels,
}
err = client.UpdateIP(emptyCtx, ip.Properties.ObjectUUID, updateRequest)
if err != nil {
log.Error("Update IP address has failed with error", err)
return
}
log.Info("Retrive IP address events: Press 'Enter' to continue...")
bufio.NewReader(os.Stdin).ReadBytes('\n')
// Get IP address events
response, err := client.GetIPEventList(emptyCtx, ip.Properties.ObjectUUID)
if err != nil {
log.Error("Get IP address events has failed with error", err)
return
}
log.WithFields(log.Fields{
"ip_uuid": ip.Properties.ObjectUUID,
"events": response,
}).Info("Events successfully events retrieved")
log.Info("Delete IP address: Press 'Enter' to continue...")
bufio.NewReader(os.Stdin).ReadBytes('\n')
}