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

Expand vlans field inside a virtual circuit object response #15

Merged
merged 5 commits into from
Jun 9, 2020

Conversation

hoanhan101
Copy link
Contributor

@hoanhan101 hoanhan101 commented Jun 2, 2020

This PR changes vlans.vlan field inside a virtual circuit object response from holding a single primary key:

{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "vcid": 101,
      "name": "curl",
      "status": "pending-configuration",
      "context": "",
      "vlans": [
        {
          "vlan": 1
        },
        {
          "vlan": 2
        }
      ]
    }
  ]
}

to holding more VLAN metadata:

{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "vcid": 101,
      "name": "curl",
      "status": "pending-configuration",
      "context": "",
      "vlans": [
        {
          "vlan": {
            "id": 1,
            "created": "2020-06-02",
            "last_updated": "2020-06-02T19:08:07.817046Z",
            "vid": 1,
            "name": "foo",
            "status": "active",
            "description": "",
            "site": null,
            "group": null,
            "tenant": null,
            "role": null
          }
        },
        {
          "vlan": {
            "id": 2,
            "created": "2020-06-02",
            "last_updated": "2020-06-02T19:08:12.453937Z",
            "vid": 2,
            "name": "bar",
            "status": "active",
            "description": "",
            "site": null,
            "group": null,
            "tenant": null,
            "role": null
          }
        }
      ]
    }
  ]
}

It also updates the POST request body from

~ curl -X POST -H "Authorization: Token REDACTED" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" http://localhost:8000/api/plugins/virtual-circuit/virtual-circuits/ --data '{"vcid": 101, "name": "curl", "vlans": [{"vlan": 1}, {"vlan": 2}]}'

to

~ curl -X POST -H "Authorization: Token REDACTED" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" http://localhost:8000/api/plugins/virtual-circuit/virtual-circuits/ --data '{"vcid": 101, "name": "curl", "vlans": [{"id": 1}, {"id": 2}]}'

where vlan field is replaced with id.

Copy link

@edaniszewski edaniszewski left a comment

Choose a reason for hiding this comment

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

given my limited knowledge of django/netbox, I think this looks okay. I know there is another PR which includes tests, so if this gets merged in first, I think the tests PR will need to be rebased and updated to reflect these changes.

Copy link

@edaniszewski edaniszewski left a comment

Choose a reason for hiding this comment

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

lgtm!

@marcoceppi
Copy link
Contributor

Is it possible to flatten the vlans list to just each object directly?

{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "vcid": 101,
      "name": "curl",
      "status": "pending-configuration",
      "context": "",
      "vlans": [
        {
          "id": 1,
          "created": "2020-06-02",
          "last_updated": "2020-06-02T19:08:07.817046Z",
          "vid": 1,
          "name": "foo",
          "status": "active",
          "description": "",
          "site": null,
          "group": null,
          "tenant": null,
          "role": null
        },
        {
          "id": 2,
          "created": "2020-06-02",
          "last_updated": "2020-06-02T19:08:12.453937Z",
          "vid": 2,
          "name": "bar",
          "status": "active",
          "description": "",
          "site": null,
          "group": null,
          "tenant": null,
          "role": null
        }
      ]
    }
  ]
}

@hoanhan101
Copy link
Contributor Author

I've spent some time looking at this but not sure how to flatten the vlans list to just each object only yet. In this implementation, it seems like a vlan key is necessary for the serializer to traverse along and bring out the nested models. That said, I'm gonna close this for now and open a new issue to track it if I find something good along the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants