This repository was archived by the owner on Dec 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathserver.py
More file actions
58 lines (50 loc) · 1.74 KB
/
server.py
File metadata and controls
58 lines (50 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
from copy import copy
class ProvyServer(object):
def __init__(self, name, address, username, roles= tuple(), password=None):
"""
:param name: Logical name of the server (key under which it resides
in the provy file)
:param address: Address of the server
:param username: Username you log into
:param roles: List of roles for the server
:param password: Login password
"""
super(ProvyServer, self).__init__()
self.name = name.strip()
self.address = address.strip()
self.roles = list(roles)
self.username = username.strip()
self.password = password
self.options = {}
self.ssh_key = None
@staticmethod
def from_dict(name, server_dict):
d = copy(server_dict)
d['name'] = name
s = ProvyServer.__new__(ProvyServer)
s.__setstate__(d)
return s
@property
def host_string(self):
return "{}@{}".format(self.username, self.address)
def __getstate__(self):
dict = {
"name": self.name,
"address": self.address,
"roles": self.roles,
"user": self.username,
"options": self.options,
"ssh_key": self.ssh_key
}
if self.password is not None:
dict['password'] = self.password
return dict
def __setstate__(self, state):
self.name = state['name'].strip()
self.address = state['address'].strip()
self.roles = state.get("roles", [])
self.username = state['user'].strip()
self.password = state.get('password', None)
self.options = state.get('options', {})
self.ssh_key = state.get('ssh_key', None)