This tutorial shows you how to add a network session identified by a set of AAA attributes on the network element, how to update the session attributes, fetch the attributes from the session on network element, and delete these network sessions.
The code used in this tutorial is available in the IdentityTutorial.py file located under <SDK Location>/python/tutorials/src/identity/IdentityTutorial.py.
First, create the list of AAA attributes.
attribute_list1 = [] attribute_list1.append(StringAttribute( OnepAAAAttributeType.ONEP_AAA_AT_FORMATTED_CLID, "mac-addr", "aa:bb:cc:dd:ee:11")) attribute_list1.append(StringAttribute( OnepAAAAttributeType.ONEP_AAA_AT_USER_NAME, "username", "test"))
Construct an instance of the Identity class.
identity = Identity(tutorial.network_element)
Use the list of attributes to add a session record to the database.
tutorial.identity_session1 = tutorial.identity.add_session(IdentityTutorial.attribute_list1) if tutorial.identity_session1 is None: logger.error("Could not add the session.") else: logger.info("Session added. The session label is:" + str(tutorial.identity_session1.session_label))
Find all the sessions matching the specified attribute list.
sessionMap = tutorial.identity.find_session_by_attributes([StringAttribute( OnepAAAAttributeType.ONEP_AAA_AT_USER_NAME, "username", "test")]) logger.info('the sessions matching the attribute list are : ') for key in sessionMap.keys(): logger.info(str(key.session_label))
Update the attributes of a particular session.
tutorial.identity_session1.update_session_attributes(IdentityTutorial.attribute_list1a)
Fetch the attributes from a session record in database.
fetched_attribute_list = tutorial.identity_session1.fetch_session_attributes() logger.info('the session attributes are : ') for attribute in fetched_attribute_list: logger.info(OnepAAAAttributeType.enumval(attribute.type_)+': '+attribute.str_value)
Delete a session record from the database.
tutorial.identity.delete_session(tutorial.identity_session1)
Delete sessions matching the attributes in the specified match list.
tutorial.identity.delete_session_by_attributes(tutorial.attribute_list2)
Congratulations! You are now able to use your onePK application to add, update, delete and query network session based on a combination of query attributes.