koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 1 | import urlparse |
| 2 | |
| 3 | |
Yulia Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 4 | class Node(object): |
| 5 | |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 6 | def __init__(self, conn_url, roles): |
Yulia Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 7 | self.roles = roles |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 8 | self.conn_url = conn_url |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 9 | self.connection = None |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 10 | self.monitor_url = None |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 11 | |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 12 | def get_ip(self): |
| 13 | return urlparse.urlparse(self.conn_url).hostname |
| 14 | |
koder aka kdanilov | 168f609 | 2015-04-19 02:33:38 +0300 | [diff] [blame] | 15 | def get_conn_id(self): |
| 16 | host = urlparse.urlparse(self.conn_url).hostname |
| 17 | port = urlparse.urlparse(self.conn_url).port |
| 18 | |
| 19 | if port is None: |
| 20 | port = 22 |
| 21 | |
| 22 | return host + ":" + str(port) |
| 23 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 24 | def __str__(self): |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 25 | templ = "<Node: url={conn_url!r} roles={roles}" + \ |
| 26 | " connected={is_connected}>" |
| 27 | return templ.format(conn_url=self.conn_url, |
| 28 | roles=", ".join(self.roles), |
| 29 | is_connected=self.connection is not None) |
Yulia Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 30 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 31 | def __repr__(self): |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 32 | return str(self) |