Initial commit

pull/8/head
Jack O'Sullivan 5 years ago
commit 22f8e24549

4
.gitignore vendored

@ -0,0 +1,4 @@
/plugin/
__pycache__/
.vscode/

@ -0,0 +1,11 @@
FROM python:3-alpine
COPY requirements.txt /opt/
RUN pip install -r /opt/requirements.txt
RUN mkdir -p /opt/plugin /run/docker/plugins
COPY plugin.sh /opt/plugin/launch.sh
COPY net-dhcp/ /opt/plugin/net_dhcp
WORKDIR /opt/plugin
ENV GUNICORN_OPTS="--log-level=DEBUG"
ENTRYPOINT [ "/opt/plugin/launch.sh" ]

@ -0,0 +1,33 @@
PLUGIN_NAME = devplayer0/net-dhcp
PLUGIN_TAG ?= latest
all: clean rootfs create
clean:
@echo "### rm ./plugin"
@rm -rf ./plugin
rootfs:
@echo "### docker build: rootfs image with net-dhcp"
@docker build -t ${PLUGIN_NAME}:rootfs .
@echo "### create rootfs directory in ./plugin/rootfs"
@mkdir -p ./plugin/rootfs
@docker create --name tmp ${PLUGIN_NAME}:rootfs
@docker export tmp | tar -x -C ./plugin/rootfs
@echo "### copy config.json to ./plugin/"
@cp config.json ./plugin/
@docker rm -vf tmp
create:
@echo "### remove existing plugin ${PLUGIN_NAME}:${PLUGIN_TAG} if exists"
@docker plugin rm -f ${PLUGIN_NAME}:${PLUGIN_TAG} || true
@echo "### create new plugin ${PLUGIN_NAME}:${PLUGIN_TAG} from ./plugin"
@docker plugin create ${PLUGIN_NAME}:${PLUGIN_TAG} ./plugin
enable:
@echo "### enable plugin ${PLUGIN_NAME}:${PLUGIN_TAG}"
@docker plugin enable ${PLUGIN_NAME}:${PLUGIN_TAG}
push: clean rootfs create enable
@echo "### push plugin ${PLUGIN_NAME}:${PLUGIN_TAG}"
@docker plugin push ${PLUGIN_NAME}:${PLUGIN_TAG}

@ -0,0 +1,29 @@
{
"description": "Docker host bridge DHCP networking",
"interface": {
"socket": "net-dhcp.sock",
"types": [
"docker.networkdriver/1.0",
"docker.ipamdriver/1.0"
]
},
"entrypoint": [ "/opt/plugin/launch.sh" ],
"workdir": "/opt/plugin",
"network": {
"type": "host"
},
"linux": {
"capabilities": [
"CAP_SYS_ADMIN"
]
},
"env": [
{
"name": "GUNICORN_OPTS",
"settable": [
"value"
],
"value": "--log-level DEBUG --log-file /var/log/net-dhcp.log"
}
]
}

@ -0,0 +1,5 @@
from flask import Flask
app = Flask(__name__)
from . import network, ipam

@ -0,0 +1,10 @@
from flask import jsonify
from . import app
@app.route('/IpamDriver.GetCapabilities')
def ipam_get_capabilities():
return jsonify({
'RequiresMACAddress': True,
'RequiresRequestReplay': False
})

@ -0,0 +1,10 @@
from flask import jsonify
from . import app
@app.route('/NetworkDriver.GetCapabilities')
def net_get_capabilities():
return jsonify({
'Scope': 'local',
'ConnectivityScope': 'global'
})

@ -0,0 +1,2 @@
#!/bin/sh
exec gunicorn $GUNICORN_OPTS --workers 1 --bind unix:/run/docker/plugins/net-dhcp.sock net_dhcp:app

@ -0,0 +1,2 @@
flask==1.1.1
gunicorn==19.9.0
Loading…
Cancel
Save