fnt adapter¶
This module provides integration with FNT Command. This version of the module provides support for resources, services and planning protocols. It only provides bare resources without entities with typed attributes, this is planned for Q1 2024
See the test cases for examples on how to use the module.
Using the fnt module¶
Consider the following simple example:
import fnt
import fnt::resources
import fnt::resources::cell
# Define the api object, all our resources will be deployed there
api = fnt::Api(
base_url="https://fnt.example.com",
auth_base_url="https://auth.fnt.example.com",
username="admin",
password="admin",
)
# Reference existing network function
# This is an unmanaged resource, we only define it in the model
# so that we can refer to it from other resources.
func = fnt::resources::NetworkFunction(
api=api,
query={
"elid": "2GQR7Q56DWGWU0", # This is the internal identifier of the existing entity
},
managed=false,
)
# Create Cell
# This is a managed resource, we can create/update/delete it from the
# inventory.
cell = fnt::resources::Cell(
api=api,
query={
"cellName": cell.cellName, # A meaningful query, which allows us to find the entity back after we created it
},
cellName="0x000000010",
mcc="111",
mnc="11",
networkFunction=[
# This is a managed relation, we can create/update/delete it from the inventory
fnt::resources::cell::LinkNetworkFunction(linked=func, purged=false),
],
purged=false,
)
:warning: Warning
There are a number of things that a traditional module would protect the user from, but this module doesn’t. It is then to the module
user to pay attention to it, and use the module wisely.
Resource consistency: the query is an input from the user, it is the responsibility of the user to make it use attributes we manage on the resource. If this is not done, we might not be able to find back a resource we deployed in a previous deployment.
Resource conflicts: there is no index in the model preventing the user from creating the same resource twice. This means the user should take its dispositions to only emit one entity for each managed resource.
Generating more entities¶
The generator doesn’t generate entities for the full fnt inventory, it only generates the ones we already have a use for.
To extend this set of supported entities:
Add a resource class in the
inmanta_plugins.fnt.resources.generated_entity
module:@inmanta.resources.resource( name="fnt::resources::Cell", # Choose this entity name, this will be the generated entity id_attribute="uri", agent="api.agent.agentname", ) class CellResource(GeneratedEntityResource): entity_type = "cell" # This value should be the entity type in the fnt inventory
Attach the new entity to a handler class using the provider decorator.
@inmanta.agent.handler.provider("fnt::resources::Cell", "") class GeneratedEntityHandler(inmanta_plugins.fnt.resources.entity.EntityABCHandler[GE]): # This class already exists, you can stack as many decorator as needed pass
Pull the api definition for the new resource.
(inmanta-module-fnt) $ python docs/pull_api_defs.py
Run the generator test to add the new resource to the model.
(inmanta-module-fnt) $ pytest tests/test_generator.py