blob: c2ae5aaa4c3e2b68f7044397695cf0edff89d61f [file] [log] [blame]
koder aka kdanilov6b1341a2015-04-21 22:44:21 +03001from wally.ssh_utils import parse_ssh_uri
koder aka kdanilov4500a5f2015-04-17 16:55:17 +03002
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):
koder aka kdanilov0c598a12015-04-21 03:01:40 +030013 if self.conn_url == 'local':
14 return '127.0.0.1'
koder aka kdanilov6b1341a2015-04-21 22:44:21 +030015
16 assert self.conn_url.startswith("ssh://")
17 return parse_ssh_uri(self.conn_url[6:]).host
koder aka kdanilov4500a5f2015-04-17 16:55:17 +030018
koder aka kdanilov168f6092015-04-19 02:33:38 +030019 def get_conn_id(self):
koder aka kdanilov0c598a12015-04-21 03:01:40 +030020 if self.conn_url == 'local':
21 return '127.0.0.1'
22
koder aka kdanilov6b1341a2015-04-21 22:44:21 +030023 assert self.conn_url.startswith("ssh://")
24 creds = parse_ssh_uri(self.conn_url[6:])
25 return "{0.host}:{0.port}".format(creds)
koder aka kdanilov168f6092015-04-19 02:33:38 +030026
koder aka kdanilove06762a2015-03-22 23:32:09 +020027 def __str__(self):
koder aka kdanilov2c473092015-03-29 17:12:13 +030028 templ = "<Node: url={conn_url!r} roles={roles}" + \
29 " connected={is_connected}>"
30 return templ.format(conn_url=self.conn_url,
31 roles=", ".join(self.roles),
32 is_connected=self.connection is not None)
Yulia Portnova21289b22015-03-18 15:21:43 +020033
Yulia Portnova0e64ea22015-03-20 17:27:22 +020034 def __repr__(self):
koder aka kdanilove06762a2015-03-22 23:32:09 +020035 return str(self)