blob: 03efd34cc45fb8479203a225eea7e9364a2fcf41 [file] [log] [blame]
Yulia Portnova21289b22015-03-18 15:21:43 +02001class Node(object):
2
3 def __init__(self, ip, roles, username=None,
4 password=None, key_path=None, port=None):
5 self.roles = roles
6 self.ip = ip
7 self.username = username
8 self.password = password
9 self.port = port
10 self.key_path = key_path
11
Yulia Portnova0e64ea22015-03-20 17:27:22 +020012 def __repr__(self):
13 return "<Node: %s %s>" % (self.ip, self.roles)
14
Yulia Portnova21289b22015-03-18 15:21:43 +020015 def set_conn_attr(self, name, value):
16 setattr(self, name, value)
17
18 @property
Yulia Portnova0e64ea22015-03-20 17:27:22 +020019 def connection_url(self):
Yulia Portnova21289b22015-03-18 15:21:43 +020020 connection = []
21
22 if self.username:
23 connection.append(self.username)
24 if self.password:
25 connection.extend([":", self.password, "@"])
26 connection.append("@")
27
28 connection.append(self.ip)
29 if self.port:
30 connection.extend([":", self.port])
31 if self.key_path:
32 connection.extend([":", self.key_path])
33 else:
34 if self.key_path:
35 connection.extend([":", ":", self.key_path])
36 return "".join(connection)