Merge pull request #131 from stevenvanrossem/master
[osm/vim-emu.git] / src / emuvim / api / rest / monitor.py
1 import logging
2 from flask_restful import Resource
3 from flask import request
4 import json
5
6 logging.basicConfig(level=logging.INFO)
7
8 net = None
9
10
11
12 class MonitorInterfaceAction(Resource):
13 """
14 Monitor the counters of a VNF interface
15 :param vnf_name: name of the VNF to be monitored
16 :param vnf_interface: name of the VNF interface to be monitored
17 :param metric: tx_bytes, rx_bytes, tx_packets, rx_packets
18 :return: message string indicating if the monitor action is succesful or not
19 """
20 global net
21
22 def put(self, vnf_name, vnf_interface, metric):
23 logging.debug("REST CALL: start monitor VNF interface")
24 try:
25 c = net.monitor_agent.setup_metric(vnf_name, vnf_interface, metric)
26 # return monitor message response
27 return str(c), 200
28 except Exception as ex:
29 logging.exception("API error.")
30 return ex.message, 500
31
32 def delete(self, vnf_name, vnf_interface, metric):
33 logging.debug("REST CALL: stop monitor VNF interface")
34 try:
35 c = net.monitor_agent.stop_metric(vnf_name, vnf_interface, metric)
36 # return monitor message response
37 return str(c), 200
38 except Exception as ex:
39 logging.exception("API error.")
40 return ex.message, 500
41
42
43 class MonitorFlowAction(Resource):
44 """
45 Monitor the counters of a specific flow
46 :param vnf_name: name of the VNF to be monitored
47 :param vnf_interface: name of the VNF interface to be monitored
48 :param metric: tx_bytes, rx_bytes, tx_packets, rx_packets
49 :param cookie: specific identifier of flows to monitor
50 :return: message string indicating if the monitor action is succesful or not
51 """
52 global net
53
54 def put(self, vnf_name, vnf_interface, metric, cookie):
55 logging.debug("REST CALL: start monitor VNF interface")
56 try:
57 c = net.monitor_agent.setup_flow(vnf_name, vnf_interface, metric, cookie)
58 # return monitor message response
59 return str(c), 200
60 except Exception as ex:
61 logging.exception("API error.")
62 return ex.message, 500
63
64 def delete(self, vnf_name, vnf_interface, metric, cookie):
65 logging.debug("REST CALL: stop monitor VNF interface")
66 try:
67 c = net.monitor_agent.stop_flow(vnf_name, vnf_interface, metric, cookie)
68 # return monitor message response
69 return str(c), 200
70 except Exception as ex:
71 logging.exception("API error.")
72 return ex.message, 500