Skip to content

Commit

Permalink
better recovery of the SSH example (#704)
Browse files Browse the repository at this point in the history
* better recovery of the SSH example
* move stuff to `start` altogether
  • Loading branch information
shadeofblue authored Oct 4, 2021
1 parent efa9b1c commit d41845d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions examples/ssh/ssh.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import asyncio
from datetime import timedelta
import pathlib
import random
import sys
Expand Down Expand Up @@ -43,19 +44,24 @@ async def get_payload():
capabilities=[vm.VM_CAPS_VPN],
)

async def run(self):
connection_uri = self.network_node.get_websocket_uri(22)
app_key = self.cluster._engine._api_config.app_key
async def start(self):
# perform the initialization of the Service
# (which includes sending the network details within the `deploy` command)
async for script in super().start():
yield script

password = "".join(random.choice(string.ascii_letters + string.digits) for _ in range(8))

script = self._ctx.new_script()
script = self._ctx.new_script(timeout=timedelta(seconds=10))
script.run("/bin/bash", "-c", "syslogd")
script.run("/bin/bash", "-c", "ssh-keygen -A")
script.run("/bin/bash", "-c", f'echo -e "{password}\n{password}" | passwd')
script.run("/bin/bash", "-c", "/usr/sbin/sshd")
yield script

connection_uri = self.network_node.get_websocket_uri(22)
app_key = self.cluster._engine._api_config.app_key

print(
"Connect with:\n"
f"{TEXT_COLOR_CYAN}"
Expand All @@ -65,9 +71,6 @@ async def run(self):

print(f"{TEXT_COLOR_RED}password: {password}{TEXT_COLOR_DEFAULT}")

# await indefinitely...
await asyncio.Future()


async def main(subnet_tag, payment_driver=None, payment_network=None):
# By passing `event_consumer=log_summary()` we enable summary logging.
Expand Down

0 comments on commit d41845d

Please sign in to comment.