Add container rename support
Signed-off-by: jason yang <jasonyangshadow@gmail.com>
This commit is contained in:
committed by
Jonathon Anderson
parent
7d17bcc6fa
commit
d262ec10ef
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user