Coder Social home page Coder Social logo

node-lxd's Introduction

npm version

A client for communicating with a local or remote instance of linux containers. The interface is object-oriented, simple and uniform. Unrestrictive with an open MIT license.

Installing

$ npm install --save node-lxd

Getting Started

The following example connects to the local LXC instance and launches a new container.

var lxd = require("node-lxd");

var client = lxd();

client.create("myContainer", "ubuntu", function(err, container) {
    container.start(function(err) {
        if (!err)
            console.log("Started " + container.name());
    });
});

Example

The following example uses an express application to allow users to create containers and execute commands.

// requires
var express = require("express");
var lxd = require("node-lxd");
var client = lxd();
var app = express();

var containers = {};

app.post("/create", function(req, res) {
	client.launch(req.query.name, function(err, container) {
		if (err) res.json({success: false, message: err.getMessage()});
		else {
			containers[req.query.name] = container;
			res.json({success: true, message: "Container launched"});
		}
	});
});

app.post("/run", function(req, res) {
	if (!containers.hasOwnProperty(req.query.name)) {
		res.json({success: false, message: "Container does not exist"});
		return;
	}

	containers[req.query.name].run(req.query.cmd.split(" "), function(err, stdOut, stdErr) {
		if (err) res.json({success: false, message: err.getMessage()});
		else if (stdErr.length > 0) res.json({success: false, message: stdErr});
		else {
			res.json({success: true, message: stdOut});
		}
	});
});

app.listen(3000, function(err) {
	if (!err)
		console.log("listening on port 3000");
});

Documentation

The client class is documented here.

The container class is documented here.

The process class is documented here.

node-lxd's People

Contributors

alandoherty avatar mysiar avatar uxes avatar papkie avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.