Initialization
The NetworkAsCodeClient
is the entry-point to all the functionality Network as Code provides.
It allows you to identify the client and devices to use Network as Code.
The Network as Code client and device creation comes right after the installation step described
in our Getting-started guide.
Creating a Network as Code Client object
import network_as_code as nac
from network_as_code.models.device import Device, DeviceIpv4Addr
client = nac.NetworkAsCodeClient(
token="<your-application-key-here>",
)
- A
client
object will be instantiated from thenac.NetworkAsCodeClient()
class, previously imported in the code. This functionality will also hold thetoken
parameter. Pass the application key, which enables to identify and authenticate the client. This "token application key" is the one that was created for your client on the API Dashboard.
Creating a Device object
The client.devices.get()
method is equally important and it will identify your client's device.
It holds the DeviceIpv4Addr()
model, previously imported in your code,
and the multiple optional parameters for the client's device.
import network_as_code as nac
from network_as_code.models.device import Device, DeviceIpv4Addr
client = nac.NetworkAsCodeClient(...)
device = client.devices.get("device@testcsp.net",
ipv4_address = DeviceIpv4Addr(public_address="233.252.0.2",
private_address="192.0.2.25",
public_port=80),
ipv6_address = "2001:db8:1234:5678:9abc:def0:fedc:ba98",
# The phone number accepts the "+" sign, but not spaces or "()" marks
phone_number = "36721601234567"
)
NOTE: All the parameters on
client.devices.get()
method are optional, but you will need to use at least one of them.
Device parameters
Parameters | Description |
---|---|
"device@testcsp.net" | The Device ID can work as an alternate for phone number. |
ipv4_address | Here public and private IPv4 addresses and ports can be passed within the DeviceIPv4Addr model. |
ipv6_address | Where a public or private IPv6 address can be informed. |
phone_number | Simple phone-number identifier for devices or users owning the mobile subscription. |
What's next?
Now you're ready to set up your Network as Code client and device and use its multiple functionalities. How about diving deeper into the multiple ways you can identify mobile network devices?