package asaModels import ( "regexp" "github.rackspace.com/gorax/tools/util" ) var ( FAILOVERENABLE = regexp.MustCompile(`(?i)(no\s+failover)`) FAILOVERLANRE = regexp.MustCompile(`(?i)failover\s+lan\s+unit\s+(\S+)`) LINKIFNAMERE = regexp.MustCompile(`(?i)failover\s+lan\s+interface\s+(\S+)`) LINKINTERFACERE = regexp.MustCompile(`(?i)failover\s+lan\s+interface\s+\S+\s+(\S+)`) LANLINKIFNAMERE = regexp.MustCompile(`(?i)failover\s+link\s+(\S+)`) LANLINKINTERFACE = regexp.MustCompile(`(?i)failover\s+link\s+\S+\s+(\S+)`) CONFIGFORE = regexp.MustCompile(`(?i)interface\s+ip\s+(\S+)\s+(\S+)\s+(\S+)\s+standby\s+(\S+)`) ) type ( Failoverconfig struct { Failover bool `json:"failover"` FailoverLanUnit string `json:"failover_lan_unit"` FailoverLink *FailoverLink `json:"failover_link"` FailoverLan *FailoverLan `json:"failover_lan"` FailoverInterface *FailoverInterface `json:"failover_interface"` } FailoverLink struct { LinkIfName string `json:"failover_link_ifname"` LinkInterface string `json:"failover_link_interface"` } FailoverLan struct { LanLinkIfName string `json:"failover_lan_ifname"` LanLinkInterface string `json:"failover_lan_interface"` } FailoverInterface struct { IfName string `json:"ifname"` PrimaryIp string `json:"primary_ip"` Netmask string `json:"netmask"` StandbyIp string `json:"standby_ip"` } ) func FailoverConfigParse(s string) *Failoverconfig { fo := new(Failoverconfig) fo.Parse(s) return fo } func (f *Failoverconfig) Parse(s string) { f.Failover = FAILOVERENABLE.MatchString(s) if f.Failover == true { f.Failover = false } else { f.Failover = true } f.FailoverLanUnit = util.RegexpString(FAILOVERLANRE, s) f.FailoverLink = &FailoverLink{ LinkIfName: util.RegexpString(LINKIFNAMERE, s), LinkInterface: util.RegexpString(LINKINTERFACERE, s), } f.FailoverLan = &FailoverLan{ LanLinkIfName: util.RegexpString(LINKINTERFACERE, s), LanLinkInterface: util.RegexpString(LANLINKINTERFACE, s), } f.FailoverInterface = func() *FailoverInterface { config := CONFIGFORE.FindStringSubmatch(s) if len(config) != 0 { return &FailoverInterface{ IfName: config[1], PrimaryIp: config[2], Netmask: config[3], StandbyIp: config[4], } } return nil }() }