Created
July 20, 2009 15:23
-
-
Save jamesez/150395 to your computer and use it in GitHub Desktop.
Sort tapes. This is dumb.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'pp' | |
current_slots = Hash.new | |
current_index = Array.new | |
temp_slot = 281 | |
File.open("tapes-in-slots.txt") do |file| | |
file.each do |line| | |
line =~ /Storage Element (\d*):.*VolumeTag=(\w\w\w\d\d\d)(L.)?/ | |
current_slots[$2] = $1 | |
current_index[$1.to_i] = $2 | |
end | |
end | |
destination_slot = 1 | |
for prefix in [ "TSM", "LSI", "TAR", "GWZ", "SCR", "GWO", "OSB" ] do | |
for i in (1 .. 999) do | |
tape_name = "%s%0.3d" % [prefix, i] | |
next if current_slots[tape_name].nil? | |
# tape in right spot, move along | |
if current_slots[tape_name].to_i == destination_slot | |
destination_slot += 1 | |
next; | |
else | |
source_slot = current_slots[tape_name] | |
wrong_tape = current_index[destination_slot] | |
# there may not be a tape in the destination slot, so just move | |
if wrong_tape.nil? | |
puts "# Moving #{tape_name} from #{source_slot} to #{destination_slot}, which is currently empty." | |
puts "mtx -f /dev/sg7 transfer #{source_slot} #{destination_slot}" | |
current_index[destination_slot.to_i] = tape_name | |
current_slots[tape_name] = destination_slot | |
else | |
puts "# Moving #{tape_name} to #{destination_slot}. Currently in #{source_slot}, swapping with #{wrong_tape}." | |
# move slot destination_slot to temp_slot | |
puts "mtx -f /dev/sg7 transfer #{destination_slot} #{temp_slot}" | |
# move source_slot to destination_slot | |
puts "mtx -f /dev/sg7 transfer #{source_slot} #{destination_slot}" | |
# move temp_slot to source_slot | |
puts "mtx -f /dev/sg7 transfer #{temp_slot} #{source_slot}" | |
# update current_slots and current_index for source_slot | |
current_index[destination_slot.to_i] = tape_name | |
current_index[source_slot.to_i] = wrong_tape | |
current_slots[tape_name] = destination_slot | |
current_slots[wrong_tape] = source_slot | |
end | |
destination_slot += 1 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment