/
failover-list.go
50 lines (43 loc) · 945 Bytes
/
failover-list.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
// SPDX-License-Identifier: MIT
//
// Copyright © 2018 Gennady Trafimenkov <gennady.trafimenkov@gmail.com>
package cmd
import (
"fmt"
"os"
hetzner "github.com/gtrafimenkov/go-hetzner"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
)
func init() {
cmd := &cobra.Command{
Use: "list",
Short: "Get list of failover ip addresses",
Run: failoverListRun,
}
failoverCmd.AddCommand(cmd)
}
func failoverListRun(cmd *cobra.Command, args []string) {
username, password := getCredentials()
client := hetzner.NewClient(username, password)
ips, _, err := client.Failover.List()
fatal(err)
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"IP",
"Netmask",
"ServerIP",
"ServerNumber",
"ActiveServerIP",
})
for _, ip := range ips {
table.Append([]string{
ip.IP,
ip.Netmask,
ip.ServerIP,
fmt.Sprintf("%d", ip.ServerNumber),
ip.ActiveServerIP,
})
}
table.Render()
}