Getting slices and attachments
Here, we will show how to get a slice using the client.slices.get()
method.
If you previously created a slice and you need to modify or delete it,
you can easily retrieve it by its ID or index.
You can do so by using the following examples:
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(...)
# This should get all the slices of a device
all_slices = client.slices.get_all()
# Or you can get a slice by its index,
# this one should get the first slice
one_slice = client.slices.get()[0]
Getting a slice by its name (ID)
Alternatively, you can get a slice by using its ID or slice name:
# Alternatively, you can also get a slice by its ID:
slice = client.slices.get(my_slice.name)
Getting attachments
If you have previously attached applications to slices,
you can get a list of all the attachments created
with the get_all_attachments
and getAllAttachments
methods like so:
# Get all slice attachments
attachments = client.slices.get_all_attachments()
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.
Good to know: There are different states in a slice life cycle, learn what they are and how you can react to them.