Ejemplo n.º 1
0
def start(servicetype, cloudname="default"):
    """eg: POST /start/php

    POSTed values might contain 'appid' to specify that the service to be
    created has to belong to a specific application. If 'appid' is omitted, the
    service will belong to the default application.

    Returns a dictionary with service data (manager's vmid and IP address,
    service name and ID) in case of successful authentication and correct
    service creation. False is returned otherwise.
    """
    appid = request.values.get('appid')

    # Use default application id if no appid was specified
    if not appid:
        appid = get_default_app(g.user.uid).aid

    return _start(servicetype, cloudname, appid)
Ejemplo n.º 2
0
def start(servicetype, cloudname="default"):
    """eg: POST /start/php

    POSTed values might contain 'appid' to specify that the service to be
    created has to belong to a specific application. If 'appid' is omitted, the
    service will belong to the default application.

    Returns a dictionary with service data (manager's vmid and IP address,
    service name and ID) in case of successful authentication and correct
    service creation. False is returned otherwise.
    """
    appid = request.values.get('appid')

    # Use default application id if no appid was specified
    if not appid:
        appid = get_default_app(g.user.uid).aid

    return _start(servicetype, cloudname, appid)
Ejemplo n.º 3
0
def _add(service_type, app_id):
    log("User '%s' is attempting to add a new %s service to application %s"
        % (g.user.username, service_type, app_id))

    # Use default application id if no appid was specified
    if not app_id:
        app = get_default_app(g.user.uid)
        if not app:
            msg = "No existing applications"
            log_error(msg)
            return error_response(msg)
        else:
            app_id = app.aid
    else:
        app = get_app_by_id(g.user.uid, app_id)

    # Check if we got a valid service type
    if service_type not in valid_services:
        msg = "Unknown service type '%s'" % service_type
        log_error(msg)
        return error_response(msg)

    data = { 'service_type': service_type }
    res  = callmanager(app_id, 0, "add_service", True, data)

    if 'service_id' in res:
        sid = res['service_id']
        s = Service(sid=sid, name="New %s service" % service_type, type=service_type,
            user=g.user, application=app, manager=app.to_dict()['manager'])
        db.session.add(s)
        db.session.commit()

        log('Service created successfully')
        return s.to_dict()

    return res