     @kitePath = path.join @lxc.pathToContainers, @lxc.name, "overlay", "opt", "kites"
 
   downloadAndExtractKite: (callback) ->
-    {kitePath, zipUrl, name} = this
+    {kitePath, zipUrl, kiteName} = this
     fs.mkdirsSync(kitePath) ## TODO mkdir creates 0777, exists check
     
-    filepath = path.join kitePath, "#{name}.zip"
+    filepath = path.join kitePath, "#{kiteName}.zip"
     file     = fs.createWriteStream filepath
 
     console.log "downloading url", zipUrl, " to ", filepath

          
          cmd.on 'close', (code) ->
            console.log 'unzip process exited with code ', code
            fs.chmodSync path.join(kitePath, "foobar.kite"), "0777"
            fs.chown kitePath, 500000, 500000
            callback()

  runKite: () ->

    kiteInLxc = path.join "/opt", "kites", "foobar.kite"
    runner    = path.join(@lxc.pathToContainers, @lxc.name, "overlay", "opt", "runner")
    fs.writeFileSync runner, "#!/bin/bash -l \n export HOME=/root \n /usr/sbin/kd.sh #{kiteInLxc} > /tmp/kd.out & \n"
    fs.chmodSync runner, "0777"
    cmd = spawn "/usr/bin/lxc-start", ["-d", "-n", @name]
    
    cmd.stdout.on 'data', (data) ->

uuid = require 'node-uuid'


class Deployment
  @pathToContainers = "/var/lib/lxc"

  constructor: (@id, @kiteName, @zipUrl) ->
    console.log "......Deployment constructor"
    @kitesPath = path.join Deployment.pathToContainers, @id, "overlay", "opt", "kites"

  createLxc: (callback) ->
    cmd = spawn "create-lxc", [@kiteName]
    console.log 'create lxc'
    cmd.stdout.on 'data', (data) ->
      console.log 'stdout: ', data.toString()
