class Rudy::Machine
Attributes
available[W]
An ephemeral value which is set after checking whether the SSH daemon is running. By default this will be set to false but can be set to true to avoid checking again. See available?
instance[R]
Public Class Methods
new(position='01', opts={})
click to toggle source
-
position
-
opts
is a hash of machine options.
Valid options are:
-
:position
(overridden byposition
arg) -
:size
-
:os
-
:ami
-
:group
-
:keypair
-
:address
Calls superclass method
Rudy::Metadata.new
# File lib/rudy/metadata/machine.rb, line 57 def initialize(position='01', opts={}) opts = { :size => current_machine_size, :os => current_machine_os, :ami => current_machine_image, :group => current_group_name, :keypair => root_keypairname }.merge opts opts[:address] = current_machine_address opts[:position] || position super Rudy::Machines::RTYPE, opts # Rudy::Metadata#initialize @position = position # Defaults: @created = Time.now.utc @available = false postprocess end
Public Instance Methods
attached_volumes()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 181 def attached_volumes volumes = [] return volumes if @instid.nil? Rudy::AWS::EC2::Volumes.list_by_instance( @instid) || [] end
available?()
click to toggle source
See available
attribute
# File lib/rudy/metadata/machine.rb, line 228 def available?; @available; end
create()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 141 def create raise "#{name} is already running" if instance_running? # Options for Rudy::AWS::EC2::Instances#create opts = { :min => 1, :size => @size, :ami => @ami, :group => @group, :keypair => @keypair, :zone => @zone, :machine_data => self.generate_machine_data.to_yaml } ld "OPTS: #{opts.inspect}" Rudy::AWS::EC2::Instances.create(opts) do |inst| @instid = inst.awsid @created = @started = Time.now @state = inst.state # We need to be safe when creating machines because if an exception is # raised, instances will have been created but the calling class won't know. end self.save sleep 1 # Eventual consistency in SimpleDB self end
create_mock()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 131 def create_mock refresh! @dns_public = @dns_private = nil inst = Rudy::AWS::EC2::Instances.list(:running).first @instid = inst.awsid self.save :replace sleep 1 self end
default_device()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 214 def default_device windows? ? Rudy::DEFAULT_WINDOWS_DEVICE : Rudy::DEFAULT_LINUX_DEVICE end
default_fstype()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 210 def default_fstype windows? ? Rudy::DEFAULT_WINDOWS_FS : Rudy::DEFAULT_LINUX_FS end
destroy()
click to toggle source
Calls superclass method
Rudy::Metadata.destroy
# File lib/rudy/metadata/machine.rb, line 172 def destroy Rudy::AWS::EC2::Instances.destroy(@instid) if instance_running? super end
disks()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 93 def disks Rudy::Disks.list end
dns_private?()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 225 def dns_private?; !@dns_private.nil? && !@dns_private.empty?; end
dns_public?()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 224 def dns_public?; !@dns_public.nil? && !@dns_public.empty?; end
generate_machine_data()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 202 def generate_machine_data d = {} [:region, :zone, :environment, :role, :position].each do |k| d[k] = self.send k end d end
get_console()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 102 def get_console raise "Instance not running" unless instance_running? raw = Rudy::AWS::EC2::Instances.console @instid console = Base64.decode64(raw) # The linux console can include ANSI escape codes for color, # clear screen etc... We strip them out to get rid of the # clear specifically. Otherwise the display is messed! console &&= console.noansi if console.respond_to? :noansi console end
get_instance()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 98 def get_instance Rudy::AWS::EC2::Instances.get @instid end
get_password()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 113 def get_password unless windows? raise "Password support is Windows only (this is #{@os})" end console = get_console raise "Console output not yet available. Please wait." if console.nil? unless console.match(/<Password>(.+)<\/Password>/m) # /m, match multiple lines raise "Password not yet available. Is this a custom AMI?" end encrtypted_text = ($1 || '').strip k = Rye::Key.from_file root_keypairpath k.decrypt encrtypted_text end
linux?()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 221 def linux?; os? 'linux'; end
os?(v)
click to toggle source
# File lib/rudy/metadata/machine.rb, line 219 def os?(v); @os.to_s == v.to_s; end
postprocess()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 80 def postprocess @position &&= @position.to_s.rjust(2, '0') @os &&= @os.to_sym end
rbox()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 89 def rbox r = Rudy::Routines::Handlers::RyeTools.create_box self end
refresh!(metadata=true)
click to toggle source
Calls superclass method
Rudy::Metadata#refresh!
# File lib/rudy/metadata/machine.rb, line 187 def refresh!(metadata=true) ## Updating the metadata isn't necessary super() if metadata # update metadata @instance = get_instance if @instance.is_a?(Rudy::AWS::EC2::Instance) @dns_public, @dns_private = @instance.dns_public, @instance.dns_private @state = @instance.state save :replace elsif @instance.nil? @awsid = @dns_public = @dns_private = nil @state = 'rogue' # Don't save it b/c it's possible the EC2 server is just down. end end
restart()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 177 def restart Rudy::AWS::EC2::Instances.restart(@instid) if instance_running? end
solaris?()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 222 def solaris?; os? 'solaris'; end
to_s(*args)
click to toggle source
# File lib/rudy/metadata/machine.rb, line 85 def to_s(*args) [self.name.bright, self.instid, self.dns_public].join '; ' end
windows?()
click to toggle source
# File lib/rudy/metadata/machine.rb, line 220 def windows?; os? 'windows'; end