vm

package
v0.0.0-...-1ca2487 Latest Latest
Warning

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

Go to latest
Published: May 29, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTimeoutValue default timeout value for virtual machines
	DefaultTimeoutValue = 30 * time.Second
	// DefaultMaxVirtualMachines max number of virtual machines that can be loaded at one time
	DefaultMaxVirtualMachines uint8 = 10

	// TypeLoad text to display in script_event table when a VM is loaded
	TypeLoad = "load"
	// TypeCreate text to display in script_event table when a VM is created
	TypeCreate = "create"
	// TypeExecute text to display in script_event table when a script is executed
	TypeExecute = "execute"
	// TypeStop text to display in script_event table when a running script is stopped
	TypeStop = "stop"
	// TypeRead text to display in script_event table when a script contents is read
	TypeRead = "read"

	// StatusSuccess text to display in script_event table on successful execution
	StatusSuccess = "success"
	// StatusFailure text to display in script_event table when script execution fails
	StatusFailure = "failure"
)
View Source
const (
	// ErrNoVMFound error returned when no virtual machine is found
	ErrNoVMFound = "VM %v not found"
)

Variables

View Source
var (
	// GCTScriptConfig initialised global copy of Config{}
	GCTScriptConfig = &Config{}
	// ScriptPath path to load/save scripts
	ScriptPath string
)
View Source
var (
	// ErrScriptingDisabled error message displayed when gctscript is disabled
	ErrScriptingDisabled = errors.New("scripting is disabled")
	// ErrNoVMLoaded error message displayed if a virtual machine has not been initialised
	ErrNoVMLoaded = errors.New("no virtual machine loaded")
)
View Source
var (

	// AllVMSync stores all current Virtual Machine instances
	AllVMSync = &sync.Map{}
	// VMSCount running total count of Virtual Machines
	VMSCount vmscount
)

Functions

func Autoload

func Autoload(name string, remove bool) error

Autoload remove entry from autoload slice

func RemoveVM

func RemoveVM(id uuid.UUID) error

RemoveVM remove VM from list

func ShutdownAll

func ShutdownAll() (err error)

ShutdownAll shutdown all

func Validate

func Validate(file string) (err error)

Validate will attempt to execute a script in a test/non-live environment to confirm it passes requirements for execution

Types

type Config

type Config struct {
	Enabled            bool          `json:"enabled"`
	ScriptTimeout      time.Duration `json:"timeout"`
	MaxVirtualMachines uint8         `json:"max_virtual_machines"`
	AllowImports       bool          `json:"allow_imports"`
	AutoLoad           []string      `json:"auto_load"`
	Verbose            bool          `json:"verbose"`
}

Config user configurable options for gctscript

type Error

type Error struct {
	Script string
	Action string
	Cause  error
}

Error interface to meet error requirements

func (Error) Error

func (e Error) Error() string

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap returns e.Cause meeting errors interface requirements.

type VM

type VM struct {
	ID       uuid.UUID
	Hash     string
	File     string
	Path     string
	Script   *tengo.Script
	Compiled *tengo.Compiled

	T       time.Duration
	NextRun time.Time
	S       chan struct{}
	// contains filtered or unexported fields
}

VM contains a pointer to "script" (precompiled source) and "compiled" (compiled byte code) instances

func New

func New() *VM

New returns a new instance of VM

func NewVM

func NewVM() (vm *VM)

NewVM attempts to create a new Virtual Machine firstly from pool

func (*VM) Compile

func (vm *VM) Compile() (err error)

Compile compiles to byte code loaded copy of vm script

func (*VM) CompileAndRun

func (vm *VM) CompileAndRun()

CompileAndRun Compile and Run script with support for task running

func (*VM) Load

func (vm *VM) Load(file string) error

Load parses and creates a new instance of tengo script vm

func (*VM) Read

func (vm *VM) Read() ([]byte, error)

Read contents of script back and create script event

func (*VM) Run

func (vm *VM) Run() (err error)

Run runs byte code

func (*VM) RunCtx

func (vm *VM) RunCtx() (err error)

RunCtx runs compiled byte code with context.Context support.

func (*VM) ShortName

func (vm *VM) ShortName() string

ShortName returns short (just filename.extension) of running script

func (*VM) Shutdown

func (vm *VM) Shutdown() error

Shutdown shuts down current VM

Jump to

Keyboard shortcuts

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