Beispiel #1
0
    def delete_snapshot(self, hostname, timestamp):
        try:
            if not Utility.is_file_path_safe(hostname) or str(timestamp).count('.') > 1:
                return Utility.return_json(0, 'Invalid hostname')

            os.remove(f"snapshots/compiled_snapshots/{hostname}_{timestamp}.xml")

        except:
            return Utility.return_json(0, 'Unable to delete snapshot, probably non-existent')

        return Utility.return_json(1, 'Snapshot deleted')
Beispiel #2
0
    def get_snapshots(self, hostname):
        if not Utility.is_file_path_safe(hostname):
            raise Exception('Hostname was invalid')

        snap_files = sorted(glob(f"snapshots/compiled_snapshots/{hostname}_*.xml"), reverse=True)

        for iter, file in enumerate(snap_files):
            snap_files[iter] = (os.path.basename(str(file)))
            (temp_hostname, temp_timestamp) = snap_files[iter].split('_')
            temp_timestamp = temp_timestamp.strip('.xml')
            snap_files[iter] = [temp_hostname, temp_timestamp]
        return snap_files