// returns a column of the routing table as a slice of strings // TODO read from /proc/net/route instead func RoutingTableColumn(name string) []string { cmd := exec.Command("route", "-n") out := chkutil.CommandOutput(cmd) table := tabular.ProbabalisticSplit(out) if len(table) < 1 { log.WithFields(log.Fields{ "column": name, "table": "\n" + tabular.ToString(table), }).Fatal("Routing table was not available or not properly parsed") } finalTable := table[1:] // has extra line before headers return tabular.GetColumnByHeader(name, finalTable) }
// getYumRepos constructs Repos from the yum.conf file at path. Gives non-zero // Names, Fullnames, and URLs. func getYumRepos() (repos []repo) { // safeAccess allows access w/o fear of a panic into a slice of strings safeAccess := func(slc []string, index int) string { // catch runtime panic defer func() { if err := recover(); err != nil { msg := "safeAccess: Please report this error" errutil.IndexError(msg, index, slc) } }() // invoke inside defer if len(slc) > index { return slc[index] } return "" } // get and parse output of `yum repolist` cmd := exec.Command("yum", "repolist") outstr := chkutil.CommandOutput(cmd) // handle empty case if strings.Contains(outstr, "repolist: 0") { return repos } slc := tabular.ProbabalisticSplit(outstr) ids := tabular.GetColumnNoHeader(0, slc) // TODO use columnbyheader here errutil.IndexError("getYumRepos", 2, ids) ids = ids[:len(ids)-2] names := tabular.GetColumnNoHeader(1, slc) // TODO and here statuses := tabular.GetColumnNoHeader(2, slc) // TODO and here if len(ids) != len(names) || len(names) != len(statuses) { log.WithFields(log.Fields{ "names": len(names), "ids": len(ids), "statuses": len(statuses), }).Warn("Could not fetch complete metadata for every repo.") } // Construct repos for i := range ids { name := safeAccess(names, i) id := safeAccess(ids, i) status := safeAccess(statuses, i) repo := repo{Name: name, ID: id, Status: status} repos = append(repos, repo) } return repos }