Attachments

Attaching a device to a sliceheader link

Device attachment presupposes a slice already exists and that it is active. Learn how to activate a slice here. For attachments, the user device requires an imsi code that identifies a mobile user to the cellular network. We also need to define a customer for the attachment. After creating the slice according to the steps, simply activate and use the attach method to attach a device.

import network_as_code as nac

from network_as_code.models.device import DeviceIpv4Addr

from network_as_code.models.slice import (
    NetworkIdentifier,
    SliceInfo,
    Customer
)

import asyncio

# We begin by creating a Network as Code client
client = nac.NetworkAsCodeClient(
token="<your-application-key-here>"
)

# This is the device object we'll attach to the slice
my_device = client.devices.get(
    "[email protected]",
    ipv4_address=DeviceIpv4Addr(
        public_address="233.252.0.2",
        private_address="192.0.2.25",
        public_port=80,
    ),
    phone_number="+3637123456",
    imsi=99999991000
)

# Then, we create a slice
my_slice = client.slices.create(
    name="slice-name",
    network_id = NetworkIdentifier(mcc="236", mnc="30"),
    slice_info = SliceInfo(service_type="eMBB", differentiator="123456"),
    # Use HTTPS to send notifications
    notification_url="https://example.com/notif",
    notification_auth_token="replace-with-your-auth-token"
)

# The slice needs to be activated
# before attaching a device or app to it.
# Once it's OPERATING, devices and apps can be attached:
async def slice_activation():

    await my_slice.wait_for(desired_state="AVAILABLE")

    # Then, activate and wait for it to become OPERATING
    my_slice.activate()
    await my_slice.wait_for(desired_state="OPERATING")

asyncio.run(slice_activation())

# Attach the device to the slice just created
# and get notifications
my_slice.attach(
    my_device,
    customer=Customer(
        name="The name of the Customer",
        description="I Am A Default Customer Who Is Ordering The Device Attach Operation",
        address="Address of the customer ordering the attach operation",
        contact="Contact of the customer ordering the attach operation"
    ),
    notification_url="https://example.com/notif",
    notification_auth_token="replace-with-your-auth-token"
)

Slice device attach parametersheader link

ParametersTypeDescriptionMandatory or Optional
my_deviceobjectDevice object that, in addition to other identifiers, requires imsi.Mandatory
imsiintegerInternational mobile subscriber identity. Required for identifying a mobile user to the cellular network.Mandatory
customerobjectCustomer object that must be populated at least with name. Other optional string values are description, address and contact. Represents information about the customer who orders the device attach operations.Mandatory
notification_urlstringThe recipient's HTTP endpoint, which is a web server configured to receive POST requests.Optional
notification_auth_tokenstringA password used to identify the sender of the notification.Optional

Attaching applications to a sliceheader link

Besides attaching a device to a network slice as a whole, you can attach specific applications instead. Application attachment enables fine-grained slice control with different connectivity parameters set for different applications on a device.

What does this mean? When you create a network slice with specific connectivity parameters, such as different amounts of bandwidth a device or slice can get, area of service, etc., you can make sure that only specific applications can access these resources.

This is done by attaching both the device and applications to the slice you just created. Then, when you are done, you can detach them in the same way.

For example, if an enterprise is authorized to use a device and create network slices for it, they can also attach specific applications to them. This way, they can prioritize network resources according to their multiple business applications.

NOTE: Before attaching an enterprise app into a slice, make sure the enterprise has the right consent to access the device and create specialized network (slices) for it. Learn how to do it in our Consent & Identity management policy.

If you have already identified your device with mandatory imsi included as shown above, created and activated a slice, you can just attach a specific application to it by following this SDK snippet:

from network_as_code.models.slice import (
    Apps,
    TrafficCategories,
    Customer
)

# The slice needs to be activated
# before attaching a device or app to it.
# Once it's OPERATING, devices and apps can be attached:
new_attachment = my_slice.attach(
    my_device,
    customer=Customer(
        name="The name of the Customer",
        description="I Am A Default Customer Who Is Ordering The Device Attach Operation",
        address="Address of the customer ordering the attach operation",
        contact="Contact of the customer ordering the attach operation"
    ),
    # Use HTTPS to send notifications
    # about slice attachments.
    notification_url="https://notify.me/here",
    notification_auth_token="replace-with-your-auth-token",
    traffic_categories=TrafficCategories(
        apps=Apps(
            # This is the OS ID used by Android
            os="97a498e3-fc92-5c94-8986-0333d06e4e47",
            apps=["ENTERPRISE", "ENTERPRISE2"]
        )
    )
)

