Support GET on a collection of devices
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/
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:/
support queries like /v1/devices?
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.
Changed in craton: | |
importance: | Undecided → Critical |
assignee: | nobody → git-harry (git-harry) |
Changed in craton: | |
milestone: | none → v0.1.0 |
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 api/v1/ schemas. py api/v1/ schemas. py
" type": "integer",
" description" : "Parent Id of this host",
"device_ type": {
" type": "string",
" description" : "Type of host",
" description" : "User defined labels",
"device_ type": {
" type": "string",
" description" : "Type of host",
index 3fecf2c..a7f68e2 100644
--- a/craton/
+++ b/craton/
@@ -76,6 +76,10 @@ DefinitionsHost = {
},
+ "type": {
+ "type": "string",
+ "description": "Type of this resource",
+ },
@@ -136,6 +140,10 @@ DefinitionsHostId = {
},
},
+ "type": {
+ "type": "string",
+ "description": "Type of resource",
+ },