Exemple #1
0
func statusRun(cmd *cobra.Command, args []string) {
	if len(args) != 1 {
		fmt.Println("Serial missing")
		os.Exit(1)
	}

	configDir, err := homedir.Expand(globalFlags.config)
	assert(err)

	machine, err := vm.Load(configDir, args[0])
	assert(err)

	status, err := machine.Status(statusFlags.TMuxSessionName)
	assert(err)

	var hds, nics []string
	for _, hd := range machine.HDs {
		hds = append(hds, fmt.Sprintf("%s %s", hd.Device, hd.Size))
	}
	for _, nic := range machine.NICs {
		nics = append(nics, fmt.Sprintf("%s %s", nic.Bridge, nic.Mac))
	}

	lines := []string{}
	lines = append(lines, fmt.Sprintf(statusScheme, "Serial:", machine.Serial))
	lines = append(lines, fmt.Sprintf(statusScheme, "Status:", status))
	lines = append(lines, fmt.Sprintf(statusScheme, "Image:", machine.Image))
	lines = append(lines, fmt.Sprintf("%s | %d", "Memory:", machine.Memory))
	lines = append(lines, fmt.Sprintf(statusScheme, "HDs:", strings.Join(hds, ",")))
	lines = append(lines, fmt.Sprintf(statusScheme, "NICs:", strings.Join(nics, ",")))
	fmt.Println(columnize.SimpleFormat(lines))
}
Exemple #2
0
func startRun(cmd *cobra.Command, args []string) {
	if len(args) != 1 {
		fmt.Println("Serial missing")
		os.Exit(1)
	}

	configDir, err := homedir.Expand(globalFlags.config)
	assert(err)

	machine, err := vm.Load(configDir, args[0])
	assert(err)

	machine.Start(startFlags.TMuxSessionName, startFlags.NoTMux)
}
Exemple #3
0
func wipeRun(cmd *cobra.Command, args []string) {
	if len(args) != 1 {
		fmt.Println("Serial missing")
		os.Exit(1)
	}

	configDir, err := homedir.Expand(globalFlags.config)
	assert(err)

	machine, err := vm.Load(configDir, args[0])
	assert(err)

	machine.Wipe(wipeVMFlags)

	err = machine.Save()
	assert(err)
}
Exemple #4
0
func stopRun(cmd *cobra.Command, args []string) {
	if len(args) != 1 {
		fmt.Println("Serial missing. If you want to stop all vms pass in 'all'.")
		os.Exit(1)
	}

	if args[0] == "all" {
		vm.StopAll(stopFlags.TMuxSessionName)
	} else {
		configDir, err := homedir.Expand(globalFlags.config)
		assert(err)

		machine, err := vm.Load(configDir, args[0])
		assert(err)

		err = machine.Stop(stopFlags.TMuxSessionName)
		assert(err)
	}
}
Exemple #5
0
func destroyRun(cmd *cobra.Command, args []string) {
	if len(args) != 1 {
		fmt.Println("Serial missing. If you want to destroy all vms pass in 'all'.")
		os.Exit(1)
	}

	configDir, err := homedir.Expand(globalFlags.config)
	assert(err)

	if args[0] == "all" {
		err = vm.DestroyAll(configDir, destroyFlags.TMuxSessionName)
		assert(err)
	} else {
		machine, err := vm.Load(configDir, args[0])
		assert(err)

		err = machine.Destroy(destroyFlags.TMuxSessionName)
		assert(err)
	}
}