Class: CloudProviders::RemoteInstance

Inherits:
Object
  • Object
show all
Includes:
Connections, Dslify
Defined in:
lib/cloud_providers/remote_instance.rb

Direct Known Subclasses

Ec2Instance

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Connections

#host, #ping_port, #rsync, #scp, #shell_escape, #ssh, #ssh_cleanup_known_hosts!, #ssh_options

Constructor Details

#initialize(init_opts = {}, &block) ⇒ RemoteInstance

Returns a new instance of RemoteInstance.



17
18
19
20
21
22
# File 'lib/cloud_providers/remote_instance.rb', line 17

def initialize(init_opts={}, &block)
  @init_opts = init_opts
  set_vars_from_options(init_opts)
  instance_eval &block if block
  after_initialized
end

Instance Attribute Details

#cloud_provider=(value) ⇒ Object

Sets the attribute cloud_provider

Parameters:

  • value

    the value to set the attribute cloud_provider to.



9
10
11
# File 'lib/cloud_providers/remote_instance.rb', line 9

def cloud_provider=(value)
  @cloud_provider = value
end

#init_optsObject (readonly)

Returns the value of attribute init_opts.



8
9
10
# File 'lib/cloud_providers/remote_instance.rb', line 8

def init_opts
  @init_opts
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/cloud_providers/remote_instance.rb', line 8

def name
  @name
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



8
9
10
# File 'lib/cloud_providers/remote_instance.rb', line 8

def raw_response
  @raw_response
end

Instance Method Details

#[](k) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/cloud_providers/remote_instance.rb', line 66

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

#[]=(k, v) ⇒ Object



74
75
76
# File 'lib/cloud_providers/remote_instance.rb', line 74

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

#accessible?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/cloud_providers/remote_instance.rb', line 31

def accessible?
  ping_port(public_ip, 22, 40)
end

#after_initializedObject



28
29
# File 'lib/cloud_providers/remote_instance.rb', line 28

def after_initialized
end

#bootstrap_chef!Object

TODO: chef_bootstrapped? should go away, since Chef#node_bootstrap! already checks node_bootstrap!. There is a force flag as well.



45
46
47
# File 'lib/cloud_providers/remote_instance.rb', line 45

def bootstrap_chef!
  cloud.chef.node_bootstrap!(self)
end

#chef_bootstrapped?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/cloud_providers/remote_instance.rb', line 39

def chef_bootstrapped?
  @chef_bootstrapped ||= cloud.chef.node_bootstrapped?(self)
end

#default_keypair_pathObject



57
58
59
# File 'lib/cloud_providers/remote_instance.rb', line 57

def default_keypair_path
  self.class.default_keypair_path
end

#eachObject

provide hash like methods to access and iterate over node attributes



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

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

#elapsed_runtimeObject

elapsed seconds since node launch time



113
114
115
# File 'lib/cloud_providers/remote_instance.rb', line 113

def elapsed_runtime
  Time.now - Time.parse(launch_time)
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/cloud_providers/remote_instance.rb', line 78

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

#keypair(n = nil) ⇒ Object



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

def keypair(n=nil)
  @keypair ||= n.nil? ? nil : Keypair.new(n)
end

#keysObject



82
83
84
# File 'lib/cloud_providers/remote_instance.rb', line 82

def keys
  dsl_options.keys
end

#pending?Boolean

Is this instance pending?

Returns:

  • (Boolean)


100
101
102
# File 'lib/cloud_providers/remote_instance.rb', line 100

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

#rsync_dir(dir) ⇒ Object



35
36
37
# File 'lib/cloud_providers/remote_instance.rb', line 35

def rsync_dir(dir)
  rsync :source => dir/"*", :destination => "/"
end

#runObject



53
54
55
# File 'lib/cloud_providers/remote_instance.rb', line 53

def run
  warn "#{self.class} does not implement run. Something is wrong"
end

#run_chef!Object



49
50
51
# File 'lib/cloud_providers/remote_instance.rb', line 49

def run_chef!
  cloud.chef.node_run!(self)
end

#running?Boolean

Is this instance running?

Returns:

  • (Boolean)


96
97
98
# File 'lib/cloud_providers/remote_instance.rb', line 96

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

#ssh_available?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/cloud_providers/remote_instance.rb', line 117

def ssh_available?
  warn "Implemented in cloudprovider instance class. something is wrong"
end

#terminated?Boolean

Has this instance been terminated?

Returns:

  • (Boolean)


108
109
110
# File 'lib/cloud_providers/remote_instance.rb', line 108

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

#terminating?Boolean

Is this instance terminating?

Returns:

  • (Boolean)


104
105
106
# File 'lib/cloud_providers/remote_instance.rb', line 104

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

#to_hashObject



90
91
92
# File 'lib/cloud_providers/remote_instance.rb', line 90

def to_hash
  dsl_options
end

#valuesObject



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

def values
  dsl_options.values
end