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 get_param_values_to_set( desired_cfg: EnodebConfiguration, device_cfg: EnodebConfiguration, data_model: DataModel, exclude_admin: bool = False, ) -> Dict[ParameterName, Any]: """ Get a map of param names to values for parameters that we will set on the eNB's configuration, excluding parameters for objects that can be added/removed. Also exclude special parameters like admin state, since it may be set at a different time in the provisioning process than most parameters. """ param_values = {} # Get the parameters we might set params = set(desired_cfg.get_parameter_names()) - set(READ_ONLY_PARAMETERS) if exclude_admin: params = set(params) - {ParameterName.ADMIN_STATE} # Values of parameters for name in params: new = desired_cfg.get_parameter(name) old = device_cfg.get_parameter(name) _type = data_model.get_parameter(name).type if not are_tr069_params_equal(new, old, _type): param_values[name] = new return param_values
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 get_obj_param_values_to_set( desired_cfg: EnodebConfiguration, device_cfg: EnodebConfiguration, data_model: DataModel, ) -> Dict[ParameterName, Dict[ParameterName, Any]]: """ Returns a map from object name to (a map of param name to value) """ param_values = {} objs = desired_cfg.get_object_names() for obj_name in objs: param_values[obj_name] = {} params = desired_cfg.get_parameter_names_for_object(obj_name) for name in params: new = desired_cfg.get_parameter_for_object(name, obj_name) old = device_cfg.get_parameter_for_object(name, obj_name) _type = data_model.get_parameter(name).type if not are_tr069_params_equal(new, old, _type): param_values[obj_name][name] = new return param_values
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)