service.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package containerd
  2. import (
  3. "context"
  4. "github.com/containerd/containerd"
  5. "github.com/containerd/containerd/plugin"
  6. "github.com/docker/docker/api/types"
  7. "github.com/docker/docker/container"
  8. "github.com/docker/docker/daemon/images"
  9. "github.com/docker/docker/image"
  10. "github.com/docker/docker/layer"
  11. )
  12. // ImageService implements daemon.ImageService
  13. type ImageService struct {
  14. client *containerd.Client
  15. snapshotter string
  16. }
  17. // NewService creates a new ImageService.
  18. func NewService(c *containerd.Client, snapshotter string) *ImageService {
  19. return &ImageService{
  20. client: c,
  21. snapshotter: snapshotter,
  22. }
  23. }
  24. // DistributionServices return services controlling daemon image storage.
  25. func (i *ImageService) DistributionServices() images.DistributionServices {
  26. return images.DistributionServices{}
  27. }
  28. // CountImages returns the number of images stored by ImageService
  29. // called from info.go
  30. func (i *ImageService) CountImages() int {
  31. imgs, err := i.client.ListImages(context.TODO())
  32. if err != nil {
  33. return 0
  34. }
  35. return len(imgs)
  36. }
  37. // Children returns the children image.IDs for a parent image.
  38. // called from list.go to filter containers
  39. // TODO: refactor to expose an ancestry for image.ID?
  40. func (i *ImageService) Children(id image.ID) []image.ID {
  41. panic("not implemented")
  42. }
  43. // CreateLayer creates a filesystem layer for a container.
  44. // called from create.go
  45. // TODO: accept an opt struct instead of container?
  46. func (i *ImageService) CreateLayer(container *container.Container, initFunc layer.MountInit) (layer.RWLayer, error) {
  47. panic("not implemented")
  48. }
  49. // GetLayerByID returns a layer by ID
  50. // called from daemon.go Daemon.restore(), and Daemon.containerExport().
  51. func (i *ImageService) GetLayerByID(cid string) (layer.RWLayer, error) {
  52. panic("not implemented")
  53. }
  54. // LayerStoreStatus returns the status for each layer store
  55. // called from info.go
  56. func (i *ImageService) LayerStoreStatus() [][2]string {
  57. // TODO(thaJeztah) do we want to add more details about the driver here?
  58. return [][2]string{
  59. {"driver-type", string(plugin.SnapshotPlugin)},
  60. }
  61. }
  62. // GetLayerMountID returns the mount ID for a layer
  63. // called from daemon.go Daemon.Shutdown(), and Daemon.Cleanup() (cleanup is actually continerCleanup)
  64. // TODO: needs to be refactored to Unmount (see callers), or removed and replaced with GetLayerByID
  65. func (i *ImageService) GetLayerMountID(cid string) (string, error) {
  66. panic("not implemented")
  67. }
  68. // Cleanup resources before the process is shutdown.
  69. // called from daemon.go Daemon.Shutdown()
  70. func (i *ImageService) Cleanup() error {
  71. return nil
  72. }
  73. // StorageDriver returns the name of the default storage-driver (snapshotter)
  74. // used by the ImageService.
  75. func (i *ImageService) StorageDriver() string {
  76. return i.snapshotter
  77. }
  78. // ReleaseLayer releases a layer allowing it to be removed
  79. // called from delete.go Daemon.cleanupContainer(), and Daemon.containerExport()
  80. func (i *ImageService) ReleaseLayer(rwlayer layer.RWLayer) error {
  81. panic("not implemented")
  82. }
  83. // LayerDiskUsage returns the number of bytes used by layer stores
  84. // called from disk_usage.go
  85. func (i *ImageService) LayerDiskUsage(ctx context.Context) (int64, error) {
  86. panic("not implemented")
  87. }
  88. // ImageDiskUsage returns information about image data disk usage.
  89. func (i *ImageService) ImageDiskUsage(ctx context.Context) ([]*types.ImageSummary, error) {
  90. panic("not implemented")
  91. }
  92. // UpdateConfig values
  93. //
  94. // called from reload.go
  95. func (i *ImageService) UpdateConfig(maxDownloads, maxUploads int) {
  96. panic("not implemented")
  97. }
  98. // GetLayerFolders returns the layer folders from an image RootFS.
  99. func (i *ImageService) GetLayerFolders(img *image.Image, rwLayer layer.RWLayer) ([]string, error) {
  100. panic("not implemented")
  101. }
  102. // GetContainerLayerSize returns the real size & virtual size of the container.
  103. func (i *ImageService) GetContainerLayerSize(containerID string) (int64, int64) {
  104. panic("not implemented")
  105. }