def newProvisionedMachineCluster(datastore, endpoint, apiVersion=None):
    '''
    Set a preprovisioned single-machine cluster. 'endpoint' is the Docker host api endpoint.
    '''
    try:
        info = __obtainDockerHostInfo__(endpoint)
        dk = docker.dockerClient(base_url=endpoint, cert_path=settings.DK_DEFAULT_MASTER_CLIENT_CERTS)

        # Generate token
        token = tokens.newClusterToken(datastore)

        # Add to filesystem: for this simple already provisioned machine, only the folder will be created
        try:
            files.createClusterDir(token)
        except os.error:
            files.deleteClusterDir(token)
            raise errors.OperationError("Couldn't create cluster reference in the filesystem")

        # Add to datastore
        datastorecluster = {'token':token, 'status':'joining',
        'description':'Ready to use', 'numberOfNodes':1, 'type':'swarm',
        'nodes':[{'endpoint':endpoint, 'status':'joining'}]}
        datastore.addCluster(token, datastorecluster)

        docker.createOneNodeSwarm(datastore, token, dk)

        return datastorecluster, 200

    except errors.ControllerError, e:
        return e.getResponse()
def __obtainDockerHostInfo__(endpoint):
    # Obtain information about docker daemon listening on endpoint
    info = None

    try:
        dk = docker.dockerClient(base_url=endpoint, cert_path=settings.DK_DEFAULT_MASTER_CLIENT_CERTS)
        info = docker.dockerInfo(dk)
    except Exception, e:
        raise errors.ControllerError("Error while connecting with provided docker host. Endpoint: '"+str(endpoint)+"' exception:"+str(e))
def getDockerInfo(endpoint):
    '''
    Retrieve docker system information
    '''
    try:
        dk = docker.dockerClient(base_url=endpoint, cert_path=settings.DK_DEFAULT_MASTER_CLIENT_CERTS)
        return docker.dockerInfo(dk)
    except Exception, e:
        aux = errors.ControllerError("Unknown error: "+ e.message)
        return aux.getResponse()
Beispiel #4
0
def __obtainDockerHostInfo__(endpoint):
    # Obtain information about docker daemon listening on endpoint
    info = None

    try:
        dk = docker.dockerClient(
            base_url=endpoint,
            cert_path=settings.DK_DEFAULT_MASTER_CLIENT_CERTS)
        info = docker.dockerInfo(dk)
    except Exception, e:
        raise errors.ControllerError(
            "Error while connecting with provided docker host. Endpoint: '" +
            str(endpoint) + "' exception:" + str(e))
Beispiel #5
0
def newComposition(datastore, composefile, clusterReference):
    '''
    Saves docker compose file and runs it.
    '''
    cluster = None
    try:
        token = tokens.newCompositionToken(datastore)
        # retrieve cluster information from datastore
        cluster = datastore.getCluster(clusterReference)
        if cluster == None:
            raise errors.ControllerError("Cluster does not exist.")
        # Check docker
        endpoint = cluster['nodes'][0]['endpoint']
        dk = docker.dockerClient(endpoint,
                                 settings.DK_DEFAULT_MASTER_CLIENT_CERTS)

        dockercheck = docker.checkDocker(dk)
        if dockercheck is not True:
            raise errors.ControllerError("Error in cluster. Docker error: " +
                                         dockercheck)

        # Create composition in datastore
        datastorecomposition = {
            'token': token,
            'cluster': clusterReference,
            'status': 'providing',
            'description': 'Providing data'
        }
        datastore.addComposition(token, datastorecomposition)

        # Save compose file
        try:
            files.saveComposeFile(token, composefile)
        except os.error:
            files.deleteComposeFile(token)
            datastore.delComposition(token)
            raise errors.OperationError(
                "Couldn't create composition in the filesystem")

        # Launch composition
        docker.runComposition(datastore, token, dk=dk)

        return datastorecomposition
    except dataStore.DataStoreError, e:
        aux = errors.ControllerError("Runtime error: " + e.message)
        return aux.getResponse()
def newComposition(datastore, composefile, clusterReference=''):
    '''
    Saves docker compose file and runs it.
    '''
    cluster = None
    try:
        token = tokens.newCompositionToken(datastore)

        # retrieve cluster information from datastore
        cluster = datastore.getCluster(clusterReference)
        if cluster == None:
            raise errors.NotFoundError("Cluster does not exist.")

        # Check docker
        endpoint = cluster['nodes'][0]['endpoint']
        dk = docker.dockerClient(endpoint, settings.DK_DEFAULT_MASTER_CLIENT_CERTS)
        dockercheck = docker.checkDocker(dk)
        if dockercheck is not True:
            raise errors.ControllerError("Error in cluster. Docker error: " + dockercheck)

        # Create composition in datastore
        datastorecomposition = {'token':token, 'cluster':clusterReference, 'status':'providing', 'description':'Providing data'}
        datastore.addComposition(token, datastorecomposition)

        # Save compose file
        try:
            files.saveComposeFile(token, composefile)
        except os.error:
            files.deleteComposeFile(token)
            datastore.delComposition(token)
            raise errors.OperationError("Couldn't create composition in the filesystem")

        # Launch composition
        if(clusterReference==''):
            docker.runComposition(datastore, token)
        else:
            docker.runComposition(datastore, token, dockerClient=cluster['endpoint'])

        return datastorecomposition
    except dataStore.DataStoreError, e:
        aux = errors.ControllerError("Runtime error: "+ e.message)
        return aux.getResponse()
Beispiel #7
0
def newProvisionedMachineCluster(datastore, endpoint, apiVersion=None):
    '''
    Set a preprovisioned single-machine cluster. 'endpoint' is the Docker host api endpoint.
    '''
    try:
        info = __obtainDockerHostInfo__(endpoint)
        dk = docker.dockerClient(
            base_url=endpoint,
            cert_path=settings.DK_DEFAULT_MASTER_CLIENT_CERTS)

        # Generate token
        token = tokens.newClusterToken(datastore)

        # Add to filesystem: for this simple already provisioned machine, only the folder will be created
        try:
            files.createClusterDir(token)
        except os.error:
            files.deleteClusterDir(token)
            raise errors.OperationError(
                "Couldn't create cluster reference in the filesystem")

        # Add to datastore
        datastorecluster = {
            'token': token,
            'status': 'joining',
            'description': 'Ready to use',
            'numberOfNodes': 1,
            'type': 'swarm',
            'nodes': [{
                'endpoint': endpoint,
                'status': 'joining'
            }]
        }
        datastore.addCluster(token, datastorecluster)

        docker.createOneNodeSwarm(datastore, token, dk)

        return datastorecluster, 200

    except errors.ControllerError, e:
        return e.getResponse()