models

package
v0.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

internal/models/health_models.go

internal/models/models.go

internal/models/ssh_models.go

internal/models/user_models.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CACreateRequest

type CACreateRequest struct {
	Name         string `json:"name,omitempty" example:"my-root-ca"`           // Defaults to "ca" if empty
	Expiry       string `json:"expiry,omitempty" example:"8760h"`              // Duration string, defaults to "87600h" (10 years)
	CommonName   string `json:"commonName,omitempty" example:"ca.example.com"` // Defaults to "containerlab.dev"
	Country      string `json:"country,omitempty" example:"US"`                // Defaults to "Internet"
	Locality     string `json:"locality,omitempty" example:"City"`             // Defaults to "Server"
	Organization string `json:"organization,omitempty" example:"MyOrg"`        // Defaults to "Containerlab"
	OrgUnit      string `json:"orgUnit,omitempty" example:"IT"`                // Defaults to "Containerlab Tools"

}

CACreateRequest mirrors flags for `clab tools cert ca create`

type CPUMetrics added in v0.1.4

type CPUMetrics struct {
	UsagePercent   float64 `json:"usagePercent"`             // Overall CPU usage percentage
	NumCPU         int     `json:"numCPU"`                   // Number of CPUs/cores
	LoadAvg1       float64 `json:"loadAvg1,omitempty"`       // 1-minute load average
	LoadAvg5       float64 `json:"loadAvg5,omitempty"`       // 5-minute load average
	LoadAvg15      float64 `json:"loadAvg15,omitempty"`      // 15-minute load average
	ProcessPercent float64 `json:"processPercent,omitempty"` // This process's CPU usage
}

CPUMetrics represents CPU usage information

type CertResponse

type CertResponse struct {
	Message  string `json:"message"`
	CertPath string `json:"certPath,omitempty"` // e.g., "my-root-ca/my-root-ca.pem" or "my-root-ca/node1.example.com.pem"
	KeyPath  string `json:"keyPath,omitempty"`  // e.g., "my-root-ca/my-root-ca.key" or "my-root-ca/node1.example.com.key"
	CSRPath  string `json:"csrPath,omitempty"`  // e.g., "my-root-ca/my-root-ca.csr" or "my-root-ca/node1.example.com.csr"
}

