mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-09-17 07:41:14 +00:00
Add KairosFS type and detectBoot with FS (#46)
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/itchyny/gojq"
|
||||
"github.com/jaypipes/ghw"
|
||||
"github.com/jaypipes/ghw/pkg/block"
|
||||
"github.com/kairos-io/kairos-sdk/types"
|
||||
"github.com/kairos-io/kairos-sdk/utils"
|
||||
"github.com/zcalusic/sysinfo"
|
||||
"gopkg.in/yaml.v3"
|
||||
@@ -132,6 +133,27 @@ func detectBoot() Boot {
|
||||
}
|
||||
}
|
||||
|
||||
// DetectBootWithVFS will detect the boot state using a vfs so it can be used for tests as well
|
||||
func DetectBootWithVFS(fs types.KairosFS) (Boot, error) {
|
||||
cmdline, err := fs.ReadFile("/proc/cmdline")
|
||||
if err != nil {
|
||||
return Unknown, err
|
||||
}
|
||||
cmdlineS := string(cmdline)
|
||||
switch {
|
||||
case strings.Contains(cmdlineS, "COS_ACTIVE"):
|
||||
return Active, nil
|
||||
case strings.Contains(cmdlineS, "COS_PASSIVE"):
|
||||
return Passive, nil
|
||||
case strings.Contains(cmdlineS, "COS_RECOVERY"), strings.Contains(cmdlineS, "COS_SYSTEM"):
|
||||
return Recovery, nil
|
||||
case strings.Contains(cmdlineS, "live:LABEL"), strings.Contains(cmdlineS, "live:CDLABEL"), strings.Contains(cmdlineS, "netboot"):
|
||||
return LiveCD, nil
|
||||
default:
|
||||
return Unknown, nil
|
||||
}
|
||||
}
|
||||
|
||||
func detectRuntimeState(r *Runtime) error {
|
||||
blockDevices, err := block.New(ghw.WithDisableTools(), ghw.WithDisableWarnings())
|
||||
// ghw currently only detects if partitions are mounted via the device
|
||||
|
7
types/fs.go
Normal file
7
types/fs.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package types
|
||||
|
||||
// KairosFS is our interface for methods that need an FS
|
||||
// We should try to keep it to a minimum so we can change between backends easily if needed
|
||||
type KairosFS interface {
|
||||
ReadFile(filename string) ([]byte, error)
|
||||
}
|
Reference in New Issue
Block a user