diff options
author | maxbr <maxbr@mi.fu-berlin.de> | 2017-01-05 12:38:00 +0100 |
---|---|---|
committer | maxbr <maxbr@mi.fu-berlin.de> | 2017-01-05 12:38:00 +0100 |
commit | 9a7cf0a9a0f22f0ed7de720e69d560d35b8f0998 (patch) | |
tree | 20eda1152c316875894e1d51306ac0726523770b /tools/pharos-dashboard/booking_communication_agent.py | |
parent | 85623f2e6a4e4bee61ac5c28ce04bf9532980094 (diff) |
Add booking communication reference implementation
JIRA: PHAROS-265
This adds an implementation of a booking communication agent that
listens for booking notifications from the dashboard and updates the pod
status in the dashboard.
Change-Id: I1ea22390a46182a185df9c5e1771c9312d462092
Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
Diffstat (limited to 'tools/pharos-dashboard/booking_communication_agent.py')
-rw-r--r-- | tools/pharos-dashboard/booking_communication_agent.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/pharos-dashboard/booking_communication_agent.py b/tools/pharos-dashboard/booking_communication_agent.py new file mode 100644 index 00000000..c52e98bd --- /dev/null +++ b/tools/pharos-dashboard/booking_communication_agent.py @@ -0,0 +1,42 @@ +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() |