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)
| 828 | // "500": |
| 829 | // $ref: "#/responses/InternalServerError" |
| 830 | func 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, |
nothing calls this directly
no test coverage detected
searching dependent graphs…