CertResponse provides paths to the generated certificate files (relative to user's cert dir)

type CertSignRequest

type CertSignRequest struct {
	Name         string   `json:"name" binding:"required" example:"node1.example.com"` // Required
	Hosts        []string `json:"hosts" binding:"required"`                            // SANs (DNS names or IPs), comma-separated in clab, array here
	CaName       string   `json:"caName" binding:"required" example:"my-root-ca"`      // Name of the CA cert/key files (without .pem/.key) previously generated
	CommonName   string   `json:"commonName,omitempty" example:"node1.example.com"`    // Defaults to Name if empty
	Country      string   `json:"country,omitempty" example:"US"`                      // Defaults to "Internet"
	Locality     string   `json:"locality,omitempty" example:"City"`                   // Defaults to "Server"
	Organization string   `json:"organization,omitempty" example:"MyOrg"`              // Defaults to "Containerlab"
	OrgUnit      string   `json:"orgUnit,omitempty" example:"Nodes"`                   // Defaults to "Containerlab Tools"
	KeySize      int      `json:"keySize,omitempty" example:"4096"`                    // Defaults to 2048

}

CertSignRequest mirrors flags for `clab tools cert sign`

type ClabContainerInfo

type ClabContainerInfo struct {
	Name        string `json:"name"`         // Name of the container node (e.g., "lab01-client1")
	ContainerID string `json:"container_id"` // Docker container ID (short)
	Image       string `json:"image"`        // Container image used
	Kind        string `json:"kind"`         // e.g., "linux", "nokia_srlinux"
	State       string `json:"state"`        // e.g., "running"
	Status      string `json:"status"`       // e.g., "Up 18 hours"
	IPv4Address string `json:"ipv4_address"` // Management IPv4 Address/Mask
	IPv6Address string `json:"ipv6_address"` // Management IPv6 Address/Mask
	LabName     string `json:"lab_name"`     // Name of the lab this node belongs to (redundant with map key but present)
	LabPath     string `json:"labPath"`      // Path to the topology file used (relative)
	AbsLabPath  string `json:"absLabPath"`   // Absolute path to topology file
	Group       string `json:"group"`        // Group assigned in topology (Might not always be present)
	Owner       string `json:"owner"`        // OS user from clab inspect output (Used for authorization)
}

ClabContainerInfo matches the structure of each item in the "Containers" array

type ClabExecInternalResult

type ClabExecInternalResult struct {
	Cmd        []string `json:"cmd"`         // The command and its arguments as executed
	ReturnCode int      `json:"return-code"` // Exit code of the command inside the container
	Stdout     string   `json:"stdout"`      // Standard output of the command
	Stderr     string   `json:"stderr"`      // Standard error of the command
}

ClabExecInternalResult matches the structure within the array in clab's JSON output. It contains details about a single command execution attempt on a node.

type ClabInspectInterfacesOutput

type ClabInspectInterfacesOutput []NodeInterfaceInfo

ClabInspectInterfacesOutput is the top-level array structure

type ClabInspectOutput

type ClabInspectOutput map[string][]ClabContainerInfo

ClabInspectOutput matches the top-level structure of `clab inspect --all --format json`

type ClabInspectOutputDetails added in v0.1.1

type ClabInspectOutputDetails map[string][]json.RawMessage

type ContainerLogInfo added in v0.1.10

type ContainerLogInfo struct {
	Name string `json:"name"`
	ID   string `json:"id"`
}

ContainerLogInfo contains information about a container needed for logs retrieval

type DeployRequest

type DeployRequest struct {
	// Option 1: Direct Topology Content.
	// Provide the full containerlab topology YAML as a json string.
	// If this is provided, 'topologySourceUrl' MUST be empty.
	// {
	// 	"topologyContent": {
	// 	  "name": "your-lab-name",
	// 	  "topology": {
	// 		"kinds": {
	// 		  "nokia_srlinux": {
	// 			"type": "ixrd3",
	// 			"image": "ghcr.io/nokia/srlinux"
	// 		  }
	// 		},
	// 		"nodes": {
	// 		  "srl1": {
	// 			"kind": "nokia_srlinux"
	// 		  },
	// 		  "srl2": {
	// 			"kind": "nokia_srlinux"
	// 		  }
	// 		},
	// 		"links": [
	// 		  {
	// 			"endpoints": [
	// 			  "srl1:e1-1",
	// 			  "srl2:e1-1"
	// 			]
	// 		  }
	// 		]
	// 	  }
	// 	}
	//   }
	TopologyContent json.RawMessage `json:"topologyContent" swaggertype:"object"`

	// Option 2: Remote Topology Source URL.
	// Provide a URL to a Git repository, a specific .clab.yml file in Git (github/gitlab), or a raw HTTP(S) URL.
	// If this is provided, 'topologyContent' MUST be empty.
	TopologySourceUrl string `json:"topologySourceUrl,omitempty"`
}

DeployRequest represents the payload for deploying a lab. Provide EITHER 'topologyContent' OR 'topologySourceUrl', but not both.

type DisableTxOffloadRequest

type DisableTxOffloadRequest struct {
	ContainerName string `json:"containerName" binding:"required" example:"clab-my-lab-srl1"`
}

DisableTxOffloadRequest represents the payload for disabling TX offload.

type DiskMetrics added in v0.1.4

type DiskMetrics struct {
	Path         string  `json:"path"`         // Mount path (usually "/")
	TotalDisk    uint64  `json:"totalDisk"`    // Total disk space in bytes
	UsedDisk     uint64  `json:"usedDisk"`     // Used disk space in bytes
	FreeDisk     uint64  `json:"freeDisk"`     // Free disk space in bytes
	UsagePercent float64 `json:"usagePercent"` // Disk usage percentage
}

DiskMetrics represents disk usage information

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

ErrorResponse represents a standard error message format

type ExecRequest

type ExecRequest struct {
	Command string `json:"command" binding:"required" example:"ip addr show eth1"`
}

ExecRequest represents the payload for executing a command on lab nodes.

type ExecResponse

type ExecResponse map[string][]ClabExecInternalResult // <--- Changed value to []ClabExecInternalResult

ExecResponse represents the structured output (JSON format) from the exec command. The keys are the container names. Values are arrays of results (usually one element per array).

type GenerateNodeTier

type GenerateNodeTier struct {
	Count int    `json:"count" binding:"required,min=1" example:"4"` // Number of nodes in this tier
	Kind  string `json:"kind,omitempty" example:"nokia_srlinux"`     // Node kind (defaults to 'srl'/'nokia_srlinux' if omitted)
	Type  string `json:"type,omitempty" example:"ixrd3"`             // Node type within the kind
}

GenerateNodeTier defines a tier in the CLOS topology for generation.

type GenerateRequest

type GenerateRequest struct {
	Name  string             `json:"name"           binding:"required" example:"3-tier-clos"`
	Tiers []GenerateNodeTier `json:"tiers"          binding:"required,min=1"`

	DefaultKind string `json:"defaultKind,omitempty"       example:"nokia_srlinux"`

	Images   map[string]string `json:"images"   example:"nokia_srlinux:ghcr.io/nokia/srlinux:latest"`
	Licenses map[string]string `json:"licenses,omitempty" example:"nokia_srlinux:/opt/licenses/srl.lic"`

	NodePrefix        string `json:"nodePrefix,omitempty"        example:"clos-node"`
	GroupPrefix       string `json:"groupPrefix,omitempty"       example:"clos-tier"`
	ManagementNetwork string `json:"managementNetwork,omitempty" example:"clos-mgmt"`
	IPv4Subnet        string `json:"ipv4Subnet,omitempty"        example:"172.20.20.0/24"`
	IPv6Subnet        string `json:"ipv6Subnet,omitempty"        example:"2001:172:20:20::/64"`
	Deploy            bool   `json:"deploy,omitempty"            example:"true"`
	MaxWorkers        int    `json:"maxWorkers,omitempty"        example:"4"`
	OutputFile        string `json:"outputFile,omitempty"        example:"clos.yml"`
}

GenerateRequest represents the payload for generating a topology file.

type GenerateResponse

type GenerateResponse struct {
	// Message indicating success or failure.
	Message string `json:"message"`
	// The generated topology YAML (only if Deploy=false and OutputFile is empty).
	TopologyYAML string `json:"topologyYaml,omitempty"`
	// The output from the deploy command (only if Deploy=true). Can be JSON or plain text.
	// Use swaggertype:"object" to represent json.RawMessage in Swagger.
	DeployOutput json.RawMessage `json:"deployOutput,omitempty" swaggertype:"object"`
	// Path where the file was saved (if Deploy=true, it's the path in the user's ~/.clab dir; if Deploy=false, it's the OutputFile path if provided).
	SavedFilePath string `json:"savedFilePath,omitempty"`
}

GenerateResponse represents the result of the generate command.

type GenericSuccessResponse

type GenericSuccessResponse struct {
	Message string `json:"message"`
}

GenericSuccessResponse for simple success messages

type HealthResponse added in v0.1.4

type HealthResponse struct {
	Status    string    `json:"status"`            // "healthy" or other status indicators
	Uptime    string    `json:"uptime"`            // Human-readable uptime
	StartTime time.Time `json:"startTime"`         // When the server started
	Version   string    `json:"version,omitempty"` // API server version
}

HealthResponse represents basic health information about the API server

type InterfaceInfo

type InterfaceInfo struct {
	Name    string `json:"name"`    // Interface name (e.g., "eth0", "e1-1")
	Alias   string `json:"alias"`   // Interface alias (e.g., "ethernet-1/1", "" if none)
	Mac     string `json:"mac"`     // MAC Address
	IfIndex int    `json:"ifindex"` // Interface index
	Mtu     int    `json:"mtu"`     // MTU size
	Type    string `json:"type"`    // Interface type (e.g., "veth", "device", "dummy")
	State   string `json:"state"`   // Interface state (e.g., "up", "down", "unknown")
}

InterfaceInfo describes a single network interface

type LoginRequest

type LoginRequest struct {
	Username string `json:"username" binding:"required"`
	Password string `json:"password" binding:"required"`
}

LoginRequest represents the payload for the login endpoint

type LoginResponse

type LoginResponse struct {
	Token string `json:"token"`
}

LoginResponse represents the payload returned after successful login

type LogsResponse added in v0.1.10

type LogsResponse struct {
	ContainerName string `json:"containerName"`
	Logs          string `json:"logs"`
}

LogsResponse represents the response for container logs in JSON format

type MemMetrics added in v0.1.4

type MemMetrics struct {
	TotalMem      uint64  `json:"totalMem"`                // Total physical memory in bytes
	UsedMem       uint64  `json:"usedMem"`                 // Used physical memory in bytes
	AvailableMem  uint64  `json:"availableMem"`            // Available memory in bytes
	UsagePercent  float64 `json:"usagePercent"`            // Memory usage percentage
	ProcessMemMB  float64 `json:"processMemMB,omitempty"`  // This process's memory in MB
	ProcessMemPct float64 `json:"processMemPct,omitempty"` // This process's memory percentage
}

MemMetrics represents memory usage information

type Metrics added in v0.1.4

type Metrics struct {
	CPU  *CPUMetrics  `json:"cpu,omitempty"`  // CPU usage metrics
	Mem  *MemMetrics  `json:"mem,omitempty"`  // Memory usage metrics
	Disk *DiskMetrics `json:"disk,omitempty"` // Disk usage metrics
}

Metrics represents system resource usage metrics

type MetricsResponse added in v0.1.4

type MetricsResponse struct {
	ServerInfo ServerInfo `json:"serverInfo"` // Basic server information
	Metrics    *Metrics   `json:"metrics"`    // Detailed system metrics
}

MetricsResponse represents detailed system metrics with server info

type NetemInterfaceInfo

type NetemInterfaceInfo struct {
	Interface  string  `json:"interface"`            // Interface name
	Delay      string  `json:"delay"`                // Duration string or empty
	Jitter     string  `json:"jitter"`               // Duration string or empty
	PacketLoss float64 `json:"packet_loss"`          // Percentage
	Rate       uint    `json:"rate"`                 // Kbit/s
	Corruption float64 `json:"corruption,omitempty"` // Percentage (might be missing in older clab versions)
}

NetemInterfaceInfo holds the netem details for a single interface from `clab tools netem show --format json`

type NetemSetRequest

type NetemSetRequest struct {
	Delay      string  `json:"delay,omitempty" example:"50ms"`     // Duration string (e.g., "100ms", "1s")
	Jitter     string  `json:"jitter,omitempty" example:"5ms"`     // Duration string, requires Delay
	Loss       float64 `json:"loss,omitempty" example:"10.5"`      // Percentage (0.0 to 100.0)
	Rate       uint    `json:"rate,omitempty" example:"1000"`      // Kbit/s (non-negative integer)
	Corruption float64 `json:"corruption,omitempty" example:"0.1"` // Percentage (0.0 to 100.0)
}

NetemSetRequest represents the parameters for setting network emulation. Use pointers to distinguish between unset and zero values if necessary, but clab defaults usually handle zero values correctly (meaning "unset").

type NetemShowResponse

type NetemShowResponse map[string][]NetemInterfaceInfo

NetemShowResponse matches the JSON output of `clab tools netem show --format json` It's a map where the key is the node name (container name) and the value is a list of interface details.

type NodeInterfaceInfo

type NodeInterfaceInfo struct {
	NodeName   string          `json:"name"` // Name of the container node
	Interfaces []InterfaceInfo `json:"interfaces"`
}

NodeInterfaceInfo holds interfaces for a single node

type PasswordChangeRequest added in v0.1.4

type PasswordChangeRequest struct {
	CurrentPassword string `json:"currentPassword,omitempty"` // Required if not superuser
	NewPassword     string `json:"newPassword" binding:"required"`
}

PasswordChangeRequest represents a request to change a user's password

type RedeployRequest

type RedeployRequest struct {
	Cleanup        bool   `json:"cleanup,omitempty"`        // Corresponds to --cleanup flag
	Graceful       bool   `json:"graceful,omitempty"`       // Corresponds to --graceful flag
	Graph          bool   `json:"graph,omitempty"`          // Corresponds to --graph flag
	Network        string `json:"network,omitempty"`        // Corresponds to --network flag
	Ipv4Subnet     string `json:"ipv4Subnet,omitempty"`     // Corresponds to --ipv4-subnet flag
	Ipv6Subnet     string `json:"ipv6Subnet,omitempty"`     // Corresponds to --ipv6-subnet flag
	MaxWorkers     int    `json:"maxWorkers,omitempty"`     // Corresponds to --max-workers flag (0 means default)
	KeepMgmtNet    bool   `json:"keepMgmtNet,omitempty"`    // Corresponds to --keep-mgmt-net flag
	SkipPostDeploy bool   `json:"skipPostDeploy,omitempty"` // Corresponds to --skip-post-deploy flag
	ExportTemplate string `json:"exportTemplate,omitempty"` // Corresponds to --export-template flag (__full is special)
	SkipLabdirAcl  bool   `json:"skipLabdirAcl,omitempty"`  // Corresponds to --skip-labdir-acl flag
}

RedeployRequest represents the payload for redeploying a lab

type SSHAccessRequest added in v0.1.4

type SSHAccessRequest struct {
	SSHUsername string `json:"sshUsername,omitempty"` // Optional override for container's SSH user
	Duration    string `json:"duration,omitempty"`    // How long the access should be valid for (e.g., "1h", "30m")
}

SSHAccessRequest represents the payload for requesting SSH access to a node

type SSHAccessResponse added in v0.1.4

type SSHAccessResponse struct {
	Port       int       `json:"port"`       // Allocated port on API server
	Host       string    `json:"host"`       // API server's hostname or IP
	Username   string    `json:"username"`   // Username to use for SSH
	Expiration time.Time `json:"expiration"` // When this access expires
	Command    string    `json:"command"`    // Example SSH command
}

SSHAccessResponse represents the response with SSH connection details

type SSHSessionInfo added in v0.1.4

type SSHSessionInfo struct {
	Port       int       `json:"port"`       // Allocated port on API server
	LabName    string    `json:"labName"`    // Lab name
	NodeName   string    `json:"nodeName"`   // Node name
	Username   string    `json:"username"`   // SSH username
	Expiration time.Time `json:"expiration"` // When this access expires
	Created    time.Time `json:"created"`    // When this access was created
}

SSHSessionInfo represents information about an active SSH session

type SaveConfigResponse

type SaveConfigResponse struct {
	// Message indicating overall success.
	Message string `json:"message"`
	// Detailed output from the 'clab save' command (often from stderr).
	Output string `json:"output"`
}

SaveConfigResponse represents the result of the save config command.

type ServerInfo added in v0.1.4

type ServerInfo struct {
	Version   string    `json:"version"`   // API server version
	Uptime    string    `json:"uptime"`    // Human-readable uptime
	StartTime time.Time `json:"startTime"` // When the server started
}

ServerInfo contains basic server information

type UserCreateRequest added in v0.1.4

type UserCreateRequest struct {
	Username    string   `json:"username" binding:"required"`
	Password    string   `json:"password" binding:"required"`
	DisplayName string   `json:"displayName,omitempty"`
	Shell       string   `json:"shell,omitempty"` // Default to /bin/bash if empty
	Groups      []string `json:"groups,omitempty"`
	IsSuperuser bool     `json:"isSuperuser,omitempty"`
}

UserCreateRequest represents a request to create a new system user

type UserDetails added in v0.1.4

type UserDetails struct {
	Username    string   `json:"username"`
	UID         string   `json:"uid,omitempty"`
	GID         string   `json:"gid,omitempty"`
	DisplayName string   `json:"displayName,omitempty"` // Full name from GECOS field
	HomeDir     string   `json:"homeDir,omitempty"`
	Shell       string   `json:"shell,omitempty"`
	Groups      []string `json:"groups,omitempty"`
	IsSuperuser bool     `json:"isSuperuser,omitempty"`
	IsAPIUser   bool     `json:"isApiUser,omitempty"`
}

UserDetails represents information about a system user

type UserUpdateRequest added in v0.1.4

type UserUpdateRequest struct {
	DisplayName string   `json:"displayName,omitempty"`
	Shell       string   `json:"shell,omitempty"`
	Groups      []string `json:"groups,omitempty"`
	IsSuperuser bool     `json:"isSuperuser,omitempty"`
}

UserUpdateRequest represents a request to update user information

type VersionCheckResponse

type VersionCheckResponse struct {
	// Raw output string from 'clab version check'.
	CheckResult string `` /* 240-byte string literal not displayed */
}

VersionCheckResponse holds the output of the 'clab version check' command.

type VersionResponse

type VersionResponse struct {
	// Raw output string from 'clab version'.
	VersionInfo string `` /* 190-byte string literal not displayed */
}

VersionResponse holds the output of the 'clab version' command.

type VethCreateRequest

type VethCreateRequest struct {
	// Endpoint A definition. Format: <node-name>:<interface-name> OR <kind>:<node-name>:<interface-name>
	// Example: "clab-demo-node1:eth1" or "bridge:br-1:br-eth1" or "host:veth-eth1"
	AEndpoint string `json:"aEndpoint" binding:"required" example:"clab-demo-node1:eth1"`

	// Endpoint B definition. Format: <node-name>:<interface-name> OR <kind>:<node-name>:<interface-name>
	// Example: "clab-demo-node2:eth1" or "ovs-bridge:ovsbr-1:br-eth1"
	BEndpoint string `json:"bEndpoint" binding:"required" example:"clab-demo-node2:eth1"`

	// MTU for the vEth pair. Defaults to 9500 if omitted.
	Mtu int `json:"mtu,omitempty" example:"1500"` // Use int, convert to string for command
}

VethCreateRequest represents the payload for `clab tools veth create`.

type VxlanCreateRequest

type VxlanCreateRequest struct {
	// Remote VTEP IP address.
	Remote string `json:"remote" binding:"required" example:"10.0.0.20"`

	// Name of the existing interface in the root namespace to bridge traffic with.
	Link string `json:"link" binding:"required" example:"srl_e1-1"`

	// VxLAN Network Identifier (VNI). Defaults to 10 if omitted.
	ID int `json:"id,omitempty" example:"100"`

	// UDP port number for the VxLAN tunnel. Defaults to 4789 if omitted.
	Port int `json:"port,omitempty" example:"4789"` // Default is 4789 (IANA standard)

	// Optional: Linux device to use for the tunnel source. Auto-detected if omitted.
	Dev string `json:"dev,omitempty" example:"eth0"`

	// Optional: MTU for the VxLAN interface. Auto-calculated if omitted.
	Mtu int `json:"mtu,omitempty" example:"1400"`
}

VxlanCreateRequest represents the payload for `clab tools vxlan create`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL