diff --git a/qubesadmin/device_protocol.py b/qubesadmin/device_protocol.py index f20cbb3f..55e7c7f8 100644 --- a/qubesadmin/device_protocol.py +++ b/qubesadmin/device_protocol.py @@ -258,29 +258,35 @@ def __init__(self, backend_domain, port_id, devclass): self.__devclass = devclass def __hash__(self): - return hash((self.backend_domain.name, self.port_id, self.devclass)) + return hash((self.backend_name, self.port_id, self.devclass)) def __eq__(self, other): if isinstance(other, Port): return ( - self.backend_domain == other.backend_domain and - self.port_id == other.port_id and - self.devclass == other.devclass + self.backend_name == other.backend_name and + self.port_id == other.port_id and + self.devclass == other.devclass ) return False def __lt__(self, other): if isinstance(other, Port): - return (self.backend_domain.name, self.devclass, self.port_id) < \ - (other.backend_domain.name, other.devclass, other.port_id) + return (self.backend_name, self.devclass, self.port_id) < \ + (self.backend_name, other.devclass, other.port_id) raise TypeError(f"Comparing instances of 'Port' and '{type(other)}' " "is not supported") def __repr__(self): - return f"{self.backend_domain.name}+{self.port_id}" + return f"{self.backend_name}+{self.port_id}" def __str__(self): - return f"{self.backend_domain.name}:{self.port_id}" + return f"{self.backend_name}:{self.port_id}" + + @property + def backend_name(self) -> str: + if self.backend_domain is not None: + return self.backend_domain.name + return "*" @classmethod def from_qarg( @@ -324,7 +330,7 @@ def port_id(self) -> str: return self.__port_id @property - def backend_domain(self) -> QubesVM: + def backend_domain(self) -> Optional[QubesVM]: """ Which domain exposed this port. (immutable)""" return self.__backend_domain @@ -387,6 +393,13 @@ def backend_domain(self): return self.port.backend_domain return '*' + @property + def backend_name(self): + if self.port != '*': + return self.port.backend_name + return '*' + + @property def port_id(self): if self.port != '*' and self.port.port_id is not None: @@ -1090,15 +1103,19 @@ def __lt__(self, other): @property def backend_domain(self): - return self.virtual_device.port.backend_domain + return self.virtual_device.backend_domain + + @property + def backend_name(self) -> str: + return self.virtual_device.backend_name @property def port_id(self): - return self.virtual_device.port.port_id + return self.virtual_device.port_id @property def devclass(self): - return self.virtual_device.port.devclass + return self.virtual_device.devclass @property def device_id(self):