swagger:operation POST /1.0/instances/{name}/console instances instance_console_post Connect to console Connects to the console of an instance. The returned operation metadata will contain two websockets, one for data and one for control. --- consumes: - application/json produces: -
(d *Daemon, r *http.Request)
| 471 | // "500": |
| 472 | // $ref: "#/responses/InternalServerError" |
| 473 | func instanceConsolePost(d *Daemon, r *http.Request) response.Response { |
| 474 | s := d.State() |
| 475 | |
| 476 | projectName := request.ProjectParam(r) |
| 477 | name, err := pathVar(r, "name") |
| 478 | if err != nil { |
| 479 | return response.SmartError(err) |
| 480 | } |
| 481 | |
| 482 | if internalInstance.IsSnapshot(name) { |
| 483 | return response.BadRequest(errors.New("Invalid instance name")) |
| 484 | } |
| 485 | |
| 486 | post := api.InstanceConsolePost{} |
| 487 | buf, err := io.ReadAll(r.Body) |
| 488 | if err != nil { |
| 489 | return response.BadRequest(err) |
| 490 | } |
| 491 | |
| 492 | err = json.Unmarshal(buf, &post) |
| 493 | if err != nil { |
| 494 | return response.BadRequest(err) |
| 495 | } |
| 496 | |
| 497 | // Forward the request if the container is remote. |
| 498 | client, err := cluster.ConnectIfInstanceIsRemote(s, projectName, name, r) |
| 499 | if err != nil { |
| 500 | return response.SmartError(err) |
| 501 | } |
| 502 | |
| 503 | if client != nil { |
| 504 | consoleURL := api.NewURL().Path(version.APIVersion, "instances", name, "console").Project(projectName) |
| 505 | resp, _, err := client.RawQuery("POST", consoleURL.String(), post, "") |
| 506 | if err != nil { |
| 507 | return response.SmartError(err) |
| 508 | } |
| 509 | |
| 510 | opAPI, err := resp.MetadataAsOperation() |
| 511 | if err != nil { |
| 512 | return response.SmartError(err) |
| 513 | } |
| 514 | |
| 515 | return operations.ForwardedOperationResponse(opAPI) |
| 516 | } |
| 517 | |
| 518 | if post.Type == "" { |
| 519 | post.Type = instance.ConsoleTypeConsole |
| 520 | } |
| 521 | |
| 522 | // Basic parameter validation. |
| 523 | if !slices.Contains([]string{instance.ConsoleTypeConsole, instance.ConsoleTypeVGA}, post.Type) { |
| 524 | return response.BadRequest(fmt.Errorf("Unknown console type %q", post.Type)) |
| 525 | } |
| 526 | |
| 527 | inst, err := instance.LoadByProjectAndName(s, projectName, name) |
| 528 | if err != nil { |
| 529 | return response.SmartError(err) |
| 530 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…