1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
package load
import (
"go.starlark.net/starlark"
"github.com/lxc/incus/v6/shared/scriptlet"
)
// nameInstancePlacement is the name used in Starlark for the instance placement scriptlet.
const nameInstancePlacement = "instance_placement"
// prefixQEMU is the prefix used in Starlark for the QEMU scriptlet.
const prefixQEMU = "qemu"
// nameAuthorization is the name used in Starlark for the Authorization scriptlet.
const nameAuthorization = "authorization"
var loader = scriptlet.NewLoader()
// InstancePlacementCompile compiles the instance placement scriptlet.
func InstancePlacementCompile(name string, src string) (*starlark.Program, error) {
return scriptlet.Compile(name, src, []string{
"log_info",
"log_warn",
"log_error",
"set_target",
"get_cluster_member_resources",
"get_cluster_member_state",
"get_instance_resources",
"get_instances",
"get_instances_count",
"get_cluster_members",
"get_project",
})
}
// InstancePlacementValidate validates the instance placement scriptlet.
func InstancePlacementValidate(src string) error {
return scriptlet.Validate(InstancePlacementCompile, nameInstancePlacement, src, scriptlet.Declaration{
scriptlet.Required("instance_placement"): {"request", "candidate_members"},
})
}
// InstancePlacementSet compiles the instance placement scriptlet into memory for use with InstancePlacementRun.
// If empty src is provided the current program is deleted.
func InstancePlacementSet(src string) error {
return loader.Set(InstancePlacementCompile, nameInstancePlacement, src)
}
// InstancePlacementProgram returns the precompiled instance placement scriptlet program.
func InstancePlacementProgram() (*starlark.Program, *starlark.Thread, error) {
return loader.Program("Instance placement", nameInstancePlacement)
}
// QEMUCompile compiles the QEMU scriptlet.
func QEMUCompile(name string, src string) (*starlark.Program, error) {
return scriptlet.Compile(name, src, []string{
"log_info",
"log_warn",
"log_error",
"run_qmp",
"run_command",
"blockdev_add",
"blockdev_del",
"chardev_add",
"chardev_change",
"chardev_remove",
"device_add",
"device_del",
"netdev_add",
"netdev_del",
"object_add",
"object_del",
"qom_get",
"qom_list",
"qom_set",
"get_qemu_cmdline",
"set_qemu_cmdline",
"get_qemu_conf",
"set_qemu_conf",
})
}
// QEMUValidate validates the QEMU scriptlet.
func QEMUValidate(src string) error {
return scriptlet.Validate(QEMUCompile, prefixQEMU, src, scriptlet.Declaration{
scriptlet.Required("qemu_hook"): {"instance", "stage"},
})
}
// QEMUSet compiles the QEMU scriptlet into memory for use with QEMURun.
// If empty src is provided the current program is deleted.
func QEMUSet(src string, instance string) error {
return loader.Set(QEMUCompile, prefixQEMU+"/"+instance, src)
}
// QEMUProgram returns the precompiled QEMU scriptlet program.
func QEMUProgram(instance string) (*starlark.Program, *starlark.Thread, error) {
return loader.Program("QEMU", prefixQEMU+"/"+instance)
}
// AuthorizationCompile compiles the authorization scriptlet.
func AuthorizationCompile(name string, src string) (*starlark.Program, error) {
return scriptlet.Compile(name, src, []string{
"log_info",
"log_warn",
"log_error",
})
}
// AuthorizationValidate validates the authorization scriptlet.
func AuthorizationValidate(src string) error {
return scriptlet.Validate(AuthorizationCompile, nameAuthorization, src, scriptlet.Declaration{
scriptlet.Required("authorize"): {"details", "object", "entitlement"},
scriptlet.Optional("get_instance_access"): {"project_name", "instance_name"},
scriptlet.Optional("get_project_access"): {"project_name"},
})
}
// AuthorizationSet compiles the authorization scriptlet into memory for use with AuthorizationRun.
// If empty src is provided the current program is deleted.
func AuthorizationSet(src string) error {
return loader.Set(AuthorizationCompile, nameAuthorization, src)
}
// AuthorizationProgram returns the precompiled authorization scriptlet program.
func AuthorizationProgram() (*starlark.Program, *starlark.Thread, error) {
return loader.Program("Authorization", nameAuthorization)
}
|