-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathblock_devices.go
53 lines (40 loc) · 1.2 KB
/
block_devices.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
/*
2020 © Postgres.ai
*/
// Package pool provides components to work with storage pools.
package pool
import (
"encoding/json"
"fmt"
"os/exec"
"github.com/pkg/errors"
"gitlab.com/postgres-ai/database-lab/v3/internal/provision/thinclones/lvm"
"gitlab.com/postgres-ai/database-lab/v3/pkg/log"
)
type blockDeviceList struct {
BlockDevices []blockDevice `json:"blockdevices"`
}
type blockDevice struct {
Type string `json:"type"`
MountPoint string `json:"mountpoint"`
}
// getBlockDeviceTypes returns a filesystem type list of mounted block devices.
func getBlockDeviceTypes() (map[string]string, error) {
output, err := exec.Command("lsblk", "--json", "--output", "type,mountpoint").Output()
if err != nil {
log.Err(output)
return nil, fmt.Errorf("failed to run command: %w", err)
}
var blockDevices blockDeviceList
if err := json.Unmarshal(output, &blockDevices); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal response")
}
blockDeviceTypes := make(map[string]string)
for _, blk := range blockDevices.BlockDevices {
if blk.MountPoint == "" || blk.Type != lvm.PoolMode {
continue
}
blockDeviceTypes[blk.MountPoint] = blk.Type
}
return blockDeviceTypes, nil
}