-
Notifications
You must be signed in to change notification settings - Fork 225
/
machines.go
103 lines (83 loc) · 1.99 KB
/
machines.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
91
92
93
94
95
96
97
98
99
100
101
102
103
package info
import (
"context"
"fmt"
"github.com/superfly/flyctl/api"
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/internal/command/apps"
"github.com/superfly/flyctl/internal/command/services"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/internal/render"
"github.com/superfly/flyctl/iostreams"
)
func showMachineInfo(ctx context.Context, appName string) error {
var (
client = client.FromContext(ctx).API()
jsonOuput = flag.GetBool(ctx, "json")
)
if jsonOuput {
return fmt.Errorf("outputting to json is not yet supported")
}
appInfo, err := client.GetAppInfo(ctx, appName)
if err != nil {
return err
}
app, err := client.GetAppCompact(ctx, appName)
if err != nil {
return err
}
ctx, err = apps.BuildContext(ctx, app)
if err != nil {
return err
}
if err := showMachineAppInfo(ctx, app); err != nil {
return err
}
if err := services.ShowMachineServiceInfo(ctx, appInfo); err != nil {
return err
}
if err := showMachineIPInfo(ctx, appName); err != nil {
return err
}
return nil
}
func showMachineAppInfo(ctx context.Context, app *api.AppCompact) error {
var (
io = iostreams.FromContext(ctx)
)
rows := [][]string{
{
app.Name,
app.Organization.Slug,
app.PlatformVersion,
app.Hostname,
},
}
var cols = []string{"Name", "Owner", "Platform", "Hostname"}
if err := render.VerticalTable(io.Out, "App", rows, cols...); err != nil {
return err
}
return nil
}
func showMachineIPInfo(ctx context.Context, appName string) error {
var (
io = iostreams.FromContext(ctx)
client = client.FromContext(ctx).API()
)
info, err := client.GetAppInfo(ctx, appName)
if err != nil {
return err
}
ips := [][]string{}
for _, ip := range info.IPAddresses.Nodes {
fields := []string{
ip.Type,
ip.Address,
ip.Region,
formatRelativeTime(ip.CreatedAt),
}
ips = append(ips, fields)
}
_ = render.Table(io.Out, "IP Addresses", ips, "Type", "Address", "Region", "Created at")
return nil
}