2018-08-27 23:44:22 +00:00
|
|
|
package hcsshim
|
|
|
|
|
|
|
|
import (
|
2020-05-11 18:32:09 +00:00
|
|
|
"context"
|
2018-08-27 23:44:22 +00:00
|
|
|
"crypto/sha1"
|
|
|
|
"path/filepath"
|
|
|
|
|
2020-02-25 02:06:30 +00:00
|
|
|
"github.com/Microsoft/go-winio/pkg/guid"
|
2018-08-27 23:44:22 +00:00
|
|
|
"github.com/Microsoft/hcsshim/internal/wclayer"
|
|
|
|
)
|
|
|
|
|
|
|
|
func layerPath(info *DriverInfo, id string) string {
|
|
|
|
return filepath.Join(info.HomeDir, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ActivateLayer(info DriverInfo, id string) error {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.ActivateLayer(context.Background(), layerPath(&info, id))
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
func CreateLayer(info DriverInfo, id, parent string) error {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.CreateLayer(context.Background(), layerPath(&info, id), parent)
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
2019-03-06 00:48:39 +00:00
|
|
|
|
2018-08-27 23:44:22 +00:00
|
|
|
// New clients should use CreateScratchLayer instead. Kept in to preserve API compatibility.
|
|
|
|
func CreateSandboxLayer(info DriverInfo, layerId, parentId string, parentLayerPaths []string) error {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.CreateScratchLayer(context.Background(), layerPath(&info, layerId), parentLayerPaths)
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
func CreateScratchLayer(info DriverInfo, layerId, parentId string, parentLayerPaths []string) error {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.CreateScratchLayer(context.Background(), layerPath(&info, layerId), parentLayerPaths)
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
func DeactivateLayer(info DriverInfo, id string) error {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.DeactivateLayer(context.Background(), layerPath(&info, id))
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
func DestroyLayer(info DriverInfo, id string) error {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.DestroyLayer(context.Background(), layerPath(&info, id))
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
2019-03-06 00:48:39 +00:00
|
|
|
|
2018-08-27 23:44:22 +00:00
|
|
|
// New clients should use ExpandScratchSize instead. Kept in to preserve API compatibility.
|
|
|
|
func ExpandSandboxSize(info DriverInfo, layerId string, size uint64) error {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.ExpandScratchSize(context.Background(), layerPath(&info, layerId), size)
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
func ExpandScratchSize(info DriverInfo, layerId string, size uint64) error {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.ExpandScratchSize(context.Background(), layerPath(&info, layerId), size)
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
func ExportLayer(info DriverInfo, layerId string, exportFolderPath string, parentLayerPaths []string) error {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.ExportLayer(context.Background(), layerPath(&info, layerId), exportFolderPath, parentLayerPaths)
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
func GetLayerMountPath(info DriverInfo, id string) (string, error) {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.GetLayerMountPath(context.Background(), layerPath(&info, id))
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
func GetSharedBaseImages() (imageData string, err error) {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.GetSharedBaseImages(context.Background())
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
func ImportLayer(info DriverInfo, layerID string, importFolderPath string, parentLayerPaths []string) error {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.ImportLayer(context.Background(), layerPath(&info, layerID), importFolderPath, parentLayerPaths)
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
func LayerExists(info DriverInfo, id string) (bool, error) {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.LayerExists(context.Background(), layerPath(&info, id))
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
func PrepareLayer(info DriverInfo, layerId string, parentLayerPaths []string) error {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.PrepareLayer(context.Background(), layerPath(&info, layerId), parentLayerPaths)
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
func ProcessBaseLayer(path string) error {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.ProcessBaseLayer(context.Background(), path)
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
func ProcessUtilityVMImage(path string) error {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.ProcessUtilityVMImage(context.Background(), path)
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
func UnprepareLayer(info DriverInfo, layerId string) error {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.UnprepareLayer(context.Background(), layerPath(&info, layerId))
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type DriverInfo struct {
|
|
|
|
Flavour int
|
|
|
|
HomeDir string
|
|
|
|
}
|
|
|
|
|
|
|
|
type GUID [16]byte
|
|
|
|
|
|
|
|
func NameToGuid(name string) (id GUID, err error) {
|
2020-05-11 18:32:09 +00:00
|
|
|
g, err := wclayer.NameToGuid(context.Background(), name)
|
2020-02-25 02:06:30 +00:00
|
|
|
return g.ToWindowsArray(), err
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewGUID(source string) *GUID {
|
|
|
|
h := sha1.Sum([]byte(source))
|
|
|
|
var g GUID
|
|
|
|
copy(g[0:], h[0:16])
|
|
|
|
return &g
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GUID) ToString() string {
|
2020-02-25 02:06:30 +00:00
|
|
|
return guid.FromWindowsArray(*g).String()
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type LayerReader = wclayer.LayerReader
|
|
|
|
|
|
|
|
func NewLayerReader(info DriverInfo, layerID string, parentLayerPaths []string) (LayerReader, error) {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.NewLayerReader(context.Background(), layerPath(&info, layerID), parentLayerPaths)
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type LayerWriter = wclayer.LayerWriter
|
|
|
|
|
|
|
|
func NewLayerWriter(info DriverInfo, layerID string, parentLayerPaths []string) (LayerWriter, error) {
|
2020-05-11 18:32:09 +00:00
|
|
|
return wclayer.NewLayerWriter(context.Background(), layerPath(&info, layerID), parentLayerPaths)
|
2018-08-27 23:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type WC_LAYER_DESCRIPTOR = wclayer.WC_LAYER_DESCRIPTOR
|