'Populate user\'s known_hosts file with pub keys from hosts in nodes list
username - name of the user to add to known hosts for
nodes - the nodes to add to the user\'s known hosts file
add_self - add this Node to known_hosts in addition to nodes'

def add_to_known_hosts(self, username, nodes, add_self=True):

    user = self.getpwnam(username)
    known_hosts_file = posixpath.join(user.pw_dir, '.ssh', 'known_hosts')
    khosts = []
    if (add_self and (self not in nodes)):
        nodes.append(self)
    self.remove_from_known_hosts(username, nodes)
    for node in nodes:
        server_pkey = node.ssh.get_server_public_key()
        node_names = {}.fromkeys([node.alias, node.private_dns_name, node.private_dns_name_short], node.private_ip_address)
        node_names[node.public_dns_name] = node.ip_address
        for (name, ip) in node_names.items():
            name_ip = ('%s,%s' % (name, ip))
            khosts.append('    '.join([name_ip, server_pkey.get_name(), base64.b64encode(str(server_pkey))]))
    khostsf = self.ssh.remote_file(known_hosts_file, 'a')
    khostsf.write(('\n'.join(khosts) + '\n'))
    khostsf.chown(user.pw_uid, user.pw_gid)
    khostsf.close()
