MCPcopy
hub / github.com/lxc/incus / instanceConsoleLogDelete

Function instanceConsoleLogDelete

cmd/incusd/instance_console.go:830–907  ·  view source on GitHub ↗

swagger:operation DELETE /1.0/instances/{name}/console instances instance_console_delete Clear the console log Clears the console log buffer. --- produces: - application/json parameters: - in: path name: name description: Instance name type: string required: true

(d *Daemon, r *http.Request)

Source from the content-addressed store, hash-verified

828// "500":
829// $ref: "#/responses/InternalServerError"
830func instanceConsoleLogDelete(d *Daemon, r *http.Request) response.Response {
831 if !liblxc.RuntimeLiblxcVersionAtLeast(liblxc.Version(), 3, 0, 0) {
832 return response.BadRequest(errors.New("Clearing the console buffer requires liblxc >= 3.0"))
833 }
834
835 name, err := pathVar(r, "name")
836 if err != nil {
837 return response.SmartError(err)
838 }
839
840 if internalInstance.IsSnapshot(name) {
841 return response.BadRequest(errors.New("Invalid instance name"))
842 }
843
844 projectName := request.ProjectParam(r)
845
846 inst, err := instance.LoadByProjectAndName(d.State(), projectName, name)
847 if err != nil {
848 return response.SmartError(err)
849 }
850
851 if inst.Type() != instancetype.Container {
852 return response.SmartError(errors.New("Instance is not container type"))
853 }
854
855 c, ok := inst.(instance.Container)
856 if !ok {
857 return response.SmartError(errors.New("Instance is not container type"))
858 }
859
860 truncateConsoleLogFile := func(logPath string) error {
861 // Check that this is a regular file. We don't want to try and unlink
862 // /dev/stderr or /dev/null or something.
863 st, err := os.Stat(logPath)
864 if err != nil {
865 return err
866 }
867
868 if !st.Mode().IsRegular() {
869 return errors.New("The console log is not a regular file")
870 }
871
872 if logPath == "" {
873 return errors.New("Container does not keep a console logfile")
874 }
875
876 return os.Truncate(logPath, 0)
877 }
878
879 if !inst.IsRunning() {
880 consoleLogpath := c.ConsoleBufferLogPath()
881 return response.SmartError(truncateConsoleLogFile(consoleLogpath))
882 }
883
884 // Send a ringbuffer request to the container.
885 console := liblxc.ConsoleLogOptions{
886 ClearLog: true,
887 ReadLog: false,

Callers

nothing calls this directly

Calls 14

BadRequestFunction · 0.92
SmartErrorFunction · 0.92
ProjectParamFunction · 0.92
LoadByProjectAndNameFunction · 0.92
GetErrnoFunction · 0.92
pathVarFunction · 0.85
VersionMethod · 0.80
ModeMethod · 0.80
IsSnapshotMethod · 0.65
StateMethod · 0.65
TypeMethod · 0.65
IsRunningMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…