| peusterm | 79ef6ae | 2016-07-08 13:53:57 +0200 | [diff] [blame] | 1 | """ |
| 2 | Copyright (c) 2015 SONATA-NFV and Paderborn University |
| 3 | ALL RIGHTS RESERVED. |
| 4 | |
| 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | you may not use this file except in compliance with the License. |
| 7 | You may obtain a copy of the License at |
| 8 | |
| 9 | http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | Unless required by applicable law or agreed to in writing, software |
| 12 | distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | See the License for the specific language governing permissions and |
| 15 | limitations under the License. |
| 16 | |
| 17 | Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION] |
| 18 | nor the names of its contributors may be used to endorse or promote |
| 19 | products derived from this software without specific prior written |
| 20 | permission. |
| 21 | |
| 22 | This work has been performed in the framework of the SONATA project, |
| 23 | funded by the European Commission under Grant number 671517 through |
| 24 | the Horizon 2020 and 5G-PPP programmes. The authors would like to |
| 25 | acknowledge the contributions of their colleagues of the SONATA |
| 26 | partner consortium (www.sonata-nfv.eu). |
| 27 | """ |
| stevenvanrossem | 73efd19 | 2016-06-29 01:44:07 +0200 | [diff] [blame] | 28 | import logging |
| 29 | from flask_restful import Resource |
| 30 | from flask import request |
| 31 | import json |
| 32 | |
| 33 | logging.basicConfig(level=logging.INFO) |
| 34 | |
| 35 | net = None |
| 36 | |
| 37 | |
| 38 | |
| 39 | class MonitorInterfaceAction(Resource): |
| 40 | """ |
| 41 | Monitor the counters of a VNF interface |
| 42 | :param vnf_name: name of the VNF to be monitored |
| 43 | :param vnf_interface: name of the VNF interface to be monitored |
| 44 | :param metric: tx_bytes, rx_bytes, tx_packets, rx_packets |
| 45 | :return: message string indicating if the monitor action is succesful or not |
| 46 | """ |
| 47 | global net |
| 48 | |
| 49 | def put(self, vnf_name, vnf_interface, metric): |
| 50 | logging.debug("REST CALL: start monitor VNF interface") |
| 51 | try: |
| 52 | c = net.monitor_agent.setup_metric(vnf_name, vnf_interface, metric) |
| 53 | # return monitor message response |
| 54 | return str(c), 200 |
| 55 | except Exception as ex: |
| 56 | logging.exception("API error.") |
| 57 | return ex.message, 500 |
| 58 | |
| 59 | def delete(self, vnf_name, vnf_interface, metric): |
| 60 | logging.debug("REST CALL: stop monitor VNF interface") |
| 61 | try: |
| 62 | c = net.monitor_agent.stop_metric(vnf_name, vnf_interface, metric) |
| 63 | # return monitor message response |
| 64 | return str(c), 200 |
| 65 | except Exception as ex: |
| 66 | logging.exception("API error.") |
| 67 | return ex.message, 500 |
| 68 | |
| 69 | |
| 70 | class MonitorFlowAction(Resource): |
| 71 | """ |
| 72 | Monitor the counters of a specific flow |
| 73 | :param vnf_name: name of the VNF to be monitored |
| 74 | :param vnf_interface: name of the VNF interface to be monitored |
| 75 | :param metric: tx_bytes, rx_bytes, tx_packets, rx_packets |
| 76 | :param cookie: specific identifier of flows to monitor |
| 77 | :return: message string indicating if the monitor action is succesful or not |
| 78 | """ |
| 79 | global net |
| 80 | |
| 81 | def put(self, vnf_name, vnf_interface, metric, cookie): |
| 82 | logging.debug("REST CALL: start monitor VNF interface") |
| 83 | try: |
| 84 | c = net.monitor_agent.setup_flow(vnf_name, vnf_interface, metric, cookie) |
| 85 | # return monitor message response |
| 86 | return str(c), 200 |
| 87 | except Exception as ex: |
| 88 | logging.exception("API error.") |
| 89 | return ex.message, 500 |
| 90 | |
| 91 | def delete(self, vnf_name, vnf_interface, metric, cookie): |
| 92 | logging.debug("REST CALL: stop monitor VNF interface") |
| 93 | try: |
| 94 | c = net.monitor_agent.stop_flow(vnf_name, vnf_interface, metric, cookie) |
| 95 | # return monitor message response |
| 96 | return str(c), 200 |
| 97 | except Exception as ex: |
| 98 | logging.exception("API error.") |
| 99 | return ex.message, 500 |