def get_nodes_and_apply_topology()

in assets/scripts/SilentInstaller.py [0:0]


def get_nodes_and_apply_topology(config_file, tsm_path, secrets, port, apply_and_restart=False):
    ''' Retrieves the nodes from the config file and apply topology update if all nodes are ready '''

    config = read_json_file(config_file)
    expected_nodes = set()
    if 'nodes' in config['topologyVersion']:
        # See if nodes are in entities, if yes get them
        nodes = config['topologyVersion']['nodes']
        for nodeId in nodes:
            expected_nodes.add(nodeId)
        nodes_output_list = run_tsm_command(tsm_path, secrets, ['topology', 'list-nodes'], port, return_tsm_result=True)
        actual_nodes = set(nodes_output_list.splitlines())
        if not expected_nodes.issubset(actual_nodes):
            # topology not ready with all expected nodes, return with no-op
            print('Not all nodes in desired topology are ready. Please make sure all worker nodes are installed properly then rerun SilentInstaller with updateTopology option.')
            print('Expected nodes: ' + ', '.join(expected_nodes))
            print('Actual nodes: ' + ', '.join(actual_nodes))
            return
        run_tsm_command(tsm_path, secrets, ['settings', 'import', '--topology-only', '-f', config_file], port)
        print('Topology applied')
        if apply_and_restart:
            run_tsm_command(tsm_path, secrets, ['pending-changes', 'apply', '--ignore-prompt', '--ignore-warnings'], port)
            print('Topology change has been applied.')
            for node in actual_nodes - expected_nodes:
                # nodes not listed in topology will be removed for consistency
                print('Removing extra node: ' + node)
                run_tsm_command(tsm_path, secrets, ['topology', 'remove-nodes', '-n', node], port)
                print('Node ' + node + 'has been removed. Please uninstall Tableau server from the node for complete clean up.')
            print('Restarting server...')
            run_tsm_command(tsm_path, secrets, ['restart'], port)
            print('Server is running after restart.')