Example #1
0
class IperfMonitor():
    def __init__(self, tenant_id, graph_id, vnf_id):

        self.iperfController = IperfController()
        self.interfaceController = InterfaceController()

        self.tenant_id = tenant_id
        self.graph_id = graph_id
        self.vnf_id = vnf_id

        self.configuration_interface = None

        self.interfacesMonitor = None

    def set_initial_configuration(self, initial_configuration):

        curr_interfaces = self.interfaceController.get_interfaces()
        self.interfacesMonitor = InterfacesMonitor(self, curr_interfaces)

        logging.debug("Setting initial configuration...")
        self.iperfController.set_configuration(initial_configuration)
        logging.debug("Setting initial configuration...done!")

    def get_address_of_configuration_interface(self, configuration_interface):
        self.configuration_interface = configuration_interface
        return self.iperfController.get_interface_ipv4Configuration_address(
            configuration_interface)

    def start(self):

        threads = []
        threads.append(
            Thread(target=self.interfacesMonitor.start_monitoring, args=()))

        # Start all threads
        for t in threads:
            t.start()

        # Wait for all of them to finish
        for t in threads:
            t.join()

    def publish_on_bus(self, url, method, data):
        msg = self.tenant_id + "." + self.graph_id + "." + self.vnf_id + "/" + url
        body = {}
        if method is not None:
            body['event'] = method.upper()
        else:
            body['event'] = "PERIODIC"
        body['timestamp'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        body['data'] = data
        MessageBusController().publish_on_bus(
            msg, json.dumps(body, indent=4, sort_keys=True))
Example #2
0
    def get(self, id):
        """
        Get the ip address of an interface  
        """
        try:
            iperfController = IperfController()
            json_data = json.dumps(iperfController.get_interface_ipv4Configuration_address(id))
            resp = Response(json_data, status=200, mimetype="application/json")
            return resp

        except ValueError as ve:
            return Response(json.dumps(str(ve)), status=404, mimetype="application/json")
        except Exception as err:
            return Response(json.dumps(str(err)), status=500, mimetype="application/json")