def update_node(self): self.node_data["services"] = [] for service_name in self.services: href = None if self.services[service_name]["href"]: if self.services[service_name]["proxy_path"]: href = self.node_data["href"] + self.services[ service_name]["proxy_path"] self.node_data["services"].append({ "href": href, "type": self.services[service_name]["type"] }) self.node_data["clocks"] = self.clocks.values() self.node_data["version"] = str(ptptime.ptp_detail()[0]) + ":" + str( ptptime.ptp_detail()[1]) try: self.aggregator.register( "node", self.node_id, **self.preprocess_resource("node", self.node_data["id"], self.node_data, NODE_REGVERSION)) except Exception as e: self.logger.writeError( "Exception re-registering node: {}".format(e))
def test_ptp_detail(self): """Testing the fallback when IPP_PYTHON doesn't load""" with mock.patch('__builtin__.__import__', side_effect=import_mock("ipppython.ptptime",False)): reload(nmoscommon.ptptime) from nmoscommon.ptptime import ptp_detail rv = ptp_detail() self.assertEqual(2, len(rv)) self.assertTrue(isinstance(rv[0], int)) self.assertTrue(isinstance(rv[1], int))
def update_node(self): self.node_data["services"] = [] for service_name in self.services: href = None if self.services[service_name]["href"]: if self.services[service_name]["proxy_path"]: href = "http://{}/{}".format( self.node_data["host"], self.services[service_name]["proxy_path"]) self.node_data["services"].append({ "href": href, "type": self.services[service_name]["type"] }) self.node_data["version"] = str(ptptime.ptp_detail()[0]) + ":" + str( ptptime.ptp_detail()[1]) try: self.aggregator.register( "node", self.node_id, **legalise_resource(self.node_data, "node", NODE_REGVERSION)) except Exception as e: self.logger.writeError( "Exception re-registering node: {}".format(e))
def start(self): if self.running: gevent.signal(signal.SIGINT, self.sig_handler) gevent.signal(signal.SIGTERM, self.sig_handler) gevent.signal(signal.SIGHUP, self.sig_hup_handler) self.mdns.start() self.node_id = get_node_id() node_version = str(ptptime.ptp_detail()[0]) + ":" + str( ptptime.ptp_detail()[1]) node_data = { "id": self.node_id, "label": nmoscommonconfig.config.get('node_label', FQDN), "description": nmoscommonconfig.config.get('node_description', "Node on {}".format(FQDN)), "tags": nmoscommonconfig.config.get('node_tags', {}), "href": self.generate_href(), "host": HOST, "services": [], "hostname": HOSTNAME, "caps": {}, "version": node_version, "api": { "versions": NODE_APIVERSIONS, "endpoints": self.generate_endpoints(), }, "clocks": [ { "name": "clk0", "ref_type": "internal", }, { "name": "clk1", "ref_type": "ptp", "version": "IEEE1588-2008", "traceable": False, "gmid": "00-00-00-00-00-00-00-00", "locked": False, }, # Extra values will be filled in as needed at point of checking ], "interfaces": self.list_interfaces() } self.registry = FacadeRegistry(self.mappings.keys(), self.aggregator, self.mdns_updater, self.node_id, node_data, self.logger) self.registry_cleaner = FacadeRegistryCleaner(self.registry) self.registry_cleaner.start() self.httpServer = HttpServer(FacadeAPI, PORT, '0.0.0.0', api_args=[self.registry]) self.httpServer.start() while not self.httpServer.started.is_set(): self.logger.writeInfo('Waiting for httpserver to start...') self.httpServer.started.wait() if self.httpServer.failed is not None: raise self.httpServer.failed self.logger.writeInfo("Running on port: {}".format( self.httpServer.port)) try: self.logger.writeInfo("Registering as {}...".format(self.node_id)) self.aggregator.register( 'node', self.node_id, **legalise_resource(node_data, "node", NODE_REGVERSION)) except Exception as e: self.logger.writeWarning("Could not register: {}".format( e.__repr__())) self.interface = FacadeInterface(self.registry, self.logger) self.interface.start()
def updateReceiverVersion(self, receiverId): timeNow = ptptime.ptp_detail() self.receivers[receiverId]['version'] = "{}:{}".format(repr(timeNow[0]), repr(timeNow[1]))
def updateDeviceVersion(self): timeNow = ptptime.ptp_detail() self.deviceData['version'] = "{}:{}".format(repr(timeNow[0]), repr(timeNow[1]))
def updateSenderVersion(self, senderId): timeNow = ptptime.ptp_detail() self.senders[senderId]['version'] = "{}:{}".format(repr(timeNow[0]), repr(timeNow[1]))
def updateFlowVersion(self, flowId): timeNow = ptptime.ptp_detail() self.flows[flowId]['version'] = "{}:{}".format(repr(timeNow[0]), repr(timeNow[1]))
def updateSourceVersion(self, sourceId): timeNow = ptptime.ptp_detail() self.sources[sourceId]['version'] = "{}:{}".format(repr(timeNow[0]), repr(timeNow[1]))