Giter Site home page Giter Site logo

flask-lxc's Introduction

Flask LXC API Blueprint


Installing locally

Install LXC

  • Debian 9 (Jessie) Setup
sudo apt-get install -y lxc python-lxc

echo 'USE_LXC_BRIDGE="true"' | sudo tee /etc/default/lxc-net

sudo bash -c 'cat << EOF > /etc/lxc/default.conf
lxc.network.type = veth
lxc.network.link = lxcbr0
lxc.network.flags = up
lxc.network.hwaddr = 00:16:3e:a1:b2:c3
EOF'

sudo service lxc-net restart

Running locally

git clone https://github.com/m4n3dw0lf/flask-lxc
sudo pip install -r requirements.txt
sudo python run.py

Running as docker container

Need to run as root user

docker pull m4n3dw0lf/flask_lxc
docker run -it --net=host --rm --privileged --name test m4n3dw0lf/flask_lxc

Importing as blueprint on your flask app

  • install the package
pip install flask_lxc
  • register the blueprint
from flask import Flask
from flask_lxc import lxc_api

# Can be your own app
app = Flask(__name__)
app.register_blueprint(lxc_api)



API

Create new LXC Container

syntax:

curl -X POST \
http://localhost:5000/lxc/create/<CONTAINER> \
-H "Content-Type:application/json" \
-d '{
 "image":"<IMAGE>",
 "args":{
   "release":"<RELEASE>",
   "arch":"<ARCH>"
 }
}'

example:

curl -X POST \
http://localhost:5000/lxc/create/debian1 \
-H "Content-Type:application/json" \
-d '{
 "image":"debian",
 "args":{
   "release":"jessie",
   "arch":"amd64"
 }
}'

List LXC Containers

syntax:

curl http://localhost:5000/lxc/list


Start LXC Container

syntax:

curl http://localhost:5000/lxc/start/<CONTAINER_NAME>

example:

curl http://localhost:5000/lxc/start/debian1


Stop LXC Container

syntax:

curl http://localhost:5000/lxc/stop/<CONTAINER_NAME>

example:

curl http://localhost:5000/lxc/stop/debian1


Destroy LXC Container

syntax:

curl http://localhost:5000/lxc/destroy/<CONTAINER_NAME>

example:

curl http://localhost:5000/lxc/destroy/debian1


Expose port of the container

syntax:

curl -X POST \
http://localhost:5000/lxc/expose/<CONTAINER_NAME> \
-H "Content-Type:application/json" \
-d '{
  "sport":"<PORT_TO_EXPOSE>",
  "dport":"<CONTAINER_PORT>",
  "protocol":"<PROTOCOL>"
}'

example:

curl -X POST \
http://localhost:5000/lxc/expose/debian1 \
-H "Content-Type:application/json" \
-d '{
  "sport":"80",
  "dport":"80",
  "protocol":"tcp"
}'

Get config keys

syntax:

curl http://localhost:5000/lxc/config/<CONTAINER>

example:

curl http://localhost:5000/lxc/config/debian1

Set config keys

syntax:

curl -X POST \
http://localhost:5000/lxc/config/<CONTAINER> \
-H "Content-Type:application/json" \
-d '{
  "<KEY>":"<VALUE>"
}'

example:

curl -X POST \
http://localhost:5000/lxc/config/debian1 \
-H "Content-Type:application/json" \
-d '{
  "lxc.network":"veth"
}'



Reference

Instructions to setup LXC and LXC Networking for Debian Jessie

flask-lxc's People

Contributors

m4n3dw0lf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

samyak-jn

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.