[lxc-devel] [lxd/master] Allow for --console=TYPE
stgraber on Github
lxc-bot at linuxcontainers.org
Mon Jul 13 13:42:37 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200713/e79c612a/attachment.bin>
-------------- next part --------------
From 2ec5276a9edf4b0abdf3bd802981deb2712ddb47 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 13 Jul 2020 09:42:01 -0400
Subject: [PATCH 1/2] lxc/console: Short argument for type
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxc/console.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lxc/console.go b/lxc/console.go
index a3d44c9e78..7a8064a33d 100644
--- a/lxc/console.go
+++ b/lxc/console.go
@@ -40,7 +40,7 @@ as well as retrieve past log entries from it.`))
cmd.RunE = c.Run
cmd.Flags().BoolVar(&c.flagShowLog, "show-log", false, i18n.G("Retrieve the instance's console log"))
- cmd.Flags().StringVar(&c.flagType, "type", "console", i18n.G("Type of connection to establish: 'console' for serial console, 'vga' for SPICE graphical output"))
+ cmd.Flags().StringVarP(&c.flagType, "type", "t", "console", i18n.G("Type of connection to establish: 'console' for serial console, 'vga' for SPICE graphical output"))
return cmd
}
From 9462cc1021db239bf7c693d98e07adcf6924fe4e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 13 Jul 2020 09:42:10 -0400
Subject: [PATCH 2/2] lxc: Allow using --console=TYPE
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxc/action.go | 15 +++++++++------
lxc/launch.go | 8 +++++---
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/lxc/action.go b/lxc/action.go
index 17b811774e..5aee383e6e 100644
--- a/lxc/action.go
+++ b/lxc/action.go
@@ -98,7 +98,7 @@ type cmdAction struct {
global *cmdGlobal
flagAll bool
- flagConsole bool
+ flagConsole string
flagForce bool
flagStateful bool
flagStateless bool
@@ -115,9 +115,11 @@ func (c *cmdAction) Command(action string) *cobra.Command {
cmd.Flags().BoolVar(&c.flagStateful, "stateful", false, i18n.G("Store the instance state"))
} else if action == "start" {
cmd.Flags().BoolVar(&c.flagStateless, "stateless", false, i18n.G("Ignore the instance state"))
- cmd.Flags().BoolVar(&c.flagConsole, "console", false, i18n.G("Immediately attach to the console"))
- } else if action == "restart" {
- cmd.Flags().BoolVar(&c.flagConsole, "console", false, i18n.G("Immediately attach to the console"))
+ }
+
+ if shared.StringInSlice(action, []string{"start", "action"}) {
+ cmd.Flags().StringVar(&c.flagConsole, "console", "", i18n.G("Immediately attach to the console"))
+ cmd.Flags().Lookup("console").NoOptDefVal = "console"
}
if shared.StringInSlice(action, []string{"restart", "stop"}) {
@@ -203,9 +205,10 @@ func (c *cmdAction) doAction(action string, conf *config.Config, nameArg string)
progress.Done("")
// Handle console attach
- if c.flagConsole {
+ if c.flagConsole != "" {
console := cmdConsole{}
console.global = c.global
+ console.flagType = c.flagConsole
return console.Console(d, name)
}
@@ -262,7 +265,7 @@ func (c *cmdAction) Run(cmd *cobra.Command, args []string) error {
}
}
- if c.flagConsole {
+ if c.flagConsole != "" {
if c.flagAll {
return fmt.Errorf(i18n.G("--console can't be used with --all"))
}
diff --git a/lxc/launch.go b/lxc/launch.go
index 019a02ed4f..384edbd1bc 100644
--- a/lxc/launch.go
+++ b/lxc/launch.go
@@ -15,7 +15,7 @@ type cmdLaunch struct {
global *cmdGlobal
init *cmdInit
- flagConsole bool
+ flagConsole string
}
func (c *cmdLaunch) Command() *cobra.Command {
@@ -33,7 +33,8 @@ lxc launch ubuntu:18.04 u1 < config.yaml
cmd.RunE = c.Run
- cmd.Flags().BoolVar(&c.flagConsole, "console", false, i18n.G("Immediately attach to the console"))
+ cmd.Flags().StringVar(&c.flagConsole, "console", "", i18n.G("Immediately attach to the console"))
+ cmd.Flags().Lookup("console").NoOptDefVal = "console"
return cmd
}
@@ -105,9 +106,10 @@ func (c *cmdLaunch) Run(cmd *cobra.Command, args []string) error {
progress.Done("")
// Handle console attach
- if c.flagConsole {
+ if c.flagConsole != "" {
console := cmdConsole{}
console.global = c.global
+ console.flagType = c.flagConsole
return console.Console(d, name)
}
More information about the lxc-devel
mailing list