-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* containerlab redeploy (#2371) redeploy command Co-authored-by: Anatoly Kolpakov <ankolpakov@gmail.com> * fix typo * remove reconfigure from the redeploy cmd * added a test --------- Co-authored-by: Anatoly Kolpakov <feroxsnake@me.com> Co-authored-by: Anatoly Kolpakov <ankolpakov@gmail.com>
- Loading branch information
1 parent
4f0d1cd
commit b6b637d
Showing
10 changed files
with
207 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package cmd | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// redeployCmd represents the redeploy command. | ||
var redeployCmd = &cobra.Command{ | ||
Use: "redeploy", | ||
Short: "destroy and redeploy a lab", | ||
Long: "destroy a lab and deploy it again based on the topology definition file\nreference: https://containerlab.dev/cmd/redeploy/", | ||
Aliases: []string{"rdep"}, | ||
PreRunE: sudoCheck, | ||
SilenceUsage: true, | ||
RunE: redeployFn, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(redeployCmd) // Add to rootCmd | ||
|
||
// Add destroy flags | ||
redeployCmd.Flags().BoolVarP(&cleanup, "cleanup", "c", false, "delete lab directory") | ||
redeployCmd.Flags().BoolVarP(&graceful, "graceful", "", false, | ||
"attempt to stop containers before removing") | ||
redeployCmd.Flags().BoolVarP(&all, "all", "a", false, "destroy all containerlab labs") | ||
redeployCmd.Flags().UintVarP(&maxWorkers, "max-workers", "", 0, | ||
"limit the maximum number of workers creating/deleting nodes") | ||
redeployCmd.Flags().BoolVarP(&keepMgmtNet, "keep-mgmt-net", "", false, "do not remove the management network") | ||
redeployCmd.Flags().StringSliceVarP(&nodeFilter, "node-filter", "", []string{}, | ||
"comma separated list of nodes to include") | ||
|
||
// Add deploy flags | ||
redeployCmd.Flags().BoolVarP(&graph, "graph", "g", false, "generate topology graph") | ||
redeployCmd.Flags().StringVarP(&mgmtNetName, "network", "", "", "management network name") | ||
redeployCmd.Flags().IPNetVarP(&mgmtIPv4Subnet, "ipv4-subnet", "4", net.IPNet{}, "management network IPv4 subnet range") | ||
redeployCmd.Flags().IPNetVarP(&mgmtIPv6Subnet, "ipv6-subnet", "6", net.IPNet{}, "management network IPv6 subnet range") | ||
redeployCmd.Flags().StringVarP(&deployFormat, "format", "f", "table", "output format. One of [table, json]") | ||
redeployCmd.Flags().BoolVarP(&skipPostDeploy, "skip-post-deploy", "", false, "skip post deploy action") | ||
redeployCmd.Flags().StringVarP(&exportTemplate, "export-template", "", "", | ||
"template file for topology data export") | ||
redeployCmd.Flags().BoolVarP(&skipLabDirFileACLs, "skip-labdir-acl", "", false, | ||
"skip the lab directory extended ACLs provisioning") | ||
} | ||
|
||
func redeployFn(cmd *cobra.Command, args []string) error { | ||
// First destroy the lab | ||
err := destroyFn(destroyCmd, args) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Then deploy it again | ||
return deployFn(deployCmd, args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# redeploy command | ||
|
||
### Description | ||
|
||
The `redeploy` command redeploys a lab referenced by a provided topology definition file. It effectively combines the `destroy` and `deploy` commands into a single operation. | ||
|
||
The two most common applications of this command are: | ||
|
||
1. Redeploying a lab while keeping the lab directory intact: | ||
|
||
```bash | ||
sudo containerlab redeploy -t mylab.clab.yml | ||
``` | ||
|
||
This command will destroy the lab and redeploy it using the same topology file and the same lab directory. This should keep intact any saved configurations for the nodes. | ||
|
||
2. Redeploying a lab while removing the lab directory at the destroy stage: | ||
|
||
```bash | ||
sudo containerlab redeploy --cleanup -t mylab.clab.yml | ||
``` | ||
|
||
or using the shorthands: | ||
|
||
```bash | ||
sudo clab rdep -c -t mylab.clab.yml | ||
``` | ||
|
||
This command will destroy the lab and remove the lab directory before deploying the lab again. This ensures a clean redeployment as if you were deploying a lab for the first time discarding any previous lab state. | ||
|
||
### Usage | ||
|
||
`containerlab [global-flags] redeploy [local-flags]` | ||
|
||
**aliases:** `rdep` | ||
|
||
### Flags | ||
|
||
#### topology | ||
|
||
With the global `--topo | -t` flag a user sets the path to the topology definition file that will be used to redeploy a lab. | ||
|
||
When the topology path refers to a directory, containerlab will look for a file with `.clab.yml` or `.clab.yaml` extension in that directory and use it as a topology definition file. | ||
|
||
When the topology file flag is omitted, containerlab will try to find the matching file name by looking at the current working directory. | ||
|
||
If more than one file is found for directory-based path or when the flag is omitted entirely, containerlab will fail with an error. | ||
|
||
#### cleanup | ||
|
||
The local `--cleanup | -c` flag instructs containerlab to remove the lab directory and all its content during the destroy phase. | ||
|
||
Without this flag present, containerlab will keep the lab directory and all files inside of it. | ||
|
||
#### graceful | ||
|
||
To make containerlab attempt a graceful shutdown of the running containers during destroy phase, add the `--graceful` flag. Without it, containers will be removed forcefully without attempting to stop them. | ||
|
||
#### graph | ||
|
||
The local `--graph | -g` flag instructs containerlab to generate a topology graph after deploying the lab. | ||
|
||
#### network | ||
|
||
With `--network` flag users can specify a custom name for the management network that containerlab creates for the lab. | ||
|
||
#### ipv4-subnet | ||
|
||
Using `--ipv4-subnet | -4` flag users can define a custom IPv4 subnet that containerlab will use to assign management IPv4 addresses. | ||
|
||
#### ipv6-subnet | ||
|
||
Using `--ipv6-subnet | -6` flag users can define a custom IPv6 subnet that containerlab will use to assign management IPv6 addresses. | ||
|
||
#### max-workers | ||
|
||
With `--max-workers` flag, it is possible to limit the number of concurrent workers that create/delete containers or wire virtual links. By default, the number of workers equals the number of nodes/links to process. | ||
|
||
#### keep-mgmt-net | ||
|
||
Do not try to remove the management network during destroy phase. Usually the management docker network (in case of docker) and the underlying bridge are being removed. If you have attached additional resources outside of containerlab and you want the bridge to remain intact just add the `--keep-mgmt-net` flag. | ||
|
||
#### skip-post-deploy | ||
|
||
The `--skip-post-deploy` flag can be used to skip the post-deploy phase of the lab deployment. This is a global flag that affects all nodes in the lab. | ||
|
||
#### export-template | ||
|
||
The local `--export-template` flag allows a user to specify a custom Go template that will be used for exporting topology data into `topology-data.json` file under the lab directory. | ||
|
||
#### node-filter | ||
|
||
The local `--node-filter` flag allows users to specify a subset of topology nodes targeted by `redeploy` command. The value of this flag is a comma-separated list of node names as they appear in the topology. | ||
|
||
When a subset of nodes is specified, containerlab will only redeploy those nodes and their links and ignore the rest. | ||
|
||
#### skip-labdir-acl | ||
|
||
The `--skip-labdir-acl` flag can be used to skip the lab directory access control list (ACL) provisioning during the deploy phase. | ||
|
||
### Examples | ||
|
||
#### Redeploy a lab using the given topology file | ||
|
||
```bash | ||
containerlab redeploy -t mylab.clab.yml | ||
``` | ||
|
||
#### Redeploy a lab with removing the Lab directory at destroy stage | ||
|
||
```bash | ||
containerlab redeploy --cleanup -t mylab.clab.yml | ||
``` | ||
|
||
#### Redeploy a lab without specifying topology file | ||
|
||
Given that a single topology file is present in the current directory. | ||
|
||
```bash | ||
containerlab redeploy | ||
``` | ||
|
||
#### Redeploy a lab using short flag names | ||
|
||
```bash | ||
clab rdep -t mylab.clab.yml | ||
``` | ||
|
||
#### Redeploy specific nodes in a lab | ||
|
||
```bash | ||
containerlab redeploy -t mylab.clab.yml --node-filter "node1,node2" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters