From 10cde710124c3cc18892c9f4edbedce979fbfcdc Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 15 Jan 2013 12:42:57 -0800 Subject: Save password set through xen agent. The get-password extension expects an encrypted b64 encoded password. If we are setting the password via a guest agent and the user has provided a public key, then we can go ahead and encrypt the password and write it to metadata. If the guest agent is not working or not installed, we leave the encrypted password to be set by posting to the metadata server. Related to blueprint get-password Change-Id: I3ed26c7e1929f3c4c84f9bb87b0c620ab27223cb --- nova/virt/xenapi/agent.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nova/virt/xenapi/agent.py b/nova/virt/xenapi/agent.py index 61cfa9631..ef08edbc1 100644 --- a/nova/virt/xenapi/agent.py +++ b/nova/virt/xenapi/agent.py @@ -21,6 +21,9 @@ import os import time import uuid +from nova.api.metadata import password +from nova import context +from nova import crypto from nova.openstack.common import cfg from nova.openstack.common import jsonutils from nova.openstack.common import log as logging @@ -207,6 +210,12 @@ class XenAPIBasedAgent(object): LOG.error(msg, instance=self.instance) raise Exception(msg) + sshkey = self.instance.get('key_data') + if sshkey: + enc = crypto.ssh_encrypt_text(sshkey, new_pass) + password.set_password(context.get_admin_context(), + self.instance['uuid'], base64.b64encode(enc)) + return resp['message'] def inject_file(self, path, contents): -- cgit