Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion cli/disk/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (

type ls struct {
*flags.DatastoreFlag
all bool
long bool
path bool
r bool
Expand All @@ -51,6 +52,7 @@ func (cmd *ls) Register(ctx context.Context, f *flag.FlagSet) {
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
cmd.DatastoreFlag.Register(ctx, f)

f.BoolVar(&cmd.all, "a", false, "List IDs with missing file backing")
f.BoolVar(&cmd.long, "l", false, "Long listing format")
f.BoolVar(&cmd.path, "L", false, "Print disk backing path instead of disk name")
f.BoolVar(&cmd.r, "R", false, "Reconcile the datastore inventory info")
Expand Down Expand Up @@ -167,7 +169,18 @@ func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
if err != nil {
if filterNotFound && fault.Is(err, &types.NotFound{}) {
// The case when an FCD is deleted by something other than DeleteVStorageObject_Task, such as VM destroy
return fmt.Errorf("%s not found: use 'disk.ls -R' to reconcile datastore inventory", id)
if cmd.all {
obj := VStorageObject{VStorageObject: types.VStorageObject{
Config: types.VStorageObjectConfigInfo{
BaseConfigInfo: types.BaseConfigInfo{
Id: types.ID{Id: id},
Name: "not found: use 'disk.ls -R' to reconcile datastore inventory",
},
},
}}
res.Objects = append(res.Objects, obj)
}
continue
}
return fmt.Errorf("retrieve %q: %s", id, err)
}
Expand Down
1 change: 1 addition & 0 deletions govc/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2150,6 +2150,7 @@ Options:
-L=false Print disk backing path instead of disk name
-R=false Reconcile the datastore inventory info
-T=false List attached tags
-a=false List IDs with missing file backing
-c= Query tag category
-ds= Datastore [GOVC_DATASTORE]
-l=false Long listing format
Expand Down
13 changes: 12 additions & 1 deletion govc/test/disk.bats
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,24 @@ load test_helper

run govc disk.ls
assert_success
[ ${#lines[@]} -eq 2 ]

path=$(govc disk.ls -json "$id" | jq -r .objects[].config.backing.filePath)
run govc datastore.rm "$path"
assert_success

# file backing was removed without using disk.rm, results in NotFound fault
run govc disk.ls "$id"
assert_failure

run govc disk.ls
assert_failure # file backing was removed without using disk.rm, results in NotFound fault
assert_success
[ ${#lines[@]} -eq 1 ]

run govc disk.ls -a
assert_success
[ ${#lines[@]} -eq 2 ]
assert_matches "not found"

run govc disk.ls -R
assert_success
Expand Down
Loading