Documentation
¶
Overview ¶
internal/api/auth_handlers.go
internal/api/clab_service.go
internal/api/events_handlers.go
internal/api/health_handlers.go
internal/api/helpers.go
internal/api/info_handlers.go
internal/api/lab_handlers.go
internal/api/logs_handlers.go
internal/api/routes.go
internal/api/ssh_handlers.go
internal/api/tools_handlers.go
internal/api/topology_handlers.go
internal/api/user_handlers.go
Index ¶
- func AuthMiddleware() gin.HandlerFunc
- func ChangeUserPasswordHandler(c *gin.Context)
- func CheckVersionHandler(c *gin.Context)
- func CreateCAHandler(c *gin.Context)
- func CreateUserHandler(c *gin.Context)
- func CreateVethHandler(c *gin.Context)
- func CreateVxlanHandler(c *gin.Context)
- func DeleteUserHandler(c *gin.Context)
- func DeleteVxlanHandler(c *gin.Context)
- func DeployLabArchiveHandler(c *gin.Context)
- func DeployLabHandler(c *gin.Context)
- func DestroyLabHandler(c *gin.Context)
- func DisableTxOffloadHandler(c *gin.Context)
- func ExecCommandHandler(c *gin.Context)
- func GenerateTopologyHandler(c *gin.Context)
- func GetClabService() *clab.Service
- func GetNodeLogsHandler(c *gin.Context)
- func GetUserDetailsHandler(c *gin.Context)
- func GetVersionHandler(c *gin.Context)
- func HealthCheckHandler(c *gin.Context)
- func InitHealth(version string)
- func InitSSHManager()
- func InspectInterfacesHandler(c *gin.Context)
- func InspectLabHandler(c *gin.Context)
- func ListLabsHandler(c *gin.Context)
- func ListSSHSessionsHandler(c *gin.Context)
- func ListUsersHandler(c *gin.Context)
- func LoginHandler(c *gin.Context)
- func RedeployLabHandler(c *gin.Context)
- func RequestSSHAccessHandler(c *gin.Context)
- func ResetNetemHandler(c *gin.Context)
- func SaveLabConfigHandler(c *gin.Context)
- func SetClabService(svc *clab.Service)
- func SetNetemHandler(c *gin.Context)
- func SetupRoutes(router *gin.Engine)
- func ShowNetemHandler(c *gin.Context)
- func ShutdownSSHManager()
- func SignCertHandler(c *gin.Context)
- func StreamEventsHandler(c *gin.Context)
- func SystemMetricsHandler(c *gin.Context)
- func TerminateSSHSessionHandler(c *gin.Context)
- func UpdateUserHandler(c *gin.Context)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
func AuthMiddleware() gin.HandlerFunc
AuthMiddleware validates the JWT token from the Authorization header
func ChangeUserPasswordHandler ¶ added in v0.1.4
@Summary Change user password @Description Changes a user's password. Requires superuser privileges or the user's own account. @Tags Users @Security BearerAuth @Accept json @Produce json @Param username path string true "Username to change password for" example="john" @Param passwordChange body models.PasswordChangeRequest true "Password change details" @Success 200 {object} models.GenericSuccessResponse "Password changed successfully" @Failure 400 {object} models.ErrorResponse "Invalid request body" @Failure 401 {object} models.ErrorResponse "Unauthorized or incorrect current password" @Failure 403 {object} models.ErrorResponse "Forbidden (Not superuser or not the user's own account)" @Failure 404 {object} models.ErrorResponse "User not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/users/{username}/password [put]
func CheckVersionHandler ¶
@Summary Check containerlab updates @Description Checks whether a newer containerlab release is available. @Tags Version @Security BearerAuth @Produce json @Success 200 {object} models.VersionCheckResponse "Result of the version check" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Router /api/v1/version/check [get]
func CreateCAHandler ¶
@Summary Create certificate authority (CA) @Description Creates a CA certificate and private key. Requires superuser privileges. @Description @Description **Notes** @Description - Files are stored in the user's `~/.clab/certs/<ca_name>/` directory on the server. @Tags Tools - Certificates @Security BearerAuth @Accept json @Produce json @Param ca_request body models.CACreateRequest true "CA Generation Parameters" @Success 200 {object} models.CertResponse "CA created successfully" @Failure 400 {object} models.ErrorResponse "Invalid input parameters" @Failure 401 {object} models.ErrorResponse "Unauthorized (JWT)" @Failure 403 {object} models.ErrorResponse "Forbidden (User is not a superuser)" @Failure 500 {object} models.ErrorResponse "Internal server error (filesystem, clab execution)" @Router /api/v1/tools/certs/ca [post]
func CreateUserHandler ¶ added in v0.1.4
@Summary Create user @Description Creates a new system user. Requires superuser privileges. @Tags Users @Security BearerAuth @Accept json @Produce json @Param user body models.UserCreateRequest true "User creation details" @Success 201 {object} models.GenericSuccessResponse "User created successfully" @Failure 400 {object} models.ErrorResponse "Invalid request body" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 403 {object} models.ErrorResponse "Forbidden (User is not a superuser)" @Failure 409 {object} models.ErrorResponse "User already exists" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/users [post]
func CreateVethHandler ¶
@Summary Create vEth pair @Description Creates a virtual Ethernet (vEth) pair between two endpoints (container, host, bridge, or ovs-bridge). Requires superuser privileges. @Tags Tools - vEth @Security BearerAuth @Accept json @Produce json @Param veth_request body models.VethCreateRequest true "vEth Creation Parameters" @Success 200 {object} models.GenericSuccessResponse "vEth pair created successfully" @Failure 400 {object} models.ErrorResponse "Invalid input parameters (endpoints, MTU)" @Failure 401 {object} models.ErrorResponse "Unauthorized (JWT)" @Failure 403 {object} models.ErrorResponse "Forbidden (User is not a superuser)" @Failure 500 {object} models.ErrorResponse "Internal server error (clab execution failed)" @Router /api/v1/tools/veth [post]
func CreateVxlanHandler ¶
@Summary Create VxLAN tunnel @Description Creates a VxLAN tunnel interface and sets up tc rules for traffic redirection. Requires superuser privileges. @Tags Tools - VxLAN @Security BearerAuth @Accept json @Produce json @Param vxlan_request body models.VxlanCreateRequest true "VxLAN Creation Parameters" @Success 200 {object} models.GenericSuccessResponse "VxLAN tunnel created successfully" @Failure 400 {object} models.ErrorResponse "Invalid input parameters (remote, link, id, port, etc.)" @Failure 401 {object} models.ErrorResponse "Unauthorized (JWT)" @Failure 403 {object} models.ErrorResponse "Forbidden (User is not a superuser)" @Failure 500 {object} models.ErrorResponse "Internal server error (clab execution failed)" @Router /api/v1/tools/vxlan [post]
func DeleteUserHandler ¶ added in v0.1.4
@Summary Delete user @Description Deletes a user from the system. Requires superuser privileges. @Tags Users @Security BearerAuth @Produce json @Param username path string true "Username to delete" example="john" @Success 200 {object} models.GenericSuccessResponse "User deleted successfully" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 403 {object} models.ErrorResponse "Forbidden (User is not a superuser)" @Failure 404 {object} models.ErrorResponse "User not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/users/{username} [delete]
func DeleteVxlanHandler ¶
@Summary Delete VxLAN tunnels by prefix @Description Deletes VxLAN tunnel interfaces that match the provided prefix (default: `vx-`). Requires superuser privileges. @Tags Tools - VxLAN @Security BearerAuth @Produce json @Param prefix query string false "Prefix of VxLAN interfaces to delete" default(vx-) example="vx-" @Success 200 {object} models.GenericSuccessResponse "VxLAN tunnels deleted successfully" @Failure 400 {object} models.ErrorResponse "Invalid prefix format" @Failure 401 {object} models.ErrorResponse "Unauthorized (JWT)" @Failure 403 {object} models.ErrorResponse "Forbidden (User is not a superuser)" @Failure 500 {object} models.ErrorResponse "Internal server error (clab execution failed)" @Router /api/v1/tools/vxlan [delete]
func DeployLabArchiveHandler ¶
@Summary Deploy lab from archive @Description Deploys a containerlab topology provided as a .zip or .tar.gz archive. @Tags Labs @Security BearerAuth @Accept multipart/form-data @Produce json @Param labArchive formData file true "Lab archive (.zip or .tar.gz)" @Param labName query string true "Name for the lab" @Param reconfigure query boolean false "Allow overwriting an existing lab" @Param maxWorkers query int false "Limit concurrent workers" @Param exportTemplate query string false "Custom Go template file for topology data export" @Param nodeFilter query string false "Comma-separated list of node names to deploy" @Param skipPostDeploy query boolean false "Skip post-deploy actions" @Param skipLabdirAcl query boolean false "Skip setting extended ACLs on lab directory" @Success 200 {object} models.ClabInspectOutput "Deployed lab details" @Failure 400 {object} models.ErrorResponse "Invalid input" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 403 {object} models.ErrorResponse "Forbidden" @Failure 409 {object} models.ErrorResponse "Conflict" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/labs/archive [post]
func DeployLabHandler ¶
@Summary Deploy lab @Description Deploys a containerlab topology. @Description @Description **Notes** @Description - The request body must include either `topologyContent` or `topologySourceUrl` (not both). @Tags Labs @Security BearerAuth @Accept json @Produce json @Param deploy_request body models.DeployRequest true "Deployment Source" @Param labNameOverride query string false "Override lab name when deploying from a URL (optional)" @Param reconfigure query boolean false "Allow overwriting an existing lab IF owned by the user" @Param maxWorkers query int false "Limit concurrent workers" @Param exportTemplate query string false "Custom Go template file for topology data export" @Param nodeFilter query string false "Comma-separated list of node names to deploy" @Param skipPostDeploy query boolean false "Skip post-deploy actions" @Param skipLabdirAcl query boolean false "Skip setting extended ACLs on lab directory" @Success 200 {object} models.ClabInspectOutput "Deployed lab details" @Failure 400 {object} models.ErrorResponse "Invalid input" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 403 {object} models.ErrorResponse "Forbidden" @Failure 409 {object} models.ErrorResponse "Conflict" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/labs [post]
func DestroyLabHandler ¶
@Summary Destroy lab @Description Destroys a lab by name after verifying ownership. @Tags Labs @Security BearerAuth @Produce json @Param labName path string true "Name of the lab to destroy" @Param cleanup query boolean false "Remove lab directory after destroy" @Param graceful query boolean false "Attempt graceful shutdown" @Param keepMgmtNet query boolean false "Keep the management network" @Param nodeFilter query string false "Destroy only specific nodes" @Success 200 {object} models.GenericSuccessResponse "Lab destroyed successfully" @Failure 400 {object} models.ErrorResponse "Invalid lab name" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 404 {object} models.ErrorResponse "Lab not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/labs/{labName} [delete]
func DisableTxOffloadHandler ¶
@Summary Disable TX checksum offload @Description Disables TX checksum offload on the eth0 interface of a container. Requires superuser privileges. @Tags Tools @Security BearerAuth @Accept json @Produce json @Param tx_request body models.DisableTxOffloadRequest true "Container Name" @Success 200 {object} models.GenericSuccessResponse "Offload disabled successfully" @Failure 400 {object} models.ErrorResponse "Invalid input" @Failure 401 {object} models.ErrorResponse "Unauthorized (JWT)" @Failure 403 {object} models.ErrorResponse "Forbidden (User is not a superuser)" @Failure 404 {object} models.ErrorResponse "Container not found" @Failure 500 {object} models.ErrorResponse "Internal server error or clab execution failed" @Router /api/v1/tools/disable-tx-offload [post]
func ExecCommandHandler ¶
@Summary Execute command in lab @Description Executes a command on nodes within a lab. @Tags Labs @Security BearerAuth @Accept json @Produce json @Param labName path string true "Name of the lab" @Param nodeFilter query string false "Execute only on this specific node" @Param exec_request body models.ExecRequest true "Command to execute" @Success 200 {object} models.ExecResponse "Execution result" @Failure 400 {object} models.ErrorResponse "Invalid input" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 404 {object} models.ErrorResponse "Lab not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/labs/{labName}/exec [post]
func GenerateTopologyHandler ¶
@Summary Generate containerlab topology @Description Generates a containerlab topology from CLOS definitions and can optionally deploy it for the authenticated user. @Description @Description **Notes** @Description - Deployment is denied if a lab with the target name already exists. @Description - The `images` and `licenses` fields map node kind to image or license path (e.g., {"nokia_srlinux":"ghcr.io/..."}). @Description - When `deploy=true`, the topology is saved to the user's `~/.clab/<labName>/` directory and `outputFile` is ignored. @Description - When `deploy=false` and `outputFile` is empty, YAML is returned in the response. @Description - When `deploy=false` and `outputFile` is set, the file is saved to that path on the server (requires API server write permissions). @Tags Topology Generation @Security BearerAuth @Accept json @Produce json @Param generate_request body models.GenerateRequest true "Topology generation parameters. The 'images' field maps kind to image path." example(`{"name": "3-tier-clos", "tiers": [{"count": 4, "kind": "nokia_srlinux", "type": "ixrd3"}, {"count": 2, "kind": "arista_ceos"}], "defaultKind": "nokia_srlinux", "images": {"nokia_srlinux": "ghcr.io/nokia/srlinux:latest", "arista_ceos": "ceos:4.28.0F", "cisco_xr": "cisco/xrd:7.8.2"}, "licenses": {"nokia_srlinux": "/path/to/license.key"}, "nodePrefix": "clos-node", "groupPrefix": "clos-tier", "managementNetwork": "clos-mgmt", "ipv4Subnet": "172.50.20.0/24", "ipv6Subnet": "2001:172:20:20::/64", "deploy": true, "maxWorkers": 0, "outputFile": ""}`) @Success 200 {object} models.GenerateResponse "Generation successful (YAML or deploy output)" @Failure 400 {object} models.ErrorResponse "Invalid input parameters" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 409 {object} models.ErrorResponse "Conflict (Lab already exists and Deploy=true)" @Failure 500 {object} models.ErrorResponse "Internal server error or clab execution failed" @Router /api/v1/generate [post]
func GetClabService ¶ added in v0.2.0
GetClabService returns the containerlab service instance.
func GetNodeLogsHandler ¶ added in v0.1.10
@Summary Get node logs @Description Returns logs for a lab node. @Description @Description **Notes** @Description - When `follow=true`, the response streams as NDJSON (one JSON object per line) until the client disconnects or the 30-minute timeout. @Tags Logs @Security BearerAuth @Produce json,application/x-ndjson @Param labName path string true "Name of the lab" example="my-lab" @Param nodeName path string true "Full name of the container (node)" example="clab-my-lab-srl1" @Param tail query string false "Number of lines to show from the end of logs (default all). Use an integer or 'all'." example="100" default(all) @Param follow query boolean false "Follow log output (stream logs as NDJSON). Note: In Swagger UI, streaming may not display correctly." example="false" @Success 200 {object} models.LogsResponse "Container logs (follow=false). When follow=true, response is NDJSON stream of LogLine objects." @Failure 400 {object} models.ErrorResponse "Invalid input (lab name, node filter, etc.)" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 403 {object} models.ErrorResponse "Forbidden (not owner of the lab)" @Failure 404 {object} models.ErrorResponse "Lab or node not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/labs/{labName}/nodes/{nodeName}/logs [get]
func GetUserDetailsHandler ¶ added in v0.1.4
@Summary Get user details @Description Returns details for a specific user. Requires superuser privileges or the user's own account. @Tags Users @Security BearerAuth @Produce json @Param username path string true "Username to get details for" example="john" @Success 200 {object} models.UserDetails "User details" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 403 {object} models.ErrorResponse "Forbidden (Not superuser or not the user's own account)" @Failure 404 {object} models.ErrorResponse "User not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/users/{username} [get]
func GetVersionHandler ¶
@Summary Get containerlab version @Description Returns version information for the containerlab library in use. @Tags Version @Security BearerAuth @Produce json @Success 200 {object} models.VersionResponse "Containerlab version details" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/version [get]
func HealthCheckHandler ¶ added in v0.1.4
@Summary Get API server health @Description Returns basic health status for the API server. @Tags Health @Produce json @Success 200 {object} models.HealthResponse "Basic health information" @Router /health [get]
func InitHealth ¶ added in v0.1.4
func InitHealth(version string)
InitHealth sets the server start time for uptime tracking and stores the version
func InitSSHManager ¶ added in v0.1.4
func InitSSHManager()
InitSSHManager initializes the SSH manager
func InspectInterfacesHandler ¶
@Summary List lab interfaces @Description Returns interface details for nodes in a lab. @Tags Labs @Security BearerAuth @Produce json @Param labName path string true "Name of the lab" @Param node query string false "Filter interfaces for a specific node" @Success 200 {object} models.ClabInspectInterfacesOutput "Interface details" @Failure 400 {object} models.ErrorResponse "Invalid lab name" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 404 {object} models.ErrorResponse "Lab not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/labs/{labName}/interfaces [get]
func InspectLabHandler ¶
@Summary Inspect lab @Description Returns details for a specific running lab. @Tags Labs @Security BearerAuth @Produce json @Param labName path string true "Name of the lab to inspect" @Success 200 {object} []models.ClabContainerInfo "Lab containers" @Failure 400 {object} models.ErrorResponse "Invalid lab name" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 404 {object} models.ErrorResponse "Lab not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/labs/{labName} [get]
func ListLabsHandler ¶
@Summary List labs @Description Returns details for all running labs. @Description @Description **Notes** @Description - Results are filtered by owner unless the caller is a superuser. @Tags Labs @Security BearerAuth @Produce json @Success 200 {object} models.ClabInspectOutput "All labs" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/labs [get]
func ListSSHSessionsHandler ¶ added in v0.1.4
@Summary List SSH sessions @Description Returns active SSH sessions. @Description @Description **Notes** @Description - Regular users see only their sessions. @Description - Superusers can include all sessions via the `all` query parameter. @Tags SSH Access @Security BearerAuth @Produce json @Param all query boolean false "If true and user is superuser, shows sessions for all users (default: false)" example="true" @Success 200 {array} models.SSHSessionInfo "List of active SSH sessions" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 403 {object} models.ErrorResponse "Forbidden (non-superuser attempting to list all sessions)" @Router /api/v1/ssh/sessions [get]
func ListUsersHandler ¶ added in v0.1.4
@Summary List users @Description Returns a list of system users. Requires superuser privileges. @Tags Users @Security BearerAuth @Produce json @Success 200 {array} models.UserDetails "List of user details" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 403 {object} models.ErrorResponse "Forbidden (User is not a superuser)" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/users [get]
func LoginHandler ¶
LoginHandler - Handles user authentication @Summary Log in @Description Authenticates a user and returns a JWT token. @Tags Auth @Accept json @Produce json @Param credentials body models.LoginRequest true "User Credentials" @Success 200 {object} models.LoginResponse "JWT token" @Failure 400 {object} models.ErrorResponse "Invalid input" @Failure 401 {object} models.ErrorResponse "Invalid credentials" @Failure 500 {object} models.ErrorResponse "Internal server error (PAM config?)" @Router /login [post]
func RedeployLabHandler ¶
@Summary Redeploy lab @Description Redeploys a lab by name. @Description @Description **Notes** @Description - This operation destroys the lab and then deploys it again. @Tags Labs @Security BearerAuth @Produce json @Param labName path string true "Name of the lab to redeploy" @Param cleanup query boolean false "Remove lab directory after destroy" @Param graceful query boolean false "Attempt graceful shutdown" @Param keepMgmtNet query boolean false "Keep the management network" @Param maxWorkers query int false "Limit concurrent workers" @Param exportTemplate query string false "Custom Go template file for topology data export" @Param skipPostDeploy query boolean false "Skip post-deploy actions" @Param skipLabdirAcl query boolean false "Skip setting extended ACLs on lab directory" @Success 200 {object} models.ClabInspectOutput "Redeployed lab details" @Failure 400 {object} models.ErrorResponse "Invalid lab name" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 404 {object} models.ErrorResponse "Lab not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/labs/{labName} [put]
func RequestSSHAccessHandler ¶ added in v0.1.4
@Summary Request SSH access to lab node @Description Creates temporary SSH access to a lab node and returns connection details. @Tags SSH Access @Security BearerAuth @Accept json @Produce json @Param labName path string true "Lab name" example="my-lab" @Param nodeName path string true "Full container name of the node (e.g., clab-my-lab-srl1)" example="clab-my-lab-srl1" @Param sshRequest body models.SSHAccessRequest false "SSH access parameters" @Success 200 {object} models.SSHAccessResponse "SSH connection details" @Failure 400 {object} models.ErrorResponse "Invalid request parameters" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 403 {object} models.ErrorResponse "Forbidden (not owner of the lab)" @Failure 404 {object} models.ErrorResponse "Lab or node not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/labs/{labName}/nodes/{nodeName}/ssh [post]
func ResetNetemHandler ¶
@Summary Reset link impairments (netem) @Description Resets (removes) netem impairments from a specific interface of a containerlab node. Requires superuser privileges. @Tags Tools - Netem @Security BearerAuth @Accept json @Produce json @Param netem_reset_request body models.NetemResetRequest true "Netem Reset Parameters" @Success 200 {object} models.GenericSuccessResponse "Impairments reset successfully" @Failure 400 {object} models.ErrorResponse "Invalid input parameters" @Failure 401 {object} models.ErrorResponse "Unauthorized (JWT)" @Failure 403 {object} models.ErrorResponse "Forbidden (User is not a superuser)" @Failure 404 {object} models.ErrorResponse "Container or interface not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/tools/netem/reset [post]
func SaveLabConfigHandler ¶
@Summary Save lab configuration @Description Saves the running configuration for nodes in a lab. @Tags Labs @Security BearerAuth @Produce json @Param labName path string true "Name of the lab" @Param nodeFilter query string false "Save config only for specific nodes" @Success 200 {object} models.SaveConfigResponse "Configuration saved" @Failure 400 {object} models.ErrorResponse "Invalid input" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 404 {object} models.ErrorResponse "Lab not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/labs/{labName}/save [post]
func SetClabService ¶ added in v0.2.0
SetClabService sets the containerlab service instance for use by handlers.
func SetNetemHandler ¶
@Summary Set link impairments (netem) @Description Sets netem impairments (delay, jitter, loss, rate limiting, corruption) on a specific interface of a containerlab node. Requires superuser privileges. @Tags Tools - Netem @Security BearerAuth @Accept json @Produce json @Param netem_set_request body models.NetemSetRequest true "Netem Set Parameters" @Success 200 {object} models.GenericSuccessResponse "Impairments set successfully" @Failure 400 {object} models.ErrorResponse "Invalid input parameters" @Failure 401 {object} models.ErrorResponse "Unauthorized (JWT)" @Failure 403 {object} models.ErrorResponse "Forbidden (User is not a superuser)" @Failure 404 {object} models.ErrorResponse "Container or interface not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/tools/netem/set [post]
func SetupRoutes ¶
SetupRoutes defines all the API endpoints and applies middleware.
func ShowNetemHandler ¶
@Summary Show link impairments (netem) @Description Lists netem impairments for a given containerlab node. Requires superuser privileges. @Tags Tools - Netem @Security BearerAuth @Produce json @Param containerName query string true "Container/node name" example(clab-my-lab-srl1) @Success 200 {object} models.NetemShowResponse "Netem impairments" @Failure 400 {object} models.ErrorResponse "Invalid input parameters" @Failure 401 {object} models.ErrorResponse "Unauthorized (JWT)" @Failure 403 {object} models.ErrorResponse "Forbidden (User is not a superuser)" @Failure 404 {object} models.ErrorResponse "Container not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/tools/netem/show [get]
func ShutdownSSHManager ¶ added in v0.1.4
func ShutdownSSHManager()
ShutdownSSHManager gracefully shuts down the SSH manager
func SignCertHandler ¶
@Summary Sign certificate @Description Creates a certificate/key and signs it with a previously generated CA. Requires superuser privileges. @Description @Description **Notes** @Description - Files are stored in the user's `~/.clab/certs/<ca_name>/` directory. @Tags Tools - Certificates @Security BearerAuth @Accept json @Produce json @Param sign_request body models.CertSignRequest true "Certificate Signing Parameters" @Success 200 {object} models.CertResponse "Certificate signed successfully" @Failure 400 {object} models.ErrorResponse "Invalid input parameters (name, hosts, CA name, etc.)" @Failure 401 {object} models.ErrorResponse "Unauthorized (JWT)" @Failure 403 {object} models.ErrorResponse "Forbidden (User is not a superuser)" @Failure 404 {object} models.ErrorResponse "Specified CA not found" @Failure 500 {object} models.ErrorResponse "Internal server error (filesystem, clab execution)" @Router /api/v1/tools/certs/sign [post]
func StreamEventsHandler ¶ added in v0.2.0
@Summary Stream containerlab events @Description Streams containerlab events in real time as NDJSON (one JSON object per line). @Description @Description **Notes** @Description - The response stays open until the client disconnects. @Description @Description **Examples** @Description NDJSON (one JSON object per line): @Description ```json @Description {"time":1706918400,"type":"container","action":"start","attributes":{"name":"clab-mylab-srl1","lab":"mylab","clab-node-name":"srl1","clab-node-kind":"nokia_srlinux"}} @Description {"time":1706918405,"type":"container","action":"start","attributes":{"name":"clab-mylab-srl2","lab":"mylab","clab-node-name":"srl2","clab-node-kind":"nokia_srlinux"}} @Description ``` @Description @Description @Description Interface stats (interfaceStats=true): @Description ```json @Description {"time":1706918410,"type":"interface-stats","action":"stats","attributes":{"name":"clab-mylab-srl1","lab":"mylab","interface":"e1-1","rx_bytes":123456,"tx_bytes":654321}} @Description ``` @Tags Events @Security BearerAuth @Produce application/x-ndjson @Param initialState query boolean false "Include initial snapshot events when the stream starts." default(false) @Param interfaceStats query boolean false "Include interface stats events." default(false) @Param interfaceStatsInterval query string false "Interval for interface stats collection (e.g., 10s). Requires interfaceStats=true." default(10s) @Success 200 {object} models.EventResponse "Event stream - NDJSON (one JSON object per line)" @Failure 400 {object} models.ErrorResponse "Invalid input" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/events [get]
func SystemMetricsHandler ¶ added in v0.1.4
@Summary Get system metrics @Description Returns detailed CPU, memory, and disk metrics for the API server. Requires superuser privileges. @Tags Health @Security BearerAuth @Produce json @Success 200 {object} models.MetricsResponse "System metrics" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 403 {object} models.ErrorResponse "Forbidden (User is not a superuser)" @Failure 500 {object} models.ErrorResponse "Internal server error gathering metrics" @Router /api/v1/health/metrics [get]
func TerminateSSHSessionHandler ¶ added in v0.1.4
@Summary Terminate SSH session @Description Terminates a specific SSH session by port. @Tags SSH Access @Security BearerAuth @Produce json @Param port path int true "SSH session port to terminate" example="2223" @Success 200 {object} models.GenericSuccessResponse "Session terminated successfully" @Failure 400 {object} models.ErrorResponse "Invalid port parameter" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 403 {object} models.ErrorResponse "Forbidden (not owner of the session)" @Failure 404 {object} models.ErrorResponse "Session not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/ssh/sessions/{port} [delete]
func UpdateUserHandler ¶ added in v0.1.4
@Summary Update user @Description Updates an existing user. Requires superuser privileges or the user's own account. @Tags Users @Security BearerAuth @Accept json @Produce json @Param username path string true "Username to update" example="john" @Param user body models.UserUpdateRequest true "User details to update" @Success 200 {object} models.GenericSuccessResponse "User updated successfully" @Failure 400 {object} models.ErrorResponse "Invalid request body" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 403 {object} models.ErrorResponse "Forbidden (Not superuser or not the user's own account)" @Failure 404 {object} models.ErrorResponse "User not found" @Failure 500 {object} models.ErrorResponse "Internal server error" @Router /api/v1/users/{username} [put] internal/api/user_handlers.go - Fix for UpdateUserHandler
Types ¶
This section is empty.