This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 276
/
gateways_info.go
74 lines (60 loc) · 2.14 KB
/
gateways_info.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
// Copyright © 2017 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.
package cmd
import (
"fmt"
"strings"
"github.com/TheThingsNetwork/api"
"github.com/TheThingsNetwork/ttn/ttnctl/util"
"github.com/spf13/cobra"
)
var gatewaysInfoCmd = &cobra.Command{
Use: "info [GatewayID]",
Short: "Get info about a gateway",
Long: `ttnctl gateways info can be used to get information about a gateway`,
Run: func(cmd *cobra.Command, args []string) {
assertArgsLength(cmd, args, 1, 1)
gatewayID := strings.ToLower(args[0])
if err := api.NotEmptyAndValidID(gatewayID, "Gateway ID"); err != nil {
ctx.Fatal(err.Error())
}
account := util.GetAccount(ctx)
gateway, err := account.FindGateway(gatewayID)
if err != nil {
ctx.WithError(err).WithField("id", gatewayID).Fatal("Could not find gateway")
}
ctx.Info("Found gateway")
fmt.Println()
printKV("Gateway ID", gateway.ID)
printKV("Frequency Plan", gateway.FrequencyPlan)
if gateway.Router != nil {
printKV("Router", gateway.Router.ID)
}
printBool("Auto Update", gateway.AutoUpdate, "on", "off")
printKV("Owner", gateway.Owner.Username)
printBool("Owner Public", gateway.OwnerPublic, "yes", "no")
if gateway.AntennaLocation != nil {
printKV("Location", fmt.Sprintf("(%f, %f, %d)", gateway.AntennaLocation.Latitude, gateway.AntennaLocation.Longitude, gateway.AntennaLocation.Altitude))
}
printBool("Location Public", gateway.LocationPublic, "yes", "no")
printBool("Status Public", gateway.StatusPublic, "yes", "no")
fmt.Println()
printKV("Brand", gateway.Attributes.Brand)
printKV("Model", gateway.Attributes.Model)
printKV("Placement", gateway.Attributes.Placement)
printKV("AntennaType", gateway.Attributes.AntennaType)
printKV("AntennaModel", gateway.Attributes.AntennaModel)
printKV("Description", gateway.Attributes.Description)
if gateway.Key != "" {
printKV("Access Key", gateway.Key)
}
if len(gateway.Collaborators) > 0 {
fmt.Println()
fmt.Println("Collaborators:")
printCollaborators(gateway.Collaborators)
}
},
}
func init() {
gatewaysCmd.AddCommand(gatewaysInfoCmd)
}