koder aka kdanilov | 3d2bc4f | 2016-11-12 18:31:18 +0200 | [diff] [blame^] | 1 | import abc |
| 2 | from typing import Any, Set, Optional, List, Dict, Callable |
| 3 | |
| 4 | |
| 5 | class NodeInfo: |
| 6 | """Node information object, result of dicovery process or config parsing""" |
| 7 | |
| 8 | def __init__(self, |
| 9 | ssh_conn_url: str, |
| 10 | roles: Set[str], |
| 11 | hops: List['NodeInfo'] = None, |
| 12 | ssh_key: bytes = None) -> None: |
| 13 | |
| 14 | self.hops = [] # type: List[NodeInfo] |
| 15 | if hops is not None: |
| 16 | self.hops = hops |
| 17 | |
| 18 | self.ssh_conn_url = ssh_conn_url # type: str |
| 19 | self.rpc_conn_url = None # type: str |
| 20 | self.roles = roles # type: Set[str] |
| 21 | self.os_vm_id = None # type: Optional[int] |
| 22 | self.ssh_key = ssh_key # type: Optional[bytes] |
| 23 | self.params = {} # type: Dict[str, Any] |
| 24 | |
| 25 | |
| 26 | class ISSHHost(metaclass=abc.ABCMeta): |
| 27 | """Minimal interface, required to setup RPC connection""" |
| 28 | info = None # type: NodeInfo |
| 29 | |
| 30 | @abc.abstractmethod |
| 31 | def run(self, cmd: str, timeout: int = 60, nolog: bool = False) -> str: |
| 32 | pass |
| 33 | |
| 34 | @abc.abstractmethod |
| 35 | def get_ip(self) -> str: |
| 36 | pass |
| 37 | |
| 38 | @abc.abstractmethod |
| 39 | def __str__(self) -> str: |
| 40 | pass |
| 41 | |
| 42 | @abc.abstractmethod |
| 43 | def put_to_file(self, path: str, content: bytes) -> None: |
| 44 | pass |
| 45 | |
| 46 | |
| 47 | class IRPCNode(metaclass=abc.ABCMeta): |
| 48 | """Remote filesystem interface""" |
| 49 | info = None # type: NodeInfo |
| 50 | |
| 51 | @abc.abstractmethod |
| 52 | def run(self, cmd: str, timeout: int = 60, nolog: bool = False) -> str: |
| 53 | pass |
| 54 | |
| 55 | @abc.abstractmethod |
| 56 | def copy_file(self, local_path: str, remote_path: str = None) -> str: |
| 57 | pass |
| 58 | |
| 59 | @abc.abstractmethod |
| 60 | def get_file_content(self, path: str) -> bytes: |
| 61 | pass |
| 62 | |
| 63 | @abc.abstractmethod |
| 64 | def put_to_file(self, path:str, content: bytes) -> None: |
| 65 | pass |
| 66 | |
| 67 | @abc.abstractmethod |
| 68 | def forward_port(self, ip: str, remote_port: int, local_port: int = None) -> int: |
| 69 | pass |
| 70 | |
| 71 | @abc.abstractmethod |
| 72 | def get_interface(self, ip: str) -> str: |
| 73 | pass |
| 74 | |
| 75 | @abc.abstractmethod |
| 76 | def stat_file(self, path:str) -> Any: |
| 77 | pass |
| 78 | |
| 79 | @abc.abstractmethod |
| 80 | def node_id(self) -> str: |
| 81 | pass |
| 82 | |
| 83 | |
| 84 | @abc.abstractmethod |
| 85 | def disconnect(self) -> str: |
| 86 | pass |
| 87 | |
| 88 | |
| 89 | |
| 90 | RPCBeforeConnCallback = Callable[[NodeInfo, int], None] |