Skip to content

Instantly share code, notes, and snippets.

@retrohacker
Last active August 29, 2015 14:13
Show Gist options
  • Save retrohacker/77c2e253e6a0a78735c0 to your computer and use it in GitHub Desktop.
Save retrohacker/77c2e253e6a0a78735c0 to your computer and use it in GitHub Desktop.
Proposed interface

node-liblxc

API

lxc.new(name,configPath,cb)

Creates a new container.

Parameters:

  • name - The name to give the new container
  • configPath - A path to the configuration file that should be used when constructing this container.
  • cb - Callback defined as function(e,container)
    • e - the error of creation fails
    • container - the newly created container

Returns nothing

container.isDefined(cb)

Checks to see if the container has already been defined on the system.

Parameters:

  • cb - Callback defined as function(defined)
    • defined - a boolean, true if defined on system.

returns nothing

container.create(template, backingStore, backingStoreArgs, flags, args, cb)

Creates the container.

Parameters:

  • template - Template to execute to instantiate the root filesystem and adjust the configuration.
  • backingStore - A string representing the backing store type to use (if NULL, dir will be used).
  • backingStoreParams - Additional parameters for the backing store.
  • flags - LXC_CREATE_* commands. Currently only (lxc.createQuiet is supported).
  • args - flags to pass to the template.
var lxc = require('liblxc')
var async = require('async')
async.series([
function(cb) {
return lxc.new(cb)
},
function(container,cb) {
container.isDefined(function(defined) {
if(defined) return cb("Already Defined")
return cb(null,container)
}
},
function(container,cb) {
var flags = [lxc.createQuiet]
var args = ["-d","ubuntu","-r","trusty","-a","amd64"]
var template = "download"
var backingStore = null
var backingStoreArgs = null
container.create(template,backingStore,backingStoreArgs,flags,args,function(e) {
return cb(e,container)
}
},
...
],function(e) {
if(e) return console.error(e)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment