blob: b2ffe4262945030527aaefa5985510793d8ec9c1 (
plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#!/usr/bin/env python3
import yaml
import json
import logging
import time
import transport
import state
import command
import endpoint
import trigger
import misc
import action
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('paramiko').setLevel(logging.WARNING)
# Use a TypeDict here
with open('endpoints.yml', 'r') as f:
endpoint_config = yaml.safe_load(f)
with open('triggers.yml', 'r') as f:
trigger_config = yaml.safe_load(f)
with open('actions.yml', 'r') as f:
action_config = yaml.safe_load(f)
endpoints = {}
for ep_key in endpoint_config:
endpoints[ep_key] = endpoint.Endpoint(ep_key, endpoint_config[ep_key])
triggers = {}
for trg_key in trigger_config:
cls = misc.import_class(trigger_config[trg_key]['class'])
del trigger_config[trg_key]['class']
if cls.NEEDS_CONTEXT:
triggers[trg_key] = cls(endpoints, **trigger_config[trg_key])
else:
triggers[trg_key] = cls(**trigger_config[trg_key])
actions = {}
for act_key in action_config:
actions[act_key] = action.Action(act_key, action_config[act_key], endpoints, triggers)
# TODO should we do that in Endpoint.__init__()?
for k in endpoints:
endpoints[k].connectTransport()
for act_key in action_config:
actions[act_key].execute()
for act_key in action_config:
actions[act_key].execute()
#print(endpoints['host1'].getState('user.jonas'))
#print(endpoints['host1'].getState('user.jonas'))
#
#time.sleep(31)
#print(endpoints['host1'].getState('user.jonas'))
#endpoints['host1'].executeCommand('notify', msg='moinsen')
#tr = transport.SshTransport('localhost', username='jonas')
#tr.connect()
#
#noti = command.NotifyCommand(tr)
#noti.execute('OwO')
#
#sta = state.UserState(tr)
#sta.collect()
#
#tr.disconnect()
|