Exemple #1
0
// Ls lists all Docker Machines.
func Ls(api libmachine.API, args map[string]string, form map[string][]string) (interface{}, error) {
	hostList, hostInError, err := persist.LoadAllHosts(api)
	if err != nil {
		return nil, err
	}

	return listHosts(hostList, hostInError), nil
}
Exemple #2
0
func cmdActive(c CommandLine, api libmachine.API) error {
	if len(c.Args()) > 0 {
		return ErrTooManyArguments
	}

	hosts, hostsInError, err := persist.LoadAllHosts(api)
	if err != nil {
		return fmt.Errorf("Error getting active host: %s", err)
	}

	items := getHostListItems(hosts, hostsInError)

	active, err := activeHost(items)

	if err != nil {
		return err
	}

	fmt.Println(active.Name)
	return nil
}
Exemple #3
0
func cmdActive(c CommandLine, api libmachine.API) error {
	if len(c.Args()) > 0 {
		return errTooManyArguments
	}

	hosts, err := persist.LoadAllHosts(api)
	if err != nil {
		return fmt.Errorf("Error getting active host: %s", err)
	}

	items := getHostListItems(hosts)

	for _, item := range items {
		if item.Active {
			fmt.Println(item.Name)
			return nil
		}
	}

	return errNoActiveHost
}
Exemple #4
0
func cmdLs(c CommandLine, api libmachine.API) error {
	stateTimeoutDuration = time.Duration(c.Int("timeout")) * time.Second
	log.Debugf("ls timeout set to %s", stateTimeoutDuration)

	quiet := c.Bool("quiet")
	filters, err := parseFilters(c.StringSlice("filter"))
	if err != nil {
		return err
	}

	hostList, hostInError, err := persist.LoadAllHosts(api)
	if err != nil {
		return err
	}

	hostList = filterHosts(hostList, filters)

	// Just print out the names if we're being quiet
	if quiet {
		for _, host := range hostList {
			fmt.Println(host.Name)
		}
		return nil
	}

	swarmMasters := make(map[string]string)
	swarmInfo := make(map[string]string)

	w := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0)
	fmt.Fprintln(w, "NAME\tACTIVE\tDRIVER\tSTATE\tURL\tSWARM\tDOCKER\tERRORS")

	for _, host := range hostList {
		if host.HostOptions != nil {
			swarmOptions := host.HostOptions.SwarmOptions
			if swarmOptions.Master {
				swarmMasters[swarmOptions.Discovery] = host.Name
			}

			if swarmOptions.Discovery != "" {
				swarmInfo[host.Name] = swarmOptions.Discovery
			}
		}
	}

	items := getHostListItems(hostList, hostInError)

	for _, item := range items {
		activeString := "-"
		if item.Active {
			activeString = "*"
		}

		swarmInfo := ""

		if item.SwarmOptions != nil && item.SwarmOptions.Discovery != "" {
			swarmInfo = swarmMasters[item.SwarmOptions.Discovery]
			if item.SwarmOptions.Master {
				swarmInfo = fmt.Sprintf("%s (master)", swarmInfo)
			}
		}
		fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
			item.Name, activeString, item.DriverName, item.State, item.URL, swarmInfo, item.DockerVersion, item.Error)
	}

	w.Flush()

	return nil
}
Exemple #5
0
func cmdLs(c CommandLine, api libmachine.API) error {
	filters, err := parseFilters(c.StringSlice("filter"))
	if err != nil {
		return err
	}

	hostList, hostInError, err := persist.LoadAllHosts(api)
	if err != nil {
		return err
	}

	hostList = filterHosts(hostList, filters)

	// Just print out the names if we're being quiet
	if c.Bool("quiet") {
		for _, host := range hostList {
			fmt.Println(host.Name)
		}
		return nil
	}

	template, table, err := parseFormat(c.String("format"))
	if err != nil {
		return err
	}

	var w io.Writer
	if table {
		tabWriter := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0)
		defer tabWriter.Flush()

		w = tabWriter

		if err := template.Execute(w, headers); err != nil {
			return err
		}
	} else {
		w = os.Stdout
	}

	timeout := time.Duration(c.Int("timeout")) * time.Second
	items := getHostListItems(hostList, hostInError, timeout)

	swarmMasters := make(map[string]string)
	swarmInfo := make(map[string]string)

	for _, host := range hostList {
		if host.HostOptions != nil {
			swarmOptions := host.HostOptions.SwarmOptions
			if swarmOptions.Master {
				swarmMasters[swarmOptions.Discovery] = host.Name
			}

			if swarmOptions.Discovery != "" {
				swarmInfo[host.Name] = swarmOptions.Discovery
			}
		}
	}

	for _, item := range items {
		swarmColumn := ""
		if item.SwarmOptions != nil && item.SwarmOptions.Discovery != "" {
			swarmColumn = swarmMasters[item.SwarmOptions.Discovery]
			if item.SwarmOptions.Master {
				swarmColumn = fmt.Sprintf("%s (master)", swarmColumn)
			}
		}
		item.Swarm = swarmColumn

		if err := template.Execute(w, item); err != nil {
			return err
		}
	}

	return nil
}
Exemple #6
0
func cmdLs(c CommandLine, api libmachine.API) error {
	stateTimeoutDuration = time.Duration(c.Int("timeout")) * time.Second
	log.Debugf("ls timeout set to %s", stateTimeoutDuration)

	filters, err := parseFilters(c.StringSlice("filter"))
	if err != nil {
		return err
	}

	hostList, hostInError, err := persist.LoadAllHosts(api)
	if err != nil {
		return err
	}

	hostList = filterHosts(hostList, filters)

	// Just print out the names if we're being quiet
	if c.Bool("quiet") {
		for _, host := range hostList {
			fmt.Println(host.Name)
		}
		return nil
	}

	template, table, err := parseFormat(c.String("format"))
	if err != nil {
		return err
	}

	var w io.Writer
	if table {
		tabWriter := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0)
		defer tabWriter.Flush()

		w = tabWriter

		headers := &Headers{
			Name:          "NAME",
			Active:        "ACTIVE",
			ActiveHost:    "DRIVER",
			ActiveSwarm:   "STATE",
			DriverName:    "URL",
			State:         "STATE",
			URL:           "URL",
			SwarmOptions:  "SWARM_OPTIONS",
			Swarm:         "SWARM",
			EngineOptions: "ENGINE_OPTIONS",
			Error:         "ERRORS",
			DockerVersion: "DOCKER",
		}

		if err := template.Execute(w, headers); err != nil {
			return err
		}
	} else {
		w = os.Stdout
	}

	items := getHostListItems(hostList, hostInError)

	swarmMasters := make(map[string]string)
	swarmInfo := make(map[string]string)

	for _, host := range hostList {
		if host.HostOptions != nil {
			swarmOptions := host.HostOptions.SwarmOptions
			if swarmOptions.Master {
				swarmMasters[swarmOptions.Discovery] = host.Name
			}

			if swarmOptions.Discovery != "" {
				swarmInfo[host.Name] = swarmOptions.Discovery
			}
		}
	}

	for _, item := range items {
		swarmColumn := ""
		if item.SwarmOptions != nil && item.SwarmOptions.Discovery != "" {
			swarmColumn = swarmMasters[item.SwarmOptions.Discovery]
			if item.SwarmOptions.Master {
				swarmColumn = fmt.Sprintf("%s (master)", swarmColumn)
			}
		}
		item.Swarm = swarmColumn

		if err := template.Execute(w, item); err != nil {
			return err
		}
	}

	return nil
}
Exemple #7
0
func cmdLs(c CommandLine, api libmachine.API) error {
	quiet := c.Bool("quiet")
	filters, err := parseFilters(c.StringSlice("filter"))
	if err != nil {
		return err
	}

	hostList, err := persist.LoadAllHosts(api)
	if err != nil {
		return err
	}

	hostList = filterHosts(hostList, filters)

	// Just print out the names if we're being quiet
	if quiet {
		for _, host := range hostList {
			fmt.Println(host.Name)
		}
		return nil
	}

	swarmMasters := make(map[string]string)
	swarmInfo := make(map[string]string)

	w := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0)
	fmt.Fprintln(w, "NAME\tACTIVE\tDRIVER\tSTATE\tURL\tSWARM")

	for _, host := range hostList {
		swarmOptions := host.HostOptions.SwarmOptions
		if swarmOptions.Master {
			swarmMasters[swarmOptions.Discovery] = host.Name
		}

		if swarmOptions.Discovery != "" {
			swarmInfo[host.Name] = swarmOptions.Discovery
		}
	}

	items := getHostListItems(hostList)

	sortHostListItemsByName(items)

	for _, item := range items {
		activeString := "-"
		if item.Active {
			activeString = "*"
		}

		swarmInfo := ""

		if item.SwarmOptions != nil && item.SwarmOptions.Discovery != "" {
			swarmInfo = swarmMasters[item.SwarmOptions.Discovery]
			if item.SwarmOptions.Master {
				swarmInfo = fmt.Sprintf("%s (master)", swarmInfo)
			}
		}
		fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\n",
			item.Name, activeString, item.DriverName, item.State, item.URL, swarmInfo)
	}

	w.Flush()

	return nil
}