layer.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package hcsshim
  2. import (
  3. "crypto/sha1"
  4. "path/filepath"
  5. "github.com/Microsoft/hcsshim/internal/guid"
  6. "github.com/Microsoft/hcsshim/internal/wclayer"
  7. )
  8. func layerPath(info *DriverInfo, id string) string {
  9. return filepath.Join(info.HomeDir, id)
  10. }
  11. func ActivateLayer(info DriverInfo, id string) error {
  12. return wclayer.ActivateLayer(layerPath(&info, id))
  13. }
  14. func CreateLayer(info DriverInfo, id, parent string) error {
  15. return wclayer.CreateLayer(layerPath(&info, id), parent)
  16. }
  17. // New clients should use CreateScratchLayer instead. Kept in to preserve API compatibility.
  18. func CreateSandboxLayer(info DriverInfo, layerId, parentId string, parentLayerPaths []string) error {
  19. return wclayer.CreateScratchLayer(layerPath(&info, layerId), parentLayerPaths)
  20. }
  21. func CreateScratchLayer(info DriverInfo, layerId, parentId string, parentLayerPaths []string) error {
  22. return wclayer.CreateScratchLayer(layerPath(&info, layerId), parentLayerPaths)
  23. }
  24. func DeactivateLayer(info DriverInfo, id string) error {
  25. return wclayer.DeactivateLayer(layerPath(&info, id))
  26. }
  27. func DestroyLayer(info DriverInfo, id string) error {
  28. return wclayer.DestroyLayer(layerPath(&info, id))
  29. }
  30. // New clients should use ExpandScratchSize instead. Kept in to preserve API compatibility.
  31. func ExpandSandboxSize(info DriverInfo, layerId string, size uint64) error {
  32. return wclayer.ExpandScratchSize(layerPath(&info, layerId), size)
  33. }
  34. func ExpandScratchSize(info DriverInfo, layerId string, size uint64) error {
  35. return wclayer.ExpandScratchSize(layerPath(&info, layerId), size)
  36. }
  37. func ExportLayer(info DriverInfo, layerId string, exportFolderPath string, parentLayerPaths []string) error {
  38. return wclayer.ExportLayer(layerPath(&info, layerId), exportFolderPath, parentLayerPaths)
  39. }
  40. func GetLayerMountPath(info DriverInfo, id string) (string, error) {
  41. return wclayer.GetLayerMountPath(layerPath(&info, id))
  42. }
  43. func GetSharedBaseImages() (imageData string, err error) {
  44. return wclayer.GetSharedBaseImages()
  45. }
  46. func ImportLayer(info DriverInfo, layerID string, importFolderPath string, parentLayerPaths []string) error {
  47. return wclayer.ImportLayer(layerPath(&info, layerID), importFolderPath, parentLayerPaths)
  48. }
  49. func LayerExists(info DriverInfo, id string) (bool, error) {
  50. return wclayer.LayerExists(layerPath(&info, id))
  51. }
  52. func PrepareLayer(info DriverInfo, layerId string, parentLayerPaths []string) error {
  53. return wclayer.PrepareLayer(layerPath(&info, layerId), parentLayerPaths)
  54. }
  55. func ProcessBaseLayer(path string) error {
  56. return wclayer.ProcessBaseLayer(path)
  57. }
  58. func ProcessUtilityVMImage(path string) error {
  59. return wclayer.ProcessUtilityVMImage(path)
  60. }
  61. func UnprepareLayer(info DriverInfo, layerId string) error {
  62. return wclayer.UnprepareLayer(layerPath(&info, layerId))
  63. }
  64. type DriverInfo struct {
  65. Flavour int
  66. HomeDir string
  67. }
  68. type FilterLayerReader = wclayer.FilterLayerReader
  69. type FilterLayerWriter = wclayer.FilterLayerWriter
  70. type GUID [16]byte
  71. func NameToGuid(name string) (id GUID, err error) {
  72. g, err := wclayer.NameToGuid(name)
  73. return GUID(g), err
  74. }
  75. func NewGUID(source string) *GUID {
  76. h := sha1.Sum([]byte(source))
  77. var g GUID
  78. copy(g[0:], h[0:16])
  79. return &g
  80. }
  81. func (g *GUID) ToString() string {
  82. return (guid.GUID)(*g).String()
  83. }
  84. type LayerReader = wclayer.LayerReader
  85. func NewLayerReader(info DriverInfo, layerID string, parentLayerPaths []string) (LayerReader, error) {
  86. return wclayer.NewLayerReader(layerPath(&info, layerID), parentLayerPaths)
  87. }
  88. type LayerWriter = wclayer.LayerWriter
  89. func NewLayerWriter(info DriverInfo, layerID string, parentLayerPaths []string) (LayerWriter, error) {
  90. return wclayer.NewLayerWriter(layerPath(&info, layerID), parentLayerPaths)
  91. }
  92. type WC_LAYER_DESCRIPTOR = wclayer.WC_LAYER_DESCRIPTOR