Skip to content

Commit 49dadde

Browse files
authored
Merge pull request aristanetworks#29 from zlesnr/switchportinterface
Add ShowInterfacesSwitchport module
2 parents 42655de + 6c95bc8 commit 49dadde

File tree

3 files changed

+996
-0
lines changed

3 files changed

+996
-0
lines changed

module/interfaces_switchport.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//
2+
// Copyright (c) 2015-2016, Arista Networks, Inc.
3+
// All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright notice,
10+
// this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Arista Networks nor the names of its
17+
// contributors may be used to endorse or promote products derived from
18+
// this software without specific prior written permission.
19+
//
20+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS
24+
// BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27+
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28+
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29+
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30+
// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
//
32+
33+
package module
34+
35+
type ShowInterfacesSwitchport struct {
36+
Switchports map[string]Switchport `json:"switchports"`
37+
}
38+
39+
type Switchport struct {
40+
Enabled bool `json:"enabled"`
41+
SwitchportInfo SwitchportInfo `json:"switchportInfo"`
42+
}
43+
44+
type SwitchportInfo struct {
45+
AccessVlanID int `json:"accessVlanId"`
46+
AccessVlanName string `json:"accessVlanName"`
47+
DynamicAllowedVlans struct{} `json:"dynamicAllowedVlans"`
48+
DynamicTrunkGroups []interface{} `json:"dynamicTrunkGroups"`
49+
MacLearning bool `json:"macLearning"`
50+
Mode string `json:"mode"`
51+
StaticTrunkGroups []interface{} `json:"staticTrunkGroups"`
52+
Tpid string `json:"tpid"`
53+
TpidStatus bool `json:"tpidStatus"`
54+
TrunkAllowedVlans string `json:"trunkAllowedVlans"`
55+
TrunkingNativeVlanID int `json:"trunkingNativeVlanId"`
56+
TrunkingNativeVlanName string `json:"trunkingNativeVlanName"`
57+
}
58+
59+
func (l *ShowInterfacesSwitchport) GetCmd() string {
60+
return "show interfaces switchport"
61+
}
62+
63+
func (s *ShowEntity) ShowInterfacesSwitchport() ShowInterfacesSwitchport {
64+
handle, _ := s.node.GetHandle("json")
65+
var showInterfacesSwitchport ShowInterfacesSwitchport
66+
handle.AddCommand(&showInterfacesSwitchport)
67+
handle.Call()
68+
handle.Close()
69+
return showInterfacesSwitchport
70+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package module
2+
3+
import (
4+
"testing"
5+
6+
"github.com/aristanetworks/goeapi"
7+
)
8+
9+
func TestShowInterfacesSwitchport_UnitTest(t *testing.T) {
10+
var dummyNode *goeapi.Node
11+
var dummyConnection *DummyConnection
12+
13+
dummyConnection = &DummyConnection{}
14+
15+
dummyNode = &goeapi.Node{}
16+
dummyNode.SetConnection(dummyConnection)
17+
18+
show := Show(dummyNode)
19+
showInterfacesSwitchport := show.ShowInterfacesSwitchport()
20+
21+
var scenarios = []struct {
22+
Interface string
23+
AccessVlanID int
24+
Mode string
25+
}{
26+
{
27+
Interface: "Ethernet48",
28+
AccessVlanID: 1,
29+
Mode: "trunk",
30+
},
31+
}
32+
33+
switchports := showInterfacesSwitchport.Switchports
34+
35+
for _, tt := range scenarios {
36+
37+
p := switchports[tt.Interface]
38+
39+
if tt.AccessVlanID != p.SwitchportInfo.AccessVlanID {
40+
t.Errorf("AccessVlanID does not match: expected %d, got %d", tt.AccessVlanID, p.SwitchportInfo.AccessVlanID)
41+
}
42+
43+
if tt.Mode != p.SwitchportInfo.Mode {
44+
t.Errorf("Mode does not match: expected %s, got %s", tt.Mode, p.SwitchportInfo.Mode)
45+
}
46+
47+
}
48+
49+
}

0 commit comments

Comments
 (0)