def loadRinorModels(self): from domoweb.exceptions import RinorNotConfigured, RinorNotAvailable from domoweb.restModel import RestModel from domoweb.models import Parameter, DeviceType, DataType, Device try: ip = Parameter.objects.get(key='rinor_ip') port = Parameter.objects.get(key='rinor_port') except Parameter.DoesNotExist: cherrypy.engine.log("RINOR not configured, pass the data loading") else: try: prefix = Parameter.objects.get(key='rinor_prefix') except Parameter.DoesNotExist: uri = "http://%s:%s" % (ip.value, port.value) else: uri = "http://%s:%s/%s" % (ip.value, port.value, prefix.value) model_loaded = False i = 0 while not model_loaded: # Wait until RINOR respond try: i = i + 1 RestModel.setRestUri(uri) Parameter.refresh() DataType.refresh() DeviceType.refresh() Device.refresh() model_loaded = True except RinorNotAvailable: cherrypy.engine.log( "RINOR not online wait 5s before retry #%s" % i) time.sleep(5)
def loadRinorModels(self): from domoweb.exceptions import RinorNotConfigured, RinorNotAvailable from domoweb.restModel import RestModel from domoweb.models import Parameter, DeviceType, DataType, Device try: ip = Parameter.objects.get(key='rinor_ip') port = Parameter.objects.get(key='rinor_port') except Parameter.DoesNotExist: cherrypy.engine.log("RINOR not configured, pass the data loading") else: try: prefix = Parameter.objects.get(key='rinor_prefix') except Parameter.DoesNotExist: uri = "http://%s:%s" % (ip.value, port.value) else: uri = "http://%s:%s/%s" % (ip.value, port.value, prefix.value) model_loaded = False i = 0 while not model_loaded: # Wait until RINOR respond try: i = i + 1 RestModel.setRestUri(uri) Parameter.refresh() DataType.refresh() DeviceType.refresh() Device.refresh() model_loaded = True except RinorNotAvailable: cherrypy.engine.log("RINOR not online wait 5s before retry #%s" % i) time.sleep(5)
def loadDevices(cls, develop): logger.info(u"MQ: Loading Devices info") Device.clean() msg = MQMessage() msg.set_action('client.list.get') res = cli.request('manager', msg.get(), timeout=10) if res is not None: _datac = res.get_data() else: _datac = {} session = Session() for client in _datac.itervalues(): # for each plugin client, we request the list of devices if client["type"] == "plugin": msg = MQMessage() msg.set_action('device.get') msg.add_data('type', 'plugin') msg.add_data('name', client["name"]) msg.add_data('host', client["host"]) logger.info(u"MQ: Get devices list for client {0}-{1}.{2}".format("plugin", client["name"], client["host"])) res = cli.request('dbmgr', msg.get(), timeout=10) if res is not None: _datad = res.get_data() else: _datad = {} if 'devices' in _datad: for device in _datad["devices"]: logger.info(u"- {0}".format(device["name"])) d = Device(id=device["id"], name=device["name"], type=device["device_type_id"], reference=device["reference"]) session.add(d) if "commands" in device: for ref, command in device["commands"].iteritems(): c = Command(id=command["id"], name=command["name"], device_id=device["id"], reference=ref, return_confirmation=command["return_confirmation"]) session.add(c) c.datatypes = "" for param in command["parameters"]: p = CommandParam(command_id=c.id, key=param["key"], datatype_id=param["data_type"]) session.add(p) c.datatypes += param["data_type"] session.add(c) if "sensors" in device: for ref, sensor in device["sensors"].iteritems(): s = Sensor(id=sensor["id"], name=sensor["name"], device_id=device["id"], reference=ref, datatype_id=sensor["data_type"], last_value=sensor["last_value"], last_received=sensor["last_received"], timeout=sensor["timeout"]) session.add(s) session.commit() session.flush()
def addField(cls, option): types = json.loads(option.types) devices = Device.getTypesFilter(types=types) cls.addModelChoiceField(key=option.key, label=option.name, required=option.required, queryset=devices, group_by_field='type', empty_label="--Select Device--", help_text=option.description)
def admin_core_deviceupgrade(request): """ Method called when the admin Domoweb Data page is accessed @param request : HTTP request @return an HttpResponse object """ msg = '' # handle the post form if request.method == 'POST': dev = Device.list_upgrade() frm = DeviceUpgradeForm(request.POST) frm.fields['old'].choices = dev[0]['old'] frm.fields['new'].choices = dev[0]['new'] if frm.is_valid(): cleaned_data = frm.clean() old = cleaned_data['old'] new = cleaned_data['new'] msg = 'post done ' + old + ' ' + new old = old.split('-') new = new.split('-') Device.do_upgrade(old[0], old[1], new[0], new[1]) else: msg = frm._errors # do the real output page_title = _("Devices Upgrade") dev = Device.list_upgrade() frm = DeviceUpgradeForm(auto_id='main_%s') frm.fields['old'].choices = dev[0]['old'] frm.fields['new'].choices = dev[0]['new'] return go_to_page(request, 'core/deviceupgrade.html', page_title, frm=frm, msg=msg, nav1_admin="selected", nav2_core_deviceupgrade="selected", parameter_data=Parameter.objects.all())
def config_loadrinordata(request): """ @param request : the HTTP request @return an HttpResponse object """ from domoweb.restModel import RestModel from domoweb.models import Parameter, DataType, DeviceType, Device ip = Parameter.objects.get(key='rinor_ip') port = Parameter.objects.get(key='rinor_port') try: prefix = Parameter.objects.get(key='rinor_prefix') except Parameter.DoesNotExist: uri = "http://%s:%s" % (ip.value, port.value) else: uri = "http://%s:%s/%s" % (ip.value, port.value, prefix.value) RestModel.setRestUri(uri) Parameter.refresh() DataType.refresh() DeviceType.refresh() Device.refresh() return redirect('index_view') # Redirect after POST
def addField(cls, option): types = json.loads(option.types) devices = Device.getTypesFilter(types=types) cls.addGroupedModelChoiceField(key=option.key, label=option.name, required=option.required, queryset=devices, group_by_field='type', empty_label="--Select Device--", help_text=option.description)
def admin_add_device(request, plugin_host, plugin_id, plugin_type, type_id): page_title = _("Add device") parameters = DeviceParametersPipe().get_detail(type_id) globalparametersform = None if parameters["global"]: globalparametersform = ParametersForm(auto_id='global_%s') for parameter in parameters["global"]: globalparametersform.addCharField(parameter.key, parameter.description, required=True) commands = [] hasscommandsparamters = 0 for command in parameters["xpl_cmd"]: form = ParametersForm(id=command.id, name=command.name, params=command.params, prefix='cmd') commands.append(form) if command.params: hasscommandsparamters = 1 stats = [] hasstatsparamters = 0 for stat in parameters["xpl_stat"]: form = ParametersForm(id=stat.id, name=stat.name, params=stat.params, prefix='stat') stats.append(form) if stat.params: hasstatsparamters = 1 if request.method == 'POST': valid = True deviceform = DeviceForm(request.POST) # A form bound to the POST data valid = valid and deviceform.is_valid() if globalparametersform: globalparametersform.setData(request.POST) globalparametersform.validate() valid = valid and globalparametersform.is_valid() for command in commands: command.setData(request.POST) command.validate() valid = valid and command.is_valid() for stat in stats: stat.setData(request.POST) stat.validate() valid = valid and stat.is_valid() if valid: cd = deviceform.cleaned_data device = Device.create(cd["name"], cd["type_id"], cd["reference"]) if globalparametersform: device.add_global_params( parameters=globalparametersform.cleaned_data) for command in commands: if command.params: device.add_xplcmd_params(id=command.id, parameters=command.getData()) for stat in stats: if stat.params: device.add_xplstat_params(id=stat.id, parameters=stat.getData()) return redirect('admin_plugins_plugin_view', plugin_host=plugin_host, plugin_id=plugin_id, plugin_type=plugin_type) # Redirect after POST else: deviceform = DeviceForm(auto_id='main_%s', initial={'type_id': type_id}) return go_to_page( request, 'plugins/device.html', page_title, plugin_host=plugin_host, plugin_id=plugin_id, plugin_type=plugin_type, deviceform=deviceform, globalparametersform=globalparametersform, hasscommansparamters=hasscommandsparamters, hasstatsparamters=hasstatsparamters, commands=commands, stats=stats, )
def loadDevices(cls, develop): logger.info(u"MQ: Loading Devices info") Device.clean() msg = MQMessage() msg.set_action('client.list.get') res = cli.request('manager', msg.get(), timeout=10) if res is not None: _datac = res.get_data() else: _datac = {} session = Session() for client in _datac.itervalues(): # for each plugin client, we request the list of devices if client["type"] == "plugin": msg = MQMessage() msg.set_action('device.get') msg.add_data('type', 'plugin') msg.add_data('name', client["name"]) msg.add_data('host', client["host"]) logger.info( u"MQ: Get devices list for client {0}-{1}.{2}".format( "plugin", client["name"], client["host"])) res = cli.request('dbmgr', msg.get(), timeout=10) if res is not None: _datad = res.get_data() else: _datad = {} if 'devices' in _datad: for device in _datad["devices"]: logger.info(u"- {0}".format(device["name"])) d = Device(id=device["id"], name=device["name"], type=device["device_type_id"], reference=device["reference"]) session.add(d) if "commands" in device: for ref, command in device["commands"].iteritems(): c = Command(id=command["id"], name=command["name"], device_id=device["id"], reference=ref, return_confirmation=command[ "return_confirmation"]) session.add(c) c.datatypes = "" for param in command["parameters"]: p = CommandParam( command_id=c.id, key=param["key"], datatype_id=param["data_type"]) session.add(p) c.datatypes += param["data_type"] session.add(c) if "sensors" in device: for ref, sensor in device["sensors"].iteritems(): s = Sensor( id=sensor["id"], name=sensor["name"], device_id=device["id"], reference=ref, datatype_id=sensor["data_type"], last_value=sensor["last_value"], last_received=sensor["last_received"], timeout=sensor["timeout"]) session.add(s) session.commit() session.flush()