mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-08-05 00:15:44 +00:00
Add a podman volume rename command, REST API endpoint, and bindings for renaming volumes. The rename updates both the VolumeConfig and VolumeState tables in a single transaction and moves the volume directory on disk, rolling back if the transaction fails. Renaming an anonymous volume converts it to a named volume. Volumes that are in use, mounted, or backed by a volume plugin or the image driver cannot be renamed. Fixes: #28189 Signed-off-by: MayorFaj <mayorfaj@gmail.com>
55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package containers
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
"go.podman.io/podman/v6/cmd/podman/common"
|
|
"go.podman.io/podman/v6/cmd/podman/registry"
|
|
"go.podman.io/podman/v6/cmd/podman/utils"
|
|
"go.podman.io/podman/v6/pkg/domain/entities"
|
|
)
|
|
|
|
var (
|
|
renameDescription = "The podman rename command allows you to rename an existing container"
|
|
renameCommand = &cobra.Command{
|
|
Use: "rename CONTAINER NAME",
|
|
Short: "Rename an existing container",
|
|
Long: renameDescription,
|
|
RunE: rename,
|
|
Args: cobra.ExactArgs(2),
|
|
ValidArgsFunction: common.AutocompleteContainerOneArg,
|
|
Example: "podman rename containerA newName",
|
|
}
|
|
|
|
containerRenameCommand = &cobra.Command{
|
|
Use: renameCommand.Use,
|
|
Short: renameCommand.Short,
|
|
Long: renameCommand.Long,
|
|
RunE: rename,
|
|
Args: renameCommand.Args,
|
|
ValidArgsFunction: common.AutocompleteContainerOneArg,
|
|
Example: "podman container rename containerA newName",
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
|
Command: renameCommand,
|
|
})
|
|
|
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
|
Command: containerRenameCommand,
|
|
Parent: containerCmd,
|
|
})
|
|
}
|
|
|
|
func rename(_ *cobra.Command, args []string) error {
|
|
args = utils.RemoveSlash(args)
|
|
return renameContainer(args)
|
|
}
|
|
|
|
func renameContainer(args []string) error {
|
|
renameOpts := entities.ContainerRenameOptions{
|
|
NewName: args[1],
|
|
}
|
|
return registry.ContainerEngine().ContainerRename(registry.Context(), args[0], renameOpts)
|
|
}
|