Add container rename support

Signed-off-by: jason yang <jasonyangshadow@gmail.com>
This commit is contained in:
jason yang
2023-12-21 23:32:10 -07:00
committed by Jonathon Anderson
parent 7d17bcc6fa
commit d262ec10ef
10 changed files with 822 additions and 385 deletions

View File

@@ -404,6 +404,69 @@ func ContainerShow(csp *wwapiv1.ContainerShowParameter) (response *wwapiv1.Conta
return
}
func ContainerRename(crp *wwapiv1.ContainerRenameParameter) (err error) {
// rename the container source folder
sourceDir := container.SourceDir(crp.ContainerName)
destDir := container.SourceDir(crp.TargetName)
err = os.Rename(sourceDir, destDir)
if err != nil {
return err
}
if crp.Build {
err = container.Build(crp.TargetName, true)
if err != nil {
return err
}
}
// update the nodes profiles container name
nodeDB, err := node.New()
if err != nil {
return err
}
nodes, err := nodeDB.FindAllNodes()
if err != nil {
return err
}
for _, node := range nodes {
if node.ContainerName.Get() == crp.ContainerName {
node.ContainerName.Set(crp.TargetName)
if err := nodeDB.NodeUpdate(node); err != nil {
return err
}
}
}
profiles, err := nodeDB.FindAllProfiles()
if err != nil {
return err
}
for _, profile := range profiles {
if profile.ContainerName.Get() == crp.ContainerName {
profile.ContainerName.Set(crp.TargetName)
if err := nodeDB.ProfileUpdate(profile); err != nil {
return err
}
}
}
err = nodeDB.Persist()
if err != nil {
return err
}
err = warewulfd.DaemonStatus()
if err != nil {
// warewulfd is not running, skip
return nil
}
// else reload daemon to apply new changes
return warewulfd.DaemonReload()
}
// Private helpers
func setOCICredentials(sCtx *types.SystemContext) error {