summaryrefslogtreecommitdiffstats
path: root/booking_communication_agent.py
blob: dc4ea4d53ee9b6bc7e937aacf09bc02569daec5c (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
##############################################################################
# Copyright (c) 2018 Sawyer Bergeron and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
from dashboard_notification.notification import Notification
from dashboard_api.api import DashboardAPI

CONFIG = {
    'dashboard_ip': '127.0.0.1',
    'dashboard_url': 'http://127.0.0.1',
    'api_token': 'f33ff43c85ecb13f5d0632c05dbb0a7d85a5a8d1',
    'user': 'opnfv',
    'password': 'opnfvopnfv'
}

api = DashboardAPI(CONFIG['dashboard_url'], api_token=CONFIG['api_token'], verbose=True)


def booking_start(message):
    content = message.content
    booking = api.get_booking(id=content['booking_id'])

    # do something here...

    # notify dashboard
    api.post_resource_status(resource_id=booking['resource_id'], type='info', title='pod setup',
                             content='details')


def booking_end(message):
    # do something here...

    # notify dashboard
    api.post_resource_status(resource_id=message.content['resource_id'], type='info',
                             title='booking end', content='details')


def main():
    with Notification(CONFIG['dashboard_ip'], CONFIG['user'], CONFIG['password']) as notification:
        notification.register(booking_start, 'Arm POD 2', 'booking_start')
        notification.register(booking_end, 'Arm POD 2', 'booking_end')
        notification.receive()  # wait for notifications


if __name__ == "__main__":
    main()