Esempio n. 1
0
def service_add(request, engine_name=None, engine_version=None):
    """
    Responds to tsuru's service_add call.
    
    Creates a new databaseinfra.
    
    Return codes:
    201: when the databaseinfra is successfully created. You don’t need to include any content in the response body.
    500: in case of any failure in the creation process. Make sure you include an explanation for the failure in the response body.
    """
    LOG.info("service_add for %s(%s)" % (engine_name, engine_version))

    LOG.debug("request DATA: %s" % request.DATA)
    LOG.debug("request QUERY_PARAMS: %s" % request.QUERY_PARAMS)
    LOG.debug("request content-type: %s" % request.content_type)
    # LOG.debug("request meta: %s" % request.META)
    engine = __check_service_availability(engine_name, engine_version)
    if not engine:
        return Response(data={
            "error":
            "endpoint not available for %s(%s)" % (engine_name, engine_version)
        },
                        status=500)

    data = request.DATA
    service_name = data.get('name', None)
    LOG.info("creating service %s" % (service_name))
    try:
        databaseinfra = DatabaseInfra.provision(engine=engine,
                                                name=service_name)
        return Response(
            {
                "hostname": databaseinfra.instance.address,
                "engine_type": engine.name,
                "version": engine.version,
                "databaseinfra_name": databaseinfra.name
            },
            status=201)
    except Exception, e:
        LOG.error("error provisioning databaseinfra %s: %s" %
                  (service_name, e))
Esempio n. 2
0
def service_add(request, engine_name=None, engine_version=None):
    """
    Responds to tsuru's service_add call.
    
    Creates a new databaseinfra.
    
    Return codes:
    201: when the databaseinfra is successfully created. You don’t need to include any content in the response body.
    500: in case of any failure in the creation process. Make sure you include an explanation for the failure in the response body.
    """
    LOG.info("service_add for %s(%s)" % (engine_name, engine_version))

    LOG.debug("request DATA: %s" % request.DATA)
    LOG.debug("request QUERY_PARAMS: %s" % request.QUERY_PARAMS)
    LOG.debug("request content-type: %s" % request.content_type)
    # LOG.debug("request meta: %s" % request.META)
    engine = __check_service_availability(engine_name, engine_version)
    if not engine:
        return Response(data={"error": "endpoint not available for %s(%s)" % (engine_name, engine_version)}, status=500)

    data = request.DATA
    service_name = data.get("name", None)
    LOG.info("creating service %s" % (service_name))
    try:
        databaseinfra = DatabaseInfra.provision(engine=engine, name=service_name)
        return Response(
            {
                "hostname": databaseinfra.instance.address,
                "engine_type": engine.name,
                "version": engine.version,
                "databaseinfra_name": databaseinfra.name,
            },
            status=201,
        )
    except Exception, e:
        LOG.error("error provisioning databaseinfra %s: %s" % (service_name, e))