Exemple #1
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
Exemple #2
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
Exemple #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
Exemple #4
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
Exemple #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
Exemple #6
0
def join_manager(args):
    config = load_configfile(args)
    thumbprint = get_thumbprint(args)
    logger.info('Join edge with manager')
    for edge in config['nsxEdge']:
        connect_cli(edge)
        _get_manager_status(edge)
        if not edge['join_manager']:
            stdin, stdout, stderr = edge['cli'].exec_command(
                "join management-plane %s username %s password %s thumbprint %s"
                % (config['nsxManager']['ip'], config['nsxManager']['user'],
                   config['nsxManager']['password'], thumbprint))
            for line in stdout:
                if len(line.strip()) == 0:
                    continue
                else:
                    if 'Node successfully registered' in line:
                        logger.info(line)
                        break
    return
Exemple #7
0
def join_manager(client, data, config):
    thumbprint = get_thumbprint(config)
    logger.info('Join controller with manager')
    for controller in config['nsxController']:
        connect_cli(controller)
        _get_manager_status(controller)
        if not controller['join_manager']:
            stdin, stdout, stderr = controller['cli'].exec_command(
                "join management-plane %s username %s password %s thumbprint %s"
                %
                (config['nsxManager']['ip'], config['nsxManager']['username'],
                 config['nsxManager']['password'], thumbprint))
            for line in stdout:
                if len(line.strip()) == 0:
                    continue
                else:
                    if 'Node successfully registered' in line:
                        print(line)
                        break
    return
Exemple #8
0
def get_thumbprint(config):
    thumbprint = ''
    logger.info('Get API Thumbprint')
    cli = connect_cli(config['nsxManager'])
    stdin, stdout, stderr = cli.exec_command('get certificate api thumbprint')
    for line in stdout:
        if len(line.strip()) == 0:
            continue
        else:
            thumbprint = line.strip()
            print("Thumbprint: %s" % thumbprint)
    return thumbprint
Exemple #9
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)