Skip to content

Commit

Permalink
feat: add readonly information to the disks API response
Browse files Browse the repository at this point in the history
Forward device readonly info from `go-blockdevice` library.

Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
  • Loading branch information
Unix4ever committed Sep 12, 2023
1 parent 735bf9e commit 2960f93
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 24 deletions.
2 changes: 2 additions & 0 deletions api/storage/storage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ message Disk {
bool system_disk = 11;
// Subsystem is the symlink path in the `/sys/block/<dev>/subsystem`.
string subsystem = 12;
// Readonly specifies if the disk is read only.
bool readonly = 13;
}

// DisksResponse represents the response of the `Disks` RPC.
Expand Down
8 changes: 8 additions & 0 deletions cmd/talosctl/cmd/talos/disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func printDisks(ctx context.Context, c *client.Client) error {
"SIZE",
"BUS_PATH",
"SUBSYSTEM",
"READ_ONLY",
"SYSTEM_DISK",
}, "\t")

Expand Down Expand Up @@ -97,6 +98,12 @@ func printDisks(ctx context.Context, c *client.Client) error {
args = append(args, node)
}

isReadonly := ""

if disk.Readonly {
isReadonly = "*"
}

isSystemDisk := ""

if disk.SystemDisk {
Expand All @@ -115,6 +122,7 @@ func printDisks(ctx context.Context, c *client.Client) error {
humanize.Bytes(disk.Size),
getWithPlaceholder(disk.BusPath),
getWithPlaceholder(disk.Subsystem),
isReadonly,
isSystemDisk,
}...)

Expand Down
1 change: 1 addition & 0 deletions internal/app/storaged/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (s *Server) Disks(ctx context.Context, in *emptypb.Empty) (reply *storage.D
BusPath: d.BusPath,
SystemDisk: systemDisk != nil && d.DeviceName == systemDisk.Device().Name(),
Subsystem: d.SubSystem,
Readonly: d.ReadOnly,
}
}

Expand Down
59 changes: 35 additions & 24 deletions pkg/machinery/api/storage/storage.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions pkg/machinery/api/storage/storage_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions website/content/v1.6/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7357,6 +7357,7 @@ Disk represents a disk.
| bus_path | [string](#string) | | BusPath is the bus path of the disk. |
| system_disk | [bool](#bool) | | SystemDisk indicates that the disk is used as Talos system disk. |
| subsystem | [string](#string) | | Subsystem is the symlink path in the `/sys/block/<dev>/subsystem`. |
| readonly | [bool](#bool) | | Readonly specifies if the disk is read only. |



Expand Down

0 comments on commit 2960f93

Please sign in to comment.