CE-2436: Integrate backend with netbox
Hosts are accessible from two different REST endpoints from NetBox since we are dealing with two independent entities (Devices and Virtual Machines). To display them as one list with pagination applied, it is necessary to cache the entire list of hosts. However, associating FQDN, VLAN name, and VLAN group name with each host would take a significant amount of time. Therefore, we only load these details for the paginated set. NetBox host data model:
The default caching time for hosts is set to 1 minute, but it is configurable via the configuration.
The unambiguous identification of hosts is another important aspect to mention because their IDs only apply to their types. So, in our system we have to generate a unique identifier for them, which carries both the host's ID and its type (which is a boolean indicating whether the host is a Virtual Machine or not). Basically: base64(hostId + "_" + isVm)
Eg.:
"hostInfo": {
"id": 130,
"fqdn": "ccce-test-ioc-01.cslab.esss.lu.se",
"name": "ccce-test-ioc-01",
"scope": null,
"description": "",
"network": null,
"deviceType": "VirtualMachine",
"hostId": "MTMwX3RydWU=",
"vm": true
}
The content of the development includes:
- Mapping the NetBox host data model.
- Queries towards NetBox.
- Code refactor: Retrieving hosts from NetBox instead of CSEntry.
- API changes: Mostly, the host ID has changed, and a few host fields disappeared that do not exist in NetBox.
How to test it:
- Modify Playbook
- Add NetBox base URL (NETBOX_HOST). Should be: https://netbox-lab-02.cslab.esss.lu.se
- Add NetBox API token (NETBOX_TOKEN) It can be generated via: https://netbox-lab-02.cslab.esss.lu.se/api/users/tokens/provision
- Undo the V23 migration script (or just delete the entry)
- Deploy to TEST
- Migrate hosts via /api/v1/migrate (Auth required)
Closes CE-2436