示例#1
0
def deploy(app_key, build):
    app = get_app(app_key)
    build = db.get_one_or_abort(app.builds.filter_by(tag=build))

    form = forms.DeploymentSetupForm(app)

    if form.validate_on_submit():
        instance = build.deploy(form.data['host'],
                                form.data['template'].template)
        session = db.Session()
        session.add(instance)

        route = Route(instance=instance, routing_key=form.data['hostname'])
        session.add(route)

        client = instance.host.get_client()
        child_ip = get_container_ip(client, instance.container)
        parent_ip = get_container_ip(
            client,
            current_app.config['FRONTEND_NAME']
        )
        allow_traffic(parent_ip, child_ip, 5510)

        session.commit()

        route.update(current_app.config['FRONTEND_NAME'])

        return redirect(url_for('.instance', app_key=app.key,
                                container_id=instance.container[:10]))

    return render_template('deploy-setup.html', form=form, app=app,
                           build=build)
示例#2
0
    def update(self, frontend_name):
        client = self.instance.host.get_client()
        instance_ip = self.instance.get_ip()
        router_ip = get_container_ip(client, frontend_name)

        payload = {
            'key': self.routing_key,
            'address': '{}:{}'.format(instance_ip, 5510),
        }

        msg = ''
        for k, v in payload.iteritems():
            k, v = str(k), str(v)
            msg += struct.pack('<h', len(k)) + str(k)
            msg += struct.pack('<h', len(v)) + v

        remove = self.instance.stopped is not None
        msg = struct.pack('<BhB', 224, len(msg), 1 if remove else 0) + msg
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.sendto(msg, (router_ip, 5500))

        logger.log(
            'route.discard' if remove else 'route.update',
            routing_key=self.routing_key,
            instance=instance_ip,
            host=self.instance.host.name,
            router=router_ip,
            weight=self.weight
        )
示例#3
0
def add_route():
    client = Client(version='1.6')
    containers = []

    deploy_repo = '{}/{}'.format(
        current_app.config['DOCKER_REGISTRY'],
        current_app.config['DOCKER_BUILDS_REPOSITORY'],
    )

    for c in client.containers(trunc=False):
        try:
            repo, tag = c['Image'].split(':')
        except ValueError:
            continue
        if repo == deploy_repo:
            c['Tag'] = tag
            c['Repo'] = repo
            c['Created'] = datetime.fromtimestamp(c['Created'])
            c['Names'] = [n[1:] for n in c['Names']]
            containers.append(c)

    form = forms.add_route_form(containers, request.form)

    if request.method == 'POST' and form.validate():
        container_ip = utils.get_container_ip(
            client,
            form.data['container']
        )
        frontend_ip = utils.get_frontend_ip(client)
        routes.add(
            frontend_ip, 5500,
            form.data['routing_key'],
            container_ip, 5510,
            form.data['weight']
        )

        return redirect(url_for('deployer.routing'))

    return render_template('add-route.html', form=form)
示例#4
0
 def get_ip(self):
     client = self.host.get_client()
     return get_container_ip(client, self.container)