Example #1
0
File: util.go Project: akutz/rexray
// ReadSpecFile reads the REX-Ray host address from the spec file.
func ReadSpecFile() (string, error) {
	host, err := gotil.ReadFileToString(SpecFilePath())
	if err != nil {
		return "", err
	}
	return gotil.Trim(host), nil
}
func (c *client) NextDevice(
	ctx types.Context,
	opts types.Store) (string, error) {

	if c.isController() {
		return "", utils.NewUnsupportedForClientTypeError(
			c.clientType, "NextDevice")
	}

	if supported, _ := c.Supported(ctx, opts); !supported {
		return "", errExecutorNotSupported
	}

	ctx = context.RequireTX(ctx.Join(c.ctx))

	serviceName, ok := context.ServiceName(ctx)
	if !ok {
		return "", goof.New("missing service name")
	}

	si, err := c.getServiceInfo(serviceName)
	if err != nil {
		return "", err
	}
	driverName := si.Driver.Name

	out, err := c.runExecutor(ctx, driverName, types.LSXCmdNextDevice)
	if err != nil {
		return "", err
	}

	ctx.Debug("xli nextdevice success")
	return gotil.Trim(string(out)), nil
}
Example #3
0
func (d *driver) Supported(
	ctx types.Context,
	opts types.Store) (bool, error) {

	// Use dmidecode if installed
	if gotil.FileExistsInPath(dmidecodeCmd) {
		out, err := exec.Command(
			dmidecodeCmd, "-s", "system-product-name").Output()
		if err == nil {
			outStr := strings.ToLower(gotil.Trim(string(out)))
			if outStr == "virtualbox" {
				return true, nil
			}
		}
		out, err = exec.Command(
			dmidecodeCmd, "-s", "system-manufacturer").Output()
		if err == nil {
			outStr := strings.ToLower(gotil.Trim(string(out)))
			if outStr == "innotek gmbh" {
				return true, nil
			}
		}
	}

	// No luck with dmidecode, try dmesg
	out, err := exec.Command("dmesg").Output()
	if err != nil {
		return false, nil
	}

	rdr := bytes.NewReader(out)
	scanner := bufio.NewScanner(rdr)

	for scanner.Scan() {
		if strings.Contains(scanner.Text(), "BIOS VirtualBox") {
			return true, nil
		}
	}

	return false, nil
}
Example #4
0
func isDebInstall(exePath string, pkgName *string) bool {
	cmd := exec.Command("dpkg-query", "-S", exePath)
	output, err := cmd.CombinedOutput()
	soutput := string(output)
	if err != nil {
		log.WithFields(log.Fields{
			"exePath": exePath,
			"output":  soutput,
			"error":   err,
		}).Debug("error checking if deb install")
		return false
	}
	log.WithField("output", soutput).Debug("deb install query result")
	*pkgName = strings.Split(gotil.Trim(soutput), ":")[0]

	log.WithFields(log.Fields{
		"exePath": exePath,
		"pkgName": *pkgName,
	}).Debug("is deb install success")
	return true
}
Example #5
0
func isRpmInstall(exePath string, pkgName *string) bool {
	cmd := exec.Command("rpm", "-qf", exePath)
	output, err := cmd.CombinedOutput()
	soutput := string(output)
	if err != nil {
		log.WithFields(log.Fields{
			"exePath": exePath,
			"output":  soutput,
			"error":   err,
		}).Debug("error checking if rpm install")
		return false
	}
	log.WithField("output", soutput).Debug("rpm install query result")
	*pkgName = gotil.Trim(soutput)

	log.WithFields(log.Fields{
		"exePath": exePath,
		"pkgName": *pkgName,
	}).Debug("is rpm install success")
	return true
}