def _mdp_reply_plugin_stop(self, data): """ Stop the plugin @param data : MQ req message First, send the MQ Rep to 'ack' the request Then, change the plugin status to STATUS_STOP_REQUEST Then, quit the plugin by calling force_leave(). This should make the plugin send a STATUS_STOPPED if all is ok Notice that no check is done on the MQ req content : we need nothing in it as it is directly addressed to a plugin """ # check if the message is for us content = data.get_data() if content['name'] != self._name or content['host'] != self.get_sanitized_hostname(): return ### Send the ack over MQ Rep msg = MQMessage() msg.set_action('plugin.stop.result') status = True reason = "" msg.add_data('status', status) msg.add_data('reason', reason) msg.add_data('name', self._name) msg.add_data('host', self.get_sanitized_hostname()) self.reply(msg.get()) ### Change the plugin status self._set_status(STATUS_STOP_REQUEST) ### Try to stop the plugin # if it fails, the manager should try to kill the plugin self.force_leave()
def client_devices_edit(client_id, did): with app.db.session_scope(): device = app.db.get_device_sql(did) MyForm = model_form(Device, \ base_class=Form, \ db_session=app.db.get_session(), exclude=['params', 'commands', 'sensors', 'address', 'xpl_commands', 'xpl_stats', 'device_type_id', 'client_id', 'client_version']) form = MyForm(request.form, device) if request.method == 'POST' and form.validate(): # save it app.db.update_device(did, \ d_name=request.form['name'], \ d_description=request.form['description'], \ d_reference=request.form['reference']) # message the suer flash(gettext("Device saved"), 'success') # reload stats req = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action( 'reload' ) resp = req.request('xplgw', msg.get(), 100) # redirect return redirect("/client/{0}/dmg_devices/known".format(client_id)) else: return render_template('client_device_edit.html', form = form, clientid = client_id, mactive="clients", active = 'devices' )
def _on_message(self, msg): """Helper method called on message receive. msg is a list w/ the message parts """ # 1st part is empty msg.pop(0) # 2nd part is protocol version # TODO: version check proto = msg.pop(0) # 3rd part is message type msg_type = msg.pop(0) # XXX: hardcoded message types! # any message resets the liveness counter self.need_handshake = False self.curr_liveness = self.HB_LIVENESS if msg_type == b'\x05': # disconnect self.curr_liveness = 0 # reconnect will be triggered by hb timer elif msg_type == b'\x02': # request # remaining parts are the user message envelope, msg = split_address(msg) envelope.append(b'') envelope = [ b'', self._proto_version, b'\x03'] + envelope # REPLY self.envelope = envelope mes = MQMessage() mes.set(msg) self.on_mdp_request(mes) else: # invalid message # ignored pass return
def check_config(type, name, host, key, exp_value): cli = MQSyncReq(zmq.Context()) msg = MQMessage() msg.set_action('config.get') msg.add_data('type', type) msg.add_data('host', host) msg.add_data('name', name) msg.add_data('key', key) result = cli.request('dbmgr', msg.get(), timeout=10) if result: data = result.get_data() if 'status' in data: if not data['status']: print(result.get()) raise RuntimeError("DbMgr did not return status true on a config.set for {0}-{1}.{2} : {3} = {4}".format(type, name, host, key, value)) else: if 'value' in data: if data['value'] != exp_value: print(result.get()) raise RuntimeError("The returned value is not the expected value for {0}-{1}.{2} : {3} = {4} but received {5}".format(type, name, host, key, exp_value, data['value'])) else: return True else: print(result.get()) raise RuntimeError("DbMgr did not return a value on a config.set for {0}-{1}.{2} : {3} = {4}".format(type, name, host, key, value)) else: print(result.get()) raise RuntimeError("DbMgr did not return a status on a config.set for {0}-{1}.{2} : {3} = {4}".format(type, name, host, key, value)) else: raise RuntimeError("Error while setting configuration for {0}-{1}.{2} : {3} = {4}".format(type, name, host, key, value))
def client_devices_new(client_id): cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('client.detail.get') res = cli.request('manager', msg.get(), timeout=10) if res is not None: detaila = res.get_data() data = detaila[client_id]['data'] else: data = {} if type(data["device_types"]) is not dict: dtypes = {} else: dtypes = list(data["device_types"].keys()) products = {} if "products" in data: for prod in data["products"]: products[prod["name"]] = prod["type"] return render_template('client_device_new.html', device_types = dtypes, products = products, clientid = client_id, mactve="clients", active = 'devices' )
def _on_mpd_message(self, msg): """Helper method called on message receive. msg is a list w/ the message parts """ # 1st part is empty msg.pop(0) # 2nd part is protocol version # TODO: version check proto = msg.pop(0) # 3rd part is message type msg_type = msg.pop(0) # XXX: hardcoded message types! # any message resets the liveness counter self.need_handshake = False self.curr_liveness = self.HB_LIVENESS if msg_type == b'\x05': # disconnect self.curr_liveness = 0 # reconnect will be triggered by hb timer elif msg_type == b'\x02': # request # remaining parts are the user message envelope, msg = split_address(msg) envelope.append(b'') envelope = [b'', self._proto_version, b'\x03'] + envelope # REPLY self.envelope = envelope mes = MQMessage() mes.set(msg) self.on_mdp_request(mes) else: # invalid message # ignored pass return
def reload_stats(self): self.log.debug(u"=============== reload stats") req = MQSyncReq(self.zmq) msg = MQMessage() msg.set_action( 'reload' ) resp = req.request('xplgw', msg.get(), 100) self.log.debug(u"Reply from xplgw: {0}".format(resp)) self.log.debug(u"=============== reload stats END")
def scenario_blocks_actions(): """ Blockly.Blocks['dom_action_log'] = { init: function() { this.setColour(160); this.appendDummyInput() .appendField('Log Message') .appendField(new Blockly.FieldTextInput("<message to log>"), "message"); this.setPreviousStatement(true, "null"); this.setNextStatement(true, "null"); this.setTooltip(''); this.setInputsInline(false); this.contextMenu = false; } }; """ js = "" cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('action.list') res = cli.request('scenario', msg.get(), timeout=10) if res is not None: res = res.get_data() if 'result' in res: res = json.loads(res['result']) for act, params in res.iteritems(): print act print params p = [] jso = "" for par, parv in params['parameters'].iteritems(): print par print parv papp = "this.appendDummyInput().appendField('{0}')".format(parv['description']) if parv['type'] == 'string': jso = '{0}, "{1}": "\'+ block.getFieldValue(\'{1}\') + \'" '.format(jso, par) papp = "{0}.appendField(new Blockly.FieldTextInput('{1}'), '{2}');".format(papp, parv['default'],par) elif parv['type'] == 'integer': jso = '{0}, "{1}": \'+ block.getFieldValue(\'{1}\') + \' '.format(jso, par) papp = "{0}.appendField(new Blockly.FieldTextInput('{1}'), '{2}');".format(papp, parv['default'],par) else: papp = "{0};".format(papp) p.append(papp) add = """Blockly.Blocks['{0}'] = {{ init: function() {{ this.setHelpUrl(''); this.setColour(160); this.appendDummyInput().appendField("{0}"); {1} this.setPreviousStatement(true, "null"); this.setNextStatement(true, "null"); this.setTooltip('{2}'); this.setInputsInline(false); }} }}; """.format(act, '\n'.join(p), params['description'], jso) js = '{0}\n\r{1}'.format(js, add) return Response(js, content_type='text/javascript; charset=utf-8')
def client_devices_delete(client_id, did): with app.db.session_scope(): app.db.del_device(did) # reload stats req = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action( 'reload' ) resp = req.request('xplgw', msg.get(), 100) return redirect("/client/{0}/devices/known".format(client_id))
def _load_client_to_xpl_target(self): cli = MQSyncReq(self.zmq) msg = MQMessage() msg.set_action('client.list.get') response = cli.request('manager', msg.get(), timeout=10) if response: self._parse_xpl_target(response.get_data()) else: self.log.error(u"Updating client list was not successfull, no response from manager")
def orphans_delete(did): with app.db.session_scope(): app.db.del_device(did) # reload stats req = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action( 'reload' ) resp = req.request('xplgw', msg.get(), 100) flash(gettext("Device deleted"), "success") return redirect("/orphans")
def _load_conversions(self): print "============================ conversion" cli = MQSyncReq(self.zmq) msg = MQMessage() msg.set_action('client.conversion.get') response = cli.request('manager', msg.get(), timeout=10) if response: self._parse_conversions(response.get_data()) else: self.log.error(u"Updating client conversion list was not successfull, no response from manager")
def __init__(self, server_interfaces, server_port): """ Initiate DbHelper, Logs and config Then, start HTTP server and give it initialized data @param server_interfaces : interfaces of HTTP server @param server_port : port of HTTP server """ XplPlugin.__init__(self, name = 'admin', nohub = True) # logging initialization self.log.info(u"Admin Server initialisation...") self.log.debug(u"locale : %s %s" % locale.getdefaultlocale()) try: try: cfg_rest = Loader('admin') config_rest = cfg_rest.load() conf_rest = dict(config_rest[1]) self.interfaces = conf_rest['interfaces'] self.port = conf_rest['port'] # if rest_use_ssl = True, set here path for ssl certificate/key self.use_ssl = conf_rest['use_ssl'] self.key_file = conf_rest['ssl_certificate'] self.cert_file = conf_rest['ssl_key'] except KeyError: # default parameters self.interfaces = server_interfaces self.port = server_port self.use_ssl = False self.key_file = "" self.cert_file = "" self.clean_json = False self.log.info(u"Configuration : interfaces:port = %s:%s" % (self.interfaces, self.port)) # get all datatypes cli = MQSyncReq(self.zmq) msg = MQMessage() msg.set_action('datatype.get') res = cli.request('manager', msg.get(), timeout=10) if res is not None: self.datatypes = res.get_data()['datatypes'] else: self.datatypes = {} # Launch server, stats self.log.info(u"Admin Initialisation OK") self.add_stop_cb(self.stop_http) self.server = None self.start_http() # calls the tornado.ioloop.instance().start() ### Component is ready self.ready(0) IOLoop.instance().start() except : self.log.error(u"%s" % self.get_exception())
def set(self, plugin, key, value): """ Send a xpl message to set value for a param @param technology : the technology of the item @param key : the key to set corresponding value, @param value : the value to set """ msg = MQMessage() msg._action = "config.set" self.cli.request("dbmgr", msg.get(), timeout=QUERY_CONFIG_WAIT)
def on_mdp_request(self, msg): # XplPlugin handles MQ Req/rep also XplPlugin.on_mdp_request(self, msg) if msg.get_action() == "reload": self.load() msg = MQMessage() msg.set_action( 'reload.result' ) self.reply(msg.get()) elif msg.get_action() == "cmd.send": self._send_xpl_command(msg)
def _load_client_to_xpl_target(self): cli = MQSyncReq(self.zmq) msg = MQMessage() msg.set_action('client.list.get') response = cli.request('manager', msg.get(), timeout=10) if response: data = response.get_data() for cli in data: self.client_xpl_map[cli] = data[cli]['xpl_source'] else: self.log.error(u"Updating client list was not successfull, no response from manager")
def get_device_list(self, quit_if_no_device = False): """ Request the dbmgr component over MQ to get the devices list for this client @param quit_if_no_device: if True, exit the plugin if there is no devices """ self.log.info(u"Retrieve the devices list for this client...") mq_client = MQSyncReq(self.zmq) msg = MQMessage() msg.set_action('device.get') msg.add_data('type', 'plugin') msg.add_data('name', self._name) msg.add_data('host', self.get_sanitized_hostname()) result = mq_client.request('dbmgr', msg.get(), timeout=10) if not result: self.log.error(u"Unable to retrieve the device list") self.force_leave() return [] else: device_list = result.get_data()['devices'] if device_list == []: self.log.warn(u"There is no device created for this client") if quit_if_no_device: self.log.warn(u"The developper requested to stop the client if there is no device created") self.force_leave() return [] for a_device in device_list: self.log.info(u"- id : {0} / name : {1} / device type id : {2}".format(a_device['id'], \ a_device['name'], \ a_device['device_type_id'])) # log some informations about the device # notice that even if we are not in the XplPlugin class we will display xpl related informations : # for some no xpl plugins, there will just be nothing to display. # first : the stats self.log.info(u" xpl_stats features :") for a_xpl_stat in a_device['xpl_stats']: self.log.info(u" - {0}".format(a_xpl_stat)) self.log.info(u" Static Parameters :") for a_feature in a_device['xpl_stats'][a_xpl_stat]['parameters']['static']: self.log.info(u" - {0} = {1}".format(a_feature['key'], a_feature['value'])) self.log.info(u" Dynamic Parameters :") for a_feature in a_device['xpl_stats'][a_xpl_stat]['parameters']['dynamic']: self.log.info(u" - {0}".format(a_feature['key'])) # then, the commands self.log.info(u" xpl_commands features :") for a_xpl_cmd in a_device['xpl_commands']: self.log.info(u" - {0}".format(a_xpl_cmd)) self.log.info(u" + Parameters :") for a_feature in a_device['xpl_commands'][a_xpl_cmd]['parameters']: self.log.info(u" - {0} = {1}".format(a_feature['key'], a_feature['value'])) self.devices = device_list return device_list
def _mdp_reply_plugin_start(self, data): """ Reply on the MQ @param data : msg REQ received """ msg = MQMessage() msg.set_action('plugin.start.result') if 'name' not in data.get_data().keys(): status = False reason = "Plugin startup request : missing 'name' field" self.log.error(reason) else: name = data.get_data()['name'] msg.add_data('name', name) # try to start the plugin pid = self._plugins[name].start() if pid != 0: status = True reason = "" else: status = False reason = "Plugin '{0}' startup failed".format(name) msg.add_data('status', status) msg.add_data('reason', reason) self.reply(msg.get())
def scenario_edit(id): # Fetch all known actions actions = [] cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('action.list') res = cli.request('scenario', msg.get(), timeout=10) if res is not None: res = res.get_data() if 'result' in res: res = json.loads(res['result']) actions = res.keys() # Fetch all known tests tests = [] cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('test.list') res = cli.request('scenario', msg.get(), timeout=10) if res is not None: res = res.get_data() if 'result' in res: res = json.loads(res['result']) tests = res.keys() # TODO laod the json for this scenario # if not exists send None == new jso = None return render_template('scenario_edit.html', mactive = "scenario", actions = actions, tests = tests, json = jso)
def test_XplCmd(self, parameters = {}, statParams = None): """Send an Xpl cmd with statics parameters by request, if necessary start testcase listener for ack message and check if insert in database is ok. """ if self.get_return_confirmation() : schema, data, statResult = self.get_XplStat_fromAck(statParams) th = threading.Thread(None, self.assert_Xpl_Stat_Ack_Wait, "th_test_0110_xpl-ack_from_{0}".format(self.command_name), (schema, data, statResult)) th.start() time.sleep(1) else : print (u"No ack required for {0}".format(self.command_name)) if self._device and self.command_id : cli = MQSyncReq(zmq.Context()) msg = MQMessage() msg.set_action('cmd.send') msg.add_data('cmdid', self.command_id) msg.add_data('cmdparams', parameters) print (u"Send xpl_cmnd {0}".format(self.command_name)) cli.request('xplgw', msg.get(), timeout=10) # if self.get_return_confirmation() : # self.assert_get_last_command_in_db(statResult) # else : # print (u"No ack required for {0}".format(self.command_name)) return True else : return False
def WSCommandSend(self, data): cli = MQSyncReq(zmq.Context()) msg = MQMessage() msg.set_action('cmd.send') msg.add_data('cmdid', data['command_id']) msg.add_data('cmdparams', data['parameters']) return cli.request('xplgw', msg.get(), timeout=10).get()
def clients(): cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('client.list.get') res = cli.request('manager', msg.get(), timeout=10) if res is not None: client_list = res.get_data() else: client_list = {} return render_template('clients.html', mactve="clients", overview_state="collapse", clients=client_list )
def scenario_blocks_tests(): """ this.setHelpUrl(''); this.setColour(160); this.appendDummyInput() .appendField('Time') .appendField(new Blockly.FieldTextInput("<cron like timestamp>"), "cron"); this.setOutput(true, null); this.setTooltip(''); this.setInputsInline(false); """ js = "" cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('test.list') res = cli.request('scenario', msg.get(), timeout=10) if res is not None: res = res.get_data() if 'result' in res: res = json.loads(res['result']) for test, params in res.iteritems(): p = [] jso = "" for par, parv in params['parameters'].iteritems(): par = parv['expected'].keys()[0] parv = parv['expected'][par] papp = "this.appendDummyInput().appendField('{0}')".format(parv['description']) if parv['type'] == 'string': jso = '{0}, "{1}": "\'+ block.getFieldValue(\'{1}\') + \'" '.format(jso, par) papp = "{0}.appendField(new Blockly.FieldTextInput('{1}'), '{2}');".format(papp, parv['default'],par) elif parv['type'] == 'integer': jso = '{0}, "{1}": \'+ block.getFieldValue(\'{1}\') + \' '.format(jso, par) papp = "{0}.appendField(new Blockly.FieldTextInput('{1}'), '{2}');".format(papp, parv['default'],par) p.append(papp) add = """Blockly.Blocks['{0}'] = {{ init: function() {{ this.setColour(160); this.appendDummyInput().appendField("{0}"); {1} this.setOutput(true); this.setInputsInline(true); this.setTooltip('{2}'); this.contextMenu = false; }} }}; """.format(test, '\n'.join(p), params['description'], jso) js = '{0}\n\r{1}'.format(js, add) return Response(js, content_type='text/javascript; charset=utf-8')
def _mdp_reply_device_types(self, data): """ Reply on the MQ @param data : message data """ msg = MQMessage() msg.set_action('device_types.result') if 'device_type' not in data.get_data(): for dev in self._device_types: msg.add_data(dev, self._device_types[dev]) else: device_type = data.get_data()['device_type'] if self._device_types.has_key(device_type): msg.add_data(device_type, self._device_types[device_type]) else: msg.add_data(device_type, None) self.reply(msg.get())
def client_devices_detected(client_id): cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('device.new.get') res = cli.request(str(client_id), msg.get(), timeout=10) if res is not None: data = res.get_data() devices = data['devices'] else: devices = {} return render_template('client_detected.html', devices = devices, clientid = client_id, mactive="clients", active = 'devices' )
def request(self, service, msg, timeout=None): """Send the given message. :param msg: message parts to send. :type msg: list of str :param timeout: time to wait in milliseconds. :type timeout: int :rtype : message parts """ ret = self.rawrequest( service, msg, timeout) msg = None if ret: msg = MQMessage() msg.set(ret) return msg
def refreshClientDevice(self, client): """Request a refresh domogik device data for a IRTrans Client.""" cli = MQSyncReq(zmq.Context()) msg = MQMessage() msg.set_action('device.get') msg.add_data('type', 'plugin') msg.add_data('name', self._xplPlugin.get_plugin_name()) msg.add_data('host', get_sanitized_hostname()) devices = cli.request('dbmgr', msg.get(), timeout=10).get() for a_device in devices: if a_device['device_type_id'] == client._device['device_type_id'] and a_device['id'] == client._device['id'] : if a_device['name'] != client.device['name'] : # rename and change key client id old_id = getIRTransId(client._device) self.irTransClients[getIRTransId(a_device)] = self.irTransClients.pop(old_id) self._xplPlugin.log.info(u"IRTransciever Client {0} is rename {1}".format(old_id, getIRTransId(a_device))) client.updateDevice(a_device) break
def scenario_edit(id): default_json = '{"type":"dom_condition","id":"1","deletable":false}' # laod the json if id == 0: name = "ikke" jso = default_json else: # TODO laod from DB jso = default_json name = "new" # create a form class F(Form): sid = HiddenField("id", default=id) sname = TextField("name", default=name) sjson = HiddenField("json") submit = SubmitField("Send") pass form = F() if request.method == 'POST' and form.validate(): print request.form flash(gettext("Changes saved"), "success") return redirect("/scenario") pass else: # Fetch all known actions actions = [] cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('action.list') res = cli.request('scenario', msg.get(), timeout=10) if res is not None: res = res.get_data() if 'result' in res: res = json.loads(res['result']) actions = res.keys() # Fetch all known tests tests = [] cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('test.list') res = cli.request('scenario', msg.get(), timeout=10) if res is not None: res = res.get_data() if 'result' in res: res = json.loads(res['result']) tests = res.keys() # ouput return render_template('scenario_edit.html', mactive = "scenario", form = form, name = name, actions = actions, tests = tests, jso = jso)
def _mdp_reply_plugin_stop(self, data): """ Stop the plugin @param data : MQ req message First, send the MQ Rep to 'ack' the request Then, change the plugin status to STATUS_STOP_REQUEST Then, quit the plugin by calling force_leave(). This should make the plugin send a STATUS_STOPPED if all is ok Notice that no check is done on the MQ req content : we need nothing in it as it is directly addressed to a plugin """ # check if the message is for us content = data.get_data() if content['name'] != self._name or content[ 'host'] != self.get_sanitized_hostname(): return ### Send the ack over MQ Rep msg = MQMessage() msg.set_action('plugin.stop.result') status = True reason = "" msg.add_data('status', status) msg.add_data('reason', reason) self.reply(msg.get()) ### Change the plugin status self._set_status(STATUS_STOP_REQUEST) ### Try to stop the plugin # if it fails, the manager should try to kill the plugin self.force_leave()
def client_detail(client_id): cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('client.detail.get') res = cli.request('manager', msg.get(), timeout=10) if res is not None: detaila = res.get_data() detail = detaila[client_id] else: detail = {} return render_template('client.html', loop = {'index': 1}, clientid = client_id, data = detail, mactve="clients", active = 'home' )
def client_devices_known(client_id): if app.datatypes == {}: cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('datatype.get') res = cli.request('manager', msg.get(), timeout=10) if res is not None: app.datatypes = res.get_data()['datatypes'] else: app.datatypes = {} with app.db.session_scope(): devices = app.db.list_devices_by_plugin(client_id) return render_template('client_devices.html', datatypes=app.datatypes, devices=devices, clientid=client_id, mactve="clients", active='devices')
def post(self): """ Create a new device Get all the clients details Finally, call the database function to create the device and give it the device types list and clients details : they will be used to fill the database as the json structure is recreated in the database """ cli = MQSyncReq(urlHandler.zmq_context) #self.log.info(u"Device creation request for {0} {1} on {2} : name = '{3}', device_type = '{4}', reference = '{5}'".format(request.form.get('type'), request.form.get('id'), request.form.get('host'), request.form.get('device_type'), request.form.get('reference'))) #urlHandler.log.info("Device creation request for {0} {1} on {2} : name = '{3}', device_type = '{4}', reference = '{5}'".format(request.form.get('type'), request.form.get('id'), request.form.get('host'), request.form.get('device_type'), request.form.get('reference'))) # get the client details msg = MQMessage() msg.set_action('client.detail.get') res = cli.request('manager', msg.get(), timeout=10) if res is None: return 500, "Error while getting the clients details" # create the full client id : #if request.form.get('type') == "plugin": # client_id = "{0}-{1}.{2}".format(DMG_VENDOR_ID, request.form.get('id'), request.form.get('host')) #else: # client_id = "{0}-{1}.{2}".format(request.form.get('type'), request.form.get('id'), request.form.get('host')) # get the corresponding json all_clients_data = res.get_data() # extract the interesting part of the json (just the client part) if all_clients_data.has_key(request.form.get('client_id')): client_data = all_clients_data[request.form.get('client_id')]['data'] else: return 500, "Error : there is no client id named '{0}'".format(request.form.get('client_id')) # create the device in database # notice that we don't give any address for the device as this will be done with another url later created_device = urlHandler.db.add_device_and_commands( name=request.form.get('name'), device_type=request.form.get('device_type'), client_id=request.form.get('client_id'), description=request.form.get('description'), reference=request.form.get('reference'), client_data=client_data ) urlHandler.reload_stats() return 201, created_device
def do_action(self, condition, tests): cli = MQSyncReq(zmq.Context()) msg = MQMessage() msg.set_action('cmd.send') msg.add_data('cmdid', self._params['cmdid']) msg.add_data('cmdparams', self._params['cmdparams']) # do the request res = cli.request('xplgw', msg.get(), timeout=10) if res: data = res.get_data() if not data['status']: self._log.error( "Command sending to XPL gw failed: {0}".format(res)) else: self._log.error("XPL gw did not respond")
def _mdp_reply_helper_help(self, data): content = data.get_data() if 'command' in contens.keys(): if content['command'] in self.helpers.keys(): msg = MQMessage() msg.set_action('helper.help.result') msg.add_data('help', self.helpers[content['command']]['help']) self.reply(msg.get())
def loadDatatypes(cls): session = Session() # get all datatypes logger.info("MQ: Loading Datatypes") msg = MQMessage() msg.set_action('datatype.get') res = cli.request('manager', msg.get(), timeout=10) if res is not None: _data = res.get_data()['datatypes'] else: _data = {} session.query(DataType).delete() for type, params in _data.iteritems(): r = DataType(id=type, parameters=json.dumps(params)) session.add(r) session.commit() session.flush()
def _mdp_reply_device_new_get(self, data): """ Return a list of new devices detected @param data : MQ req message """ ### Send the ack over MQ Rep msg = MQMessage() msg.set_action('device.new.result') msg.add_data('devices', self.new_devices) self.reply(msg.get())
def _mdp_reply_helper_list(self, data): """ Return a list of supported helpers @param data : MQ req message """ ### Send the ack over MQ Rep msg = MQMessage() msg.set_action('helper.list.result') msg.add_data('actions', self.helpers.keys()) self.reply(msg.get())