Class: CORL::Machine::FogBase

Inherits:
Object
  • Object
show all
Includes:
CORL::Mixin::Machine::SSH
Defined in:
lib/core/plugin/fog_machine.rb

Direct Known Subclasses

AWS, Rackspace

Instance Method Summary collapse

Methods included from CORL::Mixin::Machine::SSH

#close_ssh_session, #init_ssh_session, #ssh_download, #ssh_exec, #ssh_terminal, #ssh_upload

Instance Method Details

#computeObject



57
58
59
60
# File 'lib/core/plugin/fog_machine.rb', line 57

def compute
  set_connection unless @compute
  @compute
end

#compute=(compute) ⇒ Object




53
54
55
# File 'lib/core/plugin/fog_machine.rb', line 53

def compute=compute
  @compute = compute
end

#create(options = {}, &code) ⇒ Object




151
152
153
154
155
156
157
158
159
# File 'lib/core/plugin/fog_machine.rb', line 151

def create(options = {}, &code)
  super do |config|
    if compute
      code.call(config) if code
      myself.server = compute.servers.bootstrap(config.export)
    end
    myself.server ? true : false
  end
end

#create_image(options = {}, &code) ⇒ Object




204
205
206
207
208
209
210
211
# File 'lib/core/plugin/fog_machine.rb', line 204

def create_image(options = {}, &code)
  super do |config|
    image_name = sprintf("%s (%s)", node.plugin_name, Time.now.to_s)

    success = code ? code.call(image_name, config, success) : true
    success = init_ssh_session(true, config.get(:tries, 12), config.get(:sleep_time, 5)) if success
  end
end

#created?Boolean


Checks

Returns:

  • (Boolean)


23
24
25
# File 'lib/core/plugin/fog_machine.rb', line 23

def created?
  server && ! server.state != 'DELETED'
end

#destroy(options = {}, &code) ⇒ Object




224
225
226
227
228
229
230
231
232
# File 'lib/core/plugin/fog_machine.rb', line 224

def destroy(options = {}, &code)
  super do |config|
    success = server.destroy
    success = code.call(config) if success && code

    close_ssh_session if success
    success
  end
end

#download(remote_path, local_path, options = {}, &code) ⇒ Object




163
164
165
166
167
# File 'lib/core/plugin/fog_machine.rb', line 163

def download(remote_path, local_path, options = {}, &code)
  super do |config, success|
    ssh_download(remote_path, local_path, config, &code)
  end
end

#exec(commands, options = {}, &code) ⇒ Object




179
180
181
182
183
# File 'lib/core/plugin/fog_machine.rb', line 179

def exec(commands, options = {}, &code)
  super do |config|
    ssh_exec(commands, config, &code)
  end
end

#imageObject




125
126
127
128
# File 'lib/core/plugin/fog_machine.rb', line 125

def image
  return server.image.id if server
  nil
end

#imagesObject




118
119
120
121
# File 'lib/core/plugin/fog_machine.rb', line 118

def images
  return compute.images if compute
  []
end

#loadObject




142
143
144
145
146
147
# File 'lib/core/plugin/fog_machine.rb', line 142

def load
  super do
    myself.server = plugin_name if compute && plugin_name
    ! plugin_name && @server.nil? ? false : true
  end
end

#machine_typeObject




111
112
113
114
# File 'lib/core/plugin/fog_machine.rb', line 111

def machine_type
  return server.flavor.id if server
  nil
end

#machine_typesObject




104
105
106
107
# File 'lib/core/plugin/fog_machine.rb', line 104

def machine_types
  return compute.flavors if compute
  []
end

#normalize(reload) ⇒ Object


Machine plugin interface



15
16
17
18
# File 'lib/core/plugin/fog_machine.rb', line 15

def normalize(reload)
  super
  myself.plugin_name = '' if myself.plugin_provider == myself.plugin_name.to_sym
end

#private_ipObject




97
98
99
100
# File 'lib/core/plugin/fog_machine.rb', line 97

def private_ip
  return server.private_ip_address if server
  nil
end

#public_ipObject




90
91
92
93
# File 'lib/core/plugin/fog_machine.rb', line 90

def public_ip
  return server.public_ip_address if server
  nil
end

#reload(options = {}, &code) ⇒ Object




195
196
197
198
199
200
# File 'lib/core/plugin/fog_machine.rb', line 195

def reload(options = {}, &code)
  super do |config|
    success = code ? code.call(config) : true
    success = init_ssh_session(true, config.get(:tries, 12), config.get(:sleep_time, 5)) if success
  end
end

#running?Boolean


Returns:

  • (Boolean)


29
30
31
# File 'lib/core/plugin/fog_machine.rb', line 29

def running?
  created? && server.ready?
end

#serverObject



75
76
77
78
79
# File 'lib/core/plugin/fog_machine.rb', line 75

def server
  compute
  load unless @server
  @server
end

#server=(id) ⇒ Object




64
65
66
67
68
69
70
71
72
73
# File 'lib/core/plugin/fog_machine.rb', line 64

def server=id
  @server = nil

  if id.is_a?(String)
    @server = compute.servers.get(id) unless id.empty?
  elsif ! id.nil?
    @server = id
  end
  init_server
end

#ssh_wait_for_readyObject


Utilities



237
238
239
# File 'lib/core/plugin/fog_machine.rb', line 237

def ssh_wait_for_ready
  server.wait_for { ready? }
end

#stateObject




83
84
85
86
# File 'lib/core/plugin/fog_machine.rb', line 83

def state
  return translate_state(server.state) if server
  translate_state(:aborted)
end

#stop(options = {}) ⇒ Object




215
216
217
218
219
220
# File 'lib/core/plugin/fog_machine.rb', line 215

def stop(options = {})
  super do |config|
    success = false
    success = destroy(config.import({ :stop => true })) if create_image(config)
  end
end

#terminal(user, options = {}) ⇒ Object




187
188
189
190
191
# File 'lib/core/plugin/fog_machine.rb', line 187

def terminal(user, options = {})
  super do |config|
    ssh_terminal(user, config)
  end
end

#upload(local_path, remote_path, options = {}, &code) ⇒ Object




171
172
173
174
175
# File 'lib/core/plugin/fog_machine.rb', line 171

def upload(local_path, remote_path, options = {}, &code)
  super do |config, success|
    ssh_upload(local_path, remote_path, config, &code)
  end
end