2016-11-22 22:05:37 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ListImages lists existing images.
|
|
|
|
func (s *Server) ListImages(ctx context.Context, req *pb.ListImagesRequest) (*pb.ListImagesResponse, error) {
|
2016-10-18 14:48:33 +00:00
|
|
|
logrus.Debugf("ListImagesRequest: %+v", req)
|
|
|
|
filter := ""
|
|
|
|
reqFilter := req.GetFilter()
|
|
|
|
if reqFilter != nil {
|
|
|
|
filterImage := reqFilter.GetImage()
|
|
|
|
if filterImage != nil {
|
2017-02-03 14:41:28 +00:00
|
|
|
filter = filterImage.Image
|
2016-10-18 14:48:33 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-19 19:17:10 +00:00
|
|
|
results, err := s.storageImageServer.ListImages(filter)
|
2016-10-18 14:48:33 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
response := pb.ListImagesResponse{}
|
|
|
|
for _, result := range results {
|
2017-02-03 14:41:28 +00:00
|
|
|
if result.Size != nil {
|
|
|
|
response.Images = append(response.Images, &pb.Image{
|
|
|
|
Id: result.ID,
|
|
|
|
RepoTags: result.Names,
|
|
|
|
Size_: *result.Size,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
response.Images = append(response.Images, &pb.Image{
|
|
|
|
Id: result.ID,
|
|
|
|
RepoTags: result.Names,
|
|
|
|
})
|
|
|
|
}
|
2016-10-18 14:48:33 +00:00
|
|
|
}
|
|
|
|
logrus.Debugf("ListImagesResponse: %+v", response)
|
|
|
|
return &response, nil
|
2016-11-22 22:05:37 +00:00
|
|
|
}
|