def import_snapshots(share): snaps_d = snaps_info(share.pool.mnt_pt, share.name) snaps = [s.name for s in Snapshot.objects.filter(share=share)] for s in snaps: if s not in snaps_d: logger.debug("Removing, missing on disk, snapshot db entry ({}) " "from share ({}).".format(s, share.name)) Snapshot.objects.get(share=share, name=s).delete() for s in snaps_d: if s in snaps: so = Snapshot.objects.get(share=share, name=s) else: logger.debug("Adding, missing in db, on disk snapshot ({}) " "against share ({}).".format(s, share.name)) so = Snapshot( share=share, name=s, real_name=s, writable=snaps_d[s][1], qgroup=snaps_d[s][0], ) rusage, eusage = volume_usage(share.pool, snaps_d[s][0]) if rusage != so.rusage or eusage != so.eusage: so.rusage = rusage so.eusage = eusage update_shareusage_db(s, rusage, eusage) else: update_shareusage_db(s, rusage, eusage, UPDATE_TS) so.save()
def import_snapshots(share): snaps_d = snaps_info('%s%s' % (settings.MNT_PT, share.pool.name), share.name) snaps = [s.name for s in Snapshot.objects.filter(share=share)] for s in snaps: if (s not in snaps_d): Snapshot.objects.get(share=share, name=s).delete() for s in snaps_d: if (s in snaps): so = Snapshot.objects.get(share=share, name=s) else: so = Snapshot(share=share, name=s, real_name=s, writable=snaps_d[s][1], qgroup=snaps_d[s][0]) rusage, eusage = volume_usage(share.pool, snaps_d[s][0]) ts = datetime.utcnow().replace(tzinfo=utc) if (rusage != so.rusage or eusage != so.eusage): so.rusage = rusage so.eusage = eusage su = ShareUsage(name=s, r_usage=rusage, e_usage=eusage, ts=ts) su.save() else: try: su = ShareUsage.objects.filter(name=s).latest('id') su.ts = ts su.count += 1 except ShareUsage.DoesNotExist: su = ShareUsage(name=s, r_usage=rusage, e_usage=eusage, ts=ts) finally: su.save() so.save()
def import_snapshots(share): snaps_d = snaps_info('%s%s' % (settings.MNT_PT, share.pool.name), share.name) snaps = [s.name for s in Snapshot.objects.filter(share=share)] for s in snaps: if (s not in snaps_d): logger.debug('Removing, missing on disk, snapshot db entry ({}) ' 'from share ({}).'.format(s, share.name)) Snapshot.objects.get(share=share, name=s).delete() for s in snaps_d: if (s in snaps): so = Snapshot.objects.get(share=share, name=s) else: logger.debug('Adding, missing in db, on disk snapshot ({}) ' 'against share ({}).'.format(s, share.name)) so = Snapshot(share=share, name=s, real_name=s, writable=snaps_d[s][1], qgroup=snaps_d[s][0]) rusage, eusage = volume_usage(share.pool, snaps_d[s][0]) if (rusage != so.rusage or eusage != so.eusage): so.rusage = rusage so.eusage = eusage update_shareusage_db(s, rusage, eusage) else: update_shareusage_db(s, rusage, eusage, UPDATE_TS) so.save()
def import_snapshots(share): snaps_d = snaps_info('%s%s' % (settings.MNT_PT, share.pool.name), share.name) snaps = [s.name for s in Snapshot.objects.filter(share=share)] for s in snaps: if (s not in snaps_d): Snapshot.objects.get(share=share, name=s).delete() for s in snaps_d: if (s in snaps): so = Snapshot.objects.get(share=share, name=s) else: so = Snapshot(share=share, name=s, real_name=s, writable=snaps_d[s][1], qgroup=snaps_d[s][0]) rusage, eusage = volume_usage(share.pool, snaps_d[s][0]) if (rusage != so.rusage or eusage != so.eusage): so.rusage = rusage so.eusage = eusage update_shareusage_db(s, rusage, eusage) else: update_shareusage_db(s, rusage, eusage, UPDATE_TS) so.save()