api

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2025 License: Apache-2.0 Imports: 28 Imported by: 1

Documentation

Overview

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	MachineStatusInitialized string = "initialized"
	MachineStatusStopped     string = "stopped"
	MachineStatusStarting    string = "starting"
	MachineStatusRunning     string = "running"
	MachineStatusStopping    string = "stopping"
	MachineStatusFailed      string = "failed"
	SerialConsole            string = "console"
	VGAConsole               string = "vga"
)
View Source
const LinuxUnixSocketMaxLen int = 108

LinuxUnixSocketMaxLen - 108 chars max for a unix socket path (including null byte).

View Source
const MachineUnixSocketName = "machined.socket"
View Source
const (
	NoCloudFSLabel = "cidata"
)

Variables

This section is empty.

Functions

func APISocketPath

func APISocketPath() string

func ConfigureUEFIVars

func ConfigureUEFIVars(c *qcli.Config, srcCode, srcVars, runDir string, secureBoot bool) error

func CopyFileBits

func CopyFileBits(src, dest string) error

CopyFileBits - copy file content from a to b differs from CopyFile in:

  • does not do permissions - new files created with 0644
  • if src is a symlink, copies content, not link.
  • does not invoke sh.

func CopyFileRefSparse

func CopyFileRefSparse(src, dest string) error

Copy one file to a new path, i.e. cp a b

func CreateLocalDataSource added in v0.1.3

func CreateLocalDataSource(cfg CloudInitConfig, directory string) error

func EnsureDir

func EnsureDir(dir string) error
func ForceLink(oldname, newname string) error

func GenerateQConfig

func GenerateQConfig(runDir, sockDir string, v VMDef) (*qcli.Config, error)

func GetAPIURL

func GetAPIURL(endpoint string) string

func GetCommandErrorRC

func GetCommandErrorRC(err error) int

func GetCommandErrorRCDefault

func GetCommandErrorRCDefault(err error, rcError int) int

func GetKvmPath

func GetKvmPath() (string, error)

func GetTempSocketDir

func GetTempSocketDir() (string, error)

func HasCloudConfig added in v0.1.3

func HasCloudConfig(config CloudInitConfig) bool

func LogCommand

func LogCommand(args ...string) error

func LogCommandDebug

func LogCommandDebug(args ...string) error

func LogCommandWithFunc

func LogCommandWithFunc(logf func(string, ...interface{}), args ...string) error

func NewDefaultAarch64Config

func NewDefaultAarch64Config(name string, numCpus uint32, numMemMB uint32, sockDir string) (*qcli.Config, error)

func NewDefaultX86Config

func NewDefaultX86Config(name string, numCpus, numMemMB uint32, sockDir string) (*qcli.Config, error)

func NewVVFATBlockDev added in v0.1.3

func NewVVFATBlockDev(id, directory, label string) (qcli.BlockDevice, error)

func NextFreePort

func NextFreePort(first int) int

func PathExists

func PathExists(d string) bool

func PrepareMetadata added in v0.1.3

func PrepareMetadata(config *CloudInitConfig, hostname string) error

func RandomQemuMAC

func RandomQemuMAC() (string, error)

func RenderCloudInitConfig added in v0.1.3

func RenderCloudInitConfig(config CloudInitConfig, outputPath string) error

func RsyncDirWithErrorQuiet added in v0.1.3

func RsyncDirWithErrorQuiet(src, dest string) error

func RunCommand

func RunCommand(args ...string) error

func RunCommandWithOutputErrorRc

func RunCommandWithOutputErrorRc(args ...string) ([]byte, []byte, int)

func RunCommandWithRc

func RunCommandWithRc(args ...string) ([]byte, int)

func UserConfigDir

func UserConfigDir() (string, error)

XDG_CONFIG_HOME

func UserDataDir

func UserDataDir() (string, error)

XDG_DATA_HOME

func UserRuntimeDir

func UserRuntimeDir() (string, error)

XDG_RUNTIME_DIR

func UserStateDir

func UserStateDir() (string, error)

XDG_STATE_HOME

