def startNodes(self, nodes, paths, tabIndex, socket):
     """
     @nodes - and array containing live nodes and configuration nodes (i.e. ~network)
     @paths - and array describing associations between live nodes and config nodes
     """
     nets = {}
     # find all network nodes
     for node in nodes:
         if 'network' in node:
             host, container = node['network'].split(':')
             associatedNode = None
             for path in paths:
                 if path['from'] == node['label']:
                     associatedNode = path['to']
                     break
             if associatedNode == None:
                 continue
             if associatedNode not in nets: nets[associatedNode] = []
             nets[associatedNode].append({int(container):int(host)})
     # start containers
     for node in nodes:
         if 'network' in node:
             continue
         socket.log('Starting {0}, w/ image {1}'.format(node['label'], node['image']))
         portsBindings = None
         if node['label'] in nets:
             # TODO, this should be repeated for each port, not just the first
             portsBindings = nets[node['label']][0]
         dnsHost = [util.getNetAddr()]
         self.liveContainers[node['label']] = ContainerClient(
             self, node['image'], node['label'], portsBindings=portsBindings,
             dns=dnsHost, socket=socket, tab=tabIndex
         )
     # stop old containers managed by this instance
     runningContainers = {node['label']:True for node in nodes}
     sysliteInstance = '__default__'
     if 'SYSLITE_INSTACE' in os.environ:
         sysliteInstance = os.environ['SYSLITE_INSTACE']
     for container in self.client.containers(filters={'status':'running'}):
         if 'Syslite_Managed_By' in container['Labels'] and \
            'Syslite_Name' in container['Labels'] and \
            'Syslite_Tab' in container['Labels']:
             name = container['Labels']['Syslite_Name']
             tab = container['Labels']['Syslite_Tab']
             instance = container['Labels']['Syslite_Managed_By']
             if instance == sysliteInstance and tab == str(tabIndex):
                 if name not in runningContainers:
                     socket.log('Stopping stale container: {0}'.format(name))
                     self.client.stop(name)
Example #2
0
import sys
import json
from src import util
from src.util import log
from src.dockerClient import ContainerClient

DNSDOCK_IMAGE = 'tonistiigi/dnsdock'
DNSDOCK_CONTAINER = 'syslitedns'
portsBindings = {'53/udp': (util.getNetAddr(), 53)}
binds = ['/var/run/docker.sock:/var/run/docker.sock']
ports = [(53, 'udp')]
command = '-domain="syslite"'

class Client:
    def __init__(self, dockerAPI):
        self.dockerAPI = dockerAPI
        self.container = ContainerClient(
            dockerAPI,
            DNSDOCK_IMAGE,
            DNSDOCK_CONTAINER,
            portsBindings=portsBindings,
            binds=binds,
            ports=ports,
            command=command
        )
    def resolve(self, nodes, paths, socket):
        nodeMap = {}
        for node in nodes:
            nodeMap[node['label']] = node
        # A-Record: <from>.pipe0.syslite --> ip_addr(<to>)
        pathByOrigin = {}