1 Star 0 Fork 0

zongzw / go-bigip

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
net.go 16.79 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
package bigip
import (
"strings"
)
// Interfaces contains a list of every interface on the BIG-IP system.
type Interfaces struct {
Interfaces []Interface `json:"items"`
}
// Interface contains information about each individual interface.
type Interface struct {
Name string `json:"name,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
Bundle string `json:"bundle,omitempty"`
Enabled bool `json:"enabled,omitempty"`
FlowControl string `json:"flowControl,omitempty"`
ForceGigabitFiber string `json:"forceGigabitFiber,omitempty"`
IfIndex int `json:"ifIndex,omitempty"`
LLDPAdmin string `json:"lldpAdmin,omitempty"`
LLDPTlvmap int `json:"lldpTlvmap,omitempty"`
MACAddress string `json:"macAddress,omitempty"`
MediaActive string `json:"mediaActive,omitempty"`
MediaFixed string `json:"mediaFixed,omitempty"`
MediaMax string `json:"mediaMax,omitempty"`
MediaSFP string `json:"mediaSfp,omitempty"`
MTU int `json:"mtu,omitempty"`
PreferPort string `json:"preferPort,omitempty"`
SFlow struct {
PollInterval int `json:"pollInterval,omitempty"`
PollIntervalGlobal string `json:"pollIntervalGlobal,omitempty"`
} `json:"sflow,omitempty"`
STP string `json:"stp,omitempty"`
STPAutoEdgePort string `json:"stpAutoEdgePort,omitempty"`
STPEdgePort string `json:"stpEdgePort,omitempty"`
STPLinkType string `json:"stpLinkType,omitempty"`
}
// SelfIPs contains a list of every self IP on the BIG-IP system.
type SelfIPs struct {
SelfIPs []SelfIP `json:"items"`
}
// SelfIP contains information about each individual self IP. You can use all of
// these fields when modifying a self IP.
type SelfIP struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
Address string `json:"address,omitempty"`
Floating string `json:"floating,omitempty"`
InheritedTrafficGroup string `json:"inheritedTrafficGroup,omitempty"`
TrafficGroup string `json:"trafficGroup,omitempty"`
Unit int `json:"unit,omitempty"`
Vlan string `json:"vlan,omitempty"`
// AllowService []string `json:"allowService"`
}
// Trunks contains a list of every trunk on the BIG-IP system.
type Trunks struct {
Trunks []Trunk `json:"items"`
}
// Trunk contains information about each individual trunk. You can use all of
// these fields when modifying a trunk.
type Trunk struct {
Name string `json:"name,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
Bandwidth int `json:"bandwidth,omitempty"`
MemberCount int `json:"cfgMbrCount,omitempty"`
DistributionHash string `json:"distributionHash,omitempty"`
ID int `json:"id,omitempty"`
LACP string `json:"lacp,omitempty"`
LACPMode string `json:"lacpMode,omitempty"`
LACPTimeout string `json:"lacpTimeout,omitempty"`
LinkSelectPolicy string `json:"linkSelectPolicy,omitempty"`
MACAddress string `json:"macAddress,omitempty"`
STP string `json:"stp,omitempty"`
Type string `json:"type,omitempty"`
WorkingMemberCount int `json:"workingMbrCount,omitempty"`
Interfaces []string `json:"interfaces,omitempty"`
}
// Vlans contains a list of every VLAN on the BIG-IP system.
type Vlans struct {
Vlans []Vlan `json:"items"`
}
// Vlan contains information about each individual VLAN. You can use all of
// these fields when modifying a VLAN.
type Vlan struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
AutoLastHop string `json:"autoLastHop,omitempty"`
CMPHash string `json:"cmpHash,omitempty"`
DAGRoundRobin string `json:"dagRoundRobin,omitempty"`
Failsafe string `json:"failsafe,omitempty"`
FailsafeAction string `json:"failsafeAction,omitempty"`
FailsafeTimeout int `json:"failsafeTimeout,omitempty"`
IfIndex int `json:"ifIndex,omitempty"`
Learning string `json:"learning,omitempty"`
MTU int `json:"mtu,omitempty"`
SFlow struct {
PollInterval int `json:"pollInterval,omitempty"`
PollIntervalGlobal string `json:"pollIntervalGlobal,omitempty"`
SamplingRate int `json:"samplingRate,omitempty"`
SamplingRateGlobal string `json:"samplingRateGlobal,omitempty"`
} `json:"sflow,omitempty"`
SourceChecking string `json:"sourceChecking,omitempty"`
Tag int `json:"tag,omitempty"`
}
// VlanInterface contains fields to be used when adding an interface to a VLAN.
type VlanInterface struct {
Name string `json:"name,omitempty"`
Tagged bool `json:"tagged,omitempty"`
Untagged bool `json:"untagged,omitempty"`
}
// Routes contains a list of every route on the BIG-IP system.
type Routes struct {
Routes []Route `json:"items"`
}
// Route contains information about each individual route. You can use all
// of these fields when modifying a route.
type Route struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
MTU int `json:"mtu,omitempty"`
Network string `json:"network,omitempty"`
// Mutually exclusive fields
Blackhole bool `json:"blackhole,omitempty"`
Gateway string `json:"gw,omitempty"`
Pool string `json:"pool,omitempty"`
Interface string `json:"tmInterface,omitempty"`
}
// RouteDomains contains a list of every route domain on the BIG-IP system.
type RouteDomains struct {
RouteDomains []RouteDomain `json:"items"`
}
// RouteDomain contains information about each individual route domain. You can use all
// of these fields when modifying a route domain.
type RouteDomain struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
ID int `json:"id,omitempty"`
Strict string `json:"strict,omitempty"`
Vlans []string `json:"vlans,omitempty"`
}
// BGPInstances contains a list of every BGP instance on the BIG-IP system.
type BGPInstances struct {
BGPInstances []BGPInstance `json:"items"`
}
// BGPInstance contains information about each individual BGP instance. You can use all
// of these fields when modifying a BGP instance.
type BGPInstance struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
LocalAS int `json:"localAs,omitempty"`
}
// BGPNeighbors contains a list of BGP neighbors of a BGP instance on the BIG-IP system.
type BGPNeighbors struct {
BGPNeighbors []BGPNeighbor `json:"items"`
}
// BGPNeighbor contains information about each individual BGP neighbor. You can use all
// of these fields when modifying a BGP neighbor.
type BGPNeighbor struct {
Name string `json:"name,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
RemoteAS int `json:"remoteAs,omitempty"`
}
const (
uriNet = "net"
uriInterface = "interface"
uriSelf = "self"
uriTrunk = "trunk"
uriVlan = "vlan"
uriRoute = "route"
uriRouteDomain = "route-domain"
uriRouting = "routing"
uriBGP = "bgp"
uriNeighbor = "neighbor"
)
// Interfaces returns a list of interfaces.
func (b *BigIP) Interfaces() (*Interfaces, error) {
var interfaces Interfaces
err, _ := b.getForEntity(&interfaces, uriNet, uriInterface)
if err != nil {
return nil, err
}
return &interfaces, nil
}
// AddInterfaceToVlan associates the given interface to the specified VLAN.
func (b *BigIP) AddInterfaceToVlan(vlan, iface string, tagged bool) error {
config := &VlanInterface{}
config.Name = iface
if tagged {
config.Tagged = true
} else {
config.Untagged = true
}
return b.put(config, uriNet, uriVlan, vlan, "interfaces")
}
// SelfIPs returns a list of self IP's.
func (b *BigIP) SelfIPs() (*SelfIPs, error) {
var self SelfIPs
err, _ := b.getForEntity(&self, uriNet, uriSelf)
if err != nil {
return nil, err
}
return &self, nil
}
// CreateSelfIP adds a new self IP to the BIG-IP system. For <address>, you
// must include the subnet mask in CIDR notation, i.e.: "10.1.1.1/24".
func (b *BigIP) CreateSelfIP(name, address, vlan string) error {
config := &SelfIP{
Name: name,
Address: address,
Vlan: vlan,
}
return b.post(config, uriNet, uriSelf)
}
// DeleteSelfIP removes a self IP.
func (b *BigIP) DeleteSelfIP(name string) error {
return b.delete(uriNet, uriSelf, name)
}
// ModifySelfIP allows you to change any attribute of a self IP. Fields that
// can be modified are referenced in the SelfIP struct.
func (b *BigIP) ModifySelfIP(name string, config *SelfIP) error {
return b.put(config, uriNet, uriSelf, name)
}
// Trunks returns a list of trunks.
func (b *BigIP) Trunks() (*Trunks, error) {
var trunks Trunks
err, _ := b.getForEntity(&trunks, uriNet, uriTrunk)
if err != nil {
return nil, err
}
return &trunks, nil
}
// CreateTrunk adds a new trunk to the BIG-IP system. <interfaces> must be
// separated by a comma, i.e.: "1.4, 1.6, 1.8".
func (b *BigIP) CreateTrunk(name, interfaces string, lacp bool) error {
rawInts := strings.Split(interfaces, ",")
ints := []string{}
for _, i := range rawInts {
ints = append(ints, strings.Trim(i, " "))
}
config := &Trunk{
Name: name,
Interfaces: ints,
}
if lacp {
config.LACP = "enabled"
}
return b.post(config, uriNet, uriTrunk)
}
// DeleteTrunk removes a trunk.
func (b *BigIP) DeleteTrunk(name string) error {
return b.delete(uriNet, uriTrunk, name)
}
// ModifyTrunk allows you to change any attribute of a trunk. Fields that
// can be modified are referenced in the Trunk struct.
func (b *BigIP) ModifyTrunk(name string, config *Trunk) error {
return b.put(config, uriNet, uriTrunk, name)
}
// Vlans returns a list of vlans.
func (b *BigIP) Vlans() (*Vlans, error) {
var vlans Vlans
err, _ := b.getForEntity(&vlans, uriNet, uriVlan)
if err != nil {
return nil, err
}
return &vlans, nil
}
// CreateVlan adds a new VLAN to the BIG-IP system.
func (b *BigIP) CreateVlan(name string, tag int) error {
config := &Vlan{
Name: name,
Tag: tag,
}
return b.post(config, uriNet, uriVlan)
}
// DeleteVlan removes a vlan.
func (b *BigIP) DeleteVlan(name string) error {
return b.delete(uriNet, uriVlan, name)
}
// ModifyVlan allows you to change any attribute of a VLAN. Fields that
// can be modified are referenced in the Vlan struct.
func (b *BigIP) ModifyVlan(name string, config *Vlan) error {
return b.put(config, uriNet, uriVlan, name)
}
// Routes returns a list of routes.
func (b *BigIP) Routes() (*Routes, error) {
var routes Routes
err, _ := b.getForEntity(&routes, uriNet, uriRoute)
if err != nil {
return nil, err
}
return &routes, nil
}
// CreateRoute adds a new static route to the BIG-IP system. <dest> must include the
// subnet mask in CIDR notation, i.e.: "10.1.1.0/24".
func (b *BigIP) CreateRoute(name, dest, gateway string) error {
config := &Route{
Name: name,
Network: dest,
Gateway: gateway,
}
return b.post(config, uriNet, uriRoute)
}
// AddRoute adds a new static route to the BIG-IP system.
func (b *BigIP) AddRoute(config *Route) error {
return b.post(config, uriNet, uriRoute)
}
// GetRoute gets a static route.
func (b *BigIP) GetRoute(name string) (*Route, error) {
var route Route
err, _ := b.getForEntity(&route, uriNet, uriRoute, name)
if err != nil {
return nil, err
}
return &route, nil
}
// DeleteRoute removes a static route.
func (b *BigIP) DeleteRoute(name string) error {
return b.delete(uriNet, uriRoute, name)
}
// ModifyRoute allows you to change any attribute of a static route. Fields that
// can be modified are referenced in the Route struct.
func (b *BigIP) ModifyRoute(name string, config *Route) error {
return b.put(config, uriNet, uriRoute, name)
}
// RouteDomains returns a list of route domains.
func (b *BigIP) RouteDomains() (*RouteDomains, error) {
var rd RouteDomains
err, _ := b.getForEntity(&rd, uriNet, uriRouteDomain)
if err != nil {
return nil, err
}
return &rd, nil
}
// CreateRouteDomain adds a new route domain to the BIG-IP system. <vlans> must be separated
// by a comma, i.e.: "vlan1010, vlan1020".
func (b *BigIP) CreateRouteDomain(name string, id int, strict bool, vlans string) error {
strictIsolation := "enabled"
vlanMembers := []string{}
rawVlans := strings.Split(vlans, ",")
for _, v := range rawVlans {
vlanMembers = append(vlanMembers, strings.Trim(v, " "))
}
if !strict {
strictIsolation = "disabled"
}
config := &RouteDomain{
Name: name,
ID: id,
Strict: strictIsolation,
Vlans: vlanMembers,
}
return b.post(config, uriNet, uriRouteDomain)
}
// DeleteRouteDomain removes a route domain.
func (b *BigIP) DeleteRouteDomain(name string) error {
return b.delete(uriNet, uriRouteDomain, name)
}
// ModifyRouteDomain allows you to change any attribute of a route domain. Fields that
// can be modified are referenced in the RouteDomain struct.
func (b *BigIP) ModifyRouteDomain(name string, config *RouteDomain) error {
return b.put(config, uriNet, uriRouteDomain, name)
}
// BGPInstances returns a list of BGP instances.
func (b *BigIP) BGPInstances() (*BGPInstances, error) {
var bgpInstances BGPInstances
err, _ := b.getForEntity(&bgpInstances, uriNet, uriRouting, uriBGP)
if err != nil {
return nil, err
}
return &bgpInstances, nil
}
// CreateBGPInstance adds a new BGP instance to the BIG-IP system.
func (b *BigIP) CreateBGPInstance(name string, localAS int) error {
config := &BGPInstance{
Name: name,
LocalAS: localAS,
}
return b.post(config, uriNet, uriRouting, uriBGP)
}
// AddBGPInstance adds a new BGP instance to the BIG-IP system.
func (b *BigIP) AddBGPInstance(config *BGPInstance) error {
return b.post(config, uriNet, uriRouting, uriBGP)
}
// GetBGPInstance gets a BGP instance.
func (b *BigIP) GetBGPInstance(name string) (*BGPInstance, error) {
var bgpInstance BGPInstance
err, ok := b.getForEntity(&bgpInstance, uriNet, uriRouting, uriBGP, name)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return &bgpInstance, nil
}
// DeleteBGPInstance removes a BGP instance.
func (b *BigIP) DeleteBGPInstance(name string) error {
return b.delete(uriNet, uriRouting, uriBGP, name)
}
// ModifyBGPInstance allows you to change any attribute of a BGP instance. Fields that
// can be modified are referenced in the BGPInstance struct.
func (b *BigIP) ModifyBGPInstance(name string, config *BGPInstance) error {
return b.put(config, uriNet, uriRouting, uriBGP, name)
}
// BGPNeighbors returns a list of BGP neighbors of a BGP instance.
func (b *BigIP) BGPNeighbors(instance string) (*BGPNeighbors, error) {
var bgpNeighbors BGPNeighbors
err, _ := b.getForEntity(&bgpNeighbors, uriNet, uriRouting, uriBGP, instance, uriNeighbor)
if err != nil {
return nil, err
}
return &bgpNeighbors, nil
}
// CreateBGPNeighbor adds a new BGP neigbhor to a BGP instance in the BIG-IP system.
func (b *BigIP) CreateBGPNeighbor(instance, name string, remoteAS int) error {
config := &BGPNeighbor{
Name: name,
RemoteAS: remoteAS,
}
return b.post(config, uriNet, uriRouting, uriBGP, instance, uriNeighbor)
}
// AddBGPNeighbor adds a new BGP neighbor to a BGP instance in the BIG-IP system.
func (b *BigIP) AddBGPNeighbor(instance string, config *BGPNeighbor) error {
return b.post(config, uriNet, uriRouting, uriBGP, instance, uriNeighbor)
}
// GetBGPNeighbor gets a BGP neighbor of a BGP instance.
func (b *BigIP) GetBGPNeighbor(instance, name string) (*BGPNeighbor, error) {
var bgpNeighbor BGPNeighbor
err, ok := b.getForEntity(&bgpNeighbor, uriNet, uriRouting, uriBGP, instance, uriNeighbor, name)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return &bgpNeighbor, nil
}
// DeleteBGPNeighbor removes a BGP neighbor from a BGP instance.
func (b *BigIP) DeleteBGPNeighbor(instance, name string) error {
return b.delete(uriNet, uriRouting, uriBGP, instance, uriNeighbor, name)
}
// ModifyBGPNeighbor allows you to change any attribute of a BGP neighbor of a BGP instance.
// Fields that can be modified are referenced in the BGPNeighbor struct.
func (b *BigIP) ModifyBGPNeighbor(instance, name string, config *BGPNeighbor) error {
return b.put(config, uriNet, uriRouting, uriBGP, instance, uriNeighbor, name)
}
1
https://gitee.com/zongzw/go-bigip.git
git@gitee.com:zongzw/go-bigip.git
zongzw
go-bigip
go-bigip
72a9a12c0ae1

搜索帮助

53164aa7 5694891 3bd8fe86 5694891