import asyncio
-import concurrent.futures
import logging
from . import tag
# Add our ssh key to the model, to work around
# https://bugs.launchpad.net/juju/+bug/1643076
try:
- ssh_key = await self.loop.run_in_executor(
- concurrent.futures.ThreadPoolExecutor(),
- utils.read_ssh_key
- )
+ ssh_key = await utils.read_ssh_key(loop=self.loop)
await utils.execute_process(
'juju', 'add-ssh-key', '-m', model_name, ssh_key, log=log)
except Exception as e:
import asyncio
+import concurrent.futures
import os
from pathlib import Path
return p.returncode == 0
-def read_ssh_key():
+def _read_ssh_key():
'''
- Attempt to read the local juju admin's public ssh key, so that it
- can be passed on to a model.
+ Inner function for read_ssh_key, suitable for passing to our
+ Executor.
'''
default_data_dir = Path(Path.home(), ".local", "share", "juju")
ssh_key = ssh_key_file.readlines()[0].strip()
return ssh_key
+
+async def read_ssh_key(loop):
+ '''
+ Attempt to read the local juju admin's public ssh key, so that it
+ can be passed on to a model.
+
+ '''
+ ssh_key = await loop.run_in_executor(
+ concurrent.futures.ThreadPoolExecutor(),
+ _read_ssh_key
+ )
+ return ssh_key