func WaitForPath

func WaitForPath(path string, retries, sleepSeconds int) bool

func Which

func Which(commandName string) string

func WhichInRoot

func WhichInRoot(commandName string, root string) string

Types

type CloudInitConfig added in v0.1.3

type CloudInitConfig struct {
	NetworkConfig string `yaml:"network-config"`
	UserData      string `yaml:"user-data"`
	MetaData      string `yaml:"meta-data"`
}

type ConsoleInfo

type ConsoleInfo struct {
	Type   string `json:"type"`
	Path   string `json:"path"`
	Addr   string `json:"addr"`
	Port   string `json:"port"`
	Secure bool   `json:"secure"`
}

type Controller

type Controller struct {
	Config            *MachineDaemonConfig
	Router            *gin.Engine
	MachineController MachineController
	Server            *http.Server
	// contains filtered or unexported fields
}

func NewController

func NewController(config *MachineDaemonConfig) *Controller

func (*Controller) InitMachineController

func (c *Controller) InitMachineController(ctx context.Context) error

func (*Controller) Run

func (c *Controller) Run(ctx context.Context) error

func (*Controller) Shutdown

func (c *Controller) Shutdown(ctx context.Context) error

type DiskSize

type DiskSize int64

func (*DiskSize) UnmarshalYAML

func (s *DiskSize) UnmarshalYAML(unmarshal func(interface{}) error) error

type Machine

type Machine struct {
	Type        string `yaml:"type"`
	Config      VMDef  `yaml:"config"`
	Description string `yaml:"description"`
	Ephemeral   bool   `yaml:"ephemeral"`
	Name        string `yaml:"name"`
	Status      string
	// contains filtered or unexported fields
}

func LoadConfig

func LoadConfig(configFile string) (Machine, error)

func (*Machine) ConfigDir

func (cls *Machine) ConfigDir() string

Machine Functions Below

func (*Machine) ConfigFile

func (cls *Machine) ConfigFile() string

func (*Machine) Context

func (cls *Machine) Context() context.Context

func (*Machine) DataDir

func (cls *Machine) DataDir() string

func (*Machine) Delete

func (m *Machine) Delete() error

func (*Machine) GetStatus

func (m *Machine) GetStatus() string

func (*Machine) IsRunning

func (m *Machine) IsRunning() bool

func (*Machine) SaveConfig

func (cls *Machine) SaveConfig() error

func (*Machine) SerialSocket

func (m *Machine) SerialSocket() (string, error)

func (*Machine) SpiceConnection

func (m *Machine) SpiceConnection() (SpiceConnection, error)

func (*Machine) Start

func (m *Machine) Start() error

func (*Machine) StateDir

func (cls *Machine) StateDir() string

func (*Machine) Stop

func (m *Machine) Stop(force bool) error

type MachineConsoleRequest

type MachineConsoleRequest struct {
	ConsoleType string `json:"type"`
}

type MachineController

type MachineController struct {
	Machines []Machine
}

func (*MachineController) AddMachine

func (ctl *MachineController) AddMachine(newMachine Machine, cfg *MachineDaemonConfig) error

func (*MachineController) DeleteMachine

func (ctl *MachineController) DeleteMachine(machineName string, cfg *MachineDaemonConfig) error

func (*MachineController) GetMachine

func (ctl *MachineController) GetMachine(machineName string) (Machine, error)

func (*MachineController) GetMachineByName

func (ctl *MachineController) GetMachineByName(machineName string) (*Machine, error)

func (*MachineController) GetMachineConsole

func (ctl *MachineController) GetMachineConsole(machineName string, consoleType string) (ConsoleInfo, error)

func (*MachineController) GetMachines

func (ctl *MachineController) GetMachines() []Machine

func (*MachineController) StartMachine

func (ctl *MachineController) StartMachine(machineName string) error

func (*MachineController) StopMachine

func (ctl *MachineController) StopMachine(machineName string, force bool) error

func (*MachineController) StopMachines

func (ctl *MachineController) StopMachines() error

func (*MachineController) UpdateMachine

