package pkg import ( "regexp" "github.rackspace.com/gorax/tools/util" ) var ( LISTSYSMGMTIPRE = regexp.MustCompile(`(?i)(|s)ys\s+management-ip\s+(\S+)\s+{((.|\n)*?)(\n\w|$)`) LISTSYSROUTERE = regexp.MustCompile(`(?i)(|s)ys\s+management-route\s+(\S+)\s+{((.|\n)*?)(\n\w|$)`) GATEWAYRE = regexp.MustCompile(`(?i)gateway\s+(\S+)`) ) type ( MgmtIP struct { IpAddr string `json:"management-ip"` Desc string `json:"description"` } MgmtRoutes struct { MgmtRoutes []*MgmtRoute `json:"management-routes"` } MgmtRoute struct { Name string `json:"name"` Gateway string `json:"gateway"` Network string `json:"network"` } ) func ParseManagementIP(s string) *MgmtIP { i := new(MgmtIP) i.Parse(s) return i } func (m *MgmtIP) Parse(s string) { i := LISTSYSMGMTIPRE.FindStringSubmatch(s) if len(i) != 0 { m.IpAddr = i[2] m.Desc = util.RegexpString(descriptionRegex, s) } } func ParseManagementRoutes(s string) *MgmtRoutes { r := new(MgmtRoutes) r.Parse(s) return r } func (m *MgmtRoutes) Parse(s string) { for _, i := range LISTSYSROUTERE.FindAllStringSubmatch(s, -1) { m.MgmtRoutes = append(m.MgmtRoutes, &MgmtRoute{ Name: i[2], Gateway: util.RegexpString(GATEWAYRE, i[3]), Network: util.RegexpString(NETWORKRE, i[3]), }) } }