-
Notifications
You must be signed in to change notification settings - Fork 63
/
runtime.go
95 lines (76 loc) · 2.15 KB
/
runtime.go
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
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file except in compliance with the License.
package runtime
import (
"strings"
"kraftkit.sh/kconfig"
"kraftkit.sh/pack"
"kraftkit.sh/packmanager"
"kraftkit.sh/unikraft"
)
type Runtime struct {
registry packmanager.PackageManager
// Path to the kernel of the ELF loader.
kernel string
// The package representing the ELF Loader.
pack pack.Package
// The name of the elfloader.
name string
// The version of the elfloader.
version string
// The source of the elfloader (can be either remote or local, this attribute
// is ultimately handled by the packmanager).
source string
// List of kconfig key-values specific to this core.
kconfig kconfig.KeyValueMap
// The rootfs (initramfs) of the ELF loader.
rootfs string
}
var _ unikraft.Nameable = (*Runtime)(nil)
// Type implements kraftkit.sh/unikraft.Nameable
func (elfloader *Runtime) Type() unikraft.ComponentType {
return unikraft.ComponentTypeApp
}
// Name implements kraftkit.sh/unikraft.Nameable
func (elfloader *Runtime) Name() string {
return elfloader.name
}
// SetName overwrites the name of the runtime.
func (elfloader *Runtime) SetName(name string) {
if runtime := strings.Split(name, ":"); len(runtime) == 2 {
elfloader.name = runtime[0]
elfloader.version = runtime[1]
return
}
elfloader.name = name
}
// String implements fmt.Stringer
func (ocipack *Runtime) String() string {
return ocipack.pack.Name()
}
// Version implements kraftkit.sh/unikraft.Nameable
func (elfloader *Runtime) Version() string {
return elfloader.version
}
// Source of the ELF Loader runtime.
func (elfloader *Runtime) Source() string {
return elfloader.source
}
func (elfloader *Runtime) MarshalYAML() (interface{}, error) {
ret := map[string]interface{}{}
if len(elfloader.name) > 0 {
ret["name"] = elfloader.name
}
if len(elfloader.version) > 0 {
ret["version"] = elfloader.version
}
if len(elfloader.source) > 0 {
ret["source"] = elfloader.source
}
if len(ret) == 0 {
return nil, nil
}
return ret, nil
}