Skip to content

Commit

Permalink
Re-added create and destroy actions for "rudy disks"
Browse files Browse the repository at this point in the history
  • Loading branch information
delano committed Aug 25, 2009
1 parent 161a907 commit 2749dff
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -20,6 +20,8 @@ RUDY, CHANGES
* ADDED: "rudy keypairs"
* ADDED: "rudy networks --authorize"
* ADDED: "rudy networks --revoke"
* ADDED: "rudy disks --create"
* ADDED: "rudy disks --destroy"
* ADDED: Support for attaching and formating disks in Windows.


Expand Down
37 changes: 34 additions & 3 deletions lib/rudy/cli/disks.rb
Expand Up @@ -61,22 +61,53 @@ def disks_wash
end

def disks_create_valid?
@mlist = Rudy::Machines.list
raise "No machines" if @mlist.nil?

raise "No path provided" unless @argv.first
if Rudy::Disks.exists? @argv.first
raise "Disk exists" if Rudy::Disks.get(@argv.first).volume_attached?
end
raise "No size provided" unless @option.size

@mlist = Rudy::Machines.list
raise "No machines" if @mlist.nil?
true
end


def disks_create
@mlist.each do |m|
p Rudy::Routines::Handlers::RyeTools.create_box m
puts machine_separator m.name, m.instid
rbox = Rudy::Routines::Handlers::RyeTools.create_box m
rbox.stash = m
disk = Rudy::Disk.new m.position, @argv.first
disk.device = @option.device if @option.device
disk.size = @option.size if @option.size
li "Creating disk: #{disk.name}"
Rudy::Routines::Handlers::Disks.create rbox, disk, 0
end
end


def disks_destroy_valid?
@mlist = Rudy::Machines.list
raise "No machines" if @mlist.nil?

raise "No path provided" unless @argv.first
raise "Disk does not exist" unless Rudy::Disks.exists? @argv.first

true
end

def disks_destroy
@mlist.each do |m|
puts machine_separator m.name, m.instid
rbox = Rudy::Routines::Handlers::RyeTools.create_box m
rbox.stash = m
disk = Rudy::Disk.new m.position, @argv.first
li "Destroying disk: #{disk.name}"
Rudy::Routines::Handlers::Disks.destroy rbox, disk, 0
end
end
end
end
end
4 changes: 4 additions & 0 deletions lib/rudy/disks.rb
Expand Up @@ -21,5 +21,9 @@ def from_hash(h)
Rudy::Disk.from_hash h
end

def exists?(path)
!get(path).nil?
end

end
end
2 changes: 1 addition & 1 deletion lib/rudy/metadata/machine.rb
Expand Up @@ -85,7 +85,7 @@ def to_s(*args)
end

def rbox
r = Rye::Box.new self.name,
r = Rudy::Routines::Handlers::RyeTools.create_box self
end


Expand Down
20 changes: 6 additions & 14 deletions lib/rudy/routines/handlers/disks.rb
Expand Up @@ -9,6 +9,12 @@ module Disks

Rudy::Routines.add_handler :disks, self

Rye::Cmd.add_command(:rudy_rm, 'rm')
Rye::Cmd.add_command(:rudy_mkfs, 'mkfs')
Rye::Cmd.add_command(:rudy_blkid, 'blkid')
Rye::Cmd.add_command(:rudy_format, 'C:/windows/system32/format.com')
Rye::Cmd.add_command(:rudy_diskpart, 'C:/windows/system32/diskpart.exe')

def raise_early_exceptions(type, batch, rset, lbox, argv=nil)

end
Expand Down Expand Up @@ -37,14 +43,6 @@ def execute(type, routine, rset, lbox, argv=nil)
rset.add_key user_keypairpath(current_machine_user)
rset.switch_user current_machine_user

# We need to add mkfs since it's not enabled by default.
# We prepend the command with rudy_ so we can delete it.
Rye::Cmd.add_command(:rudy_rm, 'rm')
Rye::Cmd.add_command(:rudy_mkfs, 'mkfs')
Rye::Cmd.add_command(:rudy_blkid, 'blkid')
Rye::Cmd.add_command(:rudy_format, 'C:/windows/system32/format.com')
Rye::Cmd.add_command(:rudy_diskpart, 'C:/windows/system32/diskpart.exe')

routine.each_pair do |action, disks|
unless respond_to?(action.to_sym)
Rudy::Huxtable.le %Q(DiskHelper: unknown action "#{action}")
Expand All @@ -66,12 +64,6 @@ def execute(type, routine, rset, lbox, argv=nil)

end

Rye::Cmd.remove_command(:rudy_rm)
Rye::Cmd.remove_command(:rudy_mkfs)
Rye::Cmd.remove_command(:rudy_blkid)
Rye::Cmd.remove_command(:rudy_format)
Rye::Cmd.remove_command(:rudy_diskpart)

rset.switch_user original_user
end

Expand Down
13 changes: 9 additions & 4 deletions lib/rudy/routines/handlers/rye.rb
Expand Up @@ -15,16 +15,21 @@ def create_box(hostname, opts={})
opts = {
:info => (@@global.verbose >= 3), # rudy -vvv
:debug => false,
:user => Rudy.sysinfo.user,
:user => :root,
:ostype => current_machine_os || :unix,
:impltype => :linux
}.merge opts

hostname = hostname.name if hostname.kind_of? Rudy::Machine
nickname = hostname
if hostname.kind_of? Rudy::Machine
hostname, nickname = hostname.dns_public, hostname.name
end

box = ::Rye::Box.new hostname, opts


box.nickname = nickname

box.add_key user_keypairpath(opts[:user])

# We define hooks so we can still print each command and its output
# when running the command blocks. NOTE: We only print this in
# verbosity mode.
Expand Down

0 comments on commit 2749dff

Please sign in to comment.