Methods
public instance
Public instance methods
consoles
()
[show source]
# File lib/rudy/cli/aws/ec2/instances.rb, line 124 124: def consoles 125: opts = {} 126: opts[:group] = @option.group if @option.group 127: opts[:id] = @argv.instid if @argv.instid 128: opts[:id] &&= [opts[:id]].flatten 129: 130: lt = Rudy::AWS::EC2::Instances.list_group(opts[:group], :any, opts[:id]) do |inst| 131: li instance_separator(inst.dns_public || inst.state, inst.awsid) 132: console = Rudy::AWS::EC2::Instances.console(inst.awsid) 133: output = console ? Base64.decode64(console) : "Unavailable" 134: 135: # The linux console can include ANSI escape codes for color, 136: # clear screen etc... We strip them out to get rid of the 137: # clear specifically. Otherwise the display is messed! 138: output &&= output.noansi 139: 140: li output 141: 142: if output.match(/<Password>(.+)<\/Password>/m) # /m, match multiple lines 143: li 144: if @@global.pkey 145: encrtypted_text = ($1 || '').strip 146: k = Rye::Key.from_file(@@global.pkey) 147: pword = k.decrypt(encrtypted_text) 148: answer = "%s: %s" % ['password', pword] 149: Annoy.timed_display(answer, STDERR, 10) 150: li 151: else 152: li "Please supply a private key path to decode the administrator password" 153: li "rudy-ec2 -k path/2/privatekey console [-g group] [instance ID]" 154: end 155: end 156: 157: end 158: 159: end
consoles_valid?
()
[show source]
# File lib/rudy/cli/aws/ec2/instances.rb, line 116 116: def consoles_valid? 117: if @@global.pkey 118: raise "Cannot find file #{@@global.pkey}" unless File.exists?(@@global.pkey) 119: raise "Insecure permissions for #{@@global.pkey}" unless (File.stat(@@global.pkey).mode & 600) == 0 120: end 121: raise "No instances" unless Rudy::AWS::EC2::Instances.any? 122: true 123: end
instances_create
()
[show source]
# File lib/rudy/cli/aws/ec2/instances.rb, line 27 27: def instances_create 28: 29: opts = { # Defaults 30: :group => 'default', 31: :size => 'm1.small', 32: :zone => @@global.zone 33: } 34: 35: if @option.address 36: raise "Cannot specify both -a and -n" if @option.newaddress 37: unless Rudy::AWS::EC2::Addresses.exists?(@option.address) 38: raise "#{@option.address} is not allocated to you" 39: end 40: if Rudy::AWS::EC2::Addresses.associated?(@option.address) 41: raise "#{@option.address} is already associated!" 42: end 43: end 44: 45: # These can be sent directly to EC2 class 46: [:group, :ami, :size, :keypair, :private].each do |n| 47: opts[n] = @option.send(n) if @option.send(n) 48: end 49: 50: li "Creating #{opts[:size]} instance in #{@@global.zone}" 51: 52: unless opts[:keypair] 53: li "You did not specify a keypair. Unless you've prepared a user account".bright 54: li "on this image (#{opts[:ami]}) you will not be able to log in to it.".bright 55: exit unless Annoy.proceed?(:low) 56: end 57: 58: instances = Rudy::AWS::EC2::Instances.list_group(opts[:group], :running) 59: 60: if instances && instances.size > 0 61: instance_count = (instances.size == 1) ? 'is 1 instance' : "are #{instances.size} instances" 62: li "There #{instance_count} running in the #{opts[:group]} group." 63: exit unless Annoy.proceed?(:low) 64: end 65: 66: if @option.newaddress 67: print "Creating address... " 68: address = Rudy::AWS::EC2::Addresses.create 69: li "#{address.ipaddress}" 70: @option.address = address.ipaddress 71: end 72: 73: execute_action do 74: first_instance = true 75: Rudy::AWS::EC2::Instances.create(opts) do |inst| # Rudy::AWS::EC2::Instance objects 76: 77: # Assign IP address to only the first instance 78: if first_instance && @option.address 79: li "Associating #{@option.address} to #{inst.awsid}" 80: Rudy::AWS::EC2::Addresses.associate(@option.address, inst.awsid) 81: first_instance = false 82: end 83: 84: print_stobject(inst) 85: end 86: end 87: end
instances_create_valid?
()
[show source]
# File lib/rudy/cli/aws/ec2/instances.rb, line 14 14: def instances_create_valid? 15: 16: raise "Cannot supply an instance ID" if @option.instid 17: 18: if @option.group 19: unless Rudy::AWS::EC2::Groups.exists?(@option.group) 20: raise "Group #{@option.group} does not exist" 21: end 22: end 23: 24: true 25: end
instances_destroy
()
[show source]
# File lib/rudy/cli/aws/ec2/instances.rb, line 108 108: def instances_destroy 109: instances_action :destroy 110: end
instances_restart
()
[show source]
# File lib/rudy/cli/aws/ec2/instances.rb, line 112 112: def instances_restart 113: instances_action :restart 114: end
instances_restart_valid?
()
[show source]
# File lib/rudy/cli/aws/ec2/instances.rb, line 89 89: def instances_restart_valid? 90: raise InstanceAndGroupError.new(nil, @alias) if @option.group && @argv.instid 91: raise NoInstanceError.new(nil, @alias) if !@option.group && !@argv.instid 92: 93: if @option.group 94: unless Rudy::AWS::EC2::Groups.exists?(@option.group) 95: raise "Group #{@option.group} does not exist" 96: end 97: end 98: 99: if @option.private 100: raise Drydock::OptsError.new(nil, @alias, "Cannot allocate public IP for private instance") if @option.address || @option.newadress 101: end 102: 103: raise "No instances" unless Rudy::AWS::EC2::Instances.any? 104: true 105: end
status
()
[show source]
# File lib/rudy/cli/aws/ec2/instances.rb, line 161 161: def status 162: opts = {} 163: 164: opts[:group] = @option.group if @option.group 165: opts[:state] = @option.state if @option.state 166: 167: # A nil value forces the @@ec2.instances.list to return all instances 168: if @option.all 169: opts[:state] = :any 170: opts[:group] = :any 171: end 172: 173: opts[:id] = @argv.instid if @argv.instid 174: opts[:id] &&= [opts[:id]].flatten 175: 176: ilist = Rudy::AWS::EC2::Instances.list_group(opts[:group], opts[:state], opts[:id]) 177: ilist.nil? ? li( "No instances running" ) : print_stobjects(ilist) 178: end