コード例 #1
0
ファイル: test_azure_https.py プロジェクト: uicm-mas/floranet
    def test_AzureIotHttps_inbound(self):
        """Perform polling of an Azure IoT Hub instance"""

        interface = yield AzureIotHttps.find(
            where=['name = ?', AzureIoTHubName], limit=1)
        appifs = yield interface.appinterfaces.get()
        interface.appinterface = appifs[0]

        interface._pollInboundMessages()
コード例 #2
0
ファイル: test_azure_https.py プロジェクト: uicm-mas/floranet
    def test_AzureIotHttps_outbound(self):
        """Test send of sample data to an Azure IoT Hub instance"""

        interface = yield AzureIotHttps.find(
            where=['name = ?', AzureIoTHubName], limit=1)

        port = 11
        appdata = struct.pack('<f', 42.456)

        yield interface.netServerReceived(self.device, self.app, port, appdata)
コード例 #3
0
 def _test_azureiothttps(self):
     """Create a test AzureIotHttps object"""
     return AzureIotHttps(
         id=1,
         name='Test Azure',
         iothost='somewhere.azure.microsoft.com',
         keyname='mykey',
         keyvalue='ishd7635klw3084%3',
         started=True,
         poll_interval=25,
     )
コード例 #4
0
ファイル: appinterface.py プロジェクト: ikvm/floranet
    def post(self):
        """Method to create an Application Interface"""
        klass = self.args['type']
        name = self.args['name']

        message = {}

        try:

            if klass == 'azure':
                protocol = self.args['protocol']
                iothost = self.args['iothost']
                keyname = self.args['keyname']
                keyvalue = self.args['keyvalue']
                poll_interval = self.args['pollinterval']

                # Check for required args
                required = {
                    'type', 'name', 'protocol', 'iothost', 'keyname',
                    'keyvalue', 'pollinterval'
                }
                for r in required:
                    if self.args[r] is None:
                        message[r] = "Missing the {} parameter.".format(r)
                if message:
                    abort(400, message=message)

                if protocol != 'https':
                    message = "Unknown protocol type {}.".format(protocol)
                    abort(400, message=message)

                # Check this interface does not currently exist
                exists = yield AzureIotHttps.exists(where=['name = ?', name])
                if exists:
                    message = {
                        'error':
                        "Azure Https Interface {} currently exists".format(
                            name)
                    }
                    abort(400, message=message)

                # Create the interface
                interface = AzureIotHttps(name=name,
                                          iothost=iothost,
                                          keyname=keyname,
                                          keyvalue=keyvalue,
                                          poll_interval=poll_interval)

            elif klass == 'reflector':

                # Required args
                required = {'type', 'name'}
                for r in required:
                    if self.args[r] is None:
                        message[r] = "Missing the {} parameter.".format(r)
                if message:
                    abort(400, message=message)

                # Create the interface
                interface = Reflector(name=name)

            else:
                message = {'error': "Unknown interface type"}
                abort(400, message=message)

            (valid, message) = yield interface.valid()
            if not valid:
                abort(400, message=message)

            # Add the new interface
            id = interfaceManager.createInterface(interface)
            location = self.restapi.api.prefix + '/interface/' + str(id)
            returnValue(({}, 201, {'Location': location}))

        except TimeoutError:
            # Exception returns 500 to client
            log.error(
                "REST API timeout for application interface POST request")
コード例 #5
0
    def post(self):
        """Method to create an Application Interface"""
        klass = self.args['type']
        name = self.args['name']

        message = {}

        try:

            if klass == 'azure':
                protocol = self.args['protocol']
                iothost = self.args['iothost']
                keyname = self.args['keyname']
                keyvalue = self.args['keyvalue']
                poll_interval = self.args['pollinterval']

                # Check for required args
                required = {
                    'type', 'name', 'protocol', 'iothost', 'keyname',
                    'keyvalue'
                }
                for r in required:
                    if self.args[r] is None:
                        message[r] = "Missing the {} parameter.".format(r)
                if protocol == 'https' and poll_interval is None:
                    message[
                        'poll_interval'] = "Missing the poll_interval parameter."
                if message:
                    abort(400, message=message)

                # Check protocol type
                if not protocol in {'https', 'mqtt'}:
                    message = "Unknown protocol type {}.".format(protocol)
                    abort(400, message=message)

                # Create the interface
                if protocol == 'https':
                    interface = AzureIotHttps(name=name,
                                              iothost=iothost,
                                              keyname=keyname,
                                              keyvalue=keyvalue,
                                              poll_interval=poll_interval)
                elif protocol == 'mqtt':
                    interface = AzureIotMqtt(name=name,
                                             iothost=iothost,
                                             keyname=keyname,
                                             keyvalue=keyvalue)

            elif klass == 'filetext':
                file = self.args['file']
                required = {'type', 'name', 'file'}
                for r in required:
                    if self.args[r] is None:
                        message[r] = "Missing the {} parameter.".format(r)
                if message:
                    abort(400, message=message)

                # Create the interface
                interface = FileTextStore(name=name, file=file)

            elif klass == 'reflector':

                # Required args
                required = {'type', 'name'}
                for r in required:
                    if self.args[r] is None:
                        message[r] = "Missing the {} parameter.".format(r)
                if message:
                    abort(400, message=message)

                # Create the interface
                interface = Reflector(name=name)

            else:
                message = {'error': "Unknown interface type"}
                abort(400, message=message)

            (valid, message) = yield interface.valid()
            if not valid:
                abort(400, message=message)

            # Add the new interface
            id = interfaceManager.createInterface(interface)
            location = self.restapi.api.prefix + '/interface/' + str(id)
            returnValue(({}, 201, {'Location': location}))

        except TimeoutError:
            # Exception returns 500 to client
            log.error(
                "REST API timeout for application interface POST request")