DEV Community

Gonzalo Gjuka
Gonzalo Gjuka

Posted on

An unattached disk does not know how long it has been unattached

Yesterday I asked a Spanish-speaking dev subreddit how people find unattached disks and unused public IPs before the invoice does. That evening I published the commands I was using as a read-only bash script: cloud-orphans. It lists, it never deletes.

One reply asked about a grace period, so yesterday's detach does not get flagged. Answering it, I saw the gap in my script. An EBS volume has a CreateTime and no detach time, so my age_days counts from creation. You need your own first-seen-unattached tag, or the DetachVolume record in CloudTrail.

The other thing I explained there: on OCI a block volume reports AVAILABLE attached or not. You cross two lists, in every compartment, because the attachment lives with the instance:

oci bv volume list -c "$C" --all --query 'data[?"lifecycle-state"==`AVAILABLE`].id'
oci compute volume-attachment list -c "$C" --all \
  --query 'data[?"lifecycle-state"==`ATTACHED`]."volume-id"'
Enter fullscreen mode Exit fullscreen mode

How long do you wait before you call a disk an orphan?

I also build Control Cloud; the script stands on its own.

Top comments (0)