swagger:operation GET /1.0/instances/{name}/console instances instance_console_get Get console output Gets the console output for the instance either as text log or as vga screendump. --- produces: - application/json parameters: - in: path name: name description: Instance na
(d *Daemon, r *http.Request)
| 658 | // "500": |
| 659 | // $ref: "#/responses/InternalServerError" |
| 660 | func instanceConsoleLogGet(d *Daemon, r *http.Request) response.Response { |
| 661 | s := d.State() |
| 662 | |
| 663 | projectName := request.ProjectParam(r) |
| 664 | name, err := pathVar(r, "name") |
| 665 | if err != nil { |
| 666 | return response.SmartError(err) |
| 667 | } |
| 668 | |
| 669 | consoleLogType := request.QueryParam(r, "type") |
| 670 | if consoleLogType != "" && consoleLogType != "log" && consoleLogType != "vga" { |
| 671 | return response.SmartError(fmt.Errorf("Invalid value for type parameter: %s", consoleLogType)) |
| 672 | } |
| 673 | |
| 674 | if internalInstance.IsSnapshot(name) { |
| 675 | return response.BadRequest(errors.New("Invalid instance name")) |
| 676 | } |
| 677 | |
| 678 | // Forward the request if the container is remote. |
| 679 | resp, err := forwardedResponseIfInstanceIsRemote(s, r, projectName, name) |
| 680 | if err != nil { |
| 681 | return response.SmartError(err) |
| 682 | } |
| 683 | |
| 684 | if resp != nil { |
| 685 | return resp |
| 686 | } |
| 687 | |
| 688 | inst, err := instance.LoadByProjectAndName(s, projectName, name) |
| 689 | if err != nil { |
| 690 | return response.SmartError(err) |
| 691 | } |
| 692 | |
| 693 | ent := response.FileResponseEntry{} |
| 694 | |
| 695 | if !inst.IsRunning() { |
| 696 | // Check if we have data we can return. |
| 697 | consoleBufferLogPath := inst.ConsoleBufferLogPath() |
| 698 | if !util.PathExists(consoleBufferLogPath) { |
| 699 | return response.FileResponse(r, nil, nil) |
| 700 | } |
| 701 | |
| 702 | ent.Path = consoleBufferLogPath |
| 703 | ent.Filename = consoleBufferLogPath |
| 704 | return response.FileResponse(r, []response.FileResponseEntry{ent}, nil) |
| 705 | } |
| 706 | |
| 707 | if inst.Type() == instancetype.Container { |
| 708 | c, ok := inst.(instance.Container) |
| 709 | if !ok { |
| 710 | return response.SmartError(errors.New("Failed to cast inst to Container")) |
| 711 | } |
| 712 | |
| 713 | // Query the container's console ringbuffer. |
| 714 | console := liblxc.ConsoleLogOptions{ |
| 715 | ClearLog: false, |
| 716 | ReadLog: true, |
| 717 | ReadMax: 0, |
nothing calls this directly
no test coverage detected
searching dependent graphs…