def listsnapshots(self, sortbycreation=False, sortreverse=False):
output = self._srv.invoke("volume-size", "volume", self._volname)
self._check_netapp_error(output, "Failed to get volume size information")
volsize = self._volsize_to_num(output.child_get_string("volume-size"))
pct_limit = round(2147483648*100/(volsize/self._blocksize))
output = self._srv.invoke("snapshot-list-info", "volume", self._volname)
self._check_netapp_error(output, "Failed to list snapshots")
snapshotlist = output.child_get("snapshots")
snapshots = []
if (snapshotlist is not None and snapshotlist):
for ss in snapshotlist.children_get():
snapshots.append( {'id': ss.child_get_string("name"),
'creation': datetime.utcfromtimestamp(float(ss.child_get_int("access-time"))),
'numclones': 1 if ss.child_get_string("busy") == "true" else 0,
'space_total': ss.child_get_int("cumulative-total")*self._blocksize if ss.child_get_int("cumulative-percentage-of-total-blocks") < pct_limit else round(volsize*ss.child_get_int("cumulative-percentage-of-total-blocks")/100),
'space_unique': ss.child_get_int("total")*self._blocksize if ss.child_get_int("percentage-of-total-blocks") < pct_limit else round(volsize*ss.child_get_int("percentage-of-total-blocks")/100)
} )
if not sortbycreation:
return snapshots
else:
return sorted(snapshots, key=operator.itemgetter('creation'), reverse=sortreverse)
评论列表
文章目录