package asa import ( "errors" "net" "github.rackspace.com/gorax/asaapi/pkg/asaModels" "github.rackspace.com/gorax/libs/netdevice" "github.rackspace.com/gorax/tools/util" ) var ( errNotFound = errors.New("item not found") ) //ARP will perform show arp on the device and populate Status.ARP func (a *ASA) ARP() error { return a.GetArp() } //FindARP will look for the ip in status.ARP and require ARP() to be run before func (a *ASA) FindARP(ip string) (arp netdevice.ARP, err error) { for _, e := range a.Status.ARP { if e.Address == ip { return netdevice.ARP{ IPAddress: e.Address, TTL: e.TimeOut, MAC: e.Mac, IfName: func() string { for _, i := range a.Config.Interfaces { if i.Nameif != nil { if *i.Nameif == e.IfName { return i.Name } } } return "" }(), Vlan: e.IfName, Netdevice: a.Device, }, nil } } return arp, errNotFound } //InterfaceConfigs will perform a show run interface on the device and populate Config.Interfaces func (a *ASA) InterfaceConfigs() error { err := a.GetInterfaces() if err != nil { return err } return a.ShowInterfaces() } //FindInterface will look for the matching interface by name in Config.Interfaces func (a *ASA) FindInterface(name string) (config netdevice.IfConfig, err error) { conf := a.FindInterfaceConfig(name) if conf == nil { return config, errNotFound } status := asaModels.FindInterfaceStatus(name, a.Status.Interfaces) if status == nil { a.log.Println("No Status") return config, errNotFound } return netdevice.IfConfig{ IntName: conf.Name, VlanName: func() string { if conf.Nameif == nil { return "" } return *conf.Nameif }(), Sec: func() int { if conf.SecLevel == nil { return 0 } return *conf.SecLevel }(), MAC: status.MAC, IPAddress: func() string { i, _ := util.IPToCIDR(status.IPAddress, status.Netmask) return i }(), Link: status.Link, AdminUp: status.Admin, Hardware: status.Hardware, Netdevice: a.Device, }, nil } //Routes will perform a show route and populate Status.Routes func (a *ASA) Routes() error { return a.GetRoutes() } //FindRoute will find the matchin network for the ip given func (a *ASA) FindRoute(ip string) (route netdevice.Route, err error) { i := net.ParseIP(ip) if i == nil { return route, errors.New("invalide IP Address") } for _, r := range a.Status.Routes { if r.Contains(i) { return netdevice.Route{ NextHop: r.NextHop, Network: func() string { n, _ := util.IPToCIDR(r.Network, r.Netmask) return n }(), Type: r.Type, }, nil } } return route, errNotFound } //MACAddresses will run show arp since there is no mac address call on an asa, it will populate Status.ARP func (a *ASA) MACAddresses() error { return a.ARP() } //FindMAC will find a matching mac address in the Status.ARP table func (a *ASA) FindMAC(mac string) (m netdevice.MAC, err error) { return } //Vlans run show interface since there is no dedicated option on the asa func (a *ASA) VLans() error { return a.InterfaceConfigs() } //FindVlanNumber will find the vlan that matches the number given func (a *ASA) FindVlanNumber(num int) (vlan netdevice.Vlan, err error) { return } //FindVlanNumber will find the vlan that matches the name given func (a *ASA) FindVlanName(name string) (vlan netdevice.Vlan, err error) { return } //Number will return the inventory number, or -1 if none is assigned func (a *ASA) Number() int { return a.Device } //Name will return the inventory name, or "" if none is assigned func (a *ASA) Name() string { if a.Info != nil { return a.Info.Name } return "" } //Plaform will return the device Model and Type func (a *ASA) Platform() (platformModel, platformType string) { if a.Info != nil { return a.Info.PlatformModel, a.Info.PlatformName } return } //ProductionStatus will return the device rack status func (a *ASA) ProductionStatus() string { if a.Info != nil { return a.Info.Status } return "" } //DeviceActive will return the current HA status, if the device is standalone it will return true, if its not able //go gather the device status it will error out func (a *ASA) DeviceActive() (active bool, err error) { return } //IsHA will validate that the device is HA, by config or inventory assignment func (a *ASA) IsHA() bool { if a.Failover != nil { return true } return false } //FailoverDevice will return the failover device number func (a *ASA) FailoverDevice() int { if a.Failover != nil { return *a.Failover } return -1 }