コード例 #1
0
def get_status(args):
    config = load_configfile(args)
    for edge in config['nsxEdge']:
        cli = connect_cli(edge)
        exec_command(cli, 'get interface eth0', display=True)
        exec_command(cli, 'get managers', display=True)
    return
コード例 #2
0
def _get_cluster_status(controller):
    connect_cli(controller)
    ret = exec_command(controller['cli'], 'get control-cluster status')
    for line in ret.split("\n"):
        if 'master:' in line:
            if 'true' in line:
                logger.info('%s is master', controller['ip'])
                controller['master'] = True
            else:
                logger.info('%s is not master', controller['ip'])
                controller['master'] = False
        if 'majority:' in line:
            if 'true' in line:
                logger.info('%s is majority', controller['ip'])
                controller['majority'] = True
            else:
                logger.info('%s is not majority', controller['ip'])
                controller['majority'] = False
        if 'This node has not yet joined the cluster' in line:
            return
    ret = exec_command(controller['cli'], 'get control-cluster status verbose')
    numOfJoinedNode = 0
    for line in ret.split("\n"):
        if 'Zookeeper Server IP:' in line:
            numOfJoinedNode += 1

    logger.info("%s controllers shown in %s" %
                (numOfJoinedNode, controller['ip']))
    if numOfJoinedNode > 1:
        controller['activate'] = True
    else:
        controller['activate'] = False
    return
コード例 #3
0
def initialize(client, data, config):
    for controller in config['nsxController']:
        connect_cli(controller)
        _get_cluster_status(controller)
        if controller['master'] == False and controller['majority'] == False:
            exec_command(
                controller['cli'],
                "set control-cluster security-model shared-secret secret %s" %
                controller['secret'],
                display=True)
            exec_command(controller['cli'],
                         'initialize control-cluster',
                         display=True)
            return
コード例 #4
0
def _get_manager_status(edge):
    connect_cli(edge)
    ret = exec_command(edge['cli'], 'get managers')
    if 'Connected' in ret:
        logger.info('%s is connected to manager', edge['ip'])
        edge['join_manager'] = True
    else:
        logger.warning('%s is not connected to manager', edge['ip'])
        edge['join_manager'] = False
コード例 #5
0
def get_status(args):
    config = load_configfile(args)
    for controller in config['nsxController']:
        cli = connect_cli(controller)
        exec_command(cli, 'get interface eth0', display=True)
        exec_command(cli, 'get managers', display=True)
        exec_command(cli, 'get control-cluster status', display=True)
        _get_manager_status(controller)
        _get_cluster_status(controller)
    return
コード例 #6
0
def join_cluster(args):
    config = load_configfile(args)
    # Check master exists
    master = _get_master(config)
    logger.info("Master: %s" % master['ip'])
    if master is None:
        logger.error('No master node exists')
        return
    connect_cli(master)

    slaves = _get_slaves(config)
    logger.info("Slaves: %s" % ",".join([slave['ip'] for slave in slaves]))
    for controller in slaves:
        connect_cli(controller)
        controller['master'], controller['majority'] = _get_cluster_status(
            controller['cli'])

    for controller in slaves:
        if controller['majority']:
            continue
        controller['thumbprint'] = _get_thumbprint(controller['cli'])
        if controller['thumbprint'] is None:
            exec_command(
                controller['cli'],
                "set control-cluster security-model shared-secret secret %s" %
                controller['secret'],
                display=True)
            controller['thumbprint'] = _get_thumbprint(controller['cli'])

    for controller in slaves:
        if controller['majority']:
            continue
        exec_command(master['cli'],
                     "join control-cluster %s thumbprint %s" %
                     (controller['ip'], controller['thumbprint']),
                     display=True)
        exec_command(controller['cli'],
                     "activate control-cluster",
                     display=True)