Class: CORL::Machine::Fog

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



46
47
48
49
# File 'lib/core/plugin/fog_machine.rb', line 46

def compute
  set_connection unless @compute
  @compute
end

#compute=(compute) ⇒ Object




42
43
44
# File 'lib/core/plugin/fog_machine.rb', line 42

def compute=compute
  @compute = compute
end

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




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

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




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

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)


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

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

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




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

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




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

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




168
169
170
171
172
# File 'lib/core/plugin/fog_machine.rb', line 168

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

#imageObject




114
115
116
117
# File 'lib/core/plugin/fog_machine.rb', line 114

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

#imagesObject




107
108
109
110
# File 'lib/core/plugin/fog_machine.rb', line 107

def images
  return compute.images if compute
  []
end

#loadObject




131
132
133
134
135
136
# File 'lib/core/plugin/fog_machine.rb', line 131

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

#machine_typeObject




100
101
102
103
# File 'lib/core/plugin/fog_machine.rb', line 100

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

#machine_typesObject




93
94
95
96
# File 'lib/core/plugin/fog_machine.rb', line 93

def machine_types
  return compute.flavors if compute
  []
end

#private_ipObject




86
87
88
89
# File 'lib/core/plugin/fog_machine.rb', line 86

def private_ip
  return server.private_ip_address if server
  nil
end

#public_ipObject




79
80
81
82
# File 'lib/core/plugin/fog_machine.rb', line 79

def public_ip
  return server.public_ip_address if server
  nil
end

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




184
185
186
187
188
189
# File 'lib/core/plugin/fog_machine.rb', line 184

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)


21
22
23
# File 'lib/core/plugin/fog_machine.rb', line 21

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

#serverObject



64
65
66
67
68
# File 'lib/core/plugin/fog_machine.rb', line 64

def server
  compute
  load unless @server
  @server
end

#server=(id) ⇒ Object




53
54
55
56
57
58
59
60
61
62
# File 'lib/core/plugin/fog_machine.rb', line 53

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



226
227
228
# File 'lib/core/plugin/fog_machine.rb', line 226

def ssh_wait_for_ready
  server.wait_for { ready? }
end

#stateObject




72
73
74
75
# File 'lib/core/plugin/fog_machine.rb', line 72

def state
  return translate_state(server.state) if server
  nil
end

#stop(options = {}) ⇒ Object




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

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

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




176
177
178
179
180
# File 'lib/core/plugin/fog_machine.rb', line 176

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

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




160
161
162
163
164
# File 'lib/core/plugin/fog_machine.rb', line 160

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