Methods
public instance
Public instance methods
associate_machines
()
[show source]
# File lib/rudy/cli/machines.rb, line 93 93: def associate_machines 94: 95: li "Assigning static IP addresses for:" 96: li @mlist.collect { |m| m.name } 97: 98: execute_check(:medium) 99: 100: @mlist.each do |m| 101: next if @mlist_static.member?(m) 102: address = @alist_unused.shift 103: address ||= Rudy::AWS::EC2::Addresses.create.ipaddress 104: li "Associating #{address} to #{m.name} (#{m.instid})" 105: Rudy::AWS::EC2::Addresses.associate(address, m.instid) 106: sleep 2 107: m.refresh! 108: end 109: 110: @alist = Rudy::AWS::EC2::Addresses.list || [] 111: @alist_used = @alist.select { |a| a.associated? } 112: @alist_instids = @alist_used.collect { |a| a.instid } 113: @mlist_static = @mlist.select do |m| 114: @alist_instids.member?(m.instid) 115: end 116: 117: unless @mlist_static.empty? 118: @mlist_static.each do |m| 119: li "%s: %s" % [m.name, m.dns_public] 120: end 121: end 122: end
associate_machines_valid?
()
[show source]
# File lib/rudy/cli/machines.rb, line 48 48: def associate_machines_valid? 49: @mlist = get_machines 50: @alist = Rudy::AWS::EC2::Addresses.list || [] 51: @alist_used = @alist.select { |a| a.associated? } 52: @alist_unused = @alist.select { |a| !a.associated? } 53: @alist_unused.collect! { |a| a.ipaddress } 54: @alist_instids = @alist_used.collect { |a| a.instid } 55: @mlist_static = @mlist.select do |m| 56: @alist_instids.member?(m.instid) 57: end 58: 59: unless @@global.force 60: unless @mlist_static.empty? 61: msg = "Some machines already have static IP addresses: #{$/}" 62: msg << @mlist_static.collect { |m| "#{m.name}: #{m.dns_public}" }.join($/) 63: raise Rudy::Error, msg 64: end 65: 66: if !@argv.empty? && @mlist.size > @argv.size 67: msg = "You supplied #{@argv.size} addresses for #{@mlist.size} " 68: msg << "machines. Try: rudy --force machines -S #{@argv.join(' ')}" 69: raise Rudy::Error, msg 70: end 71: 72: if @alist_unused.size > 0 && @alist_unused.size < @mlist.size 73: msg = "There are only #{@alist_unused.size} available addresses for " 74: msg << "#{@mlist.size} machines. Try: rudy --force machines -S #{@argv.join(' ')}" 75: raise Rudy::Error, msg 76: end 77: end 78: 79: @argv.each do |address| 80: unless Rudy::AWS::EC2::Addresses.exists?(address) 81: raise "#{address} is not allocated to you" 82: end 83: if Rudy::AWS::EC2::Addresses.associated?(address) 84: raise "#{address} is already associated!" 85: end 86: end 87: 88: @alist_unused = @argv unless @argv.empty? 89: 90: true 91: end
available_machines
()
[show source]
# File lib/rudy/cli/machines.rb, line 180 180: def available_machines 181: mlist = get_machines 182: mlist.each do |m| 183: print "#{m.name}: " 184: m.refresh! 185: port = m.windows? ? 3389 : 22 186: Rudy::Utils.waiter(2, 60, STDOUT, nil, 0) { 187: Rudy::Utils.service_available?(m.dns_public, port) 188: } 189: available = Rudy::Utils.service_available?(m.dns_public, port) 190: li available ? 'up' : 'down' 191: end 192: 193: end
disassociate_machines
()
[show source]
# File lib/rudy/cli/machines.rb, line 138 138: def disassociate_machines 139: if @mlist_static.empty? 140: li "No machines in #{current_group_name} have static IP addresses" 141: else 142: li "The following machines will be updated:" 143: li @mlist_static.collect { |m| m.name } 144: li "NOTE: Unassigned IP addresses are not removed from your account" 145: execute_check(:medium) 146: @mlist_static.each do |m| 147: address = Resolv.getaddress m.dns_public 148: li "Disassociating #{address} from #{m.name} (#{m.instid})" 149: Rudy::AWS::EC2::Addresses.disassociate(address) 150: end 151: end 152: end
disassociate_machines_valid?
()
[show source]
# File lib/rudy/cli/machines.rb, line 125 125: def disassociate_machines_valid? 126: @mlist = get_machines 127: @alist = Rudy::AWS::EC2::Addresses.list || [] 128: @alist_used = @alist.select { |a| a.associated? } 129: @alist_instids = @alist_used.collect { |a| a.instid } 130: @mlist_static = @mlist.select do |m| 131: @alist_instids.member?(m.instid) 132: end 133: raise NoMachines, current_group_name if @mlist.empty? 134: true 135: end
machines
()
[show source]
# File lib/rudy/cli/machines.rb, line 7 7: def machines 8: mlist = get_machines 9: print_stobjects mlist 10: end
machines_console
()
[show source]
# File lib/rudy/cli/machines.rb, line 12 12: def machines_console 13: mlist = get_machines 14: mlist.each do |machine| 15: li machine_separator(machine.name, machine.instid) 16: li machine.get_console 17: end 18: end
machines_password
()
[show source]
# File lib/rudy/cli/machines.rb, line 20 20: def machines_password 21: mlist = get_machines 22: mlist.each do |machine| 23: li machine_separator(machine.name, machine.instid) 24: li "Password for %s: %s" % [machine.dns_public, machine.get_password] 25: end 26: Rudy::Routines::Handlers::Group.authorize rescue nil 27: end
machines_wash
()
[show source]
# File lib/rudy/cli/machines.rb, line 29 29: def machines_wash 30: mlist = get_machines 31: dirt = mlist.select { |m| !m.instance_running? } 32: 33: if dirt.empty? 34: li "Nothing to wash in #{current_machine_group}" 35: return 36: end 37: 38: li "The following machine metadata will be deleted:".bright 39: li dirt.collect {|m| m.name.bright } 40: execute_check(:medium) 41: 42: dirt.each do |m| 43: m.destroy 44: end 45: 46: end
ssh
()
[show source]
# File lib/rudy/cli/machines.rb, line 201 201: def ssh 202: 203: 204: # TODO: Give this method a good look over 205: pkey = current_user_keypairpath 206: unless pkey 207: li "No private key configured for #{current_machine_user} in #{current_machine_group}" 208: end 209: 210: # Options to be sent to Rye::Box 211: rye_opts = { :user => current_machine_user, :keys => [], :debug => nil, :info => STDOUT } 212: if File.exists? pkey 213: #raise "Cannot find file #{pkey}" unless File.exists?(pkey) 214: if Rudy.sysinfo.os != :windows && File.stat(pkey).mode != 33152 215: raise InsecureKeyPermissions, pkey 216: end 217: rye_opts[:keys] << pkey 218: end 219: 220: local_keys = Rye.keys 221: rye_opts[:keys] += local_keys if local_keys.is_a?(Array) 222: 223: li "# SSH OPTS", rye_opts.to_yaml if @@global.verbose > 3 224: 225: # The user specified a command to run. We won't create an interactive 226: # session so we need to prepare the command and its arguments 227: if @argv.first 228: command, command_args = @argv.shift, @argv || [] 229: Rudy::Huxtable.ld "COMMAND: #{command} #{command_args.join(' ')}" if @@global.verbose > 1 230: 231: # otherwise, we'll open an ssh session or print command 232: else 233: command, command_args = :interactive_ssh, @option.print.nil? 234: end 235: 236: if command == :interactive_ssh && @global.parallel 237: raise "Cannot run interactive sessions in parallel" 238: end 239: 240: checked = false 241: lt = get_machines 242: 243: rset = Rye::Set.new(current_machine_group, :parallel => @global.parallel) 244: lt.each do |machine| 245: if Rudy::Machine === machine 246: machine.refresh! # make sure we have the latest DNS info 247: rbox = Rye::Box.new(machine.dns_public, rye_opts) 248: rbox.nickname = machine.name 249: instid = machine.instid 250: else 251: rbox = Rye::Box.new(machine, rye_opts) 252: rbox.nickname = machine 253: instid = '' 254: end 255: 256: if command == :interactive_ssh 257: # Print header 258: if @@global.quiet 259: print "You are #{rye_opts[:user].to_s.bright}. " if !checked # only the 1st 260: else 261: li machine_separator(rbox.nickname, instid) 262: li "Connecting #{rye_opts[:user].to_s.bright}@#{rbox.host} " 263: li 264: end 265: else 266: unless @global.parallel 267: rbox.pre_command_hook do |cmd,user,host,nickname| 268: print_command user, nickname, cmd 269: end 270: end 271: rbox.post_command_hook do |ret| 272: print_response ret 273: end 274: end 275: 276: # Make sure we want to run this command on all instances 277: if !checked && command != :interactive_ssh 278: execute_check(:low) if current_machine_user == "root" 279: checked = true 280: end 281: 282: # Open the connection and run the command 283: if command == :interactive_ssh 284: rbox.send(command, command_args) 285: else 286: rset.add_box rbox 287: end 288: end 289: 290: rset.send(command, command_args) unless command == :interactive_ssh 291: 292: end
ssh_valid?
()
[show source]
# File lib/rudy/cli/machines.rb, line 196 196: def ssh_valid? 197: #raise "SSH not supported on Windows" if current_machine_os.to_s == 'windows' 198: true 199: end
update_machines
()
[show source]
# File lib/rudy/cli/machines.rb, line 154 154: def update_machines 155: mlist = get_machines 156: rset = Rye::Set.new(current_group_name, :parallel => @@global.parallel, :user => current_machine_root) 157: rset.add_key user_keypairpath(current_machine_root) 158: os = current_machine_os 159: mlist.each do |m| 160: li "Updating #{m.name}" 161: rbox = Rudy::Routines::Handlers::RyeTools.create_box m 162: rbox.stash = m 163: m.refresh! 164: rset.add_boxes rbox 165: if m.os.to_s != os.to_s 166: li "os: #{os}" 167: m.os = os 168: end 169: m.save :replace 170: end 171: 172: unless os.to_s == 'windows' 173: li "Updating hostnames for #{current_group_name}" 174: Rudy::Routines::Handlers::Host.set_hostname rset 175: li rset.hostname.flatten 176: end 177: 178: end