Esempio n. 1
0
def handleList(request):
    """
    Requires a user_name, can take a criteria to narrow
    the cluster search by.  Takes a list of strings for
    other options.  Currently the only other option is
    to turn return lite clusters.

    Input:
    { user_name : string
      ?criteria : string
      ?options  : {'lite'       : boolean,
                   'auth_token' : string
                  }
    }
    Output:
    [cluster] | [cluster_lite]
    """
    if 'auth_token' in request.body.get('options', {}):
        authToken = request.body['options']['auth_token']
        if not auth_token.validateToken(authToken):
            raise auth_token.AuthTokenError()
        
    persistManager = request.state.persistManager
    clusters = yield persistManager.loadClustersBy(request.body.get('criteria', {}),
                                                   request.body['user_name'])
    clusterDicts = map(persistManager.clusterToDict, clusters)
    if request.body.get('options', {}).get('lite', False):
        clusterDicts = map(removeDetail, clusterDicts)
        
    defer.returnValue(request.update(response=clusterDicts))
Esempio n. 2
0
def _handleTerminateCluster(request):
    # Start task running
    yield tasks_tx.updateTask(request.body['task_name'],
                              lambda t: t.setState(tasks_tx.task.TASK_RUNNING))

    persistManager = request.state.persistManager

    credClient = cred_client.CredentialClient('local', request.mq,
                                              request.state.conf)
    if request.body['cluster_name'] != 'local':
        cluster = yield terminateRemoteCluster(request)
        yield persistManager.saveCluster(cluster)

        removeTerminatedCluster(persistManager, credClient,
                                request.body['cluster_name'],
                                request.body['user_name'])

    else:
        if ('auth_token' in request.body
                and auth_token.validateToken(request.body['auth_token'])):
            yield terminateCluster(credClient, persistManager, 'local',
                                   request.body['user_name'])
            removeTerminatedCluster(persistManager, credClient,
                                    request.body['cluster_name'],
                                    request.body['user_name'])
        else:
            raise auth_token.AuthTokenError()

    yield tasks_tx.updateTask(request.body['task_name'],
                              lambda t: t.progress())

    defer.returnValue(request)
Esempio n. 3
0
def handleList(request):
    """
    Requires a user_name, can take a criteria to narrow
    the cluster search by.  Takes a list of strings for
    other options.  Currently the only other option is
    to turn return lite clusters.

    Input:
    { user_name : string
      ?criteria : string
      ?options  : {'lite'       : boolean,
                   'auth_token' : string
                  }
    }
    Output:
    [cluster] | [cluster_lite]
    """
    if 'auth_token' in request.body.get('options', {}):
        authToken = request.body['options']['auth_token']
        if not auth_token.validateToken(authToken):
            raise auth_token.AuthTokenError()

    persistManager = request.state.persistManager
    clusters = yield persistManager.loadClustersBy(
        request.body.get('criteria', {}), request.body['user_name'])
    clusterDicts = map(persistManager.clusterToDict, clusters)
    if request.body.get('options', {}).get('lite', False):
        clusterDicts = map(removeDetail, clusterDicts)

    defer.returnValue(request.update(response=clusterDicts))
Esempio n. 4
0
def _handleTerminateCluster(request):
    # Start task running
    yield tasks_tx.updateTask(request.body["task_name"], lambda t: t.setState(tasks_tx.task.TASK_RUNNING))

    persistManager = request.state.persistManager

    credClient = cred_client.CredentialClient("local", request.mq, request.state.conf)
    if request.body["cluster_name"] != "local":
        cluster = yield terminateRemoteCluster(request)
        yield persistManager.saveCluster(cluster)

        removeTerminatedCluster(persistManager, credClient, request.body["cluster_name"], request.body["user_name"])

    else:
        if "auth_token" in request.body and auth_token.validateToken(request.body["auth_token"]):
            yield terminateCluster(credClient, persistManager, "local", request.body["user_name"])
            removeTerminatedCluster(persistManager, credClient, request.body["cluster_name"], request.body["user_name"])
        else:
            raise auth_token.AuthTokenError()

    yield tasks_tx.updateTask(request.body["task_name"], lambda t: t.progress())

    defer.returnValue(request)