-
Notifications
You must be signed in to change notification settings - Fork 1
/
gretunnelinfo.go
37 lines (33 loc) · 1.14 KB
/
gretunnelinfo.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
package gretunnelinfo
import (
"fmt"
"net/url"
"strings"
)
const (
ipGreTunnelInfoEndpoint = "/orgProvisioning/ipGreTunnelInfo"
)
type GRETunnelInfo struct {
TunID int `json:"tunID,omitempty"`
IPaddress string `json:"ipAddress,omitempty"`
GREEnabled bool `json:"greEnabled,omitempty"`
GREtunnelIP string `json:"greTunnelIP,omitempty"`
PrimaryGW string `json:"primaryGW,omitempty"`
SecondaryGW string `json:"secondaryGW,omitempty"`
GRERangePrimary string `json:"greRangePrimary,omitempty"`
GRERangeSecondary string `json:"greRangeSecondary,omitempty"`
}
// Gets a list of IP addresses with GRE tunnel details.
func (service *Service) GetGRETunnelInfo(ipAddress string) (*GRETunnelInfo, error) {
var greTunnelInfo []GRETunnelInfo
err := service.Client.Read(fmt.Sprintf("%s?ipAddress=%s", ipGreTunnelInfoEndpoint, url.QueryEscape(ipAddress)), &greTunnelInfo)
if err != nil {
return nil, err
}
for _, greIP := range greTunnelInfo {
if strings.EqualFold(greIP.IPaddress, ipAddress) {
return &greIP, nil
}
}
return nil, fmt.Errorf("no information for gre tunnel ip address: %s", ipAddress)
}