Permalink
Browse files

ADDED: "rudy machines -S" to create static IP addresses

  • Loading branch information...
1 parent e30aa2f commit 65f1781559baa82b41fb967d88734bec78d6ba2a @delano delano committed Aug 3, 2009
Showing with 103 additions and 20 deletions.
  1. +1 −0 CHANGES.txt
  2. +1 −0 README.rdoc
  3. +23 −16 bin/rudy
  4. +1 −1 lib/rudy/cli/execbase.rb
  5. +73 −1 lib/rudy/cli/machines.rb
  6. +4 −2 lib/rudy/cli/status.rb
View
@@ -18,6 +18,7 @@ RUDY, CHANGES
* ADDED: "rudy machines -A" to display available machines
* ADDED: "rudy status" to display all EC2 objects
* ADDED: "rudy machines -U" to update hostnames
+* ADDED: "rudy machines -S" to create static IP addresses
* ADDED: Rudy::Routines::Handlers::Disks.mount? etc... methods
View
@@ -119,6 +119,7 @@ NOTE: <em>If you are not installing via RubyGems, you need to make sure the depe
== Thanks
+* Kalin Harvey for all the feedback
* The Rilli.com[http://rilli.com] team
* Adam Bognar
* Andrew Simpson
View
@@ -34,24 +34,24 @@ class RudyCLI < Rudy::CLI::Base
global :P, :parallel, "Execute remote commands in parallel (EXPERIMENTAL)."
global :F, :force, "Force an action despite warnings"
+
# ------------------------------------------ RUDY OBJECTS --------
# ------------------------------------------------------------------
- about "View Routines"
- usage "rudy routines"
- usage "rudy routines -l"
- option :l, :all, "Display routines for all environments and roles"
- command :routines => Rudy::CLI::Routines
- command_alias :routines, :r
-
about "View Machines"
usage "rudy"
usage "rudy machines"
usage "rudy machines -l"
+ usage "rudy machines -U"
+ usage "rudy machines -A"
+ usage "rudy machines -S [static ip address]"
+ usage "rudy machines -D"
option :l, :all, "Display machines for all environments and roles"
action :W, :wash, "Wash machine metadata"
action :A, :available, "Display availablity"
action :U, :update, "Update machines based on configuration"
+ action :S, :static, "Create static IP addresses or display existing ones"
+ action :D, :dynamic, "Delete static IP addresses"
command :machines => Rudy::CLI::Machines
command_alias :machines, :m
@@ -82,7 +82,7 @@ class RudyCLI < Rudy::CLI::Base
argv :oid
command :metadata => Rudy::CLI::Metadata
- about "View Network configuration"
+ about "View Network configuration (local network only)"
usage "rudy networks"
usage "rudy networks -L"
usage "rudy networks -L -i"
@@ -95,18 +95,17 @@ class RudyCLI < Rudy::CLI::Base
command :networks => Rudy::CLI::Networks
command_alias :networks, :n
- about "Log in to a machine"
- command :ssh => Rudy::CLI::Machines
-
- #about "Open the machine in your default browser (OSX only)"
- #option :s, :https, "Use HTTPS"
- #option :p, :port, Integer, "Port"
- #command :open => Rudy::CLI::Candy
-
# ----------------------------------------- RUDY ROUTINES --------
# ------------------------------------------------------------------
+ about "View Routines"
+ usage "rudy routines"
+ usage "rudy routines -l"
+ option :l, :all, "Display routines for all environments and roles"
+ command :routines => Rudy::CLI::Routines
+ command_alias :routines, :r
+
# A "do nothing" routine. Passthrough simply executes a routine
# config block. Drydock's trawler uses this for unknown commands.
about "A passthrough for custom routines"
@@ -137,6 +136,14 @@ class RudyCLI < Rudy::CLI::Base
option :l, :all, "Include all regions"
command :status => Rudy::CLI::Status
+ about "Log in to a machine"
+ command :ssh => Rudy::CLI::Machines
+
+ #about "Open the machine in your default browser (OSX only)"
+ #option :s, :https, "Use HTTPS"
+ #option :p, :port, Integer, "Port"
+ #command :open => Rudy::CLI::Candy
+
usage "rudy [-f config-file] config [param-name]"
about "Check Rudy configuration."
option :l, :all, "Display all configs for all machines"
@@ -6,7 +6,7 @@ module Rudy::CLI
class Base
extend Drydock
- debug :on
+ debug :off
before do |obj|
# Don't print Rudy header unless requested to
@@ -45,6 +45,78 @@ def machines_wash
end
+ def static_machines_valid?
+ @mlist = Rudy::Machines.list || []
+ @alist = Rudy::AWS::EC2::Addresses.list || []
+ @alist_used = @alist.select { |a| a.associated? }
+ @alist_unused = @alist.select { |a| !a.associated? }
+ @alist_unused.collect! { |a| a.ipaddress }
+ @alist_instids = @alist_used.collect { |a| a.instid }
+ @mlist_static = @mlist.select do |m|
+ @alist_instids.member?(m.instid)
+ end
+
+ unless @@global.force
+ unless @mlist_static.empty?
+ msg = "Some machines already have static IP addresses: #{$/}"
+ msg << @mlist_static.collect { |m| "#{m.name}: #{m.dns_public}" }.join($/)
+ raise Rudy::Error, msg
+ end
+
+ if !@argv.empty? && @mlist.size > @argv.size
+ msg = "You supplied #{@argv.size} addresses for #{@mlist.size} "
+ msg << "machines. Try: rudy --force machines -S #{@argv.join(' ')}"
+ raise Rudy::Error, msg
+ end
+
+ if @alist_unused.size > 0 && @alist_unused.size < @mlist.size
+ msg = "There are only #{@alist_unused.size} available addresses for "
+ msg << "#{@mlist.size} machines. Try: rudy --force machines -S #{@argv.join(' ')}"
+ raise Rudy::Error, msg
+ end
+ end
+
+ @argv.each do |address|
+ unless Rudy::AWS::EC2::Addresses.exists?(address)
+ raise "#{address} is not allocated to you"
+ end
+ if Rudy::AWS::EC2::Addresses.associated?(address)
+ raise "#{address} is already associated!"
+ end
+ end
+
+ @alist_unused = @argv unless @argv.empty?
+
+ true
+ end
+
+ def static_machines
+
+ @mlist.each do |m|
+ next if @mlist_static.member?(m)
+ address = @alist_unused.shift
+ puts "Associating #{address} to #{m.name} (#{m.instid})"
+ Rudy::AWS::EC2::Addresses.associate(address, m.instid)
+ sleep 2
+ m.refresh!
+ end
+
+ @alist = Rudy::AWS::EC2::Addresses.list || []
+ @alist_used = @alist.select { |a| a.associated? }
+ @alist_instids = @alist_used.collect { |a| a.instid }
+ @mlist_static = @mlist.select do |m|
+ @alist_instids.member?(m.instid)
+ end
+
+ unless @mlist_static.empty?
+ @mlist_static.each do |m|
+ puts "%s: %s" % [m.name, m.dns_public]
+ end
+ end
+ end
+
+ def dynamic_machines
+ end
def update_machines
fields, less = {}, []
@@ -53,7 +125,7 @@ def update_machines
rset = Rye::Set.new(current_group_name, :parallel => @@global.parallel, :user => 'root')
mlist.each do |m|
m.refresh!
- rbox = Rye::Box.new( m.dns_public, :user => 'root')
+ rbox = Rye::Box.new(m.dns_public, :user => 'root')
rbox.add_key user_keypairpath('root')
rbox.nickname = m.name
rbox.stash = m
@@ -29,7 +29,7 @@ def process_region(region)
puts " Volumes".bright
(Rudy::AWS::EC2::Volumes.list || []).collect do |vol|
- puts " %s: %sGB; %s (%s); %s" % [vol.awsid, vol.size, vol.status, vol.instid, vol.created]
+ puts " %s (%s): %sGB; %s" % [vol.awsid, vol.instid || vol.status, vol.size, vol.created]
end
puts " Snapshots".bright
@@ -38,7 +38,9 @@ def process_region(region)
end
puts " Addresses".bright
- puts (Rudy::AWS::EC2::Addresses.list || []).collect { |o| " #{o.address}" }
+ (Rudy::AWS::EC2::Addresses.list || []).collect do |o|
+ puts " %s (%s)" % [o.ipaddress, o.instid || 'available']
+ end
puts " Groups".bright
puts Rudy::AWS::EC2::Groups.list.collect { |o| " #{o.name}" }

0 comments on commit 65f1781

Please sign in to comment.