Beispiel #1
0
 def reserve_ip_addresses(self,
                          bridge: Bridge,
                          ip_gen: Optional[Iterator[IpAddress]] = None):
     bridge.assign_ip_address(self._COORD_CADDY,
                              next(ip_gen) if ip_gen is not None else None)
     bridge.assign_ip_address(self._COORD_HUEY,
                              next(ip_gen) if ip_gen is not None else None)
Beispiel #2
0
    def start(self, *, host: Host, bridge: Bridge, internal_url: str,
              publish_at: Optional[UnderlayAddress], cpu_affinity: CpuSet,
              **args) -> None:
        dc = host.docker_client

        # Check wheather the coordinator is already running
        if self._cntr_id:
            try:
                cntr = dc.containers.get(self._cntr_id)
            except docker.errors.NotFound:
                self._cntr_id = None
            else:
                if cntr.status == 'running':
                    return  # coordinator is already running
                else:
                    # Remove old container
                    cntr.stop()
                    cntr.remove()

        # Expose coordinator on host interface
        ports = {}
        if publish_at is not None:
            external_ip, external_port = publish_at
            ports['%d/tcp' % const.COORD_PORT] = (str(external_ip),
                                                  int(external_port))
            log.info("Exposing coordinator at http://%s",
                     publish_at.format_url())

        # Create and run the container
        kwargs = {}
        if not cpu_affinity.is_unrestricted():
            kwargs['cpuset_cpus'] = str(cpu_affinity)
        cntr = dc.containers.run(const.COORD_IMG_NAME,
                                 name=self._cntr_name,
                                 ports=ports,
                                 environment={"SCIONLAB_SITE": internal_url},
                                 detach=True,
                                 **kwargs)
        self._cntr_id = cntr.id
        log.info("Started coordinator %s [%s] (%s).", self._cntr_name,
                 host.name, self._cntr_id)
        ip = unwrap(bridge.get_ip_address(self._COORD_DEBUG_SERVER))
        bridge.connect_container(cntr, ip, host)
Beispiel #3
0
 def __init__(self, bridge: Bridge):
     self._iter = bridge.valid_ip_iter()
     self.current = next(self._iter)
Beispiel #4
0
    def start(self, *, host: Host, bridge: Bridge, internal_url: str,
              publish_at: Optional[UnderlayAddress], cpu_affinity: CpuSet,
              **args) -> None:
        dc = host.docker_client

        # Check wheather the coordinator is already running
        restart_existing = False
        if self._django_cntr_id:
            result = host.run_cmd(self._compose_cmd(["ps"]),
                                  check=True,
                                  capture_output=True)
            lines = result.output.splitlines()
            if len(lines) < 3:
                # coordinator is down
                restart_existing = False
            else:
                for line in lines:
                    if line.startswith(
                            self._project_name) and not "Up" in line:
                        # some containers are not running
                        restart_existing = True
                        break
                else:
                    return  # coordinator is already running

        # Invoke docker-compose
        if restart_existing:
            result = host.run_cmd(self._compose_cmd(["restart"]),
                                  check=True,
                                  capture_output=True)
            log.info("Restarting coordinator containers:\n" + result.output)

        else:
            env = {
                "SCIONLAB_SITE": internal_url,
                "COORD_CPUSET": str(cpu_affinity),
                "COORD_ADDR": str(publish_at) if publish_at is not None else ""
            }
            if publish_at is not None:
                log.info("Exposing coordinator at http://%s",
                         publish_at.format_url())

            result = host.run_cmd(self._compose_cmd(["up", "--detach"]),
                                  env=env,
                                  check=True,
                                  capture_output=True)
            log.info("Starting coordinator:\n%s", result.output)

        # Get the django and the caddy container
        django_cntr = dc.containers.get(self._project_name + "_django_1")
        self._django_cntr_id = django_cntr.id
        caddy_cntr = dc.containers.get(self._project_name + "_caddy_1")
        self._caddy_cntr_id = caddy_cntr.id
        huey_cntr = dc.containers.get(self._project_name + "_huey_1")
        self._huey_cntr_id = huey_cntr.id

        # Connect caddy to the coordinator network to publish the web interface
        bridge.connect_container(
            caddy_cntr, unwrap(bridge.get_ip_address(self._COORD_CADDY)), host)
        # Connect huey to the coordinator network to enable AS configuration over SSH
        bridge.connect_container(
            huey_cntr, unwrap(bridge.get_ip_address(self._COORD_HUEY)), host)
Beispiel #5
0
 def get_http_interface(self, bridge: Bridge) -> UnderlayAddress:
     return UnderlayAddress(
         unwrap(bridge.get_ip_address(self._COORD_CADDY)),
         L4Port(const.COORD_PORT))