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.

from network_as_code.client import NetworkAsCodeClient
 
from network_as_code.models.device import Device, DeviceIpv4Addr
 
from network_as_code.models.slice import (
    Point,
    AreaOfService,
    NetworkIdentifier,
    Slice,
    SliceInfo,
    Throughput
)
 
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,
    "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,
    "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.

Slice attach and detach parameters

Attach and detach methods require the following parameters:

ParametersDescription
deviceDevice ID callback parameter.
notification_urlThe recipient's HTTP endpoint, which is a web server configured to receive POST requests.
notification_auth_tokenA password used to identify the sender of the notification.

Last updated on May 23, 2024