Add GC of layers in Clair

Fixes https://www.pivotaltracker.com/story/show/135583207
This commit is contained in:
Joseph Schorr 2016-12-06 19:52:56 -05:00
parent 0aa6e6cd58
commit 49872838ab
5 changed files with 57 additions and 23 deletions

View file

@ -28,6 +28,7 @@ class APIRequestFailure(Exception):
_API_METHOD_INSERT = 'layers'
_API_METHOD_GET_LAYER = 'layers/%s'
_API_METHOD_DELETE_LAYER = 'layers/%s'
_API_METHOD_MARK_NOTIFICATION_READ = 'notifications/%s'
_API_METHOD_GET_NOTIFICATION = 'notifications/%s'
_API_METHOD_PING = 'metrics'
@ -122,6 +123,26 @@ class SecurityScannerAPI(object):
'Layer': layer_request,
}
def delete_layers(self, layers):
""" Deletes the given layers in the security scanner. """
if self._config is None:
# Not configured.
return
for layer in layers:
layer_id = '%s.%s' % (layer.docker_image_id, layer.storage.uuid)
self.delete_layer(layer_id)
def delete_layer(self, layer_id):
""" Calls DELETE on the layer with the given ID in the security scanner, removing it from
its database.
"""
try:
response = self._call('DELETE', _API_METHOD_DELETE_LAYER % layer_id)
return response.status_code / 100 == 2
except requests.exceptions.RequestException:
logger.exception('Failed to delete layer: %s', layer_id)
return False
def ping(self):
""" Calls GET on the metrics endpoint of the security scanner to ensure it is running