예제 #1
0
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()
}
예제 #2
0
func releaseListCmdRun(cmd *cobra.Command, args []string) {
	releases := core.GetAllReleases()

	wf := core.NewOutputWriter([]string{"name", "patchlevel"}, MachineOutput)
	for _, release := range releases {
		fmt.Fprintf(wf, "%s\t%s\n", release.Name, release.Patchlevel)
	}
	wf.Flush()
}
예제 #3
0
func snaplistCmdRun(cmd *cobra.Command, args []string) {
	jail, err := core.FindJail(args[0])
	if err != nil {
		gologit.Fatalf("No jail found by '%s'\n", args[0])
	}

	zfsArgs := []string{"list", "-Hrt", "snapshot",
		"-o", "name,creation,used,referenced", "-d2"}
	if ParsableValues {
		zfsArgs = append(zfsArgs, "-p")
	}
	zfsArgs = append(zfsArgs, jail.Path)

	lines := core.SplitOutput(core.ZFSMust(
		fmt.Errorf("Error listing snapshots"),
		zfsArgs...))
	gologit.Debugf("%#v", lines)
	if len(lines) == 0 || len(lines[0]) == 0 || len(lines[0][0]) == 0 {
		return
	}

	var rxmatch *regexp.Regexp
	if snaplistRegex != "" {
		rxmatch, err = regexp.Compile(snaplistRegex)
		if err != nil {
			gologit.Fatalf("Bad regex: %s", err)
		}
	}

	outputHeaders := []string{"name", "created", "rsize", "used"}
	wf := core.NewOutputWriter(outputHeaders, MachineOutput)
	for _, line := range lines {
		if len(line) < 4 {
			continue
		}

		snapname := strings.SplitN(line[0], "@", 2)[1]

		if rxmatch != nil && !rxmatch.MatchString(snapname) {
			continue
		}
		fmt.Fprintf(wf, "%s\t%s\t%s\t%s\n", snapname, line[1], line[2], line[3])
	}
	wf.Flush()
}
예제 #4
0
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()
}