Adding an optional VM's UI type for the virtualbox driver ("--virtualbox-ui-type")

NOTE: with this one can specify the UI Type: gui,sdl,separate instead of the default choice (headless)
NOTE: running X11 server is required if UI type is not headless
Signed-off-by: Oleksandr Motsak <http://goo.gl/mcpzY>
This commit is contained in:
Oleksandr Motsak 2016-05-28 16:16:45 +02:00
parent 2420975f4e
commit 6a2221fd97
1 changed files with 14 additions and 4 deletions

View File

@ -28,6 +28,7 @@ const (
defaultHostOnlyCIDR = "192.168.99.1/24"
defaultHostOnlyNictype = "82540EM"
defaultHostOnlyPromiscMode = "deny"
defaultUIType = "headless"
defaultDiskSize = 20000
defaultDNSProxy = true
defaultDNSResolver = false
@ -62,6 +63,7 @@ type Driver struct {
HostOnlyCIDR string
HostOnlyNicType string
HostOnlyPromiscMode string
UIType string
NoShare bool
DNSProxy bool
NoVTXCheck bool
@ -86,6 +88,7 @@ func NewDriver(hostName, storePath string) *Driver {
HostOnlyCIDR: defaultHostOnlyCIDR,
HostOnlyNicType: defaultHostOnlyNictype,
HostOnlyPromiscMode: defaultHostOnlyPromiscMode,
UIType: defaultUIType,
DNSProxy: defaultDNSProxy,
HostDNSResolver: defaultDNSResolver,
BaseDriver: &drivers.BaseDriver{
@ -158,6 +161,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Value: defaultHostOnlyPromiscMode,
EnvVar: "VIRTUALBOX_HOSTONLY_NIC_PROMISC",
},
mcnflag.StringFlag{
Name: "virtualbox-ui-type",
Usage: "Specify the UI Type: (gui|sdl|headless|separate)",
Value: defaultUIType,
EnvVar: "VIRTUALBOX_UI_TYPE",
},
mcnflag.BoolFlag{
Name: "virtualbox-no-share",
Usage: "Disable the mount of your home directory",
@ -220,6 +229,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.HostOnlyCIDR = flags.String("virtualbox-hostonly-cidr")
d.HostOnlyNicType = flags.String("virtualbox-hostonly-nictype")
d.HostOnlyPromiscMode = flags.String("virtualbox-hostonly-nicpromisc")
d.UIType = flags.String("virtualbox-ui-type")
d.NoShare = flags.Bool("virtualbox-no-share")
d.DNSProxy = !flags.Bool("virtualbox-no-dns-proxy")
d.NoVTXCheck = flags.Bool("virtualbox-no-vtx-check")
@ -493,14 +503,14 @@ func (d *Driver) Start() error {
return err
}
if err := d.vbm("startvm", d.MachineName, "--type", "headless"); err != nil {
if err := d.vbm("startvm", d.MachineName, "--type", d.UIType); err != nil {
if lines, readErr := d.readVBoxLog(); readErr == nil && len(lines) > 0 {
return fmt.Errorf("Unable to start the VM: %s\nDetails: %s", err, lines[len(lines)-1])
}
return fmt.Errorf("Unable to start the VM: %s", err)
}
case state.Paused:
if err := d.vbm("controlvm", d.MachineName, "resume", "--type", "headless"); err != nil {
if err := d.vbm("controlvm", d.MachineName, "resume", "--type", d.UIType); err != nil {
return err
}
log.Infof("Resuming VM ...")
@ -569,7 +579,7 @@ func (d *Driver) Start() error {
// We have to be sure the adapter is updated before starting the VM
d.sleeper.Sleep(5 * time.Second)
if err := d.vbm("startvm", d.MachineName, "--type", "headless"); err != nil {
if err := d.vbm("startvm", d.MachineName, "--type", d.UIType); err != nil {
return fmt.Errorf("Unable to start the VM: %s", err)
}
@ -584,7 +594,7 @@ func (d *Driver) Stop() error {
}
if currentState == state.Paused {
if err := d.vbm("controlvm", d.MachineName, "resume"); err != nil { // , "--type", "headless"
if err := d.vbm("controlvm", d.MachineName, "resume"); err != nil { // , "--type", d.UIType
return err
}
log.Infof("Resuming VM ...")