package unipede import ( "net/http" "regexp" ) var ( AGGRRE = regexp.MustCompile(`(?i)aggr(.*?)[a|b]-([0-9]+|[0-9]+e)\..*$`) ) type ( UpNeighbor struct { Count int `json:"count" bson:"count"` Errors *[]Error `json:"errors" bson:"errors"` Items []*NeighborItem `json:"items" bson:"items"` Links map[string]Links `json:"links" bson:"links"` } NeighborItem struct { Created string `json:"created" bson:"created"` Direction string `json:"direction" bson:"direction"` Id int `json:"id" bson:"id"` LocalHostname string `json:"local_hostname" bson:"local_hostname"` LocalInterface string `json:"local_interface" bson:"local_interface"` Protocol string `json:"protocol" bson:"protocol"` RemoteHostname string `json:"remote_hostname" bson:"remote_hostname"` RemoteInterface string `json:"remote_interface" bson:"remote_interface"` UpDeviceId int `json:"up_device_id" bson:"up_device_id"` Updated string `json:"updated" bson:"updated"` } ) func (u *Client) UpNeighbors(switchName string, refresh *int, options ...*UnipedeOptions) (*UpNeighbor, error) { o := processOptions(refresh, nil, options...) req, err := u.newRequest(unipedeURL+"devices/"+switchName+"/UpNeighbor::Model", http.MethodGet, o, nil) if err != nil { return nil, err } swconf := new(UpNeighbor) _, err = u.do(req, o, swconf) return swconf, err } func (u *UpNeighbor) NeighborMap() map[string][]*NeighborItem { nm := make(map[string][]*NeighborItem) for _, data := range u.Items { nm[data.RemoteHostname] = append(nm[data.RemoteHostname], data) } return nm } // func (u *UpNeighbor) GetAggrs() (aggrs []string) { // for _, i := range u.Items { // if util.RegexpFindStringSubmatch(AGGRRE, &i.RemoteHostname) != nil { // aggrs = append(aggrs, i.RemoteHostname) // } // } // return // } func (u *UpNeighbor) SouthNeighbors() (ni []*NeighborItem) { return u.NeighborByPath("south") } func (u *UpNeighbor) NorthNeighbors() (ni []*NeighborItem) { return u.NeighborByPath("north") } func (u *UpNeighbor) NeighborByPath(path string) (ni []*NeighborItem) { for _, n := range u.Items { if n.Direction == path { ni = append(ni, n) } } return } func (u *UpNeighbor) SouthNeighborList() (nl []string) { for _, n := range u.NeighborByPath("south") { nl = append(nl, n.RemoteHostname) } return } func (u *UpNeighbor) NorthNeighborList() (nl []string) { for _, n := range u.NeighborByPath("north") { nl = append(nl, n.RemoteHostname) } return }