Support GET on a collection of devices

Bug #1664696 reported by Jim Baker
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
craton
Fix Released
Critical
git-harry

Bug Description

We need to support an endpoint for getting access to a heterogeneous
collection of Device resources, which currently include NetworkDevice
(to represent concrete networks like top-of-rack switches); and Host
(which also include containers). In this future, this will expand to
other CIs (component instances in CMDB parlance) like AWS resources.

(Note this does not incude CIs like Network or NetworkInterface, which
have a separate representation to better support a flat network
topology (which may, or may not, be real, but is the abstraction that
Craton supports). Also this flat representation doesn't imply anything
about routability/security groups. But mostly irrelevant details for
this discussion, except when thinking about future device sharing.)

Let's assume the REST endpoint is /v1/devices, with standard query
filters available; but especially support for parent/ancestry based
queries. This endpoint only supports GET (and eventually HEAD). It
will work in conjunction with such queries as
https://bugs.launchpad.net/craton/+bug/1662614, e.g., being able to
support queries like /v1/devices?parent_id=1

For GET, it returns a list of devices, which at this time can be
either a Host or NetworkDevice. The only challenge is we need to
expose the `type` (or discriminant used in the object
polymorphism). The `type` field has two values at this time: 'hosts'
or 'network_devices'. This can be readily exposed by adding to
DefinitionsHost, DefinitionsHostID (what is the actual difference???),
along with NetworkdDevice equivalents. Also `type` needs to be
read-only.

The Python client can then instantiate the specific resource as
desired by dispatching on `type` when building a list of returned
devices.

Revision history for this message
Jim Baker (jimbaker) wrote :

Some example code to return the desired object type;
it is sort of unfortunate we also have `device_type`!

diff --git a/craton/api/v1/schemas.py b/craton/api/v1/schemas.py
index 3fecf2c..a7f68e2 100644
--- a/craton/api/v1/schemas.py
+++ b/craton/api/v1/schemas.py
@@ -76,6 +76,10 @@ DefinitionsHost = {
             "type": "integer",
             "description": "Parent Id of this host",
         },
+ "type": {
+ "type": "string",
+ "description": "Type of this resource",
+ },
         "device_type": {
             "type": "string",
             "description": "Type of host",
@@ -136,6 +140,10 @@ DefinitionsHostId = {
             },
             "description": "User defined labels",
         },
+ "type": {
+ "type": "string",
+ "description": "Type of resource",
+ },
         "device_type": {
             "type": "string",
             "description": "Type of host",

Jim Baker (jimbaker)
Changed in craton:
importance: Undecided → Critical
assignee: nobody → git-harry (git-harry)
Ian Cordasco (icordasc)
Changed in craton:
milestone: none → v0.1.0
Revision history for this message
Thomas Maddox (thomas-maddox) wrote :
Changed in craton:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.