-
Notifications
You must be signed in to change notification settings - Fork 63
/
platform.go
121 lines (95 loc) · 2.84 KB
/
platform.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
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
// 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 plat
import (
"context"
"os"
"kraftkit.sh/kconfig"
"kraftkit.sh/unikraft"
"kraftkit.sh/unikraft/component"
)
type Platform interface {
component.Component
}
type PlatformConfig struct {
// name of the platform.
name string
// version of the platform.
version string
// source of the platform (can be either remote or local, this attribute is
// ultimately handled by the packmanager).
source string
// path is the location to this platform within the context of a project.
path string
// internal dictates whether the platform comes from the Unikraft core
// repository.
internal bool
// kconfig list of kconfig key-values specific to this platform.
kconfig kconfig.KeyValueMap
}
// NewPlatformFromOptions is a constructor that configures a platform configuration.
func NewPlatformFromOptions(opts ...PlatformOption) (Platform, error) {
pc := PlatformConfig{}
for _, opt := range opts {
if err := opt(&pc); err != nil {
return nil, err
}
}
return &pc, nil
}
func (pc PlatformConfig) Name() string {
return pc.name
}
func (pc PlatformConfig) String() string {
return pc.name
}
func (pc PlatformConfig) Source() string {
return pc.source
}
func (pc PlatformConfig) Version() string {
return pc.version
}
func (pc PlatformConfig) Type() unikraft.ComponentType {
return unikraft.ComponentTypePlat
}
func (pc PlatformConfig) Path() string {
return pc.path
}
func (pc PlatformConfig) IsUnpacked() bool {
if f, err := os.Stat(pc.Path()); err == nil && f.IsDir() {
return true
}
return false
}
func (pc PlatformConfig) KConfigTree(context.Context, ...*kconfig.KeyValue) (*kconfig.KConfigFile, error) {
// TODO: Try within the Unikraft codebase as well as via an external
// microlibrary. For now, return nil as undetermined.
return nil, nil
}
func (pc PlatformConfig) KConfig() kconfig.KeyValueMap {
values := kconfig.KeyValueMap{}
values.OverrideBy(pc.kconfig)
// The following are built-in assumptions given the naming conventions used
// within the Unikraft core.
switch pc.Name() {
case "fc", "firecracker", "kraftcloud":
values.Set("CONFIG_PLAT_KVM", kconfig.Yes)
values.Set("CONFIG_KVM_VMM_FIRECRACKER", kconfig.Yes)
case "kvm", "qemu":
values.Set("CONFIG_PLAT_KVM", kconfig.Yes)
values.Set("CONFIG_KVM_VMM_QEMU", kconfig.Yes)
case "xen":
values.Set("CONFIG_PLAT_XEN", kconfig.Yes)
case "linuxu":
values.Set("CONFIG_PLAT_LINUXU", kconfig.Yes)
}
return values
}
func (pc PlatformConfig) MarshalYAML() (interface{}, error) {
return nil, nil
}
func (pc PlatformConfig) PrintInfo(ctx context.Context) string {
return "not implemented: unikraft.plat.PlatformConfig.PrintInfo"
}