Skip to content

Commit

Permalink
add gui feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mhewedy committed Jun 5, 2020
1 parent 4a814a9 commit 7bea68e
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Vermin in Action:
* [Install CockroachDB cluster in a Virtual Machine](https://medium.com/swlh/install-cockroachdb-on-a-virtual-machine-2f25878fd70?source=friends_link&sk=52b4c1c16794f8d15943c8c48a7103b5)
* [Install Redis inside Ubuntu VM](https://medium.com/swlh/install-redis-inside-a-ubuntu-vm-d5022d42d8cc?source=friends_link&sk=b7073861f8050c5318683d1ebfcd800a)
* [Install Kubernetes cluster in Virtual Machines the easy way](https://medium.com/@mhewedy_46874/install-kubernetes-cluster-in-virtual-machines-the-easy-way-337ef0c4e37f?source=friends_link&sk=dbb40739c54c864d1bd2f779032b2de2)
* [Install Desktop environment on Ubuntu Server](https://medium.com/@mhewedy_46874/ubuntu-20-04-desktop-vm-using-vermin-764d20f43c4d?source=friends_link&sk=d78dd1b863aaa0ea8bd05dc3e681c7ec)

Also, you can check [Why not Vagrant](#Why-not-Vagrant) section.

Expand Down Expand Up @@ -86,6 +87,7 @@ Available Commands:
cp Copy files/folders between a VM and the local filesystem or between two VMs
create Create a new VM
exec Run a command in a running VM
gui open the GUI for the VM
help Help about any command
images List remote and cached images
ip Show IP address for a running VM
Expand Down
63 changes: 63 additions & 0 deletions cmd/gui.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"errors"
"fmt"
"github.com/mhewedy/vermin/vms"
"github.com/spf13/cobra"
"os"
)

// guiCmd represents the gui command
var guiCmd = &cobra.Command{
Use: "gui",
Short: "open the GUI for the VM",
Long: `open the GUI for the VM`,
Example: `
$ vermin gui vm_02
`,
Run: func(cmd *cobra.Command, args []string) {
vmName := args[0]
if err := vms.GUI(vmName); err != nil {
fmt.Println(err)
os.Exit(1)
}
},
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("vm required")
}
return nil
},
ValidArgsFunction: listRunningVms,
}

func init() {
rootCmd.AddCommand(guiCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// guiCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
//guiCmd.Flags().BoolP("purge", "p", false, "Purge the IP cache")
}
12 changes: 12 additions & 0 deletions vms/vms.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,15 @@ func Modify(vmName string, cpus int, mem int) error {
_, err := command.VBoxManage(params...).Call()
return err
}

func GUI(vmName string) error {
if err := checkRunningVM(vmName); err != nil {
return err
}

if err := ssh.EstablishConn(vmName); err != nil {
return err
}

return command.VBoxManage("startvm", "--type", "separate", vmName).Run()
}

0 comments on commit 7bea68e

Please sign in to comment.