Filter unused disks

3,762 views
Skip to first unread message

Damir Markovic

unread,
Jul 15, 2016, 10:15:55 AM7/15/16
to gce-discussion
Hello,
I am trying to get the list of unused disks by using gcloud util.

Disks that are used have defined users:
    "users": [
      "https://www.googleapis.com/compute/v1/projects/compute-engine-666/zones/us-central1-b/instances/wicked_instance"
    ],

Others don't have users key at all.

How to do something like this:
gcloud compute disks list --filter="users not defined"

Documentation is really vague and incomplete.

Thank you.

Michael Basilyan

unread,
Jul 15, 2016, 2:26:00 PM7/15/16
to Damir Markovic, gce-discussion
I looked through the documentation (did you see this?) and I agree it's not clear on how to query whether a key is missing. Fortunately, you can determine if a key is present just by doing this: 

gcloud compute disks list --filter="users:*" > used.txt 

to get a list of disks that have users and then 

gcloud compute disks list  > all-disks.txt 

and then just find the difference: 

grep -Fxv -f used.txt all-disks.txt




--
© 2016 Google Inc. 1600 Amphitheatre Parkway, Mountain View, CA 94043
 
Email preferences: You received this email because you signed up for the Google Compute Engine Discussion Google Group (gce-dis...@googlegroups.com) to participate in discussions with other members of the Google Compute Engine community and the Google Compute Engine Team.
---
You received this message because you are subscribed to the Google Groups "gce-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gce-discussio...@googlegroups.com.
To post to this group, send email to gce-dis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gce-discussion/62868f1c-9e3b-4b90-b40a-12edb53dd88d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Michael Basilyan | Product Manager, Compute Engine | basi...@google.com | 415-794-8881

Michael Basilyan

unread,
Jul 15, 2016, 2:26:56 PM7/15/16
to Damir Markovic, gce-discussion
Sorry linked to the wrong doc. Here's the filters documentation: https://cloud.google.com/sdk/gcloud/reference/topic/filters

Damir Markovic

unread,
Jul 15, 2016, 3:00:26 PM7/15/16
to gce-discussion
Yeah, this totally works.

I did saw that doc, just missed "and the pattern * matches any non-empty string". But `users` is not even a string. :-)

Thank you very much!

Michael Basilyan

unread,
Jul 15, 2016, 3:48:31 PM7/15/16
to Damir Markovic, gce-discussion
Quick follow up (in case someone needs this in the future): turns out you can actually just do this to find disks without the users key (not the - in front of users) -- no need for grep magic :). 

gcloud compute disks list --filter="-users:*"

The docs team will update the documentation to make this clearer too. 

Mike


For more options, visit https://groups.google.com/d/optout.

santhosh chakilam

unread,
Mar 8, 2018, 9:03:16 AM3/8/18
to gce-discussion
Hello Team , 

Quick question, 

1. If there is a persistent disk that is lying around and not attached to any instance , can we assume that it would not be used by any other resource on google cloud ? In other ways " the only way to access a persistent disk is through an instance " - Is my understanding correct. 
  
2. How would I know when was the persistent disk last used ?   
Reply all
Reply to author
Forward
0 new messages