Merge "Adds migrations"
[pharos-tools.git] / dashboard / booking_communication_agent.py
1 ##############################################################################
2 # Copyright (c) 2018 Sawyer Bergeron and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from dashboard_notification.notification import Notification
10 from dashboard_api.api import DashboardAPI
11
12 CONFIG = {
13     'dashboard_ip': '127.0.0.1',
14     'dashboard_url': 'http://127.0.0.1',
15     'api_token': 'f33ff43c85ecb13f5d0632c05dbb0a7d85a5a8d1',
16     'user': 'opnfv',
17     'password': 'opnfvopnfv'
18 }
19
20 api = DashboardAPI(CONFIG['dashboard_url'], api_token=CONFIG['api_token'], verbose=True)
21
22
23 def booking_start(message):
24     content = message.content
25     booking = api.get_booking(id=content['booking_id'])
26
27     # do something here...
28
29     # notify dashboard
30     api.post_resource_status(resource_id=booking['resource_id'], type='info', title='pod setup',
31                              content='details')
32
33
34 def booking_end(message):
35     # do something here...
36
37     # notify dashboard
38     api.post_resource_status(resource_id=message.content['resource_id'], type='info',
39                              title='booking end', content='details')
40
41
42 def main():
43     with Notification(CONFIG['dashboard_ip'], CONFIG['user'], CONFIG['password']) as notification:
44         notification.register(booking_start, 'Arm POD 2', 'booking_start')
45         notification.register(booking_end, 'Arm POD 2', 'booking_end')
46         notification.receive()  # wait for notifications
47
48
49 if __name__ == "__main__":
50     main()