Documentation
¶
Index ¶
- Variables
- func ExtractTarStream(ctx context.Context, r io.Reader, extractDir string, uid, gid uint32) error
- func ExtractTarToPath(ctx context.Context, r io.Reader, dest string, uid, gid uint32) error
- func StreamTarArchive(ctx context.Context, w io.Writer, parentDir, baseName string) error
- func ValidRelPath(p string) bool
- type CreateSecretRequest
- type Secret
- type SlicerClient
- func (c *SlicerClient) CpFromVM(ctx context.Context, vmName, vmPath, localPath string, uid, gid uint32) error
- func (c *SlicerClient) CpToVM(ctx context.Context, vmName, localPath, vmPath string, uid, gid uint32) error
- func (c *SlicerClient) CreateNode(ctx context.Context, groupName string, request SlicerCreateNodeRequest) (*SlicerCreateNodeResponse, error)
- func (c *SlicerClient) CreateSecret(ctx context.Context, request CreateSecretRequest) error
- func (c *SlicerClient) CreateVM(ctx context.Context, groupName string, request SlicerCreateVMRequest) (*SlicerCreateNodeResponse, error)
- func (c *SlicerClient) DeleteNode(groupName, nodeName string) error
- func (c *SlicerClient) DeleteSecret(ctx context.Context, secretName string) error
- func (c *SlicerClient) DeleteVM(ctx context.Context, groupName, hostname string) (*SlicerDeleteResponse, error)
- func (c *SlicerClient) Exec(ctx context.Context, nodeName string, execReq SlicerExecRequest) (chan SlicerExecWriteResult, error)
- func (c *SlicerClient) GetHostGroupNodes(ctx context.Context, groupName string) ([]SlicerNode, error)
- func (c *SlicerClient) GetHostGroups(ctx context.Context) ([]SlicerHostGroup, error)
- func (c *SlicerClient) GetVMLogs(ctx context.Context, hostname string, lines int) (*SlicerLogsResponse, error)
- func (c *SlicerClient) GetVMStats(ctx context.Context, hostname string) ([]SlicerNodeStat, error)
- func (c *SlicerClient) ListSecrets(ctx context.Context) ([]Secret, error)
- func (c *SlicerClient) ListVMs(ctx context.Context) ([]SlicerNode, error)
- func (c *SlicerClient) PatchSecret(ctx context.Context, secretName string, request UpdateSecretRequest) error
- type SlicerCpRequest
- type SlicerCreateNodeRequest
- type SlicerCreateNodeResponse
- type SlicerCreateVMRequest
- type SlicerDeleteResponse
- type SlicerExecRequest
- type SlicerExecWriteResult
- type SlicerHostGroup
- type SlicerLogsResponse
- type SlicerNode
- type SlicerNodeStat
- type SlicerSnapshot
- type UpdateSecretRequest
Constants ¶
This section is empty.
Variables ¶
var ( // ErrSecretExists is an error returned when a secret with given name already exists. ErrSecretExists = errors.New("secret already exists") )
Functions ¶
func ExtractTarStream ¶ added in v0.0.10
ExtractTarStream extracts a tar stream from r into extractDir. This is a streaming implementation that doesn't buffer entire files in memory. If uid or gid are non-zero, files will be chowned to that uid/gid after creation.
func ExtractTarToPath ¶ added in v0.0.10
ExtractTarToPath extracts a tar stream to a local path with proper renaming logic. This handles the cp-like behavior of renaming files/directories and moving contents into existing directories. If uid or gid are non-zero, files will be chowned to that uid/gid after creation.
func StreamTarArchive ¶ added in v0.0.10
StreamTarArchive streams a tar archive of the given path to w. This is a streaming implementation that doesn't buffer entire files in memory. parentDir and baseName are used to strip leading paths, making it more like cp.
func ValidRelPath ¶ added in v0.0.10
ValidRelPath validates that a path is a valid relative path and doesn't contain directory traversal attempts
Types ¶
type CreateSecretRequest ¶ added in v0.0.6
type CreateSecretRequest struct {
// Name is the unique name of the secret
Name string `json:"name"`
// Data is the secret content
Data string `json:"data"`
// Permissions specifies the file permissions (defaults to system default)
Permissions string `json:"permissions,omitempty"`
// GID is the user ID that should own the secret file. If not set, the default for
// a uint32 will be used i.e root.
UID uint32 `json:"uid,omitempty"`
// GID is the group ID that should own the secret file. If not set, the default for
// a uint32 will be used i.e root.
GID uint32 `json:"gid,omitempty"`
}
CreateSecretRequest is the payload for creating a new secret via the REST API.
type Secret ¶ added in v0.0.6
type Secret struct {
// Name is the unique name of the secret
Name string `json:"name"`
// Size is the size of the secret data in bytes
Size int64 `json:"size"`
// Permissions specifies the file permissions for the secret (e.g., "0600")
Permissions string `json:"permissions"`
// GID is the user ID that should own the secret file. If not set, the default for
// a uint32 will be used i.e root.
UID uint32 `json:"uid,omitempty"`
// GID is the group ID that should own the secret file. If not set, the default for
// a uint32 will be used i.e root.
GID uint32 `json:"gid,omitempty"`
// ModifiedAt is the time the secret was last modified
ModifiedAt *time.Time `json:"modified_at,omitempty"`
}
Secret represents a secret stored in the slicer system. Secrets can be used to store sensitive configuration data, keys, or other private information that can be mounted into nodes or used by services.
type SlicerClient ¶
type SlicerClient struct {
// contains filtered or unexported fields
}
SlicerClient handles all HTTP communication with the Slicer API
func NewSlicerClient ¶
func NewSlicerClient(baseURL, token string, userAgent string, httpClient *http.Client) *SlicerClient
NewSlicerClient creates a new Slicer API client
func (*SlicerClient) CpFromVM ¶ added in v0.0.10
func (c *SlicerClient) CpFromVM(ctx context.Context, vmName, vmPath, localPath string, uid, gid uint32) error
CpFromVM copies files from a VM path to a local path. The tar stream is received from the VM and extracted to localPath with proper renaming logic (supports renaming files/directories). If uid or gid are 0, the current user's UID/GID will be used. On Windows, chown operations are skipped (uid/gid are ignored).
func (*SlicerClient) CpToVM ¶ added in v0.0.10
func (c *SlicerClient) CpToVM(ctx context.Context, vmName, localPath, vmPath string, uid, gid uint32) error
CpToVM copies files from a local path to a VM path. The localPath can be a file or directory. The tar stream is created internally and sent to the VM. uid and gid specify the ownership for extracted files (0 means use default).
func (*SlicerClient) CreateNode ¶
func (c *SlicerClient) CreateNode(ctx context.Context, groupName string, request SlicerCreateNodeRequest) (*SlicerCreateNodeResponse, error)
CreateNode creates a new node in the specified host group
func (*SlicerClient) CreateSecret ¶ added in v0.0.6
func (c *SlicerClient) CreateSecret(ctx context.Context, request CreateSecretRequest) error
CreateSecret creates a new secret. Returns ErrSecretExists if a secret with the same name already exists. An error is returned if creation fails.
func (*SlicerClient) CreateVM ¶ added in v0.0.10
func (c *SlicerClient) CreateVM(ctx context.Context, groupName string, request SlicerCreateVMRequest) (*SlicerCreateNodeResponse, error)
CreateVM creates a new VM in a host group
func (*SlicerClient) DeleteNode ¶
func (c *SlicerClient) DeleteNode(groupName, nodeName string) error
DeleteNode deletes a node from the specified host group
func (*SlicerClient) DeleteSecret ¶ added in v0.0.6
func (c *SlicerClient) DeleteSecret(ctx context.Context, secretName string) error
DeleteSecret removes a secret. Returns an error if the secret doesn't exist or if the deletion fails.
func (*SlicerClient) DeleteVM ¶ added in v0.0.10
func (c *SlicerClient) DeleteVM(ctx context.Context, groupName, hostname string) (*SlicerDeleteResponse, error)
DeleteVM deletes a VM from a host group
func (*SlicerClient) Exec ¶ added in v0.0.9
func (c *SlicerClient) Exec(ctx context.Context, nodeName string, execReq SlicerExecRequest) (chan SlicerExecWriteResult, error)
Exec executes a command on the specified node and streams the output. The channel is unbuffered so the caller should read from it promptly to avoid blocking.
func (*SlicerClient) GetHostGroupNodes ¶
func (c *SlicerClient) GetHostGroupNodes(ctx context.Context, groupName string) ([]SlicerNode, error)
GetHostGroupNodes fetches nodes for a specific host group
func (*SlicerClient) GetHostGroups ¶
func (c *SlicerClient) GetHostGroups(ctx context.Context) ([]SlicerHostGroup, error)
GetHostGroups fetches all host groups from the API
func (*SlicerClient) GetVMLogs ¶ added in v0.0.10
func (c *SlicerClient) GetVMLogs(ctx context.Context, hostname string, lines int) (*SlicerLogsResponse, error)
GetVMLogs fetches logs for a specific VM
func (*SlicerClient) GetVMStats ¶ added in v0.0.10
func (c *SlicerClient) GetVMStats(ctx context.Context, hostname string) ([]SlicerNodeStat, error)
GetVMStats fetches stats for all VMs or a specific VM if hostname is provided. If hostname is empty, returns stats for all VMs.
func (*SlicerClient) ListSecrets ¶ added in v0.0.6
func (c *SlicerClient) ListSecrets(ctx context.Context) ([]Secret, error)
ListSecrets retrieves all secrets. Note: The actual secret data is not returned for security reasons.
func (*SlicerClient) ListVMs ¶ added in v0.0.10
func (c *SlicerClient) ListVMs(ctx context.Context) ([]SlicerNode, error)
ListVMs fetches all VMs (nodes)
func (*SlicerClient) PatchSecret ¶ added in v0.0.6
func (c *SlicerClient) PatchSecret(ctx context.Context, secretName string, request UpdateSecretRequest) error
PatchSecret updates an existing secret with new data and/or metadata. Only the fields provided in the UpdateSecretRequest will be modified. Returns an error if the secret doesn't exist or if the update fails.
type SlicerCpRequest ¶ added in v0.0.10
SlicerCpRequest contains parameters for copying files to/from a VM
type SlicerCreateNodeRequest ¶
type SlicerCreateNodeRequest struct {
RamGB int `json:"ram_gb"`
CPUs int `json:"cpus"`
Tags []string `json:"tags,omitempty"`
ImportUser string `json:"import_user"`
Userdata string `json:"userdata,omitempty"`
SSHKeys []string `json:"ssh_keys,omitempty"`
Secrets []string `json:"secrets,omitempty"`
}
SlicerCreateNodeRequest is the payload for creating a node via the REST API.
type SlicerCreateNodeResponse ¶
type SlicerCreateNodeResponse struct {
Hostname string `json:"hostname"`
IP string `json:"ip"`
CreatedAt time.Time `json:"created_at"`
Arch string `json:"arch,omitempty"`
}
SlicerCreateNodeResponse is the response from the REST API when creating a node.
func (*SlicerCreateNodeResponse) IPAddress ¶
func (n *SlicerCreateNodeResponse) IPAddress() net.IP
type SlicerCreateVMRequest ¶ added in v0.0.10
type SlicerCreateVMRequest struct {
GPUCount int `json:"gpuCount"`
Persistent bool `json:"persistent"`
DiskImage string `json:"diskImage,omitempty"`
ImportUser string `json:"importUser,omitempty"`
SSHKeys []string `json:"sshKeys,omitempty"`
Userdata string `json:"userdata,omitempty"`
IP string `json:"ip,omitempty"`
Tags []string `json:"tags,omitempty"`
Secrets []string `json:"secrets,omitempty"`
}
SlicerCreateVMRequest contains parameters for creating a VM
type SlicerDeleteResponse ¶ added in v0.0.10
type SlicerDeleteResponse struct {
Message string `json:"message"`
DiskRemoved string `json:"disk_removed"`
Error string `json:"error"`
}
SlicerDeleteResponse represents the response from the delete endpoint
type SlicerExecRequest ¶ added in v0.0.9
type SlicerExecRequest struct {
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
UID uint32 `json:"uid,omitempty"`
GID uint32 `json:"gid,omitempty"`
Stdin bool `json:"stdin,omitempty"`
Stdout bool `json:"stdout,omitempty"`
Stderr bool `json:"stderr,omitempty"`
Shell string `json:"shell,omitempty"`
Cwd string `json:"cwd,omitempty"`
Permissions string `json:"permissions,omitempty"`
}
SlicerExecRequest contains parameters for invoking a command within a VM.
type SlicerExecWriteResult ¶ added in v0.0.9
type SlicerExecWriteResult struct {
Stdout string `json:"stdout,omitempty"`
Stderr string `json:"stderr,omitempty"`
ExitCode int `json:"exit_code,omitempty"`
Error string `json:"error,omitempty"`
}
ExecWriteResult represents output from commands executing within a microVM.
type SlicerHostGroup ¶
type SlicerHostGroup struct {
Name string `json:"name"`
Count int `json:"count"`
RamGB int `json:"ram_gb"`
CPUs int `json:"cpus"`
Arch string `json:"arch,omitempty"`
GPUCount int `json:"gpu_count,omitempty"`
}
SlicerHostGroup represents a host group from the /hostgroup endpoint.
type SlicerLogsResponse ¶ added in v0.0.10
type SlicerLogsResponse struct {
Hostname string `json:"hostname"`
Lines int `json:"lines"`
Content string `json:"content"`
}
SlicerLogsResponse represents the response from the logs endpoint
type SlicerNode ¶
type SlicerNode struct {
Hostname string `json:"hostname"`
IP string `json:"ip"`
CreatedAt time.Time `json:"created_at"`
Arch string `json:"arch,omitempty"`
Tags []string `json:"tags,omitempty"`
}
SlicerNode represents a node managed by the slicer REST API.
type SlicerNodeStat ¶ added in v0.0.10
type SlicerNodeStat struct {
Hostname string `json:"hostname"`
IP string `json:"ip"`
CreatedAt time.Time `json:"created_at"`
Snapshot *SlicerSnapshot `json:"snapshot"`
Error string `json:"error"`
}
SlicerNodeStat represents stats for a VM node
type SlicerSnapshot ¶ added in v0.0.10
type SlicerSnapshot struct {
Hostname string `json:"hostname"`
Arch string `json:"arch"`
Timestamp time.Time `json:"timestamp"`
Uptime string `json:"uptime"`
TotalCPUS int `json:"totalCpus"`
TotalMemory uint64 `json:"totalMemory"`
MemoryUsed uint64 `json:"memoryUsed"`
MemoryAvailable uint64 `json:"memoryAvailable"`
MemoryUsedPercent float64 `json:"memoryUsedPercent"`
LoadAvg1 float64 `json:"loadAvg1"`
LoadAvg5 float64 `json:"loadAvg5"`
LoadAvg15 float64 `json:"loadAvg15"`
DiskReadTotal float64 `json:"diskReadTotal"`
DiskWriteTotal float64 `json:"diskWriteTotal"`
NetworkReadTotal float64 `json:"networkReadTotal"`
NetworkWriteTotal float64 `json:"networkWriteTotal"`
DiskIOInflight int64 `json:"diskIOInflight"`
OpenConnections int64 `json:"openConnections"`
OpenFiles int64 `json:"openFiles"`
Entropy int64 `json:"entropy"`
DiskSpaceTotal uint64 `json:"diskSpaceTotal"`
DiskSpaceUsed uint64 `json:"diskSpaceUsed"`
DiskSpaceFree uint64 `json:"diskSpaceFree"`
DiskSpaceUsedPercent float64 `json:"diskSpaceUsedPercent"`
}
SlicerSnapshot represents a snapshot of VM metrics
type UpdateSecretRequest ¶ added in v0.0.6
type UpdateSecretRequest struct {
// Data is the updated secret content
Data string `json:"data"`
// Permissions specifies the file permissions
Permissions string `json:"permissions,omitempty"`
// GID is the user ID that should own the secret file. If not set, the default for
// a uint32 will be used i.e root.
UID uint32 `json:"uid,omitempty"`
// GID is the group ID that should own the secret file. If not set, the default for
// a uint32 will be used i.e root.
GID uint32 `json:"gid,omitempty"`
}
UpdateSecretRequest is the payload for updating an existing secret via the REST API. All fields are optional - only provided fields will be updated.