ConfigDrive: better support public-keys in meta flags

This makes the user able to pass in multi-line input to the public-key flag,
and it will be handled correctly (just as if it came from the authorized_keys
file)
This commit is contained in:
Scott Moser 2012-02-17 16:59:04 -05:00
parent a10e5474d3
commit 13ff9f2386

View File

@ -162,6 +162,7 @@ def read_config_drive_dir(source_dir):
flist = ("etc/network/interfaces", "root/.ssh/authorized_keys", "meta.js")
found = [f for f in flist if os.path.isfile("%s/%s" % (source_dir, f))]
keydata = ""
if len(found) == 0:
raise nonConfigDriveDir("%s: %s" % (source_dir, "no files found"))
@ -172,10 +173,7 @@ def read_config_drive_dir(source_dir):
if "root/.ssh/authorized_keys" in found:
with open("%s/%s" % (source_dir, "root/.ssh/authorized_keys")) as fp:
content = fp.read()
lines = content.splitlines()
keys = [l for l in lines if len(l) and not l.startswith("#")]
md['public-keys'] = keys
keydata = fp.read()
meta_js = {}
@ -190,7 +188,14 @@ def read_config_drive_dir(source_dir):
raise nonConfigDriveDir("%s: %s" %
(source_dir, "invalid json in meta.js"))
for copy in ('public-keys', 'dsmode', 'instance-id', 'dscfg'):
keydata = meta_js.get('public-keys', keydata)
if keydata:
lines = keydata.splitlines()
md['public-keys'] = [l for l in lines
if len(l) and not l.startswith("#")]
for copy in ('dsmode', 'instance-id', 'dscfg'):
if copy in meta_js:
md[copy] = meta_js[copy]