class CORL::Machine::Fog

Public Instance Methods

compute() click to toggle source
# File lib/core/plugin/fog_machine.rb, line 46
def compute
  set_connection unless @compute
  @compute
end
compute=(compute) click to toggle source
# File lib/core/plugin/fog_machine.rb, line 42
def compute=compute
  @compute = compute
end
create(options = {}, &code) click to toggle source
# 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) click to toggle source
# 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, 5), config.get(:sleep_time, 5)) if success
  end
end
created?() click to toggle source
# File lib/core/plugin/fog_machine.rb, line 15
def created?
  server && ! server.state != 'DELETED'
end
destroy(options = {}, &code) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/core/plugin/fog_machine.rb, line 168
def exec(commands, options = {}, &code)
  super do |config|
    ssh_exec(commands, config, &code)
  end
end
image() click to toggle source
# File lib/core/plugin/fog_machine.rb, line 114
def image
  return server.image.id if server
  nil
end
images() click to toggle source
# File lib/core/plugin/fog_machine.rb, line 107
def images
  return compute.images if compute
  []
end
load() click to toggle source
# 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_type() click to toggle source
# File lib/core/plugin/fog_machine.rb, line 100
def machine_type
  return server.flavor.id if server
  nil
end
machine_types() click to toggle source
# File lib/core/plugin/fog_machine.rb, line 93
def machine_types
  return compute.flavors if compute
  []
end
private_ip() click to toggle source
# File lib/core/plugin/fog_machine.rb, line 86
def private_ip
  return server.private_ip_address if server
  nil
end
public_ip() click to toggle source
# File lib/core/plugin/fog_machine.rb, line 79
def public_ip
  return server.public_ip_address if server
  nil
end
reload(options = {}, &code) click to toggle source
# 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, 5), config.get(:sleep_time, 5)) if success
  end
end
running?() click to toggle source
# File lib/core/plugin/fog_machine.rb, line 21
def running?
  created? && server.ready?
end
server() click to toggle source
# File lib/core/plugin/fog_machine.rb, line 64
def server
  compute
  load unless @server
  @server
end
server=(id) click to toggle source
# 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_ready() click to toggle source
# File lib/core/plugin/fog_machine.rb, line 226
def ssh_wait_for_ready
  server.wait_for { ready? }
end
state() click to toggle source
# File lib/core/plugin/fog_machine.rb, line 72
def state
  return translate_state(server.state) if server
  nil
end
stop(options = {}) click to toggle source
# 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 = {}) click to toggle source
# 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) click to toggle source
# 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

Protected Instance Methods

init_server() { || ... } click to toggle source
# File lib/core/plugin/fog_machine.rb, line 122
def init_server
  unless @server.nil?
    yield # Implement in fog machine providers
  end  
end
set_connection() click to toggle source
# File lib/core/plugin/fog_machine.rb, line 28
def set_connection
  logger.info("Initializing Fog Compute connection to cloud hosting provider")
  logger.debug("Compute settings: #{export.inspect}")
  
  ENV['DEBUG'] = 'true' if CORL.log_level == :debug
  
  require 'fog'
          
  myself.compute = ::Fog::Compute.new(export)
end