示例#1
0
def main(options, _args):
    res = []
    runSingleProgramEx('hostname -f', res.append, errorPrintS)
    localHost = ''.join(res).strip()
    outFile = createDataFile(options, [options('general.mode')],
                             options('general.output'))
    open(outFile, 'a').write('MASTER_IP=' + localHost + '\n')
示例#2
0
def main(options, _args):
    res = []
    runSingleProgramEx('hostname -f', res.append, errorPrintS)
    localHost = ''.join(res).strip()
    outFile = createDataFile(options, [options('general.mode')], options('general.output'))
    open(outFile, 'a').write('MASTER_IP=' + localHost + '\n')
示例#3
0
def startMaster(state, credClient, taskName, cluster):
    @defer.inlineCallbacks
    def _saveCluster(instances):
        instances = yield credClient.updateInstances(instances)
        cl = yield state.persistManager.loadCluster(cluster.clusterName,
                                                    cluster.userName)

        cl = cl.setMaster(instances[0])
        yield state.persistManager.saveCluster(cl)
        defer.returnValue(func.Record(succeeded=instances, failed=[]))

    credConfigMap = yield credClient.credentialConfig()
    credConfig = config.configFromMap(credConfigMap)
    baseConf = config.configFromConfig(cluster.config, base=credConfig)
    clusterConf = config.configFromMap(
        {
            'general.ctype': credConfig('general.ctype'),
            'cluster.cluster_public_key': '/mnt/keys/devel1.pem.pub'
        },
        base=baseConf)
    cl = cluster.update(config=clusterConf)

    mode = [vappio_config.MASTER_NODE]
    masterConfFilename = '/tmp/machine.' + global_state.make_ref() + '.conf'
    masterConf = vappio_config.createDataFile(cl.config,
                                              mode,
                                              outFile=masterConfFilename)
    dataFile = vappio_config.createMasterDataFile(cl, masterConf)

    groups = [g.strip() for g in cl.config('cluster.master_groups').split(',')]
    masterInstanceList = yield runInstances(
        credClient, cl.config('cluster.ami'), cl.config('cluster.key'),
        cl.config('cluster.master_type'), groups,
        cl.config('cluster.availability_zone', default=None),
        cl.config('cluster.master_bid_price', default=None), 1, 1,
        open(dataFile).read())

    cl = cl.setMaster(masterInstanceList[0])
    yield state.persistManager.saveCluster(cl)

    os.remove(masterConf)
    os.remove(dataFile)

    instances = yield waitForInstances(masterInstanceList, [
        updateTask(taskName, 'Waiting for master'),
        waitForState(credClient, 'running',
                     WAIT_FOR_STATE_TRIES), _saveCluster,
        updateTask(taskName, 'Master in running state'),
        waitForSSH(cl.config('ssh.user'), cl.config('ssh.options'),
                   WAIT_FOR_SSH_TRIES), _saveCluster,
        updateTask(taskName, 'SSH up'),
        waitForBoot('/tmp/startup_complete', cl.config('ssh.user'),
                    cl.config('ssh.options'),
                    WAIT_FOR_BOOT_TRIES), _saveCluster,
        updateTask(taskName, 'Booted'),
        waitForClusterInfo('local', 'guest', WAIT_FOR_SERVICES_TRIES),
        _saveCluster,
        updateTask(taskName, 'Cluster info responded')
    ])

    yield credClient.terminateInstances(instances.failed)

    if not instances.succeeded:
        raise Error('Master failed to start')

    cl = yield state.persistManager.loadCluster(cl.clusterName, cl.userName)

    cl = cl.setState(cl.RUNNING)
    yield state.persistManager.saveCluster(cl)

    defer.returnValue(cl)
示例#4
0
def startMaster(state, credClient, taskName, cluster):
    @defer.inlineCallbacks
    def _saveCluster(instances):
        instances = yield credClient.updateInstances(instances)
        cl = yield state.persistManager.loadCluster(cluster.clusterName,
                                                    cluster.userName)

        cl = cl.setMaster(instances[0])
        yield state.persistManager.saveCluster(cl)
        defer.returnValue(func.Record(succeeded=instances,
                                      failed=[]))

    credConfigMap = yield credClient.credentialConfig()
    credConfig = config.configFromMap(credConfigMap)
    baseConf = config.configFromConfig(cluster.config,
                                       base=credConfig)
    clusterConf = config.configFromMap({'general.ctype': credConfig('general.ctype'),
                                        'cluster.cluster_public_key': '/mnt/keys/devel1.pem.pub'},
                                       base=baseConf)
    cl = cluster.update(config=clusterConf)

    mode = [vappio_config.MASTER_NODE]
    masterConfFilename = '/tmp/machine.' + global_state.make_ref() + '.conf'
    masterConf = vappio_config.createDataFile(cl.config,
                                              mode,
                                              outFile=masterConfFilename)
    dataFile = vappio_config.createMasterDataFile(cl, masterConf)

    groups = [g.strip()
              for g in cl.config('cluster.master_groups').split(',')]
    masterInstanceList = yield runInstances(credClient,
                                            cl.config('cluster.ami'),
                                            cl.config('cluster.key'),
                                            cl.config('cluster.master_type'),
                                            groups,
                                            cl.config('cluster.availability_zone',
                                                      default=None),
                                            cl.config('cluster.master_bid_price',
                                                      default=None),
                                            1,
                                            1,
                                            open(dataFile).read())

    cl = cl.setMaster(masterInstanceList[0])
    yield state.persistManager.saveCluster(cl)

    os.remove(masterConf)
    os.remove(dataFile)

    instances = yield waitForInstances(masterInstanceList,
                                       [updateTask(taskName,
                                                   'Waiting for master'),
                                        waitForState(credClient,
                                                     'running',
                                                     WAIT_FOR_STATE_TRIES),
                                        _saveCluster,
                                        updateTask(taskName,
                                                   'Master in running state'),
                                        waitForSSH(cl.config('ssh.user'),
                                                   cl.config('ssh.options'),
                                                   WAIT_FOR_SSH_TRIES),
                                        _saveCluster,
                                        updateTask(taskName,
                                                   'SSH up'),
                                        waitForBoot('/tmp/startup_complete',
                                                    cl.config('ssh.user'),
                                                    cl.config('ssh.options'),
                                                    WAIT_FOR_BOOT_TRIES),
                                        _saveCluster,
                                        updateTask(taskName,
                                                   'Booted'),
                                        waitForClusterInfo('local',
                                                           'guest',
                                                           WAIT_FOR_SERVICES_TRIES),
                                        _saveCluster,
                                        updateTask(taskName,
                                                   'Cluster info responded')])

    yield credClient.terminateInstances(instances.failed)
    
    if not instances.succeeded:
        raise Error('Master failed to start')

    cl = yield state.persistManager.loadCluster(cl.clusterName,
                                                cl.userName)

    cl = cl.setState(cl.RUNNING)
    yield state.persistManager.saveCluster(cl)
    
    defer.returnValue(cl)