Core of image's duplication feature

This commit is contained in:
Arnaud Lecomte
2023-08-25 13:54:39 +02:00
parent 84e97d2169
commit b56f024e6f
8 changed files with 149 additions and 5 deletions

View File

@@ -32,6 +32,13 @@ message ContainerDeleteParameter {
repeated string containerNames = 1;
}
// ContainerCopyParameter contains 2 inputs : first one for the source container name and second one for the duplicated container name.
message ContainerCopyParameter {
repeated string containerSourceName = 1;
repeated string containerDestName = 1;
}
// ContainerImportParameter has all input for importing a container.
message ContainerImportParameter{
string source = 1; // container source uri

View File

@@ -251,6 +251,16 @@ func (x *ContainerDeleteParameter) GetContainerNames() []string {
return nil
}
type ContainerCopyParameter struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
ContainerSource string `protobuf:"bytes,1,rep,name=ContainerSource,proto3" json:"ContainerSource,omitempty"`
ContainerDestination string `protobuf:"bytes,1,rep,name=ContainerDestination,proto3" json:"ContainerDestination,omitempty"`
}
// ContainerImportParameter has all input for importing a container.
type ContainerImportParameter struct {
state protoimpl.MessageState

View File

@@ -37,7 +37,7 @@ func Build(name string, buildForce bool) error {
}
err := util.BuildFsImage(
"VNFS container " + name,
"VNFS container "+name,
rootfsPath,
imagePath,
[]string{"*"},

View File

@@ -48,14 +48,22 @@ func ListSources() ([]string, error) {
return ret, nil
}
func ValidSource(name string) bool {
fullPath := RootFsDir(name)
func DoesContainerExists(name string) bool {
fullPath := ImageFile(name)
return util.IsFile(fullPath)
}
func DoesSourceExist(name string) bool {
fullPath := RootFsDir(name)
return util.IsDir(fullPath)
}
func ValidSource(name string) bool {
if !ValidName(name) {
return false
}
if !util.IsDir(fullPath) {
if !DoesSourceExist(name) {
wwlog.Verbose("Location is not a VNFS source directory: %s", name)
return false
}
@@ -73,6 +81,23 @@ func DeleteSource(name string) error {
return os.RemoveAll(fullPath)
}
func Duplicate(name string, destination string) error {
fullPathImageSource := RootFsDir(name)
wwlog.Info("Copying sources...")
err := ImportDirectory(fullPathImageSource, destination)
if err != nil {
return err
}
wwlog.Info("Building container: %s", destination)
err = Build(destination, true)
if err != nil {
return err
}
return nil
}
/*
Delete the image of a container
*/