Example #1
0
// GetHostConfig gets the machine config from docker-machine.
// It takes an initialized driver.HostConfig struct with the Driver
// field initialized to the driver-specific type.
// The passed-in object is filled in with the contents of the config.
func GetHostConfig(name string, config *drivers.HostConfig) error {
	contents, err := stream.Contents(stream.Command(dockerMachineBinary, "inspect", name))
	if err != nil {
		return err
	}

	return json.Unmarshal([]byte(strings.Join(contents, "\n")), config)
}
Example #2
0
// GetDockerFlags returns the list of flags we need to pass to docker to
// talk to the given machine's docker daemon.
// We expect a single line, but then split that line into individual flags.
func GetDockerFlags(name string) ([]string, error) {
	contents, err := stream.Contents(stream.Command(dockerMachineBinary, "config", name))
	if err != nil {
		return nil, err
	}

	if len(contents) != 1 {
		return nil, util.Errorf("expected a single output line, got: %v", contents)
	}
	return strings.Split(contents[0], " "), nil
}
Example #3
0
// ListMachines returns a list of machine names.
func ListMachines() ([]string, error) {
	return stream.Contents(stream.Command(dockerMachineBinary, "ls", "-q"))
}
Example #4
0
func ExampleContents() {
	out, err := stream.Contents(stream.Numbers(1, 3))
	fmt.Println(out, err)
	// Output:
	// [1 2 3] <nil>
}