MCPcopy
hub / github.com/google/seesaw / showVLANs

Function showVLANs

cli/show.go:78–138  ·  view source on GitHub ↗
(cli *SeesawCLI, args []string)

Source from the content-addressed store, hash-verified

76}
77
78func showVLANs(cli *SeesawCLI, args []string) error {
79 if len(args) > 1 {
80 fmt.Println("show vlans [<id>|<ip>]")
81 return nil
82 }
83
84 vlans, err := cli.seesaw.VLANs()
85 if err != nil {
86 return fmt.Errorf("failed to get VLANs: %v", err)
87 }
88
89 if len(args) == 0 {
90 // Display all VLANs.
91 sort.Sort(vlans)
92 printHdr("VLANs")
93 for i, v := range vlans.VLANs {
94 fmt.Printf("[%3d] VLAN ID %d - %s\n", i+1, v.ID, v.Hostname)
95 }
96 return nil
97 }
98
99 // Display details for a single VLAN (by ID or IP address).
100 var vlan *seesaw.VLAN
101 if id, err := strconv.ParseUint(args[0], 10, 16); err == nil {
102 // By ID
103 for _, v := range vlans.VLANs {
104 if uint(v.ID) == uint(id) {
105 vlan = v
106 break
107 }
108 }
109 if vlan == nil {
110 return fmt.Errorf("VLAN ID %d not found", id)
111 }
112 } else if ip := net.ParseIP(args[0]); ip != nil {
113 // By IP
114 for _, v := range vlans.VLANs {
115 if v.IPv4Net().Contains(ip) || v.IPv6Net().Contains(ip) {
116 vlan = v
117 break
118 }
119 }
120 if vlan == nil {
121 return fmt.Errorf("VLAN not found for IP address %v", ip)
122 }
123 } else {
124 return fmt.Errorf("unknown value %q - must be a VLAN ID or IP address", args[0])
125 }
126
127 printHdr("VLAN")
128 printVal("ID:", vlan.ID)
129 printVal("Hostname:", vlan.Hostname)
130 printFmt("IPv4 Address:", vlan.IPv4Printable())
131 printFmt("IPv6 Address:", vlan.IPv6Printable())
132 printVal("IPv4 Backend Count:", vlan.BackendCount[seesaw.IPv4])
133 printVal("IPv6 Backend Count:", vlan.BackendCount[seesaw.IPv6])
134 printVal("IPv4 VIP Count:", vlan.VIPCount[seesaw.IPv4])
135 printVal("IPv6 VIP Count:", vlan.VIPCount[seesaw.IPv6])

Callers

nothing calls this directly

Calls 8

printHdrFunction · 0.85
printValFunction · 0.85
printFmtFunction · 0.85
IPv4NetMethod · 0.80
IPv6NetMethod · 0.80
IPv4PrintableMethod · 0.80
IPv6PrintableMethod · 0.80
VLANsMethod · 0.65

Tested by

no test coverage detected