Deleting sessions
How to delete and clear sessions
Here, we will clarify how to delete a session or multiple ones by using the deletion and clear methods.
Deleting a session
In the example below, we delete specific sessions by their index or ID.
import network_as_code as nac
from network_as_code.models.device import Device, DeviceIpv4Addr
client = nac.NetworkAsCodeClient(...)
my_device = client.devices.get(...)
# Create a session
my_session = device.create_session(...)
# Notice how we can use the number '0'
# to get our first session, in this case:
first_session = my_device.sessions()[0]
# Alternatively, get the session by its ID
session = client.sessions.get(my_session.id)
# Then, delete the session
my_session.delete()
Clearing all sessions
Now, since creating and maintaining sessions can cost time and effort, you can delete all QoD sessions associated with a particular device. By using the helper function to clear all session, you can retrieve a list with all the sessions created for a device, delete them and your code will return to a clear state.
import network_as_code as nac
from network_as_code.models.device import Device, DeviceIpv4Addr
client = nac.NetworkAsCodeClient(...)
my_device = client.devices.get(...)
my_session = device.create_session(...)
# Delete all QoD sessions associated with a particular device
my_device.clear_sessions()
Note that the snippets above assume you have already created a QoD session before, which you can learn how to do here. It also implies that you have already created a Network-as-Code client, and identified your mobile network device.
Keep track of your session statuses and learn more about the QoD session life cycle.
Last updated on July 25, 2024