Abstract out namenode logic to a function get_namenodes