X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=modules%2Flibjuju%2Fjuju%2Fmachine.py;h=39bfa119195b864e32500f0a8fed49f2d0509f48;hp=bd3d030e92414e896e72837a8f67eef9b963e2cc;hb=e2051cca7dac12aa09f6ed33555dcc4548c4b52b;hpb=c3e6c2ec9a1fddfc8e9bd31509b366e633b6d99e diff --git a/modules/libjuju/juju/machine.py b/modules/libjuju/juju/machine.py index bd3d030..39bfa11 100644 --- a/modules/libjuju/juju/machine.py +++ b/modules/libjuju/juju/machine.py @@ -14,7 +14,18 @@ log = logging.getLogger(__name__) class Machine(model.ModelEntity): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.on_change(self._workaround_1695335) + self.model.loop.create_task(self._queue_workarounds()) + + async def _queue_workarounds(self): + model = self.model + if not model.info: + await utils.run_with_interrupt(model.get_info(), + model._watch_stopping, + loop=model.loop) + if model._watch_stopping.is_set(): + return + if model.info.agent_version < client.Number.from_json('2.2.3'): + self.on_change(self._workaround_1695335) async def _workaround_1695335(self, delta, old, new, model): """ @@ -39,7 +50,7 @@ class Machine(model.ModelEntity): full_status = await utils.run_with_interrupt(model.get_status(), model._watch_stopping, - model.loop) + loop=model.loop) if model._watch_stopping.is_set(): return @@ -135,7 +146,8 @@ class Machine(model.ModelEntity): :param str destination: Remote destination of transferred files :param str user: Remote username :param bool proxy: Proxy through the Juju API server - :param str scp_opts: Additional options to the `scp` command + :param scp_opts: Additional options to the `scp` command + :type scp_opts: str or list """ if proxy: raise NotImplementedError('proxy option is not implemented') @@ -152,7 +164,8 @@ class Machine(model.ModelEntity): :param str destination: Local destination of transferred files :param str user: Remote username :param bool proxy: Proxy through the Juju API server - :param str scp_opts: Additional options to the `scp` command + :param scp_opts: Additional options to the `scp` command + :type scp_opts: str or list """ if proxy: raise NotImplementedError('proxy option is not implemented') @@ -170,10 +183,10 @@ class Machine(model.ModelEntity): '-i', os.path.expanduser('~/.local/share/juju/ssh/juju_id_rsa'), '-o', 'StrictHostKeyChecking=no', '-q', - '-B', - source, destination + '-B' ] - cmd += scp_opts.split() + cmd.extend(scp_opts.split() if isinstance(scp_opts, str) else scp_opts) + cmd.extend([source, destination]) loop = self.model.loop process = await asyncio.create_subprocess_exec(*cmd, loop=loop) await process.wait()