Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: OBS-397 - [NetBox Diode Plugin] create API endpoint for retrieving NetBox object state #44

Conversation

Julio-Oliveira-Encora
Copy link
Contributor

@Julio-Oliveira-Encora Julio-Oliveira-Encora commented Feb 23, 2024

  • Add endpoint "/api/plugins/diode/object-state/";
  • Parameter object_type is mandatory.
  • Parameters must have q or ID.
  • Endpoint returns only one object per request.
  • The q parameter uses CachedValue to get the object ID, and then the cache must be updated.
  • If there is any error in the payload, return 400.
  • If the query is empty, the endpoint returns 200 and an empty list.

Copy link

linear bot commented Feb 23, 2024

OBS-397 Create API endpoint for retrieving NetBox object state

In the NetBox diode plugin, create API endpoint GET /api/plugins/diode/object-state to retrieve current state of the requested NetBox object.

We want to utilise existing NetBox core search functionality (see: https://github.com/netbox-community/netbox/blob/develop/netbox/netbox/views/misc.py#L65), so we should be able to support following query params:

  • object_type (required) - only accepting one of supported object types for diode, i.e. device, site, platform, manufacturer, etc., let's start with device first
  • q for arbitrary string phrase (i.e. device name, etc.), should be in use only if id param is not provided
  • id object's ID (if already known by diode)

The endpoint should return single exact object state (if found) or an empty result (200 OK in both cases, unless it's a server side error then 5xx).

We should use iexact lookup type when using NetBox search functionality.

The response containing found object, should also include its latest known objectchange ID.

Response structure:

{
  "object_type": "{OBJECT_TYPE}",
  "object_change_id": {LATEST_OBJECTCHANGE_ID},
  "object": {
    {OBJECT_PROPERTIES}
  }
}

Example for dcim.site:

{
  "object_type": "dcim.site",
  "object_change_id": 4,
  "object": {
    "id": 1,
    "url": "http://localhost:8000/api/dcim/sites/1/",
    "display": "test123",
    "name": "test123",
    "slug": "test1",
    "status": {
      "value": "active",
      "label": "Active"
    },
    "region": null,
    "group": null,
    "tenant": null,
    "facility": "",
    "time_zone": null,
    "description": "",
    "physical_address": "",
    "shipping_address": "",
    "latitude": null,
    "longitude": null,
    "comments": "",
    "asns": [],
    "tags": [],
    "custom_fields": {},
    "created": "2024-02-20T14:32:32.381112Z",
    "last_updated": "2024-02-21T10:36:38.038324Z",
    "circuit_count": 0,
    "device_count": 0,
    "prefix_count": 0,
    "rack_count": 0,
    "virtualmachine_count": 0,
    "vlan_count": 0
  }
}

Copy link
Member

@mfiedorowicz mfiedorowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Julio-Oliveira-Encora, to start with, could you please resolve linting issues detected by ruff and commented here https://github.com/netboxlabs/diode/pull/44/files?

Can you also add instructions how do you run these tests on local environment, i.e. add instruction in the diode-netbox-plugin/README.md?

@mfiedorowicz mfiedorowicz changed the title feat: OBS-397 - [NetBox Diode Plugin] Create API endpoint for retrieving Netbox object state. feat: OBS-397 - [NetBox Diode Plugin] create API endpoint for retrieving NetBox object state Feb 23, 2024
@Julio-Oliveira-Encora Julio-Oliveira-Encora merged commit dac29dd into develop Feb 26, 2024
14 checks passed
@Julio-Oliveira-Encora Julio-Oliveira-Encora deleted the obs-397-create-api-endpoint-for-retrieving-netbox-object-state branch February 26, 2024 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants