def process_inform_message( inform: Any, data_model: DataModel, device_cfg: EnodebConfiguration, ) -> None: """ Modifies the device configuration based on what is received in the Inform message. Will raise an error if it turns out that the data model we are using is incorrect. This is decided based on the device OUI and software-version that is reported in the Inform message. Args: inform: Inform Tr069 message device_handler: The state machine we are using for our device """ param_values_by_path = _get_param_values_by_path(inform) param_name_list = data_model.get_parameter_names() name_to_val = {} for name in param_name_list: path = data_model.get_parameter(name).path if path in param_values_by_path: value = param_values_by_path[path] name_to_val[name] = value for name, val in name_to_val.items(): device_cfg.set_parameter(name, val) # In case the SerialNumber does not come in the inform ParameterList # it can still be present in the Inform structure, fill it in. if (hasattr(inform, 'DeviceId') and hasattr(inform.DeviceId, 'SerialNumber')): device_cfg.set_parameter(ParameterName.SERIAL_NUMBER, inform.DeviceId.SerialNumber)
def process_inform_message( inform: Any, data_model: DataModel, device_cfg: EnodebConfiguration, ) -> None: """ Modifies the device configuration based on what is received in the Inform message. Will raise an error if it turns out that the data model we are using is incorrect. This is decided based on the device OUI and software-version that is reported in the Inform message. Args: inform: Inform Tr069 message device_handler: The state machine we are using for our device """ param_values_by_path = _get_param_values_by_path(inform) param_name_list = data_model.get_parameter_names() name_to_val = {} for name in param_name_list: path = data_model.get_parameter(name).path if path in param_values_by_path: value = param_values_by_path[path] name_to_val[name] = value for name, val in name_to_val.items(): device_cfg.set_parameter(name, val)
def parse_get_parameter_values_response( data_model: DataModel, message: models.GetParameterValuesResponse, ) -> Dict[ParameterName, Any]: """ Returns a map of ParameterName to the value read from the response """ param_values_by_path = {} for param_value_struct in message.ParameterList.ParameterValueStruct: param_values_by_path[param_value_struct.Name] = \ param_value_struct.Value.Data param_name_list = data_model.get_parameter_names() name_to_val = {} for name in param_name_list: path = data_model.get_parameter(name).path if path in param_values_by_path: value = param_values_by_path[path] name_to_val[name] = value return name_to_val
def process_inform_message( inform: Any, device_name: EnodebDeviceName, data_model: DataModel, device_cfg: EnodebConfiguration, ) -> None: """ Modifies the device configuration based on what is received in the Inform message. Will raise an error if it turns out that the data model we are using is incorrect. This is decided based on the device OUI and software-version that is reported in the Inform message. Args: inform: Inform Tr069 message device_handler: The state machine we are using for our device """ logging.info('Processing Inform message') def _get_param_value_from_path_suffix( suffix: str, path_list: List[str], param_values_by_path: Dict[str, Any], ) -> Any: for path in path_list: if path.endswith(suffix): return param_values_by_path[path] raise ConfigurationError('Did not receive expected info in Inform') if hasattr(inform, 'ParameterList') and \ hasattr(inform.ParameterList, 'ParameterValueStruct'): param_values_by_path = {} for param_value in inform.ParameterList.ParameterValueStruct: path = param_value.Name value = param_value.Value.Data logging.debug('(Inform msg) Received parameter: %s = %s', path, value) param_values_by_path[path] = value # Check the OUI and version number to see if the data model matches path_list = list(param_values_by_path.keys()) device_oui = _get_param_value_from_path_suffix( 'DeviceInfo.ManufacturerOUI', path_list, param_values_by_path, ) sw_version = _get_param_value_from_path_suffix( 'DeviceInfo.SoftwareVersion', path_list, param_values_by_path, ) logging.info('OUI: %s, Software: %s', device_oui, sw_version) correct_device_name = get_device_name(device_oui, sw_version) if device_name is not correct_device_name: raise IncorrectDeviceHandlerError( device_name=correct_device_name) param_name_list = data_model.get_parameter_names() name_to_val = {} for name in param_name_list: path = data_model.get_parameter(name).path if path in param_values_by_path: value = param_values_by_path[path] name_to_val[name] = value for name, val in name_to_val.items(): device_cfg.set_parameter(name, val)