| import getpass |
| |
| from wally.ssh_utils import parse_ssh_uri |
| |
| |
| class Node(object): |
| |
| def __init__(self, conn_url, roles): |
| self.roles = roles |
| self.conn_url = conn_url |
| self.connection = None |
| self.monitor_ip = None |
| self.os_vm_id = None |
| |
| def get_ip(self): |
| if self.conn_url == 'local': |
| return '127.0.0.1' |
| |
| assert self.conn_url.startswith("ssh://") |
| return parse_ssh_uri(self.conn_url[6:]).host |
| |
| def get_conn_id(self): |
| if self.conn_url == 'local': |
| return '127.0.0.1' |
| |
| assert self.conn_url.startswith("ssh://") |
| creds = parse_ssh_uri(self.conn_url[6:]) |
| return "{0.host}:{0.port}".format(creds) |
| |
| def get_user(self): |
| if self.conn_url == 'local': |
| return getpass.getuser() |
| |
| assert self.conn_url.startswith("ssh://") |
| creds = parse_ssh_uri(self.conn_url[6:]) |
| return creds.user |
| |
| def __str__(self): |
| templ = "<Node: url={conn_url!r} roles={roles}" + \ |
| " connected={is_connected}>" |
| return templ.format(conn_url=self.conn_url, |
| roles=", ".join(self.roles), |
| is_connected=self.connection is not None) |
| |
| def __repr__(self): |
| return str(self) |