Exemplo n.º 1
0
    def createInterface(self, interface):
        """Add an interface to the interface list"
        
        Args:
            interface: The concrete application interface
            
        Returns:
            Appinterface id on success
        """

        # Create the interface and AppInterface
        yield interface.save()
        appinterface = AppInterface()
        yield appinterface.save()
        yield interface.appinterfaces.set([appinterface])

        # Add the new interface to the list
        interface.appinterface = appinterface
        self.interfaces.append(interface)

        # Start the interface
        interface.start(self.netserver)
        if not interface.started:
            log.error("Could not start application interface "
                      "id {id}", interface.appinterface.id)
        returnValue(appinterface.id)
        yield
Exemplo n.º 2
0
    def start(self, netserver):
        """Load all application interfaces and start them.
        
        Args:
            netserver (NetServer): The network server
        """

        self.netserver = netserver

        # Get all concrete application interface objects
        appinterfaces = yield AppInterface.all()
        for appinterface in appinterfaces:
            # Get the interface, set the appinterface
            interface = yield appinterface.interfaces.get()
            if interface:
                interface.appinterface = appinterface
                self.interfaces.append(interface)

        # Start the interfaces
        for interface in self.interfaces:
            log.info("Starting application interface id {id}: {name}",
                     id=interface.appinterface.id,
                     name=interface.name)
            interface.start(self.netserver)
            if not interface.started:
                log.error("Could not start application interface "
                          "id {id}",
                          id=interface.appinterface.id)
Exemplo n.º 3
0
    def valid(self):
        """Validate an application object.
            
        Returns:
            valid (bool), message(dict): (True, empty) on success,
            (False, error message dict) otherwise.
        """
        messages = {}

        # Check for unique appkeys
        duplicate = yield Application.exists(
            where=['appkey = ? AND appeui != ?', self.appkey, self.appeui])
        if duplicate:
            messages['appkey'] = "Duplicate application key exists: appkey " \
                "must be unique."

        # Check the app interface exists
        if self.appinterface_id:
            exists = yield AppInterface.exists(
                where=['id = ?', self.appinterface_id])
            if not exists:
                messages['appinterface_id'] = "Application interface {} does not " \
                "exist.".format(self.appinterface_id)

        valid = not any(messages)
        returnValue((valid, messages))
Exemplo n.º 4
0
    def _test_appinterface(self):
        """Create a test application object."""

        return AppInterface(
            id=1,
            application_id=1,
            interfaces_type='AzureIotHttps',
            interfaces_id=1,
        )