layer.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 GUID [16]byte
  69. func NameToGuid(name string) (id GUID, err error) {
  70. g, err := wclayer.NameToGuid(name)
  71. return GUID(g), err
  72. }
  73. func NewGUID(source string) *GUID {
  74. h := sha1.Sum([]byte(source))
  75. var g GUID
  76. copy(g[0:], h[0:16])
  77. return &g
  78. }
  79. func (g *GUID) ToString() string {
  80. return (guid.GUID)(*g).String()
  81. }
  82. type LayerReader = wclayer.LayerReader
  83. func NewLayerReader(info DriverInfo, layerID string, parentLayerPaths []string) (LayerReader, error) {
  84. return wclayer.NewLayerReader(layerPath(&info, layerID), parentLayerPaths)
  85. }
  86. type LayerWriter = wclayer.LayerWriter
  87. func NewLayerWriter(info DriverInfo, layerID string, parentLayerPaths []string) (LayerWriter, error) {
  88. return wclayer.NewLayerWriter(layerPath(&info, layerID), parentLayerPaths)
  89. }
  90. type WC_LAYER_DESCRIPTOR = wclayer.WC_LAYER_DESCRIPTOR