Infinidat / infinisdk

Python SDK for INFINIDAT storage products
https://infinisdk.readthedocs.org
Other
9 stars 5 forks source link

volume snapshots by volume #6

Closed Orenus closed 5 years ago

Orenus commented 5 years ago

Hi,

How can I query all the snapshot of volume given I have its name only.

I have tries:

system.volumes.find(name=volume_name, type='snapshots')

and volume = system.volumes.find(name==volume_name) system.volumes.find(parent_id=volume.id, type='snapshots')

but couldnt get the list

can you please advise?

daramosch commented 5 years ago

Hi Orenus,

This may help. So I have a volume called test-snap which has 2 snapshots called test-snap_1 and test-snap_2

First I defined a volume object

for volume in system.volumes: ... if str(volume.get_name())==str('test-snap'): ... v = volume ... v

#Then I can iterate the get_snapshots() for snapshot in v.get_snapshots(): ... snapshot.get_name() ... u'test-snap_1' u'test-snap_2'
daramosch commented 5 years ago

Less lines using .find

for volume in system.volumes.find(name='test-snap'): ... for snapshots in volume.get_snapshots(): ... snapshot.get_name() ... u'test-snap_2' u'test-snap_2'

Orenus commented 5 years ago

@daramosch thanks a lot! it helped. I got misdirected by the not so elaborated documentation.

ayalash commented 5 years ago

@Orenus Your second try had a small mistake. You tried:

volume = system.volumes.find(name==volume_name)
system.volumes.find(parent_id=volume.id, type='snapshots')

But the type is called SNAPSHOT, not snapshots, so the second line should be changed to:

system.volumes.find(parent_id=vol.id, type='SNAPSHOT')

This will return a Query object, if you want the list of the snapshots, use the to_list method. So, the full code (for getting the list of snapshots) is:

volume = system.volumes.find(name==volume_name)
system.volumes.find(parent_id=volume.id, type='SNAPSHOT').to_list()

You can use:

volume.get_children().to_list()

As well.

ayalash commented 5 years ago

@daramosch Please notice that find is not only "less lines" but better for memory consumption and execution time as well. The find method perform the filtering through API (on system side) while iterating all the volumes in the system and then checking if the name is the requested one, is performed on client side.