Getting a QoD session
Getting a session by its name (ID)
Here, we will show how to get a session using the client.sessions.get()
method.
If you previously created a QoD session or if there are multiple ones and you need to modify or delete a specific one, you can easily retrieve it with its unique name (ID) or with a number.
In the code snippet below, we suppose you previously created a session or even multiple ones.
Then, if you want to retrieve the first session you created, because you do not have its exact ID or for any other reason, you can do so with a number session = device.sessions()[0]
.
import network_as_code as nac
from network_as_code.models.device import Device, DeviceIpv4Addr
client = nac.NetworkAsCodeClient(...)
device = client.devices.get(...)
session = device.create_session(...)
# Notice how we can use the number '0' to retrieve our first session in this case:
session = device.sessions()[0]
Alternatively, you can also use the session_id
variable:
session = client.sessions.get(session_id)
Additionally, use its specific name (ID) if you have it, which is a string
value:
session = client.sessions.get("session-name_1")
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.