'Set the root/admin password on the VM instance.
This is done via an agent running on the VM. Communication between nova
and the agent is done via writing xenstore records. Since communication
is done over the XenAPI RPC calls, we need to encrypt the password.
We\'re using a simple Diffie-Hellman class instead of a more advanced
library (such as M2Crypto) for compatibility with the agent code.'

def set_admin_password(self, new_pass):

    LOG.debug('Setting    admin    password', instance=self.instance)
    try:
        dh = self._exchange_key_with_agent()
    except exception.AgentError as error:
        self._add_instance_fault(error, sys.exc_info())
        return
    enc_pass = dh.encrypt((new_pass + '\n'))
    args = {'enc_pass': enc_pass}
    self._call_agent(host_agent.password, args)
    self._save_instance_password_if_sshkey_present(new_pass)
