Esempio n. 1
0
def updateHost():
    if nmoscommonconfig.config.get('node_hostname') is not None:
        return nmoscommonconfig.config.get('node_hostname')
    elif nmoscommonconfig.config.get('prefer_ipv6', False) == False:
        return getLocalIP()
    else:
        return "[" + getLocalIP(None, socket.AF_INET6) + "]"
Esempio n. 2
0
 def gen_ws_href(self):
     scheme = "ws"
     if self.secure:
         scheme = "wss"
     if nmoscommonconfig.config.get('prefer_ipv6',False) == False:
         href = '{}://{}/x-nmos/query/{}/ws/?uid={}'.format(scheme, getLocalIP(), self.api_version, self.uuid)
     else:
         href = '{}://[{}]/x-nmos/query/{}/ws/?uid={}'.format(scheme, getLocalIP(), self.api_version, self.uuid)
     return href
Esempio n. 3
0
def updateHost():
    if _config.get('node_hostname') is not None:
        return _config.get('node_hostname')
    elif _config.get('prefer_hostnames', False) is True:
        return FQDN
    elif _config.get('prefer_ipv6', False) is False:
        return getLocalIP()
    else:
        return "[" + getLocalIP(None, socket.AF_INET6) + "]"
    def start(self):
        if self.running:
            gevent.signal(signal.SIGINT, self.sig_handler)
            gevent.signal(signal.SIGTERM, self.sig_handler)

        self.running = True
        self.mdns.start()

        HOST = getLocalIP()

        self.logger.writeDebug('Running web socket server on %i' % WS_PORT)

        self.httpServer.start()

        while not self.httpServer.started.is_set():
            self.logger.writeDebug('Waiting for httpserver to start...')
            self.httpServer.started.wait()

        if self.httpServer.failed is not None:
            raise self.httpServer.failed

        self.logger.writeDebug("Running on port: {}".format(
            self.httpServer.port))

        priority = self.config["priority"]
        if not str(priority).isdigit() or priority < 100:
            priority = 0

        self.mdns.register('query_' + str(HOST), '_nmos-query._tcp',
                           DNS_SD_PORT, {
                               "pri": priority,
                               "api_ver": "v1.0,v1.1,v1.2",
                               "api_proto": "http"
                           })
Esempio n. 5
0
 def sig_hup_handler(self):
     if getLocalIP() != "":
         global HOST
         HOST = updateHost()
         self.registry.modify_node(href=self.generate_href(),
                                   host=HOST,
                                   api={
                                       "versions": NODE_APIVERSIONS,
                                       "endpoints":
                                       self.generate_endpoints()
                                   },
                                   interfaces=self.list_interfaces())
Esempio n. 6
0
 def sig_hup_handler(self):
     if getLocalIP() != "":
         HOST = updateHost()
         self.registry.modify_node(href='http://{}/'.format(HOST),
                                   host=HOST,
                                   api={
                                       "versions":
                                       NODE_APIVERSIONS,
                                       "endpoints": [{
                                           "host": HOST,
                                           "port": 80,
                                           "protocol": "http"
                                       }]
                                   },
                                   interfaces=self.list_interfaces())
Esempio n. 7
0
from gevent import monkey; monkey.patch_all()

import json
import signal
import time
import gevent
import os

from nmoscommon.httpserver import HttpServer
from nmoscommon.logger import Logger
from nmoscommon.mdns import MDNSEngine
from nmosquery.api import QueryServiceAPI
from nmoscommon.utils import getLocalIP

reg = {'host': 'localhost', 'port': 4001}
HOST = getLocalIP()
WS_PORT = 8870
DNS_SD_HTTP_PORT = 80
DNS_SD_HTTPS_PORT = 443
DNS_SD_NAME = 'query_' + str(HOST)
DNS_SD_TYPE = '_nmos-query._tcp'
API_VERSIONS = ["v1.0", "v1.1", "v1.2"]

class QueryService:

    def __init__(self, logger=None):
        self.running = False
        self.logger = Logger("regquery")
        self.logger.writeDebug('Running QueryService')
        # HTTPS under test only at present
        # enabled = Use HTTPS only in all URLs and mDNS adverts
Esempio n. 8
0
    def test_getLocalIP__falls_back_to_returning_None(self, interfaces):
        interfaces.return_value.get_default_interfaces.return_value = []

        self.assertIsNone(getLocalIP())
Esempio n. 9
0
 def test_getLocalIP(self, interfaces):
     interfaces.return_value.get_default_interfaces.return_value = [
         mock.sentinel.if0, mock.sentinel.if1
     ]
     self.assertEqual(getLocalIP(), mock.sentinel.if0)
Esempio n. 10
0
 def setUpClass(cls):
     local_ip = getLocalIP()
     version = getattr(cls, 'api_version', DEFAULT_API_VERSION)
     cls._aggr_host = "http://{}:{}/x-ipstudio/grouping/v{}".format(
         local_ip, PORT, version)
 def gen_ws_href(self):
     if nmoscommonconfig.config.get('prefer_ipv6',False) == False:
         href = 'ws://{}/x-nmos/query/{}/ws/?uid={}'.format(getLocalIP(), self.api_version, self.uuid)
     else:
         href = 'ws://[{}]/x-nmos/query/{}/ws/?uid={}'.format(getLocalIP(), self.api_version, self.uuid)
     return href
 def addControl(self):
     # Add a device level control to the connection management API
     for api_version in CONN_APIVERSIONS:
         url = "http://{}{}{}/".format(getLocalIP(), CONN_ROOT, api_version)
         type = "urn:x-nmos:control:sr-ctrl/" + api_version
         self.facade.addControl(self.deviceId, {"type": type, "href": url})