func dfCmdRun(cmd *cobra.Command, args []string) { propertyList := "org.freebsd.iocage:host_hostuuid," + "org.freebsd.iocage:tag,compressratio,reservation," + "quota,used,available" outputHeaders := []string{"uuid", "tag", "crt", "res", "qta", "use", "ava"} zfsArgs := []string{"list", "-H", "-o", propertyList} if ParsableValues { zfsArgs = append(zfsArgs, "-p") } if len(args) == 0 { zfsArgs = append(zfsArgs, "-d", "1", core.GetJailsPath()) } else { jail, err := core.FindJail(args[0]) if err != nil { gologit.Fatalf("No jail found by '%s'\n", args[0]) } zfsArgs = append(zfsArgs, jail.Path) } out := core.ZFSMust(fmt.Errorf("Error listing jails"), zfsArgs...) lines := strings.Split(out, "\n") wf := core.NewOutputWriter(outputHeaders, MachineOutput) for _, line := range lines { if strings.HasPrefix(line, "-") { continue } fmt.Fprintf(wf, "%s\n", line) } wf.Flush() }
func listCmdRun(cmd *cobra.Command, args []string) { const propertyList = "org.freebsd.iocage:host_hostuuid," + "org.freebsd.iocage:tag,org.freebsd.iocage:boot" outputHeaders := []string{"jid", "uuid", "tag", "boot", "state"} running := core.JlsMust( fmt.Errorf("Error getting jls data"), "jid", "name") jails := make(map[string]string, 0) for _, jinfo := range strings.Split(running, "\n") { jail := strings.Split(jinfo, " ") if len(jail) < 2 { continue } jid := strings.TrimSpace(jail[0]) jname := strings.TrimSpace(jail[1]) jails[jname] = jid } out := core.ZFSMust( fmt.Errorf("Error listing jails"), "list", "-H", "-o", propertyList, "-d", "1", core.GetJailsPath()) lines := strings.Split(out, "\n") wf := core.NewOutputWriter(outputHeaders, MachineOutput) for _, line := range lines { if strings.HasPrefix(line, "-") { continue } iocid := fmt.Sprintf("ioc-%s", strings.SplitN(line, "\t", 2)[0]) state := "up" jid, ok := jails[iocid] if !ok { jid = "-" state = "down" } fmt.Fprintf(wf, "%s\t%s\t%s\n", jid, line, state) } wf.Flush() }