initial commit after bringing over cleaned up code and testing some examples
This commit is contained in:
parent
c4858e6e0d
commit
00f4ebf5a9
93 changed files with 15189 additions and 13083 deletions
|
@ -1,12 +1,5 @@
|
|||
#
|
||||
# CORE
|
||||
# Copyright (c)2014 the Boeing Company.
|
||||
# See the LICENSE file included in this distribution.
|
||||
#
|
||||
# authors: Stuart Marsden
|
||||
# Jeff Ahrenholz <jeffrey.m.ahrenholz@boeing.com>
|
||||
#
|
||||
''' Docker service allows running docker containers within CORE nodes.
|
||||
"""
|
||||
Docker service allows running docker containers within CORE nodes.
|
||||
|
||||
The running of Docker within a CORE node allows for additional extensibility to
|
||||
the CORE services. This allows network applications and protocols to be easily
|
||||
|
@ -20,7 +13,7 @@ service to the Docker group. The image will then be auto run if that service is
|
|||
selected.
|
||||
|
||||
This requires a recent version of Docker. This was tested using a PPA on Ubuntu
|
||||
with version 1.2.0. The version in the standard Ubuntu repo is to old for
|
||||
with version 1.2.0. The version in the standard Ubuntu repo is to old for
|
||||
this purpose (we need --net host).
|
||||
|
||||
It also requires docker-py (https://pypi.python.org/pypi/docker-py) which can be
|
||||
|
@ -47,13 +40,13 @@ The id will be different on your machine so use it in the following command:
|
|||
|
||||
sudo docker tag 4833487e66d2 stuartmarsden/multicastping:core
|
||||
|
||||
This image will be listed in the services after we restart the core-daemon:
|
||||
This image will be listed in the services after we restart the core-daemon:
|
||||
|
||||
sudo service core-daemon restart
|
||||
|
||||
You can set up a simple network with a number of PCs connected to a switch. Set
|
||||
the stuartmarsden/multicastping service for all the PCs. When started they will
|
||||
all begin sending Multicast pings.
|
||||
all begin sending Multicast pings.
|
||||
|
||||
In order to see what is happening you can go in to the terminal of a node and
|
||||
look at the docker log. Easy shorthand is:
|
||||
|
@ -89,11 +82,11 @@ Datagram 'Client: Ping' received from ('10.0.5.20', 8005)
|
|||
|
||||
Limitations:
|
||||
|
||||
1. Docker images must be downloaded on the host as usually a CORE node does not
|
||||
1. Docker images must be downloaded on the host as usually a CORE node does not
|
||||
have access to the internet.
|
||||
2. Each node isolates running containers (keeps things simple)
|
||||
3. Recent version of docker needed so that --net host can be used. This does
|
||||
not further abstract the network within a node and allows multicast which
|
||||
3. Recent version of docker needed so that --net host can be used. This does
|
||||
not further abstract the network within a node and allows multicast which
|
||||
is not enabled within Docker containers at the moment.
|
||||
4. The core-daemon must be restarted for new images to show up.
|
||||
5. A Docker-daemon is run within each node but the images are shared. This
|
||||
|
@ -101,43 +94,46 @@ Limitations:
|
|||
host. At startup all the nodes will try to access this and it will be locked
|
||||
for most due to contention. The service just does a hackish wait for 1 second
|
||||
and retry. This means all the docker containers can take a while to come up
|
||||
depending on how many nodes you have.
|
||||
depending on how many nodes you have.
|
||||
"""
|
||||
|
||||
'''
|
||||
from core.misc import log
|
||||
from core.service import CoreService
|
||||
from core.service import ServiceManager
|
||||
|
||||
logger = log.get_logger(__name__)
|
||||
|
||||
import os
|
||||
import sys
|
||||
try:
|
||||
from docker import Client
|
||||
except Exception:
|
||||
pass
|
||||
except ImportError:
|
||||
logger.error("failure to import docker")
|
||||
|
||||
from core.service import CoreService, addservice
|
||||
from core.misc.ipaddr import IPv4Prefix, IPv6Prefix
|
||||
|
||||
class DockerService(CoreService):
|
||||
''' This is a service which will allow running docker containers in a CORE
|
||||
node.
|
||||
'''
|
||||
"""
|
||||
This is a service which will allow running docker containers in a CORE
|
||||
node.
|
||||
"""
|
||||
_name = "Docker"
|
||||
_group = "Docker"
|
||||
_depends = ()
|
||||
_dirs = ('/var/lib/docker/containers/', '/run/shm', '/run/resolvconf',)
|
||||
_configs = ('docker.sh', )
|
||||
_configs = ('docker.sh',)
|
||||
_startindex = 50
|
||||
_startup = ('sh docker.sh',)
|
||||
_shutdown = ('service docker stop', )
|
||||
_shutdown = ('service docker stop',)
|
||||
# Container image to start
|
||||
_image = ""
|
||||
|
||||
@classmethod
|
||||
def generateconfig(cls, node, filename, services):
|
||||
''' Returns a string having contents of a docker.sh script that
|
||||
can be modified to start a specific docker image.
|
||||
'''
|
||||
"""
|
||||
Returns a string having contents of a docker.sh script that
|
||||
can be modified to start a specific docker image.
|
||||
"""
|
||||
cfg = "#!/bin/sh\n"
|
||||
cfg += "# auto-generated by Docker (docker.py)\n"
|
||||
# Docker likes to think it has DNS set up or it complains.
|
||||
# Docker likes to think it has DNS set up or it complains.
|
||||
# Unless your network was attached to the Internet this is
|
||||
# non-functional but hides error messages.
|
||||
cfg += 'echo "nameserver 8.8.8.8" > /run/resolvconf/resolv.conf\n'
|
||||
|
@ -156,27 +152,30 @@ until [ $result -eq 0 ]; do
|
|||
# this is to alleviate contention to docker's SQLite database
|
||||
sleep 0.3
|
||||
done
|
||||
""" % (cls._image, )
|
||||
""" % (cls._image,)
|
||||
return cfg
|
||||
|
||||
addservice(DockerService)
|
||||
|
||||
# This auto-loads Docker images having a :core tag, adding them to the list
|
||||
# of services under the "Docker" group.
|
||||
if 'Client' in globals():
|
||||
client = Client(version='1.10')
|
||||
images = client.images()
|
||||
del client
|
||||
else:
|
||||
images = []
|
||||
for image in images:
|
||||
if u'<none>' in image['RepoTags'][0]:
|
||||
continue
|
||||
for repo in image['RepoTags']:
|
||||
if u':core' not in repo:
|
||||
def load_services():
|
||||
ServiceManager.add(DockerService)
|
||||
|
||||
# This auto-loads Docker images having a :core tag, adding them to the list
|
||||
# of services under the "Docker" group.
|
||||
# TODO: change this logic, should be a proper configurable, or docker needs to be a required library
|
||||
# TODO: also should make this call possible real time for reloading removing "magic" auto loading on import
|
||||
if 'Client' in globals():
|
||||
client = Client(version='1.10')
|
||||
images = client.images()
|
||||
del client
|
||||
else:
|
||||
images = []
|
||||
for image in images:
|
||||
if u'<none>' in image['RepoTags'][0]:
|
||||
continue
|
||||
dockerid = repo.encode('ascii','ignore').split(':')[0]
|
||||
SubClass = type('SubClass', (DockerService,),
|
||||
{'_name': dockerid, '_image': dockerid})
|
||||
addservice(SubClass)
|
||||
del images
|
||||
for repo in image['RepoTags']:
|
||||
if u':core' not in repo:
|
||||
continue
|
||||
dockerid = repo.encode('ascii', 'ignore').split(':')[0]
|
||||
sub_class = type('SubClass', (DockerService,), {'_name': dockerid, '_image': dockerid})
|
||||
ServiceManager.add(sub_class)
|
||||
del images
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue