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.

Managing slice-status notifications

In Network as Code, a network slice (or specialized network) will be in one of the following states:

Slice StatusDescription
PENDINGDO Center is working on planning or installing the network slice
AVAILABLESlice has been provisioned, but it is not active for users yet
OPERATINGSlice has been activated and is accepting or serving users
DELETEDSlice has been deactivated, and it's in the process of removal or has been removed
FAILEDSlice could not be provisioned correctly by the network

You can react to different slice states based on the notifications received from the web server we will create below. For example, if a slice is AVAILABLE, just use our SDKs to activate it. Whenever needed, call a method to deactivate an OPERATING slice and delete it afterwards.

Keep in mind: Slices need to be deactivated before deletion. It's not possible to delete an active slice (with OPERATING status). So, if you plan to delete one, then call the deactivate() method. This means the slice will go through a retiring process before it's permanently deleted.

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. The good news is that you can use the wait_done() method to wait for an ongoing order to complete. This method will return the new slice state, for example, not pending anymore.

Use the following example:

new_state = await my_slice.wait_done()

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.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(...)
 
...
 
# 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)

What is a notification URL?

Learn more about the notification URL/auth token and how to create a web server for them.

Note that the snippets above assume you have already created 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.

Last updated on May 21, 2024