Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the headings in multiple functions of multiple files #11986

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lxc/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type cmdConsole struct {
flagType string
}

// Command sets up the 'console' command, which is used to interact with an instance's console or retrieve its log.
func (c *cmdConsole) Command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = usage("console", i18n.G("[<remote>:]<instance>"))
Expand All @@ -46,6 +47,7 @@ as well as retrieve past log entries from it.`))
return cmd
}

// sendTermSize sends the current terminal size over a websocket connection to adjust the size of the instance's console.
func (c *cmdConsole) sendTermSize(control *websocket.Conn) error {
width, height, err := termios.GetSize(int(os.Stdout.Fd()))
if err != nil {
Expand Down Expand Up @@ -94,6 +96,7 @@ func (er stdinMirror) Read(p []byte) (int, error) {
return n, err
}

// Run parses the command line arguments, validates flags, connects to the LXD instance and initiates the instance's console session or displays its console log.
func (c *cmdConsole) Run(cmd *cobra.Command, args []string) error {
conf := c.global.conf

Expand Down Expand Up @@ -143,6 +146,7 @@ func (c *cmdConsole) Run(cmd *cobra.Command, args []string) error {
return c.Console(d, name)
}

// Console establishes a console or VGA connection with the specified LXD instance based on the provided flag.
func (c *cmdConsole) Console(d lxd.InstanceServer, name string) error {
if c.flagType == "" {
c.flagType = "console"
Expand All @@ -158,6 +162,7 @@ func (c *cmdConsole) Console(d lxd.InstanceServer, name string) error {
return fmt.Errorf(i18n.G("Unknown console type %q"), c.flagType)
}

// console attaches the terminal to the console of the specified LXD instance and handles terminal resize events and detach sequence.
func (c *cmdConsole) console(d lxd.InstanceServer, name string) error {
// Configure the terminal
cfd := int(os.Stdin.Fd())
Expand Down Expand Up @@ -223,6 +228,7 @@ func (c *cmdConsole) console(d lxd.InstanceServer, name string) error {
return nil
}

// vga sets up a remote VGA console for the specified LXD instance, creating a SPICE socket and launching a viewer if available.
func (c *cmdConsole) vga(d lxd.InstanceServer, name string) error {
var err error
conf := c.global.conf
Expand Down
2 changes: 2 additions & 0 deletions lxc/console_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/canonical/lxd/shared/logger"
)

// controlSocketHandler listens for terminal window size changes and updates the terminal geometry accordingly, then closes the websocket connection.
func (c *cmdConsole) controlSocketHandler(control *websocket.Conn) {
ch := make(chan os.Signal, 10)
signal.Notify(ch, unix.SIGWINCH)
Expand All @@ -31,6 +32,7 @@ func (c *cmdConsole) controlSocketHandler(control *websocket.Conn) {
_ = control.WriteMessage(websocket.CloseMessage, closeMsg)
}

// findCommand returns the path of the specified command if it exists in the system's PATH.
func (c *cmdConsole) findCommand(name string) string {
path, _ := exec.LookPath(name)
return path
Expand Down
3 changes: 3 additions & 0 deletions lxc/console_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import (
"github.com/gorilla/websocket"
)

// getTERM returns a hardcoded terminal type ("dumb") and a boolean indicating the terminal type is set.
func (c *cmdConsole) getTERM() (string, bool) {
return "dumb", true
}

// controlSocketHandler initializes the console size in the websocket connection, noting resize won't be handled correctly on Windows.
func (c *cmdConsole) controlSocketHandler(control *websocket.Conn) {
// TODO: figure out what the equivalent of signal.SIGWINCH is on
// windows and use that; for now if you resize your terminal it just
Expand All @@ -26,6 +28,7 @@ func (c *cmdConsole) controlSocketHandler(control *websocket.Conn) {
}
}

// findCommand looks up the executable path for a given command name, with special handling for "VirtViewer" on Windows.
func (c *cmdConsole) findCommand(name string) string {
path, _ := exec.LookPath(name)
if path == "" {
Expand Down