fixed a bug with the async with statements

This commit is contained in:
UpstreamData
2021-10-26 13:29:28 -06:00
parent edbd1bbe94
commit 1372183af8
3 changed files with 7 additions and 10 deletions

View File

@@ -62,7 +62,7 @@ async def scan_network(network):
async def miner_light(ips: list): async def miner_light(ips: list):
await asyncio.gather(flip_light(ip) for ip in ips) await asyncio.gather(*[flip_light(ip) for ip in ips])
async def flip_light(ip): async def flip_light(ip):

View File

@@ -25,7 +25,7 @@ class BOSminer(BaseMiner):
async def send_ssh_command(self, cmd: str) -> None: async def send_ssh_command(self, cmd: str) -> None:
result = None result = None
async with self._get_ssh_connection() as conn: async with (await self._get_ssh_connection()) as conn:
for i in range(3): for i in range(3):
try: try:
result = await conn.run(cmd) result = await conn.run(cmd)
@@ -58,8 +58,7 @@ class BOSminer(BaseMiner):
await self.send_ssh_command('/sbin/reboot') await self.send_ssh_command('/sbin/reboot')
async def get_config(self) -> None: async def get_config(self) -> None:
async with asyncssh.connect(str(self.ip), known_hosts=None, username='root', password='admin', async with (await self._get_ssh_connection()) as conn:
server_host_key_algs=['ssh-rsa']) as conn:
async with conn.start_sftp_client() as sftp: async with conn.start_sftp_client() as sftp:
async with sftp.open('/etc/bosminer.toml') as file: async with sftp.open('/etc/bosminer.toml') as file:
toml_data = toml.loads(await file.read()) toml_data = toml.loads(await file.read())
@@ -69,8 +68,7 @@ class BOSminer(BaseMiner):
self.config = config self.config = config
async def get_hostname(self) -> str: async def get_hostname(self) -> str:
async with asyncssh.connect(str(self.ip), known_hosts=None, username='root', password='admin', async with (await self._get_ssh_connection()) as conn:
server_host_key_algs=['ssh-rsa']) as conn:
data = await conn.run('cat /proc/sys/kernel/hostname') data = await conn.run('cat /proc/sys/kernel/hostname')
return data.stdout.strip() return data.stdout.strip()
@@ -108,8 +106,7 @@ class BOSminer(BaseMiner):
async def send_config(self, config: dict) -> None: async def send_config(self, config: dict) -> None:
toml_conf = toml.dumps(config) toml_conf = toml.dumps(config)
async with asyncssh.connect(str(self.ip), known_hosts=None, username='root', password='admin', async with (await self._get_ssh_connection()) as conn:
server_host_key_algs=['ssh-rsa']) as conn:
async with conn.start_sftp_client() as sftp: async with conn.start_sftp_client() as sftp:
async with sftp.open('/etc/bosminer.toml', 'w+') as file: async with sftp.open('/etc/bosminer.toml', 'w+') as file:
await file.write(toml_conf) await file.write(toml_conf)

View File

@@ -27,7 +27,7 @@ class CGMiner(BaseMiner):
async def send_ssh_command(self, cmd): async def send_ssh_command(self, cmd):
result = None result = None
async with self._get_ssh_connection() as conn: async with (await self._get_ssh_connection()) as conn:
for i in range(3): for i in range(3):
try: try:
result = await conn.run(cmd) result = await conn.run(cmd)
@@ -86,7 +86,7 @@ class CGMiner(BaseMiner):
await self.send_ssh_command(commands) await self.send_ssh_command(commands)
async def get_config(self) -> None: async def get_config(self) -> None:
async with self._get_ssh_connection() as conn: async with (await self._get_ssh_connection()) as conn:
command = 'cat /etc/config/cgminer' command = 'cat /etc/config/cgminer'
result = await conn.run(command, check=True) result = await conn.run(command, check=True)
self._result_handler(result) self._result_handler(result)