/
status.go
63 lines (58 loc) · 1.88 KB
/
status.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
package cluster
import (
"context"
"errors"
"fmt"
"github.com/appcelerator/amp/api/rpc/cluster"
"github.com/appcelerator/amp/cli"
"github.com/appcelerator/amp/pkg/cloud"
"github.com/spf13/cobra"
grpcStatus "google.golang.org/grpc/status"
)
// NewStatusCommand returns a new instance of the status command for querying the state of amp cluster.
func NewStatusCommand(c cli.Interface) *cobra.Command {
cmd := &cobra.Command{
Use: "status",
Aliases: []string{"info"},
Short: "Retrieve details about an amp cluster",
PreRunE: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return status(c, cmd)
},
}
return cmd
}
func status(c cli.Interface, cmd *cobra.Command) error {
req := &cluster.StatusRequest{}
client := cluster.NewClusterClient(c.ClientConn())
reply, err := client.ClusterStatus(context.Background(), req)
if err != nil {
if s, ok := grpcStatus.FromError(err); ok {
return errors.New(s.Message())
}
}
if reply.Provider == "" {
return errors.New("empty reply from server, probably an API mismatch")
}
fmt.Printf("Provider: %s\n", reply.Provider)
if reply.Provider != string(cloud.ProviderLocal) {
fmt.Printf("Cluster name: %s\n", reply.Name)
fmt.Printf("Region: %s\n", reply.Region)
}
fmt.Printf("Swarm Status: %s\n", reply.SwarmStatus)
fmt.Printf("Core Services: %s\n", reply.CoreServices)
fmt.Printf("User Services: %s\n", reply.UserServices)
if reply.Endpoint != "" {
fmt.Printf("DNS Target: %s\n", reply.Endpoint)
}
if reply.InternalEndpoint != "" {
fmt.Printf("Docker Host (internal): %s\n", reply.InternalEndpoint)
}
if reply.InternalPki != "" {
fmt.Printf("PKI Endpoint (internal): %s\n", reply.InternalPki)
}
if reply.NfsEndpoint != "disabled" {
fmt.Printf("NFS Endpoint: %s\n", reply.NfsEndpoint)
}
return nil
}