Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/m4n3dw0lf/flask-lxc

Flask LXC API Blueprint
https://github.com/m4n3dw0lf/flask-lxc

flask-api flask-application flask-blueprints lxc lxc-containers

Last synced: 3 months ago
JSON representation

Flask LXC API Blueprint

Awesome Lists containing this project

README

        

# 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/ \
-H "Content-Type:application/json" \
-d '{
"image":"",
"args":{
"release":"",
"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/`

example:

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


### Stop LXC Container

syntax:

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

example:

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


### Destroy LXC Container

syntax:

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

example:

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


### Expose port of the container

syntax:

```
curl -X POST \
http://localhost:5000/lxc/expose/ \
-H "Content-Type:application/json" \
-d '{
"sport":"",
"dport":"",
"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/`

example:

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

### Set config keys

syntax:
```
curl -X POST \
http://localhost:5000/lxc/config/ \
-H "Content-Type:application/json" \
-d '{
"":""
}'
```

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

- https://wiki.debian.org/LXC