func (ctl *MachineController) UpdateMachine(updateMachine Machine, cfg *MachineDaemonConfig) error

type MachineDaemonConfig

type MachineDaemonConfig struct {
	ConfigDirectory string
	DataDirectory   string
	StateDirectory  string
}

func DefaultMachineDaemonConfig

func DefaultMachineDaemonConfig() *MachineDaemonConfig

func (*MachineDaemonConfig) GetConfigContext

func (c *MachineDaemonConfig) GetConfigContext() context.Context

type MetaData added in v0.1.3

type MetaData struct {
	InstanceId    string `yaml:"instance-id"`
	LocalHostname string `yaml:"local-hostname"`
}

type NetworkDef

type NetworkDef struct {
	Name    string `yaml:"name"`
	Address string `yaml:"address",omitempty`
	Type    string `yaml:"type"`
	IFName  string `yaml:"interface",omitempty`
}

type NicDef

type NicDef struct {
	BusAddr string `yaml:"addr,omitempty"`
	Device  string `yaml:"device"`
	ID      string `yaml:"id",omitempty`
	Mac     string `yaml:"mac",omitempty`

	Network   string     `yaml:"network",omitempty`
	Ports     []PortRule `yaml:"ports",omitempty`
	BootIndex string     `yaml:"bootindex,omitempty`
	ROMFile   string     `yaml:"romfile,omitempty`
	// contains filtered or unexported fields
}

func (NicDef) QNetDevice

func (nd NicDef) QNetDevice(qti *qcli.QemuTypeIndex) (qcli.NetDevice, error)

type Port

type Port struct {
	Address string
	Port    int
}

type PortRule

type PortRule struct {
	Protocol string
	Host     Port
	Guest    Port
}

func (*PortRule) String

func (p *PortRule) String() string

type QMPMachineLogger

type QMPMachineLogger struct{}

func (QMPMachineLogger) Errorf

func (l QMPMachineLogger) Errorf(format string, v ...interface{})

func (QMPMachineLogger) Infof

func (l QMPMachineLogger) Infof(format string, v ...interface{})

func (QMPMachineLogger) V

func (l QMPMachineLogger) V(level int32) bool

func (QMPMachineLogger) Warningf

func (l QMPMachineLogger) Warningf(format string, v ...interface{})

type QemuDisk

type QemuDisk struct {
	File      string   `yaml:"file,omitempty"`
	Format    string   `yaml:"format,omitempty"`
	Size      DiskSize `yaml:"size"`
	Attach    string   `yaml:"attach,omitempty"`
	Type      string   `yaml:"type"`
	BlockSize int      `yaml:"blocksize,omitempty"`
	BusAddr   string   `yaml:"addr,omitempty"`
	BootIndex string   `yaml:"bootindex,omitempty"`
	ReadOnly  bool     `yaml:"read-only,omitempty"`
}

func (*QemuDisk) Create

func (q *QemuDisk) Create() error

Create - create the qemu disk at fpath or its File if it does not exist.

func (*QemuDisk) ImportDiskImage

func (qd *QemuDisk) ImportDiskImage(imageDir string) error

FIXME: what to do with remote client/server ? push to zot and use zot URLs? ImportDiskImage will copy/create a source image to server image

func (*QemuDisk) QBlockDevice

func (qd *QemuDisk) QBlockDevice(qti *qcli.QemuTypeIndex) (qcli.BlockDevice, error)

func (*QemuDisk) Sanitize

func (q *QemuDisk) Sanitize(basedir string) error

type RouteHandler

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

func NewRouteHandler

func NewRouteHandler(c *Controller) *RouteHandler

func (*RouteHandler) DeleteMachine

func (rh *RouteHandler) DeleteMachine(ctx *gin.Context)

func (*RouteHandler) GetMachine

func (rh *RouteHandler) GetMachine(ctx *gin.Context)

func (*RouteHandler) GetMachineConsole

func (rh *RouteHandler) GetMachineConsole(ctx *gin.Context)

func (*RouteHandler) GetMachines

