コード例 #1
0
ファイル: container_info.go プロジェクト: mxjxn/eris-cli
func ErisContainersByType(typ string, running bool) []*ContainerName {
	containers := []*ContainerName{}
	r := erisRegExp(typ)      // eris containers
	q := erisRegExpLinks(typ) // skip past these -- they're containers docker makes especially to handle links

	contns, err := DockerClient.ListContainers(docker.ListContainersOptions{All: running})

	if len(contns) == 0 || err != nil {
		if err != nil {
			log.Debugf("Marmot error during Docker container listing: %v", err)
		}
		return containers
	}

	for _, con := range contns {
		for _, c := range con.Names {
			if q.MatchString(c) {
				continue
			}
			if r.MatchString(c) {
				c = strings.Replace(c, "/", "", 1) // Docker's leading slash
				cont := ContainerDisassemble(c)
				cont.ContainerID = con.ID
				containers = append(containers, cont)
			}
		}
	}

	return containers
}
コード例 #2
0
ファイル: docker_client.go プロジェクト: mxjxn/eris-cli
func createErisMachine(driver string) error {
	log.Warn("Creating the Eris Docker Machine")
	log.Warn("This will take some time, please feel free to go feed your marmot")
	log.WithField("driver", driver).Debug()
	cmd := "docker-machine"
	args := []string{"create", "--driver", driver, "eris"}
	if err := exec.Command(cmd, args...).Run(); err != nil {
		log.Debugf("There was an error creating the Eris Docker Machine: %v", err)
		return mustInstallError()
	}
	log.Debug("Eris Docker Machine created")

	return startErisMachine()
}
コード例 #3
0
ファイル: operate.go プロジェクト: antonylewis/eris-cli
func copyFiles(dst string, files []stringPair) error {
	for _, f := range files {
		if f.key != "" {
			log.WithFields(log.Fields{
				"from": f.key,
				"to":   filepath.Join(dst, f.value),
			}).Debug("Copying files")
			if err := Copy(f.key, filepath.Join(dst, f.value)); err != nil {
				log.Debugf("Error copying files: %v", err)
				return err
			}
		}
	}
	return nil
}
コード例 #4
0
ファイル: term_windows.go プロジェクト: mxjxn/eris-cli
// SetWinsize sets the size of the given terminal connected to the passed file descriptor.
func SetWinsize(fd uintptr, ws *Winsize) error {
	// TODO(azlinux): Implement SetWinsize
	logrus.Debugf("[windows] SetWinsize: WARNING -- Unsupported method invoked")
	return nil
}
コード例 #5
0
ファイル: docker_client.go プロジェクト: mxjxn/eris-cli
func DockerConnect(verbose bool, machName string) { // TODO: return an error...?
	var err error
	var dockerHost string
	var dockerCertPath string
	if runtime.GOOS == "linux" {
		// this means we aren't gonna use docker-machine (kind of)
		if (machName == "eris" || machName == "default") && (os.Getenv("DOCKER_HOST") == "" && os.Getenv("DOCKER_CERT_PATH") == "") {
			//if os.Getenv("DOCKER_HOST") == "" && os.Getenv("DOCKER_CERT_PATH") == "" {
			endpoint := "unix:///var/run/docker.sock"

			log.WithField("=>", endpoint).Debug("Checking Linux Docker socket")
			u, _ := url.Parse(endpoint)
			_, err := net.Dial(u.Scheme, u.Path)
			if err != nil {
				IfExit(fmt.Errorf("%v\n", mustInstallError()))
			}
			log.WithField("=>", endpoint).Debug("Connecting to Docker")
			DockerClient, err = docker.NewClient(endpoint)
			if err != nil {
				IfExit(fmt.Errorf("%v\n", mustInstallError()))
			}
		} else {
			log.WithFields(log.Fields{
				"host":      os.Getenv("DOCKER_HOST"),
				"cert path": os.Getenv("DOCKER_CERT_PATH"),
			}).Debug("Getting connection details from environment")
			log.WithField("machine", machName).Debug("Getting connection details from Docker Machine")
			dockerHost, dockerCertPath, err = getMachineDeets(machName)
			if err != nil {
				IfExit(fmt.Errorf("Error getting Docker Machine details for connection via TLS.\nERROR =>\t\t\t%v\n\nEither re-run the command without a machine or correct your machine name.\n", err))
			}

			log.WithFields(log.Fields{
				"host":      dockerHost,
				"cert path": dockerCertPath,
			}).Debug()

			if err := connectDockerTLS(dockerHost, dockerCertPath); err != nil {
				IfExit(fmt.Errorf("Error connecting to Docker via TLS.\nERROR =>\t\t\t%v\n", err))
			}

			setIPFSHostViaDockerHost(dockerHost)
		}

		log.Debug("Successfully connected to Docker daemon")

	} else {
		log.WithFields(log.Fields{
			"host":      os.Getenv("DOCKER_HOST"),
			"cert path": os.Getenv("DOCKER_CERT_PATH"),
		}).Debug("Getting connection details from environment")
		log.WithField("machine", machName).Debug("Getting connection details from Docker Machine")

		dockerHost, dockerCertPath, err = getMachineDeets(machName) // machName is "eris" by default

		if err != nil {
			log.Debug("Could not connect to Eris Docker Machine")
			log.Errorf("Trying %q Docker Machine: %v", "default", err)
			dockerHost, dockerCertPath, err = getMachineDeets("default") // during toolbox setup this is the machine that is created
			if err != nil {
				log.Debugf("Could not connect to %q Docker Machine", "default")
				log.Debugf("Error: %v", err)
				log.Debug("Trying to set up new machine")
				if e2 := CheckDockerClient(); e2 != nil {
					IfExit(fmt.Errorf("%v\n", e2))
				}
				dockerHost, dockerCertPath, _ = getMachineDeets("eris")
			}

		}

		log.WithFields(log.Fields{
			"host":      dockerHost,
			"cert path": dockerCertPath,
		}).Debug()

		if err := connectDockerTLS(dockerHost, dockerCertPath); err != nil {
			IfExit(fmt.Errorf("Error connecting to Docker Backend via TLS.\nERROR =>\t\t\t%v\n", err))
		}
		log.Debug("Successfully connected to Docker daemon")

		setIPFSHostViaDockerHost(dockerHost)
	}
}
コード例 #6
0
ファイル: console_windows.go プロジェクト: mxjxn/eris-cli
// HandleOutputCommand interpretes the Ansi commands and then makes appropriate Win32 calls
func (term *WindowsTerminal) HandleOutputCommand(handle uintptr, command []byte) (n int, err error) {
	// always consider all the bytes in command, processed
	n = len(command)

	parsedCommand := parseAnsiCommand(command)
	logrus.Debugf("[windows] HandleOutputCommand: %v", parsedCommand)

	// console settings changes need to happen in atomic way
	term.outMutex.Lock()
	defer term.outMutex.Unlock()

	switch parsedCommand.Command {
	case "m":
		// [Value;...;Valuem
		// Set Graphics Mode:
		// Calls the graphics functions specified by the following values.
		// These specified functions remain active until the next occurrence of this escape sequence.
		// Graphics mode changes the colors and attributes of text (such as bold and underline) displayed on the screen.
		screenBufferInfo, err := GetConsoleScreenBufferInfo(handle)
		if err != nil {
			return n, err
		}
		flag := screenBufferInfo.Attributes
		for _, e := range parsedCommand.Parameters {
			value, _ := strconv.ParseInt(e, 10, 16) // base 10, 16 bit
			if value == ANSI_ATTR_RESET {
				flag = term.screenBufferInfo.Attributes // reset
			} else {
				flag, err = getWindowsTextAttributeForAnsiValue(flag, term.screenBufferInfo.Attributes, int16(value))
				if err != nil {
					return n, err
				}
			}
		}
		if err := setConsoleTextAttribute(handle, flag); err != nil {
			return n, err
		}
	case "H", "f":
		// [line;columnH
		// [line;columnf
		// Moves the cursor to the specified position (coordinates).
		// If you do not specify a position, the cursor moves to the home position at the upper-left corner of the screen (line 0, column 0).
		screenBufferInfo, err := GetConsoleScreenBufferInfo(handle)
		if err != nil {
			return n, err
		}
		line, err := parseInt16OrDefault(parsedCommand.getParam(0), 1)
		if err != nil {
			return n, err
		}
		if line > int16(screenBufferInfo.Window.Bottom) {
			line = int16(screenBufferInfo.Window.Bottom) + 1
		}
		column, err := parseInt16OrDefault(parsedCommand.getParam(1), 1)
		if err != nil {
			return n, err
		}
		if column > int16(screenBufferInfo.Window.Right) {
			column = int16(screenBufferInfo.Window.Right) + 1
		}
		// The numbers are not 0 based, but 1 based
		logrus.Debugf("[windows] HandleOutputCommmand: Moving cursor to (%v,%v)", column-1, line-1)
		if err := setConsoleCursorPosition(handle, false, column-1, line-1); err != nil {
			return n, err
		}

	case "A":
		// [valueA
		// Moves the cursor up by the specified number of lines without changing columns.
		// If the cursor is already on the top line, ignores this sequence.
		value, err := parseInt16OrDefault(parsedCommand.getParam(0), 1)
		if err != nil {
			return len(command), err
		}
		if err := setConsoleCursorPosition(handle, true, 0, -value); err != nil {
			return n, err
		}
	case "B":
		// [valueB
		// Moves the cursor down by the specified number of lines without changing columns.
		// If the cursor is already on the bottom line, ignores this sequence.
		value, err := parseInt16OrDefault(parsedCommand.getParam(0), 1)
		if err != nil {
			return n, err
		}
		if err := setConsoleCursorPosition(handle, true, 0, value); err != nil {
			return n, err
		}
	case "C":
		// [valueC
		// Moves the cursor forward by the specified number of columns without changing lines.
		// If the cursor is already in the rightmost column, ignores this sequence.
		value, err := parseInt16OrDefault(parsedCommand.getParam(0), 1)
		if err != nil {
			return n, err
		}
		if err := setConsoleCursorPosition(handle, true, value, 0); err != nil {
			return n, err
		}
	case "D":
		// [valueD
		// Moves the cursor back by the specified number of columns without changing lines.
		// If the cursor is already in the leftmost column, ignores this sequence.
		value, err := parseInt16OrDefault(parsedCommand.getParam(0), 1)
		if err != nil {
			return n, err
		}
		if err := setConsoleCursorPosition(handle, true, -value, 0); err != nil {
			return n, err
		}
	case "J":
		// [J   Erases from the cursor to the end of the screen, including the cursor position.
		// [1J  Erases from the beginning of the screen to the cursor, including the cursor position.
		// [2J  Erases the complete display. The cursor does not move.
		// Clears the screen and moves the cursor to the home position (line 0, column 0).
		value, err := parseInt16OrDefault(parsedCommand.getParam(0), 0)
		if err != nil {
			return n, err
		}
		var start COORD
		var cursor COORD
		var end COORD
		screenBufferInfo, err := GetConsoleScreenBufferInfo(handle)
		if err != nil {
			return n, err
		}
		switch value {
		case 0:
			start = screenBufferInfo.CursorPosition
			// end of the buffer
			end.X = screenBufferInfo.Size.X - 1
			end.Y = screenBufferInfo.Size.Y - 1
			// cursor
			cursor = screenBufferInfo.CursorPosition
		case 1:

			// start of the screen
			start.X = 0
			start.Y = 0
			// end of the screen
			end = screenBufferInfo.CursorPosition
			// cursor
			cursor = screenBufferInfo.CursorPosition
		case 2:
			// start of the screen
			start.X = 0
			start.Y = 0
			// end of the buffer
			end.X = screenBufferInfo.Size.X - 1
			end.Y = screenBufferInfo.Size.Y - 1
			// cursor
			cursor.X = 0
			cursor.Y = 0
		}
		if _, err := clearDisplayRange(uintptr(handle), term.screenBufferInfo.Attributes, start, end); err != nil {
			return n, err
		}
		// remember the the cursor position is 1 based
		if err := setConsoleCursorPosition(handle, false, int16(cursor.X), int16(cursor.Y)); err != nil {
			return n, err
		}

	case "K":
		// [K
		// Clears all characters from the cursor position to the end of the line (including the character at the cursor position).
		// [K  Erases from the cursor to the end of the line, including the cursor position.
		// [1K  Erases from the beginning of the line to the cursor, including the cursor position.
		// [2K  Erases the complete line.
		value, err := parseInt16OrDefault(parsedCommand.getParam(0), 0)
		var start COORD
		var cursor COORD
		var end COORD
		screenBufferInfo, err := GetConsoleScreenBufferInfo(uintptr(handle))
		if err != nil {
			return n, err
		}
		switch value {
		case 0:
			// start is where cursor is
			start = screenBufferInfo.CursorPosition
			// end of line
			end.X = screenBufferInfo.Size.X - 1
			end.Y = screenBufferInfo.CursorPosition.Y
			// cursor remains the same
			cursor = screenBufferInfo.CursorPosition

		case 1:
			// beginning of line
			start.X = 0
			start.Y = screenBufferInfo.CursorPosition.Y
			// until cursor
			end = screenBufferInfo.CursorPosition
			// cursor remains the same
			cursor = screenBufferInfo.CursorPosition
		case 2:
			// start of the line
			start.X = 0
			start.Y = screenBufferInfo.CursorPosition.Y - 1
			// end of the line
			end.X = screenBufferInfo.Size.X - 1
			end.Y = screenBufferInfo.CursorPosition.Y - 1
			// cursor
			cursor.X = 0
			cursor.Y = screenBufferInfo.CursorPosition.Y - 1
		}
		if _, err := clearDisplayRange(uintptr(handle), term.screenBufferInfo.Attributes, start, end); err != nil {
			return n, err
		}
		// remember the the cursor position is 1 based
		if err := setConsoleCursorPosition(uintptr(handle), false, int16(cursor.X), int16(cursor.Y)); err != nil {
			return n, err
		}

	case "l":
		for _, value := range parsedCommand.Parameters {
			switch value {
			case "?25", "25":
				SetCursorVisible(uintptr(handle), BOOL(0))
			case "?1049", "1049":
				// TODO (azlinux):  Restore terminal
			case "?1", "1":
				// If the DECCKM function is reset, then the arrow keys send ANSI cursor sequences to the host.
				term.inputEscapeSequence = []byte(KEY_ESC_CSI)
			}
		}
	case "h":
		for _, value := range parsedCommand.Parameters {
			switch value {
			case "?25", "25":
				SetCursorVisible(uintptr(handle), BOOL(1))
			case "?1049", "1049":
				// TODO (azlinux): Save terminal
			case "?1", "1":
				// If the DECCKM function is set, then the arrow keys send application sequences to the host.
				// DECCKM (default off): When set, the cursor keys send an ESC O prefix, rather than ESC [.
				term.inputEscapeSequence = []byte(KEY_ESC_O)
			}
		}

	case "]":
		/*
			TODO (azlinux):
				Linux Console Private CSI Sequences

			       The following sequences are neither ECMA-48 nor native VT102.  They are
			       native  to the Linux console driver.  Colors are in SGR parameters: 0 =
			       black, 1 = red, 2 = green, 3 = brown, 4 = blue, 5 = magenta, 6 =  cyan,
			       7 = white.

			       ESC [ 1 ; n ]       Set color n as the underline color
			       ESC [ 2 ; n ]       Set color n as the dim color
			       ESC [ 8 ]           Make the current color pair the default attributes.
			       ESC [ 9 ; n ]       Set screen blank timeout to n minutes.
			       ESC [ 10 ; n ]      Set bell frequency in Hz.
			       ESC [ 11 ; n ]      Set bell duration in msec.
			       ESC [ 12 ; n ]      Bring specified console to the front.
			       ESC [ 13 ]          Unblank the screen.
			       ESC [ 14 ; n ]      Set the VESA powerdown interval in minutes.

		*/
	}
	return n, nil
}