X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=juju%2Futils.py;h=c0a500c252e6bb1ba494a1737d8e56d722768f4f;hb=a09dd5038d226fbcda54a79bdddc995054857198;hp=b9a9b6707a1f6ea5f45d40b55e0d5015a766e4dd;hpb=e42708b6ce89b35b88ae526065951f994128ceed;p=osm%2FN2VC.git diff --git a/juju/utils.py b/juju/utils.py index b9a9b67..c0a500c 100644 --- a/juju/utils.py +++ b/juju/utils.py @@ -3,7 +3,7 @@ import os from pathlib import Path -async def execute_process(*cmd, log=None): +async def execute_process(*cmd, log=None, loop=None): ''' Wrapper around asyncio.create_subprocess_exec. @@ -13,7 +13,7 @@ async def execute_process(*cmd, log=None): stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, - ) + loop=loop) stdout, stderr = await p.communicate() if log: log.debug("Exec %s -> %d", cmd, p.returncode) @@ -24,10 +24,10 @@ async def execute_process(*cmd, log=None): 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") @@ -37,3 +37,11 @@ def read_ssh_key(): 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. + + ''' + return await loop.run_in_executor(None, _read_ssh_key)