   # Destroy a previously created server.
   @destroy: (instance, callback) ->
 
+  # Get an instance by name
+  @get: (name, callback) ->
+
   # List instances in the cloud
   @list: (callback) ->
 


    int = setInterval f, 1000

  # Spawn a command locally
  # TODO: put somewhere more sane
  _local_sh: (command, callbacks) ->
    cmd = spawn 'sh', command.split ' '
    cmd.stdout.on 'data', callbacks.stdout
    cmd.stderr.on 'data', callbacks.stderr
    cmd.on 'exit', callbacks.exit

  state: (callback) ->

  # Run a shell command as root on the server.
  sh: (command, callback) ->
    @_ssh LithiumConfig.sshkey_private, command, callback

  # Copy files to the instance
  cp: (files, callback) ->
    @_scp LithiumConfig.sshkey_private, files, callback

  # Copy & run hooks on instance
  # TODO: coupled
  run_hooks: (callback) ->
    files_to_cp = _.select @config.hooks, (hook) ->
      /\d+_.+\.r\.\w/.test hook

    files_to_cp = _.map files_to_cp, (f) =>
      "class/#{@config.name}/hooks/#{f}"

    @cp files_to_cp, (exit_code) =>
      console.log "cp exit code: #{exit_code}"
      async.forEachSeries @config.hooks, @_call_hook, callback


  #### Private methods ####

  _call_hook: (hook, callback) =>
    console.log "Running #{hook}"
    if /\d+_.+\.r\..+/.test hook
      @sh "sh /root/#{hook}", callback
    if /\d+_.+\.l\..+/.test hook
      @_local_sh "class/#{@config.name}/hooks/#{hook}", callback

  # Connect via SSH and execute command
  # TODO: proper callbacks?
  _ssh: (key, command, callback) ->
    @_wait_for_sshd()
    args = [
      '-o', 'LogLevel=ERROR', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', '-i', key, "root@#{@ip_address}"]
    args = args.concat(command.split ' ')

    ssh = spawn 'ssh', args
    ssh.stdout.on 'data', (data) -> console.log 'ssh: ' + data.toString('ascii')
    ssh.stderr.on 'data', (data) -> console.log 'ssh: ' + data.toString('ascii')
    ssh.on 'exit', callback

  # Copy files via SCP
  # TODO: factor out into SSH & SCP class, proper callbacks?
  _scp: (key, files, callback) ->
    @_wait_for_sshd()
    args = [
      '-o', 'LogLevel=ERROR', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', '-i', key ]
