Yulia Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 1 | class 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 Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame^] | 12 | def __repr__(self): |
| 13 | return "<Node: %s %s>" % (self.ip, self.roles) |
| 14 | |
Yulia Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 15 | def set_conn_attr(self, name, value): |
| 16 | setattr(self, name, value) |
| 17 | |
| 18 | @property |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame^] | 19 | def connection_url(self): |
Yulia Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 20 | 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) |