ws

package
v0.0.0-...-7f8d8f8 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package ws is for our websocket handlers All the websocket handlers send 2 messages to the UI. The first is what we are attempting, running a command, etc. The next is the status or output of that item

Index

Constants

This section is empty.

Variables

Conf is our main config

MessageBuffer will house our outgoing messages so clients can navigate around and get updates

Functions

func BootstrapContainer

func BootstrapContainer(buffer *circularbuffer.CircularBuffer[OutgoingMessage], host string, name string)

BootstrapContainer loops over all the FileOrCommand objects in the bootstrap section of the config and performs each item sequentially

func ContainerPlaybookHandler

func ContainerPlaybookHandler(buffer *circularbuffer.CircularBuffer[OutgoingMessage], msg IncomingMessage)

ContainerPlaybookHandler handles requests to run various playbooks on the container, including re-bootstrapping it if asked. Playbooks and bootstrap should be idempotent so no harm should come from running these multiple times.

func CreateContainerHandler

func CreateContainerHandler(buffer *circularbuffer.CircularBuffer[OutgoingMessage], msg IncomingMessage)

CreateContainerHandler creates the container on our host, then if we are using a 3rd party DNS gets an A record from there. It then uploads the appropriate network config file to the container before starting it by calling setupContainerNetwork Finally if any bootstrapping configuration is set, it to perform that by calling BootstrapContainer.

func DeleteContainerHandler

func DeleteContainerHandler(buffer *circularbuffer.CircularBuffer[OutgoingMessage], msg IncomingMessage)

DeleteContainerHandler first stops a running container (there is no force like the lxc command line), then deletes any DNS entry for it from our 3rd party, and then deletes the container.

func Handler

func Handler(w http.ResponseWriter, r *http.Request)

Handler is our overall websocket router, it unmarshals the request and then sends it to the appropriate handler

func ManageBuffers

func ManageBuffers()

ManageBuffers starts a backend goroutine to periodically check our buffers and remove any that are old.

func MoveContainerHandler

func MoveContainerHandler(buffer *circularbuffer.CircularBuffer[OutgoingMessage], msg IncomingMessage)

MoveContainerHandler wraps lxd.MoveContainer and reports any errors it returns

func StartContainerHandler

func StartContainerHandler(buffer *circularbuffer.CircularBuffer[OutgoingMessage], msg IncomingMessage) error

StartContainerHandler starts a stopped container

func StopContainerHandler

func StopContainerHandler(buffer *circularbuffer.CircularBuffer[OutgoingMessage], msg IncomingMessage) error

StopContainerHandler stops a running container

Types

type IncomingMessage

type IncomingMessage struct {
	Action    string            `json:"action"` // what type of request: create, start, etc.
	BrowserID string            `json:"id"`     // ID of our users browser
	Data      map[string]string `json:"data"`   // in the UI this is a single level JSON object so requests can have varying options
}

IncomingMessage is for messages from the client to us

type OutgoingMessage

type OutgoingMessage struct {
	ID       int64  // ID to keep messages and their status together
	Message  string // message to show the user
	Success  bool   // success is used to give a visual hint to the user how the command went (true = green, false = red)
	Redirect string // If we want to suggest a redirect to another page, like back to /containers after we create a new one
}

OutgoingMessage is from us to the UI

Jump to

Keyboard shortcuts

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