What's behind this technology?header link

There's a set of rules, which will enable the User Equipment (UE) to know how to route the traffic to specific applications within the network environment. On the network side, Network as Code will configure these UE Route Selection Policy (URSP) rules according to the Operating System Identifier (OSId) and OS specific Application Identifier (OsAppId) to establish the traffic categories. So, all you will need to provide is the OSId, according to the OS you use (Android, iOS, etc.) and the OsAppId (Enterprise app name).

For example, Android's 5G Network Slicing documentation defines their OSId with a 5 (UUID) sequence, which is 97a498e3-fc92-5c94-8986-0333d06e4e47. You can also refer to the iOS documentation for further information on their OSId. Now, for the OsAppId, you will need to pass the enterprise app name.

Application attachment parametersheader link

traffic_categories is an optional parameter in the format "[OS]/[Category]", which is converted by NaC backend into an OSId and OSAppId for URSP. If this parameter is omitted, the slice will be attached as a default for the device. Otherwise, the slice will be only used for the mentioned traffic categories.

ParametersTypeDescriptionMandatory or Optional
my_deviceobjectDevice object that, in addition to other identifiers, requires integer type imsi ("International mobile subscriber identity") field.Mandatory
customerobjectCustomer object that must be populated at least with name. Other optional string values are description, address and contact. Represents information about the customer who orders the device attach operations.Mandatory
traffic_categoriesobjectTrafficCategories object that ultimately holds the information about the OSId, according to the OS you use (Android, iOS, etc.) and the OsAppId (Enterprise app name).Optional
appsarrayThe enterprise app name (ID)Mandatory (if traffic_categories is used)
osstringThe OSId identifier according to the OS you use (Android, iOS, etc.)Mandatory (if traffic_categories is used)
notification_urlstringThe recipient's HTTP endpoint, which is a web server configured to receive POST requests.Optional
notification_auth_tokenstringThe password used to identify the sender of the notification.Optional
idstringIt's possible to define an identifier for the attachment and use it to get the resource.Optional

Detaching a device or an application from a sliceheader link

Briefly, here is a snippet which summarizes the process of detaching a device or an application from a slice:

# Detach a device
my_slice.detach(my_device)

# Deactivate and delete a slice
my_slice.deactivate()

my_slice.delete()

Remember: There are different states in a slice life cycle, learn what they are and how you can react to them.

Managing attachmentsheader link

Get all attachmentsheader link

You can get a list of all the attachments with the get_all_attachments and getAllAttachments methods like so:

# Get all slice attachments
attachments = client.slices.get_all_attachments()

Getting an attachment by its IDheader link

You can get an attachment also by getting a slice since applications are attached to slices.

# Get an attachment using the resource identifier
# The attachment id can be accessed using new_attachment['nac_resource_id']
attachment = client.slices.get_attachment(new_attachment['nac_resource_id'])

Attachment response parametersheader link

ParametersTypeDescription
nac_resource_idstringResource identifier of the attachment data.
deviceobjectHolds the device object identifiers, e.g. phoneNumber and imsi.
customerobjectInformation about the customer who orders the device attach operations.
sliceIdstringSlice resource identifier.
mobile_serviceslistContains string type information about the services allowed for the device, e.g. Voicemail or 5G-Data.
deviceStatusstringStatus of the device in relation to the given slice, e.g. ATTACHED.
deviceAttachStatestringState of the device attach order, e.g. Completed, Accepted, Rejected.
webhookobjectIf defined, shows the recipient's notificationUrl endpoint and notificationAuthToken password for receiving and identifying notifications.
traffic_categoriesobjectIf defined, denotes the operating system id and the applications' identifiers.
appslistList of application identifiers of enterprise app names (ID) if traffic_categories is defined.
osstringThe OSId identifier according to the OS you use (Android, iOS, etc.) if traffic_categories is defined.

Last updated November 05, 2025