Skip to content

Commit

Permalink
Scan sort order if the plugin supplies it. (#196)
Browse files Browse the repository at this point in the history
* Scan sort order if the plugin supplies it.

* rev synse grpc
  • Loading branch information
MatthewHink committed Jul 11, 2018
1 parent df6af2d commit eef51a8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ requests==2.19.1 # via kubernetes, requests-oauthlib
rsa==3.4.2 # via google-auth
sanic==0.7.0
six==1.11.0 # via google-auth, grpcio, kubernetes, protobuf, python-dateutil, websocket-client
synse-grpc==1.0.0
synse-grpc==1.0.1 # via https://pypi.org/project/synse-grpc/ For dev workflow, copy to this repo and change Dockerfile to use copy.
ujson==1.35 # via sanic
urllib3==1.23 # via kubernetes, requests
uvloop==0.9.1 # via sanic
Expand Down
26 changes: 22 additions & 4 deletions synse/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def _build_scan_cache(device_info):
"""Build the scan cache.
This builds the scan cache, adhering to the Scan response scheme,
using the contents of the meta-info cache.
using the contents of the device-info cache.
Args:
device_info (dict): The device info cache dictionary.
Expand Down Expand Up @@ -519,6 +519,8 @@ def _build_scan_cache(device_info):
rack_id = source.location.rack
board_id = source.location.board
device_id = source.uid
plugin = source.plugin
sort_ordinal = source.sortOrdinal

# The given rack does not yet exist in our scan cache.
# In this case, we will create it, along with the board
Expand All @@ -530,7 +532,9 @@ def _build_scan_cache(device_info):
{
'id': device_id,
'info': source.info,
'type': utils.type_from_kind(source.kind)
'type': utils.type_from_kind(source.kind),
'plugin': plugin,
'sort_ordinal': sort_ordinal,
}
]
}
Expand Down Expand Up @@ -563,7 +567,9 @@ def _build_scan_cache(device_info):
{
'id': device_id,
'info': source.info,
'type': utils.type_from_kind(source.kind)
'type': utils.type_from_kind(source.kind),
'plugin': plugin,
'sort_ordinal': sort_ordinal,
}
]
}
Expand All @@ -574,7 +580,9 @@ def _build_scan_cache(device_info):
r['boards'][board_id]['devices'].append({
'id': device_id,
'info': source.info,
'type': utils.type_from_kind(source.kind)
'type': utils.type_from_kind(source.kind),
'plugin': plugin,
'sort_ordinal': sort_ordinal,
})

if _tracked:
Expand All @@ -589,6 +597,16 @@ def _build_scan_cache(device_info):
# Sort the scan cache by racks['id']
scan_cache['racks'] = sorted(scan_cache['racks'], key=lambda rck: rck['id'])

# Sort each rack by plugin and sort_ordinal.
for rack in scan_cache['racks']:
for board in rack['boards']:
board['devices'] = \
sorted(board['devices'], key=lambda o: (o['plugin'], o['sort_ordinal']))
# Delete the plugin and sort_ordinal keys after sorting.
for device in board['devices']:
del device['plugin']
del device['sort_ordinal']

return scan_cache


Expand Down
Binary file added synse_grpc-1.0.0.tar.gz
Binary file not shown.

0 comments on commit eef51a8

Please sign in to comment.