def onStart(self): super(Nexus, self).onStart() # onStart is called when the reactor starts, not when the connection is made. # Check for provisioning keys and attempt to connect if not self.provisioned() and not provisioning.can_provision(): out.warn("The node is not provisioned and is not configured to self-provision.") return while not self.provisioned(): yield provisioning.provision_self(self.update_manager) try: # Set up communication with pdserver. # 1. Create a report of the current system state and send that. # 2. Send the node public key. # 3. Poll for a list of updates that should be applied. # 4. Open WAMP session. yield sendStateReport() yield sendNodeIdentity() yield self.update_fetcher.start_polling() yield self.connect(WampSession) except Exception: out.warn('The router ID or password is invalid!') else: out.info('WAMP session is ready!')
def onStart(self): super(Nexus, self).onStart() # onStart is called when the reactor starts, not when the connection is made. # Check for provisioning keys and attempt to connect if not self.provisioned() and not provisioning.can_provision(): out.warn( "The node is not provisioned and is not configured to self-provision." ) return while not self.provisioned(): yield provisioning.provision_self(self.update_manager) try: # Set up communication with pdserver. # 1. Create a report of the current system state and send that. # 2. Send the node public key. # 3. Poll for a list of updates that should be applied. # 4. Open WAMP session. yield sendStateReport() yield sendNodeIdentity() yield self.update_fetcher.start_polling() yield self.connect(WampSession) except Exception: out.warn('The router ID or password is invalid!') else: out.info('WAMP session is ready!')
def provision(self, request): """ Provision the device with credentials from a cloud controller. """ cors.config_cors(request) body = json.loads(request.content.read().decode('utf-8')) routerId = body['routerId'] apitoken = body['apitoken'] pdserver = body['pdserver'] wampRouter = body['wampRouter'] changed = False if routerId != nexus.core.info.pdid \ or pdserver != nexus.core.info.pdserver \ or wampRouter != nexus.core.info.wampRouter: if pdserver and wampRouter: nexus.core.provision(routerId, pdserver, wampRouter) else: nexus.core.provision(routerId) changed = True if apitoken != nexus.core.getKey('apitoken'): nexus.core.saveKey(apitoken, 'apitoken') changed = True if changed: PDServerRequest.resetToken() nexus.core.jwt_valid = False def set_update_fetcher(session): session.set_update_fetcher(self.update_fetcher) @inlineCallbacks def start_polling(result): yield self.update_fetcher.start_polling() def send_response(result): response = dict() response['provisioned'] = True response['httpConnected'] = nexus.core.jwt_valid response['wampConnected'] = nexus.core.wamp_connected request.setHeader('Content-Type', 'application/json') return json.dumps(response) wampDeferred = nexus.core.connect(WampSession) wampDeferred.addCallback(set_update_fetcher) httpDeferred = sendStateReport() httpDeferred.addCallback(start_polling) identDeferred = sendNodeIdentity() dl = DeferredList([wampDeferred, httpDeferred, identDeferred], consumeErrors=True) dl.addBoth(send_response) reactor.callLater(6, dl.cancel) return dl else: return json.dumps({'success': False, 'message': 'No change on the provision parameters'})
def onStart(self): super(Nexus, self).onStart() # onStart is called when the reactor starts, not when the connection is made. # Check for provisioning keys and attempt to connect if not self.provisioned(): out.warn( 'Router has no keys or identity. Waiting to connect to to server.' ) else: try: # Set up communication with pdserver. # 1. Create a report of the current system state and send that. # 2. Poll for a list of updates that should be applied. # 3. Open WAMP session. yield sendStateReport() yield self.update_fetcher.start_polling() yield self.connect(WampSession) except Exception: out.warn('The router ID or password is invalid!') else: out.info('WAMP session is ready!')