blob: a3d58f96aa1c5f382d5e21cfb7cf13dfa7b39b4a [file] [log] [blame]
koder aka kdanilova4a570f2015-04-23 22:11:40 +03001import getpass
2
koder aka kdanilov6b1341a2015-04-21 22:44:21 +03003from wally.ssh_utils import parse_ssh_uri
koder aka kdanilov4500a5f2015-04-17 16:55:17 +03004
5
Yulia Portnova21289b22015-03-18 15:21:43 +02006class Node(object):
7
koder aka kdanilov2c473092015-03-29 17:12:13 +03008 def __init__(self, conn_url, roles):
Yulia Portnova21289b22015-03-18 15:21:43 +02009 self.roles = roles
koder aka kdanilov2c473092015-03-29 17:12:13 +030010 self.conn_url = conn_url
koder aka kdanilove06762a2015-03-22 23:32:09 +020011 self.connection = None
koder aka kdanilovf86d7af2015-05-06 04:01:54 +030012 self.monitor_ip = None
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +030013 self.os_vm_id = None
koder aka kdanilove06762a2015-03-22 23:32:09 +020014
koder aka kdanilov4500a5f2015-04-17 16:55:17 +030015 def get_ip(self):
koder aka kdanilov0c598a12015-04-21 03:01:40 +030016 if self.conn_url == 'local':
17 return '127.0.0.1'
koder aka kdanilov6b1341a2015-04-21 22:44:21 +030018
19 assert self.conn_url.startswith("ssh://")
20 return parse_ssh_uri(self.conn_url[6:]).host
koder aka kdanilov4500a5f2015-04-17 16:55:17 +030021
koder aka kdanilov168f6092015-04-19 02:33:38 +030022 def get_conn_id(self):
koder aka kdanilov0c598a12015-04-21 03:01:40 +030023 if self.conn_url == 'local':
24 return '127.0.0.1'
25
koder aka kdanilov6b1341a2015-04-21 22:44:21 +030026 assert self.conn_url.startswith("ssh://")
27 creds = parse_ssh_uri(self.conn_url[6:])
28 return "{0.host}:{0.port}".format(creds)
koder aka kdanilov168f6092015-04-19 02:33:38 +030029
koder aka kdanilova4a570f2015-04-23 22:11:40 +030030 def get_user(self):
31 if self.conn_url == 'local':
32 return getpass.getuser()
33
34 assert self.conn_url.startswith("ssh://")
35 creds = parse_ssh_uri(self.conn_url[6:])
36 return creds.user
37
koder aka kdanilove06762a2015-03-22 23:32:09 +020038 def __str__(self):
koder aka kdanilov2c473092015-03-29 17:12:13 +030039 templ = "<Node: url={conn_url!r} roles={roles}" + \
40 " connected={is_connected}>"
41 return templ.format(conn_url=self.conn_url,
42 roles=", ".join(self.roles),
43 is_connected=self.connection is not None)
Yulia Portnova21289b22015-03-18 15:21:43 +020044
Yulia Portnova0e64ea22015-03-20 17:27:22 +020045 def __repr__(self):
koder aka kdanilove06762a2015-03-22 23:32:09 +020046 return str(self)