Attaching and detaching devices
Attaching a device to a slice
Device attachment presupposes a slice already exists and that it is active. Learn how to activate a slice here. So, after creating and activating the desired slice according to the steps in the previous page, simply use the attach method to attach a device.
import network_as_code as nac
from network_as_code.models.device import Device, DeviceIpv4Addr
from network_as_code.models.slice import (
Point,
AreaOfService,
NetworkIdentifier,
Slice,
SliceInfo,
Throughput
)
client = nac.NetworkAsCodeClient(...)
my_device = client.devices.get(...)
my_slice = client.slices.create(...)
my_slice.activate(...)
# Attach a device to a slice and get notifications
my_slice.attach(
my_device,
notification_url="https://notify.me/here",
notification_auth_token="replace-with-your-auth-token"
)
Detaching a device from a slice
Use the following SDK snippet to detach a device from a slice.
my_slice.activate(...)
...
# Detach a device from a slice and get notifications
my_slice.detach(
my_device,
notification_url="https://notify.me/here",
notification_auth_token="replace-with-your-auth-token"
)
Note that the snippets above assume you have already created and activated a slice 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.
Good to know: There are different states in a slice life cycle, learn what they are and how you can react to them.
Slice attach and detach parameters
Attach and detach methods require the following parameters:
Parameters | Description |
---|---|
device | Device ID callback parameter. |
notification_url | The recipient's HTTP endpoint, which is a web server configured to receive POST requests. |
notification_auth_token | A password used to identify the sender of the notification. |
Last updated on July 25, 2024