def find_session_by_attributes(self, match_list, retrieve_list = None): """ Finds sessions matching the attributes specified in match_list. The attributes associated with each of the found sessions will be retrieved and returned as the values of the dictionary. If the optional retrieve_list is None, all attributes will be retrieved. If the retrieve_list is not null, only a subset of the attributes listed in the retrieve_list will be retrieved. @param match_list: The attributes and their corresponding values in the match_list specifies the sessions that match these attributes. @param retrieve_list: The retrieve_list specifies a list of attribute to be retrieved. If it is None or missing, all attributes will be retrieved; otherwise only a subset of the attributes listed in the retrieve_list will be retrieved. @return A dictionary that contains Identity sessions as keys and list of Attribute as corresponding values. @throws OnepIllegalArgumentException The exception is thrown when any of input parameter is invalid. @throws OnepConnectionException The exception is thrown when the network element is not connected. @throws OnepRemoteProcedureException The exception is thrown when an error has occurred in the remote procedure call made to the network element. """ if self._ne == None or self._ne.session_handle == None: raise OnepConnectionException() match_idl_list = Attribute.toIDLList(match_list, self._ne) if match_idl_list == None: match_idl_list = [] retrieve_id_list = Attribute.toIDLList(retrieve_list, self._ne) try: if retrieve_list == None: ss_id_list = self._identity_client.Sanet_Find_By_Attributes_IDL(self._ne.session_handle.id, match_idl_list) else: ss_id_list = self._identity_client.Sanet_Find_By_Attributes_With_Reqd_List_IDL(self._ne.session_handle.id, match_idl_list, retrieve_id_list) if ss_id_list == None: return else: ss_map = {} for ss_idl in ss_id_list: if ss_idl == None: continue ss = IdentitySession(self, self._ne, ss_idl.sessionNum) attr_list = _from_idl_list(ss_idl.attr_list, self._ne) ss_map[ss] = attr_list return ss_map except ExceptionIDL as e: raise OnepRemoteProcedureException(e.getCode(), e.getText(), e) except TException as e: raise OnepConnectionException(e.getMessage(), e)
def update_session_attributes(self, attr_list): """ Updates the attributes of the session record in database. The method will fail if the session record hasn't been created previously using add_session(). Only the attributes passed in will be updated while retaining the older values for other attributes, if any. @param attr_list List of attributes that needed to be updated. @throws OnepIllegalArgumentException The exception is thrown when any of input parameter is invalid. @throws OnepConnectionException The exception is thrown when the network element is not connected. @throws OnepRemoteProcedureException The exception is thrown when an error has occurred in the remote procedure call made to the network element. """ if attr_list == None: raise OnepIllegalArgumentException('attr_list', 'null') if self._ne == None or self._ne.session_handle == None: raise OnepConnectionException() attr_idl_list = Attribute.toIDLList(attr_list, self._ne) try: self._parent._identity_client.Sanet_Set_Attributes_IDL( self._ne.session_handle.id, self._session_label, attr_idl_list, 1) return except ExceptionIDL as e: raise OnepRemoteProcedureException(e) except TException as e: raise OnepConnectionException(e)
def fetch_session_attributes(self, retrieve_list = None): """ Retrieves the attributes from a session record in database. @param retrieve_list The retrieve_list specifies a list of Attribute to be retrieved. If the optional retrieve_list is None or an empty list, all attributes will be retrieved. If the retrieve_list is not null, only a subset of the attributes listed in the retrieveList will be retrieved. @return the list of attributes retrieved. @throws OnepIllegalArgumentException The exception is thrown when any of input parameter is invalid. @throws OnepConnectionException The exception is thrown when the network element is not connected. @throws OnepRemoteProcedureException The exception is thrown when an error has occurred in the remote procedure call made to the network element. """ if self._ne == None or self._ne.session_handle == None: raise OnepConnectionException() retrieve_id_list = Attribute.toIDLList(retrieve_list, self._ne) try: result_list = self._parent._identity_client.Sanet_Get_Attributes_IDL(self._ne.session_handle.id, self._session_label, retrieve_id_list) return result_list except ExceptionIDL as e: raise OnepRemoteProcedureException(e.getCode(), e.getText(), e) except TException as e: raise OnepConnectionException(e.getMessage(), e)
def delete_session_by_attributes(self, match_list, enforce_multi_delete=False): """ Deletes sessions matching the attributes specified in match_list. The attributes and their corresponding values in the match_list need to be specified in order to find the sessions that match these attributes. If multiple sessions are found and the enforce_multi_delete parameter is True, then all found sessions will be deleted. If multiple sessions are found but the enforce_multi_delete parameter is False, then none of the found sessions will be deleted. @param match_list: The attributes and their corresponding values in the match_list specifies the sessions that match these attributes. @param enforce_multi_delete: This parameter determines whether to proceed with the deletion when multiple sessions are found. If the parameter is true, then all found sessions will be deleted. Otherwise, none of the found sessions will be deleted. @throws OnepIllegalArgumentException The exception is thrown when any of input parameter is invalid. @throws OnepConnectionException The exception is thrown when the network element is not connected. @throws OnepRemoteProcedureException The exception is thrown when an error has occurred in the remote procedure call made to the network element. """ if self._ne == None or self._ne.session_handle == None: raise OnepConnectionException() match_id_list = Attribute.toIDLList(match_list, self._ne) if match_id_list == None: match_id_list = [] try: self._identity_client.Sanet_Delete_Session_By_Attrs_IDL( self._ne.session_handle.id, match_id_list, 1 if enforce_multi_delete else 0) return except ExceptionIDL as e: raise OnepRemoteProcedureException(e) except TException as e: raise OnepConnectionException(e)
def add_session(self, attr_list): """ Adds a session record to the database and updates it with the attribute values. Note that "mac-addr" must be specified in the AAA attributes when adding a session. @param attr_ist: List of AAA attributes to be stored in the record. @return an IdentitySession object representing the session record in the database of the network element; None is returned if the method failed to add a session. @throws OnepIllegalArgumentException The exception is thrown when any of input parameter is invalid. @throws OnepConnectionException The exception is thrown when the network element is not connected. @throws OnepRemoteProcedureException The exception is thrown when an error has occurred in the remote procedure call made to the network element or the session cannot be created. """ if attr_list == None: raise OnepIllegalArgumentException('attr_list', 'None') if self._ne == None or self._ne.session_handle == None: raise OnepConnectionException() attr_id_list = Attribute.toIDLList(attr_list, self._ne) try: session_label = self._identity_client.Sanet_Set_Attributes_IDL( self._ne.session_handle.id, -1, attr_id_list, 0) if session_label == -1: return else: return IdentitySession(self, self._ne, session_label) except ExceptionIDL as e: raise OnepRemoteProcedureException(e) except TException as e: raise OnepConnectionException(e)