func (rh *RouteHandler) GetMachines(ctx *gin.Context)

func (*RouteHandler) PostMachine

func (rh *RouteHandler) PostMachine(ctx *gin.Context)

func (*RouteHandler) SetupRoutes

func (rh *RouteHandler) SetupRoutes()

func (*RouteHandler) StartMachine

func (rh *RouteHandler) StartMachine(ctx *gin.Context)

func (*RouteHandler) StopMachine

func (rh *RouteHandler) StopMachine(ctx *gin.Context)

func (*RouteHandler) UpdateMachine

func (rh *RouteHandler) UpdateMachine(ctx *gin.Context)

type SpiceConnection

type SpiceConnection struct {
	HostAddress string
	Port        string
	TLSPort     string
}

type StopChannel

type StopChannel chan struct{}

type SwTPM

type SwTPM struct {
	StateDir string
	Socket   string
	Version  string
	// contains filtered or unexported fields
}

func (*SwTPM) Setup

func (s *SwTPM) Setup() error

func (*SwTPM) Start

func (s *SwTPM) Start() error

func (*SwTPM) Stop

func (s *SwTPM) Stop() error

type VM

type VM struct {
	Ctx    context.Context
	Cancel context.CancelFunc
	Config VMDef
	State  VMState
	RunDir string

	Cmd   *exec.Cmd
	SwTPM *SwTPM
	// contains filtered or unexported fields
}

TODO: Rename fields

func (*VM) BackgroundRun

func (v *VM) BackgroundRun() error

func (*VM) Delete

func (v *VM) Delete() error

func (*VM) IsRunning

func (v *VM) IsRunning() bool

func (*VM) MonitorSocket

func (v *VM) MonitorSocket() (string, error)

func (*VM) Name

func (v *VM) Name() string

func (*VM) QMPStatus

func (v *VM) QMPStatus() qcli.RunState

func (*VM) SerialSocket

func (v *VM) SerialSocket() (string, error)

func (*VM) SocketDir

func (v *VM) SocketDir() string

note VM.sockDir is the path to the real sockets and runDir/sockets is a symlink to the socket

func (*VM) SpiceDevice

func (v *VM) SpiceDevice() (qcli.SpiceDevice, error)

func (*VM) Start

func (v *VM) Start() error

func (*VM) StartQMP

func (v *VM) StartQMP() error

func (*VM) Status

func (v *VM) Status() VMState

func (*VM) Stop

func (v *VM) Stop(force bool) error

func (*VM) TPMSocket

func (v *VM) TPMSocket() (string, error)

type VMDef

type VMDef struct {
	Name       string          `yaml:"name"`
	Cpus       uint32          `yaml:"cpus" default:1`
	Memory     uint32          `yaml:"memory"`
	Serial     string          `yaml:"serial"`
	Nics       []NicDef        `yaml:"nics"`
	Disks      []QemuDisk      `yaml:"disks"`
	Boot       string          `yaml:"boot"`
	Cdrom      string          `yaml:"cdrom"`
	UEFICode   string          `yaml:"uefi-code"`
	UEFIVars   string          `yaml:"uefi-vars"`
	TPM        bool            `yaml:"tpm"`
	TPMVersion string          `yaml:"tpm-version"`
	SecureBoot bool            `yaml:"secure-boot"`
	Gui        bool            `yaml:"gui"`
	CloudInit  CloudInitConfig `yaml:"cloud-init"`
}

func (*VMDef) AdjustBootIndicies

func (v *VMDef) AdjustBootIndicies(qti *qcli.QemuTypeIndex) error

type VMNic

type VMNic struct {
	BusAddr    string
	DeviceType string
	HWAddr     string
	ID         string
	IFName     string
	NetIFName  string
	NetType    string
	NetAddr    string
	BootIndex  string
	Ports      []PortRule
}

type VMState

type VMState int
const (
	VMInit VMState = iota
	VMStarted
	VMStopped
	VMFailed
	VMCleaned
)

func (VMState) String

func (v VMState) String() string

Jump to

Keyboard shortcuts

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