Slice notifications and life cycle
A slice (or specialized network) life cycle consists of creation, activation, deactivation and removal. In Network as Code, a slice will be in one of the following states:
| Slice Status | Description |
|---|---|
PENDING | The slice provisioning software is planning or installing the network slice |
AVAILABLE | Slice has been provisioned, but it is not active for users yet |
OPERATING | Slice has been activated and is accepting or serving users |
DELETED | Slice has been deactivated, and it's in the process of removal or has been removed |
FAILED | Slice could not be provisioned correctly by the network |
For example, if a slice is PENDING, it means your request is being processed.
Once your slice is provisioned successfully,
it will become AVAILABLE, but it does not mean that it is active or serving users yet at this point.
So, just use our SDKs to activate it.
When you activate a slice, it changes to the OPERATING state and can serve users.
However, OPERATING slices cannot be directly deleted.
Whenever needed, call a method to deactivate
an OPERATING slice first, and then you can delete it subsequently.
Once deactivated or deleted, the slice will become inactive and move on to the DELETED state.
If something goes wrong with a slice, its status will be
FAILED. It is also not possible to activateOPERATINGslices, since they are already active.
Managing slice statuses
How do I know if a slice is not pending anymore?
If a slice has a PENDING status, it means it is not ready to serve users yet.
You will need to wait for the slice to be AVAILABLE to activate it.
Similarly, you can wait for a desired state,
such as OPERATING to know that,
in this case, the slice is in use and will need to be deactivated before deletion.
You can react to different slice states
based on the notifications received from a web server, such as this one.
Or you can also use the wait_for() or waitFor() method as you wish to wait for a slice to reach a specified state.
import network_as_code as nac
from network_as_code.models.device import DeviceIpv4Addr
from network_as_code.models.slice import(
NetworkIdentifier,
SliceInfo,
)
import asyncio
import time
# We begin by creating a Network as Code client
client = nac.NetworkAsCodeClient(
token="<your-application-key-here>"
)
# This is the device object we'll later 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
),
)
# 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="http://notify.me/here",
notification_auth_token="replace-with-your-auth-token"
)
# Alternatively, you can also get a slice by its ID:
slice = client.slices.get(my_slice.name)
async def slice_attachments():
# We can take advantage of Slice.wait_for() in async functions
# This allows us to, e.g., wait for a slice to become available
await my_slice.wait_for(desired_state="AVAILABLE")
# Slices must be activated before devices can be added
my_slice.activate()
await my_slice.wait_for(desired_state="OPERATING")
# Afterwards we can attach or detach devices
device = client.devices.get(my_device)
my_slice.attach(my_device)
my_slice.detach(my_device)
# For deallocating a slice, we first deactivate the slice
my_slice.deactivate()
await my_slice.wait_for(desired_state="AVAILABLE")
# A deactivated slice can be freely removed
my_slice.delete()
# Since we use the asynchronous Slice.wait_for(), we must execute
# in an async function. We can run such functions with asyncio:
asyncio.run(slice_attachments())
# If you cannot run async functions, you can also utilize webhook
# handlers or polling to handle slice state transitions.
# Simple manual polling can be implemented like this:
while my_slice.state != "AVAILABLE":
my_slice.refresh()
time.sleep(1)Slice notifications
A slice may take a significant amount of time (minutes) to be set up. So, after creating a slice, activating it, attaching or detaching devices, which were done in previous steps, we will configure a web server to receive slice-status notifications. This will allow you to know when a slice is ready to be configured as desired. Then, slice operations like activation, deactivation and deletion can be done based on its current status notifications.
Learn more about the notification URL/auth token and how to create an HTTP server with a POST endpoint for slice notifications.
Slice-status notifications SDK
import time
from fastapi import FastAPI, Header
from pydantic import BaseModel
from typing_extensions import Annotated
from typing import Union
import network_as_code as nac
from network_as_code.models.slice import (
NetworkIdentifier,
SliceInfo,
)
# We begin by creating a Network as Code client
client = nac.NetworkAsCodeClient(
token="<your-application-key-here>"
)
# 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/notifications",
notification_auth_token="replace-with-your-auth-token"
)
# Our web server for receiving notifications
app = FastAPI()
class Notification(BaseModel):
resource: str
action: str
state: str
# We'll keep track of when we are retiring the slice between the notifications
retiring = False
@app.post("/notifications")
def receive_notification(
notification: Notification,
authorization: Annotated[Union[str, None], Header]
):
if authorization == "Bearer my-token":
# We can now react to the notifications
# based on the Notification object
print(notification)Specialized Network notification details
Here, you will find the JSON schema for Specialized-Network notifications.
Its purpose is to monitor changes made to slices, such as creation,
the several outcomes for these changes and the current slice state, e.g.: pending, available, deleted, etc.
Underneath the JSON schema, there is a table with further information on the specific keyword values.
Remember that the string values represented below are just examples that can be used. So, they should contain your real slice values.
JSON schema for Specialized Network notifications
{
"resource": "slice-01",
"action": "add | delete | noChange",
"outcome": "acknowledged | rejected | pending | held | inProgress |
cancelled | completed | failed | partial | assessingCancellation | pendingCancellation",
"current_slice_state": "AVAILABLE | OPERATING | DELETED"
}
| Specialized-Network-keyword values | Type | Description |
|---|---|---|
resource | string | Contains the slice name or identifier. |
action | string | Describes the slice operation performed. The possible values are: add, delete, noChange. |
outcome | string | Cointains the different outcomes or results of the previous slice action/operation. They can be: acknowledged, rejected, pending, held, inProgress, cancelled, completed, failed, partial, assessingCancellation, pendingCancellation. |
current_slice_state | string | The current slice state or status, which can be: PENDING, OPERATING, AVAILABLE, DELETED. |
Last updated November 05, 2025