Merge "Adds various conveniences for hosters."
[pharos-tools.git] / dashboard / booking_communication_agent.py
1 from dashboard_notification.notification import Notification
2 from dashboard_api.api import DashboardAPI
3
4 CONFIG = {
5     'dashboard_ip': '127.0.0.1',
6     'dashboard_url': 'http://127.0.0.1',
7     'api_token': 'f33ff43c85ecb13f5d0632c05dbb0a7d85a5a8d1',
8     'user': 'opnfv',
9     'password': 'opnfvopnfv'
10 }
11
12 api = DashboardAPI(CONFIG['dashboard_url'], api_token=CONFIG['api_token'], verbose=True)
13
14
15 def booking_start(message):
16     content = message.content
17     booking = api.get_booking(id=content['booking_id'])
18
19     # do something here...
20
21     # notify dashboard
22     api.post_resource_status(resource_id=booking['resource_id'], type='info', title='pod setup',
23                              content='details')
24
25
26 def booking_end(message):
27     # do something here...
28
29     # notify dashboard
30     api.post_resource_status(resource_id=message.content['resource_id'], type='info',
31                              title='booking end', content='details')
32
33
34 def main():
35     with Notification(CONFIG['dashboard_ip'], CONFIG['user'], CONFIG['password']) as notification:
36         notification.register(booking_start, 'Arm POD 2', 'booking_start')
37         notification.register(booking_end, 'Arm POD 2', 'booking_end')
38         notification.receive()  # wait for notifications
39
40
41 if __name__ == "__main__":
42     main()