// SetString sets the guestinfo.KEY with the string VALUE
func (c *Config) SetString(key string, value string) error {
	_, _, err := rpcout.SendOne("info-set guestinfo.%s %s", key, value)
	if err != nil {
		return err
	}
	return nil
}
Beispiel #2
0
// Fork triggers vmfork and handles the necessary pre/post OS level operations
func (t *BaseOperations) Fork() error {
	// unload vmxnet3 module

	// fork
	out, ok, err := rpcout.SendOne("vmfork-begin -1 -1")
	if err != nil {
		detail := fmt.Sprintf("error while calling vmfork: err=%s, out=%s, ok=%t", err, out, ok)
		log.Error(detail)
		return errors.New(detail)
	}

	if !ok {
		detail := fmt.Sprintf("failed to vmfork: %s", out)
		log.Error(detail)
		return errors.New(detail)
	}

	log.Infof("vmfork call succeeded: %s", out)

	// update system time

	// rescan scsi bus

	// reload vmxnet3 module

	// ensure memory and cores are brought online if not using udev

	return nil
}
// String returns the config string in the guestinfo.* namespace
func (c *Config) String(key string, defaultValue string) (string, error) {
	out, ok, err := rpcout.SendOne("info-get guestinfo.%s", key)
	if err != nil {
		return "", err
	} else if !ok {
		return defaultValue, nil
	}
	return string(out), nil
}
Beispiel #4
0
// SetString sets the guestinfo.KEY with the string VALUE
func (c *Config) SetString(key string, value string) error {
	// add "guestinfo." prefix if missing
	if !strings.HasPrefix(key, prefix) {
		key = fmt.Sprintf("%s.%s", prefix, key)
	}

	_, _, err := rpcout.SendOne("info-set %s %s", key, value)
	if err != nil {
		return err
	}
	return nil
}
Beispiel #5
0
// String returns the config string in the guestinfo.* namespace
func (c *Config) String(key string, defaultValue string) (string, error) {
	// add "guestinfo." prefix if missing
	if !strings.HasPrefix(key, prefix) {
		key = fmt.Sprintf("%s.%s", prefix, key)
	}

	out, ok, err := rpcout.SendOne("info-get %s", key)
	if err != nil {
		return "", err
	} else if !ok {
		return defaultValue, nil
	}
	return string(out), nil
}
Beispiel #6
0
func main() {
	if version.Show() {
		fmt.Fprintf(os.Stdout, "%s\n", version.String())
		return
	}

	if !vmcheck.IsVirtualWorld() {
		log.Fatalf("ERROR: not in a virtual world.")
	}

	if !set && !get && !fork {
		flag.Usage()
	}

	config := rpcvmx.NewConfig()
	if set {
		if flag.NArg() != 2 {
			log.Fatalf("ERROR: Please provide guestinfo key / value pair (eg; -set foo bar")
		}
		if err := config.SetString(flag.Arg(0), flag.Arg(1)); err != nil {
			log.Fatalf("ERROR: SetString failed with %s", err)
		}
	}

	if get {
		if flag.NArg() != 1 {
			log.Fatalf("ERROR: Please provide guestinfo key (eg; -get foo)")
		}
		if out, err := config.String(flag.Arg(0), ""); err != nil {
			log.Fatalf("ERROR: String failed with %s", err)
		} else {
			fmt.Printf("%s\n", out)
		}
	}

	if fork {
		out, ok, err := rpcout.SendOne("vmfork-begin -1 -1")
		if err != nil {
			log.Fatalf("ERROR: %s | %s | %t", err, out, ok)
		} else if !ok {
			log.Fatalf("FAILED: %s", out)
		} else {
			fmt.Printf("%s\n", out)
		}
	}
}