Nokia logo
DocumentationBlogPricing
Request access

Session deletion

How to delete and clear sessions

Here, we will clarify how to delete a session (session.delete()) or clear all of them (device.clear_sessions()).

Deleting a session

In the example below, we have assigned a session.delete() method following a device object to delete a specific session established before.

import network_as_code as nac
 
from network_as_code.models.device import Device, DeviceIpv4Addr
 
client = nac.NetworkAsCodeClient(...)
 
device = client.devices.get(...)
 
# Notice how we can use the number '0' to retrieve our first session in this case:
session = device.sessions()[0]
 
# Alternatively, get the session by its ID
session = client.sessions.get(session_id)
 
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 device.clear_sessions() following the device object, like below, you can retrieve a list with all the sessions associated with it, 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(...)
 
device = client.devices.get(...)
 
# Delete all QoD sessions associated with a particular device
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.

Last updated on December 04, 2023

On this page
How to delete and clear sessionsDeleting a sessionClearing all sessions