Skip to content

Commit

Permalink
Added disk mount and umount for routines
Browse files Browse the repository at this point in the history
  • Loading branch information
delano committed May 8, 2009
1 parent 9736350 commit 67ce60b
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGES.txt
Expand Up @@ -7,7 +7,7 @@ RUDY, CHANGES
* TODO: Support for product codes
* TODO: Tests for AWS HTTPS

#### 0.7.4 (2009-05-??) ###############################
#### 0.7.4 (2009-05-08) ###############################

* CHANGE: Keypairs now include zone. This was necessary to allow US and EU keypairs to
be stored in the same directory.
Expand Down
9 changes: 3 additions & 6 deletions Rudyfile
Expand Up @@ -135,17 +135,14 @@ routines do
uptime
end
disks do
destroy "/rudy/disk1" # Unmount and destroy the EBS volume
destroy "/rudy/disk1"
end
end

chained do
depends :uptime
script :rudy do
ls :l, '/'
end
disks do
create "/rudy/disk1" # Unmount and destroy the EBS volume
umount "/rudy/disk2"
mount "/rudy/disk3"
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/rudy/config/objects.rb
Expand Up @@ -117,6 +117,8 @@ class Routines < Caesars
forced_hash :create
forced_hash :destroy
forced_hash :restore
forced_hash :umount
forced_hash :unmount
forced_hash :mount

# Script blocks
Expand Down
84 changes: 83 additions & 1 deletion lib/rudy/routines/helpers/diskhelper.rb
Expand Up @@ -124,7 +124,89 @@ def create(disks)

end
end

def mount(disks)
rdisk = Rudy::Disks.new
disks.each_pair do |path, props|
adisk = Rudy::Disk.new(path, props[:size], props[:device], @machine.position)
disk = rdisk.get(adisk.name)
if disk == nil
puts "Not found: #{adisk.name}".color(:red)
return
end

msg = "Attaching #{disk.awsid} to #{@machine.awsid}... "
disk.attach(@machine.awsid)
Rudy::Utils.waiter(2, 10, STDOUT, msg) {
disk.attached?
}

sleep 2

begin
@rbox.mkdir(:p, disk.path)

print "Mounting at #{disk.path}... "

ret = @rbox.mount(:t, disk.fstype, disk.device, disk.path)
print_response ret
if ret.exit_code > 0
STDERR.puts "Error creating disk".color(:red)
return
else
puts "done"
end
disk.mounted = true
disk.save

rescue Net::SSH::AuthenticationFailed, Net::SSH::HostKeyMismatch => ex
STDERR.puts "Error creating disk".color(:red)
STDERR.puts ex.message.color(:red)
rescue Rye::CommandNotFound => ex
puts " CommandNotFound: #{ex.message}".color(:red)

rescue
STDERR.puts "Error creating disk" .color(:red)
Rudy::Utils.bug
end

end
end


def umount(disks)
rdisk = Rudy::Disks.new
disks.each_pair do |path, props|
adisk = Rudy::Disk.new(path, props[:size], props[:device], @machine.position)
disk = rdisk.get(adisk.name)
if disk == nil
puts "Not found: #{adisk.name}".color(:red)
return
end

if disk.mounted?
print "Unmounting #{disk.path}..."
execute_rbox_command { @rbox.umount(disk.path) }
puts " done"
sleep 0.5
end

sleep 2

if disk.attached?
msg = "Detaching #{disk.awsid}..."
disk.detach
Rudy::Utils.waiter(2, 60, STDOUT, msg) {
disk.available?
}
sleep 0.5
end


end
end
alias_method :unmount, :umount

def destroy(disks)
rdisk = Rudy::Disks.new

Expand Down Expand Up @@ -159,6 +241,6 @@ def destroy(disks)

end
end

end
end;end

0 comments on commit 67ce60b

Please sign in to comment.