Class: PoolParty::Remote::RemoteInstance

Inherits:
Object
  • Object
show all
Includes:
Dslify
Defined in:
lib/poolparty/net/remote_instance.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ RemoteInstance

Returns a new instance of RemoteInstance.



15
16
17
18
19
# File 'lib/poolparty/net/remote_instance.rb', line 15

def initialize(opts={})
  opts.choose{|k,v| dsl_options.has_key? k}
  set_vars_from_options(opts) if opts.is_a?(Hash)
  on_init
end

Instance Method Details

#[](k) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/poolparty/net/remote_instance.rb', line 28

def [](k)
  if dsl_options.has_key? k
    dsl_options[k]
  else
    nil
  end
end

#[]=(k, v) ⇒ Object



36
37
38
# File 'lib/poolparty/net/remote_instance.rb', line 36

def []=(k,v)
  dsl_options[k] = v
end

#eachObject

hash like methods TODO: move these into a module, or into dslify include Enumerable



24
25
26
# File 'lib/poolparty/net/remote_instance.rb', line 24

def each
  dsl_options.each{ |k,v| yield k,v }
end

#elapsed_runtimeObject



70
71
72
# File 'lib/poolparty/net/remote_instance.rb', line 70

def elapsed_runtime
  Time.now.to_i - launching_time.to_time.to_i
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/poolparty/net/remote_instance.rb', line 40

def has_key?(key)
  dsl_options.has_key?(key)
end

#keysObject



44
45
46
# File 'lib/poolparty/net/remote_instance.rb', line 44

def keys
  dsl_options.keys
end

#loadObject

This is how we get the current load of the instance The approach of this may change entirely, but the usage of it will always be the same



86
87
88
# File 'lib/poolparty/net/remote_instance.rb', line 86

def load
  current_load ||= 0.0  #NOTE MF: returning 0.0 seems like a bad idea here.  should return nil if we dont have a real value
end

#on_initObject

Callback



75
76
# File 'lib/poolparty/net/remote_instance.rb', line 75

def on_init
end

#pending?Boolean

Is this instance pending?

Returns:

  • (Boolean)


58
59
60
# File 'lib/poolparty/net/remote_instance.rb', line 58

def pending?
  !(status =~ /pending/).nil?
end

#running?Boolean

Is this instance running?

Returns:

  • (Boolean)


54
55
56
# File 'lib/poolparty/net/remote_instance.rb', line 54

def running?
  !(status =~ /running/).nil?
end

#terminated?Boolean

Has this instance been terminated?

Returns:

  • (Boolean)


66
67
68
# File 'lib/poolparty/net/remote_instance.rb', line 66

def terminated?
  !(status =~ /terminated/).nil?
end

#terminating?Boolean

Is this instance terminating?

Returns:

  • (Boolean)


62
63
64
# File 'lib/poolparty/net/remote_instance.rb', line 62

def terminating?
  !(status =~ /shutting/).nil?
end

#valid?Boolean

The remote instances is only valid if there is an ip and a name

Returns:

  • (Boolean)


79
80
81
# File 'lib/poolparty/net/remote_instance.rb', line 79

def valid?
  (ip.nil? || name.nil?) ? false : true
end

#valuesObject



48
49
50
# File 'lib/poolparty/net/remote_instance.rb', line 48

def values
  dsl_options.values
end