make miner ips a true ip address, and allow sorting miners using __lt__ and __gt__

This commit is contained in:
UpstreamData
2022-05-18 11:34:39 -06:00
parent 8ebcbd3c33
commit 8cbf3a20a3
8 changed files with 61 additions and 54 deletions

View File

@@ -1,5 +1,6 @@
import asyncssh
import logging
import ipaddress
class BaseMiner:
@@ -18,6 +19,15 @@ class BaseMiner:
def __repr__(self):
return f"{'' if not self.api_type else self.api_type} {'' if not self.model else self.model}: {str(self.ip)}"
def __lt__(self, other):
return ipaddress.ip_address(self.ip) < ipaddress.ip_address(other.ip)
def __gt__(self, other):
return ipaddress.ip_address(self.ip) > ipaddress.ip_address(other.ip)
def __eq__(self, other):
return ipaddress.ip_address(self.ip) == ipaddress.ip_address(other.ip)
async def _get_ssh_connection(self) -> asyncssh.connect:
"""Create a new asyncssh connection"""
try: