blob: dc1c9b0155d5696877fa015bf522ecec3f70e56e [file] [log] [blame]
koder aka kdanilov4500a5f2015-04-17 16:55:17 +03001import urlparse
2
3
Yulia Portnova21289b22015-03-18 15:21:43 +02004class Node(object):
5
koder aka kdanilov2c473092015-03-29 17:12:13 +03006 def __init__(self, conn_url, roles):
Yulia Portnova21289b22015-03-18 15:21:43 +02007 self.roles = roles
koder aka kdanilov2c473092015-03-29 17:12:13 +03008 self.conn_url = conn_url
koder aka kdanilove06762a2015-03-22 23:32:09 +02009 self.connection = None
koder aka kdanilov168f6092015-04-19 02:33:38 +030010 self.monitor_url = None
koder aka kdanilove06762a2015-03-22 23:32:09 +020011
koder aka kdanilov4500a5f2015-04-17 16:55:17 +030012 def get_ip(self):
13 return urlparse.urlparse(self.conn_url).hostname
14
koder aka kdanilov168f6092015-04-19 02:33:38 +030015 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 kdanilove06762a2015-03-22 23:32:09 +020024 def __str__(self):
koder aka kdanilov2c473092015-03-29 17:12:13 +030025 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 Portnova21289b22015-03-18 15:21:43 +020030
Yulia Portnova0e64ea22015-03-20 17:27:22 +020031 def __repr__(self):
koder aka kdanilove06762a2015-03-22 23:32:09 +020032 return str(self)