Skip to content

Commit

Permalink
Merge pull request #904 from stgraber/main
Browse files Browse the repository at this point in the history
Improve console log handling
  • Loading branch information
tych0 authored May 30, 2024
2 parents ce46bfa + 70fc5ef commit 799b03e
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 257 deletions.
4 changes: 2 additions & 2 deletions cmd/incus/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ func (c *cmdConsole) Run(cmd *cobra.Command, args []string) error {
return err
}

stuff, err := io.ReadAll(log)
content, err := io.ReadAll(log)
if err != nil {
return err
}

fmt.Printf("\n"+i18n.G("Console log:")+"\n\n%s\n", string(stuff))
fmt.Println(string(content))
return nil
}

Expand Down
15 changes: 8 additions & 7 deletions cmd/incusd/instance_console.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/lxc/incus/v6/internal/version"
"github.com/lxc/incus/v6/shared/api"
"github.com/lxc/incus/v6/shared/logger"
"github.com/lxc/incus/v6/shared/util"
"github.com/lxc/incus/v6/shared/ws"
)

Expand Down Expand Up @@ -584,24 +585,24 @@ func instanceConsoleLogGet(d *Daemon, r *http.Request) response.Response {
return resp
}

if !liblxc.RuntimeLiblxcVersionAtLeast(liblxc.Version(), 3, 0, 0) {
return response.BadRequest(fmt.Errorf("Querying the console buffer requires liblxc >= 3.0"))
}

inst, err := instance.LoadByProjectAndName(s, projectName, name)
if err != nil {
return response.SmartError(err)
}

if inst.Type() != instancetype.Container {
return response.SmartError(fmt.Errorf("Instance is not container type"))
return response.SmartError(fmt.Errorf("Console backlog is only supported on containers"))
}

c := inst.(instance.Container)
ent := response.FileResponseEntry{}
if !c.IsRunning() {
// Hand back the contents of the console ringbuffer logfile.
// Check if we have data we can return.
consoleBufferLogPath := c.ConsoleBufferLogPath()
if !util.PathExists(consoleBufferLogPath) {
return response.FileResponse(r, nil, nil)
}

ent.Path = consoleBufferLogPath
ent.Filename = consoleBufferLogPath
return response.FileResponse(r, []response.FileResponseEntry{ent}, nil)
Expand All @@ -624,7 +625,7 @@ func instanceConsoleLogGet(d *Daemon, r *http.Request) response.Response {
}

if errno == unix.ENODATA {
return response.FileResponse(r, []response.FileResponseEntry{ent}, nil)
return response.FileResponse(r, nil, nil)
}

return response.SmartError(err)
Expand Down
6 changes: 1 addition & 5 deletions po/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: LXD\n"
"Report-Msgid-Bugs-To: lxc-devel@lists.linuxcontainers.org\n"
"POT-Creation-Date: 2024-05-28 18:48-0400\n"
"POT-Creation-Date: 2024-05-30 15:15-0400\n"
"PO-Revision-Date: 2024-05-16 15:01+0000\n"
"Last-Translator: Tobias Gerold <tobias@g3ro.eu>\n"
"Language-Team: German <https://hosted.weblate.org/projects/incus/cli/de/>\n"
Expand Down Expand Up @@ -1641,10 +1641,6 @@ msgstr ""
msgid "Connecting to the daemon (attempt %d)"
msgstr ""

#: cmd/incus/console.go:140
msgid "Console log:"
msgstr ""

#: cmd/incus/storage_volume.go:584
msgid "Content type, block or filesystem"
msgstr ""
Expand Down
9 changes: 4 additions & 5 deletions po/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: lxd\n"
"Report-Msgid-Bugs-To: lxc-devel@lists.linuxcontainers.org\n"
"POT-Creation-Date: 2024-05-28 18:48-0400\n"
"POT-Creation-Date: 2024-05-30 15:15-0400\n"
"PO-Revision-Date: 2023-06-16 20:55+0000\n"
"Last-Translator: Francisco Serrador <fserrador@gmail.com>\n"
"Language-Team: Spanish <https://hosted.weblate.org/projects/linux-containers/"
Expand Down Expand Up @@ -1577,10 +1577,6 @@ msgstr ""
msgid "Connecting to the daemon (attempt %d)"
msgstr ""

#: cmd/incus/console.go:140
msgid "Console log:"
msgstr "Log de la consola:"

#: cmd/incus/storage_volume.go:584
msgid "Content type, block or filesystem"
msgstr ""
Expand Down Expand Up @@ -9590,6 +9586,9 @@ msgstr ""
msgid "yes"
msgstr ""

#~ msgid "Console log:"
#~ msgstr "Log de la consola:"

#, fuzzy
#~ msgid "The --mode flag can't be used with --storage or --target-project"
#~ msgstr ""
Expand Down
Loading

0 comments on commit 799b03e

Please sign in to comment.