api

package
v0.27.3 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api exposes the domain services twice from one process: REST/JSON under /api/v1 for the portal and cluster-manager, and MCP tools for muster. Both map onto the same service methods so behavior cannot drift between them.

Index

Constants

View Source
const (
	ToolGetInfo          = "get_info"
	ToolGetHost          = "get_host"
	ToolListImages       = "list_images"
	ToolGetImage         = "get_image"
	ToolListNetworks     = "list_networks"
	ToolGetNetwork       = "get_network"
	ToolListVMs          = "list_vms"
	ToolGetVM            = "get_vm"
	ToolGetVMConsole     = "get_vm_console"
	ToolGetVMMetrics     = "get_vm_metrics"
	ToolGetVMAttestation = "get_vm_attestation"
	ToolCreateNetwork    = "create_network"
	ToolDeleteNetwork    = "delete_network"
	ToolCreateVM         = "create_vm"
	ToolStartVM          = "start_vm"
	ToolStopVM           = "stop_vm"
	ToolRebootVM         = "reboot_vm"
	ToolDeleteVM         = "delete_vm"
	ToolExecVM           = "exec_vm"
	ToolForwardPort      = "forward_port"
)

MCP tool names (docs/design.md "MCP tool surface"). Through muster they appear as x_<server>_<tool>, e.g. x_vm-manager_get_host.

View Source
const (
	DefaultCPUs      = 2
	DefaultMemoryMiB = 2048
	DefaultDiskGiB   = 20
	// DefaultNetwork is the network VMs attach to when neither the request
	// nor Services.DefaultNetwork names one.
	DefaultNetwork = "default"
	// DefaultConsoleLines is how many lines get_vm_console returns.
	DefaultConsoleLines = 100
	// MetricsNote is set on get_vm_metrics while the guest has not uploaded
	// a report, MetricsUnparsedNote when the last upload is not a
	// systemd-report.
	MetricsNote         = "no systemd-report upload from the guest yet; host metrics only"
	MetricsUnparsedNote = "the guest's last upload is not a systemd-report and was not exported; see raw_report_url"
)

Defaults create_vm applies to fields the caller leaves empty. Image and Kubernetes version default inside the VM service (catalog default, newest available version); hostname defaults to the name.

View Source
const AttrGenAIToolName = "gen_ai.tool.name"

AttrGenAIToolName is the OpenTelemetry GenAI key naming the tool a tools/call runs, the key muster puts on its side of the same call.

View Source
const MaxBodyBytes = 8 << 20

MaxBodyBytes bounds request bodies, the REST API's and the MCP endpoint's; user_data (Ignition JSON with embedded certificates) is the largest field.

View Source
const Prefix = "/api/v1"

Prefix is the REST base path.

View Source
const TracerName = "github.com/giantswarm/vm-manager"

TracerName names the tracer of vm-manager's own spans.

Variables

This section is empty.

Functions

func NewMCPServer

func NewMCPServer(svc Services, build buildinfo.Info) *mcpserver.MCPServer

NewMCPServer builds an MCP server exposing the same operations as the REST API as tools. Results are JSON text with the same shapes as the REST bodies. build is what get_info and the MCP server identity report as the version.

func ToolNames

func ToolNames() []string

ToolNames lists every tool the MCP server registers, in registration order: the read-only tools first, then the writes.

Types

type ConsoleResponse added in v0.8.0

type ConsoleResponse struct {
	ID      string `json:"id"`
	Lines   int    `json:"lines"`
	Console string `json:"console"`
}

ConsoleResponse is the body of get_vm_console / GET /vms/{id}/console.

type CreateNetworkRequest added in v0.8.0

type CreateNetworkRequest struct {
	Name            string `json:"name"`
	CIDR            string `json:"cidr"`
	DNSSearchDomain string `json:"dns_search_domain,omitempty"`
}

CreateNetworkRequest is create_network / POST /networks.

type CreateVMRequest added in v0.8.0

type CreateVMRequest struct {
	Name               string            `json:"name"`
	Image              string            `json:"image,omitempty"`
	KubernetesVersion  string            `json:"kubernetes_version,omitempty"`
	CPUs               int               `json:"cpus,omitempty"`
	MemoryMiB          int               `json:"memory_mib,omitempty"`
	DiskGiB            int               `json:"disk_gib,omitempty"`
	Network            string            `json:"network,omitempty"`
	UserData           string            `json:"user_data,omitempty"`
	SSHAuthorizedKeys  []string          `json:"ssh_authorized_keys,omitempty"`
	Hostname           string            `json:"hostname,omitempty"`
	Metadata           map[string]string `json:"metadata,omitempty"`
	RequireAttestation *bool             `json:"require_attestation,omitempty"`
	WaitFor            string            `json:"wait_for,omitempty"`
}

CreateVMRequest is create_vm / POST /vms.

type DeletedResponse added in v0.8.0

type DeletedResponse struct {
	ID      string `json:"id"`
	Deleted bool   `json:"deleted"`
}

DeletedResponse is what the delete tools return; REST answers 204.

type ExecRequest added in v0.8.0

type ExecRequest struct {
	Command []string `json:"command"`
}

ExecRequest is exec_vm / POST /vms/{id}/exec.

type ForwardRequest added in v0.8.0

type ForwardRequest struct {
	Port int `json:"port"`
}

ForwardRequest is forward_port / POST /vms/{id}/forward.

type ForwardResponse added in v0.8.0

type ForwardResponse struct {
	ID   string `json:"id"`
	Port int    `json:"port"`
	// Address is the host loopback address the guest port is reachable on.
	Address string `json:"address"`
}

ForwardResponse is the body of forward_port / POST /vms/{id}/forward.

type Info added in v0.20.3

type Info struct {
	// Version is the release (the image tag), dev for an untagged local
	// build; Commit and Built identify the source and the build time.
	Version string   `json:"version"`
	Commit  string   `json:"commit"`
	Built   string   `json:"built"`
	Tools   []string `json:"tools"`
}

Info is get_info's answer: the build this server runs and the tools it registers.

type MetricsResponse added in v0.8.0

type MetricsResponse struct {
	ID string `json:"id"`
	metrics.VMMetrics
	// RawReportURL serves the guest's last upload in full (REST only, it is
	// too large for a tool result); Note explains a missing guest section.
	RawReportURL string `json:"raw_report_url,omitempty"`
	Note         string `json:"note,omitempty"`
}

MetricsResponse is the body of get_vm_metrics / GET /vms/{id}/metrics: the host's view of the VM and a summary of the guest's last report.

type REST

type REST struct {
	// contains filtered or unexported fields
}

REST serves the JSON API.

func NewREST

func NewREST(svc Services, log *slog.Logger) *REST

NewREST builds the REST handler set.

func (*REST) Register

func (h *REST) Register(mux *http.ServeMux)

Register mounts the routes on mux. Each route mirrors one MCP tool.

type Services

type Services struct {
	Host   *host.Service
	VM     *vm.Service
	Images *images.Catalog
	// Metrics summarizes a VM for get_vm_metrics; it must be the registry
	// the VM service reports to.
	Metrics *metrics.Registry
	// DefaultNetwork is the network create_vm attaches to when the request
	// names none, and the one the tool descriptions point at; empty means
	// the DefaultNetwork constant.
	DefaultNetwork string
}

Services are the domain services both API surfaces expose. A new domain package plugs in here: add its Service, then register its tools in NewMCPServer and its routes in REST.Register, both over the same methods.

Jump to

Keyboard shortcuts

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