-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #632 from rgooch/master
Add remote console (VNC) support for VMs.
- Loading branch information
Showing
19 changed files
with
430 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
|
||
"github.com/Symantec/Dominator/lib/errors" | ||
"github.com/Symantec/Dominator/lib/log" | ||
proto "github.com/Symantec/Dominator/proto/hypervisor" | ||
) | ||
|
||
func changeVmConsoleTypeSubcommand(args []string, | ||
logger log.DebugLogger) error { | ||
if err := changeVmConsoleType(args[0], logger); err != nil { | ||
return fmt.Errorf("Error changing VM console type: %s", err) | ||
} | ||
return nil | ||
} | ||
|
||
func changeVmConsoleType(vmHostname string, | ||
logger log.DebugLogger) error { | ||
if vmIP, hypervisor, err := lookupVmAndHypervisor(vmHostname); err != nil { | ||
return err | ||
} else { | ||
return changeVmConsoleTypeOnHypervisor(hypervisor, vmIP, logger) | ||
} | ||
} | ||
|
||
func changeVmConsoleTypeOnHypervisor(hypervisor string, ipAddr net.IP, | ||
logger log.DebugLogger) error { | ||
request := proto.ChangeVmConsoleTypeRequest{ | ||
ConsoleType: consoleType, | ||
IpAddress: ipAddr, | ||
} | ||
client, err := dialHypervisor(hypervisor) | ||
if err != nil { | ||
return err | ||
} | ||
defer client.Close() | ||
var reply proto.ChangeVmOwnerUsersResponse | ||
err = client.RequestReply("Hypervisor.ChangeVmConsoleType", | ||
request, &reply) | ||
if err != nil { | ||
return err | ||
} | ||
return errors.New(reply.Error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net" | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/Symantec/Dominator/lib/bufwriter" | ||
"github.com/Symantec/Dominator/lib/errors" | ||
"github.com/Symantec/Dominator/lib/log" | ||
proto "github.com/Symantec/Dominator/proto/hypervisor" | ||
) | ||
|
||
func connectToVmConsoleSubcommand(args []string, | ||
logger log.DebugLogger) error { | ||
if err := connectToVmConsole(args[0], logger); err != nil { | ||
return fmt.Errorf("Error connecting to VM console: %s", err) | ||
} | ||
return nil | ||
} | ||
|
||
func connectToVmConsole(vmHostname string, logger log.DebugLogger) error { | ||
if vmIP, hypervisor, err := lookupVmAndHypervisor(vmHostname); err != nil { | ||
return err | ||
} else { | ||
return connectToVmConsoleOnHypervisor(hypervisor, vmIP, logger) | ||
} | ||
} | ||
|
||
func connectToVmConsoleOnHypervisor(hypervisor string, ipAddr net.IP, | ||
logger log.DebugLogger) error { | ||
client, err := dialHypervisor(hypervisor) | ||
if err != nil { | ||
return err | ||
} | ||
defer client.Close() | ||
serverConn, err := client.Call("Hypervisor.ConnectToVmConsole") | ||
if err != nil { | ||
return err | ||
} | ||
defer serverConn.Close() | ||
request := proto.ConnectToVmConsoleRequest{ | ||
IpAddress: ipAddr, | ||
} | ||
if err := serverConn.Encode(request); err != nil { | ||
return err | ||
} | ||
if err := serverConn.Flush(); err != nil { | ||
return err | ||
} | ||
var response proto.ConnectToVmConsoleResponse | ||
if err := serverConn.Decode(&response); err != nil { | ||
return err | ||
} | ||
if err := errors.New(response.Error); err != nil { | ||
return err | ||
} | ||
listener, err := net.Listen("tcp", "localhost:") | ||
if err != nil { | ||
return err | ||
} | ||
defer listener.Close() | ||
_, port, err := net.SplitHostPort(listener.Addr().String()) | ||
if err != nil { | ||
return err | ||
} | ||
if *vncViewer == "" { | ||
fmt.Fprintf(os.Stderr, "Listening on port %s for VNC connection\n", | ||
port) | ||
} else { | ||
cmd := exec.Command(*vncViewer, "::"+port) | ||
cmd.Stderr = os.Stderr | ||
if err := cmd.Start(); err != nil { | ||
logger.Println(err) | ||
} else { | ||
fmt.Fprintf(os.Stderr, "Listening on port %s for VNC connection\n", | ||
port) | ||
} | ||
} | ||
clientConn, err := listener.Accept() | ||
if err != nil { | ||
return err | ||
} | ||
listener.Close() | ||
closed := false | ||
go func() { // Copy from server to client. | ||
_, err := io.Copy(clientConn, serverConn) | ||
if err != nil && !closed { | ||
logger.Fatalln(err) | ||
} | ||
os.Exit(0) | ||
}() | ||
// Copy from client to server. | ||
_, err = io.Copy(bufwriter.NewAutoFlushWriter(serverConn), clientConn) | ||
closed = true | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package main | ||
|
||
const defaultVncViewer = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package main | ||
|
||
const defaultVncViewer = "vncviewer" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.