mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-09-05 17:20:15 +00:00
seedling: Detect more information about runtime (#956)
* 🌱 Detect more information about runtime This introduces a `system` and a `kairos` block available in kairos-agent get state. This allows for instance to query the agent for the kairos version as such: `kairos-agent get state kairos.version` Part of #755 Signed-off-by: mudler <mudler@c3os.io> * 🤖 Fixup tests Signed-off-by: mudler <mudler@c3os.io> --------- Signed-off-by: mudler <mudler@c3os.io>
This commit is contained in:
committed by
Itxaka
parent
27a33ce381
commit
61cc567cd8
@@ -10,6 +10,8 @@ import (
|
|||||||
"github.com/jaypipes/ghw"
|
"github.com/jaypipes/ghw"
|
||||||
"github.com/jaypipes/ghw/pkg/block"
|
"github.com/jaypipes/ghw/pkg/block"
|
||||||
"github.com/kairos-io/kairos/pkg/machine"
|
"github.com/kairos-io/kairos/pkg/machine"
|
||||||
|
"github.com/kairos-io/kairos/pkg/utils"
|
||||||
|
"github.com/zcalusic/sysinfo"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,6 +37,11 @@ type PartitionState struct {
|
|||||||
UUID string `yaml:"uuid" json:"uuid"` // This would be volume UUID on macOS, PartUUID on linux, empty on Windows
|
UUID string `yaml:"uuid" json:"uuid"` // This would be volume UUID on macOS, PartUUID on linux, empty on Windows
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Kairos struct {
|
||||||
|
Flavor string `yaml:"flavor" json:"flavor"`
|
||||||
|
Version string `yaml:"version" json:"version"`
|
||||||
|
}
|
||||||
|
|
||||||
type Runtime struct {
|
type Runtime struct {
|
||||||
UUID string `yaml:"uuid" json:"uuid"`
|
UUID string `yaml:"uuid" json:"uuid"`
|
||||||
Persistent PartitionState `yaml:"persistent" json:"persistent"`
|
Persistent PartitionState `yaml:"persistent" json:"persistent"`
|
||||||
@@ -42,6 +49,8 @@ type Runtime struct {
|
|||||||
OEM PartitionState `yaml:"oem" json:"oem"`
|
OEM PartitionState `yaml:"oem" json:"oem"`
|
||||||
State PartitionState `yaml:"state" json:"state"`
|
State PartitionState `yaml:"state" json:"state"`
|
||||||
BootState Boot `yaml:"boot" json:"boot"`
|
BootState Boot `yaml:"boot" json:"boot"`
|
||||||
|
System sysinfo.SysInfo `yaml:"system" json:"system"`
|
||||||
|
Kairos Kairos `yaml:"kairos" json:"kairos"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func detectPartition(b *block.Partition) PartitionState {
|
func detectPartition(b *block.Partition) PartitionState {
|
||||||
@@ -100,12 +109,36 @@ func detectRuntimeState(r *Runtime) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func detectSystem(r *Runtime) {
|
||||||
|
var si sysinfo.SysInfo
|
||||||
|
|
||||||
|
si.GetSysInfo()
|
||||||
|
r.System = si
|
||||||
|
}
|
||||||
|
|
||||||
|
func detectKairos(r *Runtime) {
|
||||||
|
k := &Kairos{}
|
||||||
|
flavor, err := utils.OSRelease("FLAVOR")
|
||||||
|
if err == nil {
|
||||||
|
k.Flavor = flavor
|
||||||
|
}
|
||||||
|
v, err := utils.OSRelease("VERSION")
|
||||||
|
if err == nil {
|
||||||
|
k.Version = v
|
||||||
|
}
|
||||||
|
r.Kairos = *k
|
||||||
|
}
|
||||||
|
|
||||||
func NewRuntime() (Runtime, error) {
|
func NewRuntime() (Runtime, error) {
|
||||||
runtime := &Runtime{
|
runtime := &Runtime{
|
||||||
BootState: detectBoot(),
|
BootState: detectBoot(),
|
||||||
UUID: machine.UUID(),
|
UUID: machine.UUID(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
detectSystem(runtime)
|
||||||
|
detectKairos(runtime)
|
||||||
err := detectRuntimeState(runtime)
|
err := detectRuntimeState(runtime)
|
||||||
|
|
||||||
return *runtime, err
|
return *runtime, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user