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.
It's also good to know that every slice has a life cycle. This allows you to manage your applications and get notifications for when a slice is available, operating, pending, and so on.
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)
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 July 25, 2024