diff --git a/providers/os/connection/device/device_connection.go b/providers/os/connection/device/device_connection.go index 213e27779b..2ab89d6fb3 100644 --- a/providers/os/connection/device/device_connection.go +++ b/providers/os/connection/device/device_connection.go @@ -33,6 +33,8 @@ type DeviceConnection struct { deviceManager DeviceManager MountedDirs []string + // map of mountpoints to partition infos + partitions map[string]*snapshot.PartitionInfo } func getDeviceManager(conf *inventory.Config) (DeviceManager, error) { @@ -76,12 +78,15 @@ func NewDeviceConnection(connId uint32, conf *inventory.Config, asset *inventory asset.IdDetector = []string{ids.IdDetector_Hostname, ids.IdDetector_SshHostkey} } + res.partitions = make(map[string]*snapshot.PartitionInfo) + // we iterate over all the blocks and try to run OS detection on each one of them // we only return one asset, if we find the right block (e.g. the one with the root FS) for _, block := range blocks { fsConn, scanDir, err := tryDetectAsset(connId, block, manager, conf, asset) if scanDir != "" { res.MountedDirs = append(res.MountedDirs, scanDir) + res.partitions[scanDir] = block } if err != nil { log.Error().Err(err).Msg("partition did not return an asset, continuing") @@ -158,6 +163,14 @@ func (p *DeviceConnection) Conf() *inventory.Config { return p.FileSystemConnection.Conf } +func (p *DeviceConnection) Partitions() map[string]*snapshot.PartitionInfo { + if p.partitions == nil { + p.partitions = make(map[string]*snapshot.PartitionInfo) + } + + return p.partitions +} + // tryDetectAsset tries to detect the OS on a given block device func tryDetectAsset(connId uint32, partition *snapshot.PartitionInfo, manager DeviceManager, conf *inventory.Config, asset *inventory.Asset) (*fs.FileSystemConnection, string, error) { log.Debug().Str("name", partition.Name).Str("type", partition.FsType).Msg("mounting partition") diff --git a/providers/os/connection/snapshot/blockdevices.go b/providers/os/connection/snapshot/blockdevices.go index 287ee58765..1e4ae7879f 100644 --- a/providers/os/connection/snapshot/blockdevices.go +++ b/providers/os/connection/snapshot/blockdevices.go @@ -189,7 +189,10 @@ func (device BlockDevice) GetMountablePartitions(includeAll bool) ([]*PartitionI if filter(partition) { log.Debug().Str("name", partition.Name).Msg("found suitable partition") devFsName := "/dev/" + partition.Name - partitions = append(partitions, &PartitionInfo{Name: devFsName, FsType: partition.FsType}) + partitions = append(partitions, &PartitionInfo{ + Name: devFsName, FsType: partition.FsType, + Label: partition.Label, Uuid: partition.Uuid, + }) } else { log.Debug(). Str("name", partition.Name). diff --git a/providers/os/connection/snapshot/blockdevices_test.go b/providers/os/connection/snapshot/blockdevices_test.go index c3690b07b8..0800636b73 100644 --- a/providers/os/connection/snapshot/blockdevices_test.go +++ b/providers/os/connection/snapshot/blockdevices_test.go @@ -247,7 +247,7 @@ func TestGetMountablePartition(t *testing.T) { } partition, err := block.GetMountablePartition() require.Nil(t, err) - require.Equal(t, &PartitionInfo{FsType: "xfs", Name: "/dev/sde1"}, partition) + require.Equal(t, &PartitionInfo{FsType: "xfs", Name: "/dev/sde1", Uuid: "12346", Label: "ROOT"}, partition) }) t.Run("largest suitable partition", func(t *testing.T) { @@ -260,7 +260,7 @@ func TestGetMountablePartition(t *testing.T) { } partition, err := block.GetMountablePartition() require.Nil(t, err) - require.Equal(t, &PartitionInfo{FsType: "xfs", Name: "/dev/sda2"}, partition) + require.Equal(t, &PartitionInfo{FsType: "xfs", Name: "/dev/sda2", Uuid: "12346", Label: "ROOT"}, partition) }) } @@ -280,8 +280,8 @@ func TestGetMountablePartitions(t *testing.T) { parts, err := block.GetMountablePartitions(true) require.NoError(t, err) expected := []*PartitionInfo{ - {Name: "/dev/sda2", FsType: "xfs"}, - {Name: "/dev/sda3", FsType: "xfs"}, + {Name: "/dev/sda2", FsType: "xfs", Uuid: "12345", Label: "ROOT"}, + {Name: "/dev/sda3", FsType: "xfs", Uuid: "12346", Label: "ROOT"}, } require.ElementsMatch(t, expected, parts) }) diff --git a/providers/os/connection/snapshot/partition.go b/providers/os/connection/snapshot/partition.go index 456433ad8b..c573dcfc66 100644 --- a/providers/os/connection/snapshot/partition.go +++ b/providers/os/connection/snapshot/partition.go @@ -10,6 +10,11 @@ import ( type PartitionInfo struct { Name string FsType string + + // (optional) Label is the partition label + Label string + // (optional) UUID is the partition UUID + Uuid string } func (entry BlockDevice) isNoBootVolume() bool {