forked from openshift-powervs/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.go
41 lines (35 loc) · 1.12 KB
/
node.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
package ignition
import (
"path/filepath"
ignition "github.com/coreos/ignition/config/v2_2/types"
"github.com/vincent-petithory/dataurl"
"github.com/openshift/installer/pkg/asset"
)
// FilesFromAsset creates ignition files for each of the files in the specified
// asset.
func FilesFromAsset(pathPrefix string, mode int, asset asset.WritableAsset) []ignition.File {
var files []ignition.File
for _, f := range asset.Files() {
files = append(files, FileFromBytes(filepath.Join(pathPrefix, f.Filename), mode, f.Data))
}
return files
}
// FileFromString creates an ignition-config file with the given contents.
func FileFromString(path string, mode int, contents string) ignition.File {
return FileFromBytes(path, mode, []byte(contents))
}
// FileFromBytes creates an ignition-config file with the given contents.
func FileFromBytes(path string, mode int, contents []byte) ignition.File {
return ignition.File{
Node: ignition.Node{
Filesystem: "root",
Path: path,
},
FileEmbedded1: ignition.FileEmbedded1{
Mode: &mode,
Contents: ignition.FileContents{
Source: dataurl.EncodeBytes(contents),
},
},
}
}