|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "net" |
| 5 | + |
| 6 | + "github.com/spf13/cobra" |
| 7 | +) |
| 8 | + |
| 9 | +// redeployCmd represents the redeploy command. |
| 10 | +var redeployCmd = &cobra.Command{ |
| 11 | + Use: "redeploy", |
| 12 | + Short: "destroy and redeploy a lab", |
| 13 | + Long: "destroy a lab and deploy it again based on the topology definition file\nreference: https://containerlab.dev/cmd/redeploy/", |
| 14 | + Aliases: []string{"rdep"}, |
| 15 | + PreRunE: sudoCheck, |
| 16 | + SilenceUsage: true, |
| 17 | + RunE: redeployFn, |
| 18 | +} |
| 19 | + |
| 20 | +func init() { |
| 21 | + rootCmd.AddCommand(redeployCmd) // Add to rootCmd |
| 22 | + |
| 23 | + // Add destroy flags |
| 24 | + redeployCmd.Flags().BoolVarP(&cleanup, "cleanup", "c", false, "delete lab directory") |
| 25 | + redeployCmd.Flags().BoolVarP(&graceful, "graceful", "", false, |
| 26 | + "attempt to stop containers before removing") |
| 27 | + redeployCmd.Flags().BoolVarP(&all, "all", "a", false, "destroy all containerlab labs") |
| 28 | + redeployCmd.Flags().UintVarP(&maxWorkers, "max-workers", "", 0, |
| 29 | + "limit the maximum number of workers creating/deleting nodes") |
| 30 | + redeployCmd.Flags().BoolVarP(&keepMgmtNet, "keep-mgmt-net", "", false, "do not remove the management network") |
| 31 | + redeployCmd.Flags().StringSliceVarP(&nodeFilter, "node-filter", "", []string{}, |
| 32 | + "comma separated list of nodes to include") |
| 33 | + |
| 34 | + // Add deploy flags |
| 35 | + redeployCmd.Flags().BoolVarP(&graph, "graph", "g", false, "generate topology graph") |
| 36 | + redeployCmd.Flags().StringVarP(&mgmtNetName, "network", "", "", "management network name") |
| 37 | + redeployCmd.Flags().IPNetVarP(&mgmtIPv4Subnet, "ipv4-subnet", "4", net.IPNet{}, "management network IPv4 subnet range") |
| 38 | + redeployCmd.Flags().IPNetVarP(&mgmtIPv6Subnet, "ipv6-subnet", "6", net.IPNet{}, "management network IPv6 subnet range") |
| 39 | + redeployCmd.Flags().StringVarP(&deployFormat, "format", "f", "table", "output format. One of [table, json]") |
| 40 | + redeployCmd.Flags().BoolVarP(&skipPostDeploy, "skip-post-deploy", "", false, "skip post deploy action") |
| 41 | + redeployCmd.Flags().StringVarP(&exportTemplate, "export-template", "", "", |
| 42 | + "template file for topology data export") |
| 43 | + redeployCmd.Flags().BoolVarP(&skipLabDirFileACLs, "skip-labdir-acl", "", false, |
| 44 | + "skip the lab directory extended ACLs provisioning") |
| 45 | +} |
| 46 | + |
| 47 | +func redeployFn(cmd *cobra.Command, args []string) error { |
| 48 | + // First destroy the lab |
| 49 | + err := destroyFn(destroyCmd, args) |
| 50 | + if err != nil { |
| 51 | + return err |
| 52 | + } |
| 53 | + |
| 54 | + // Then deploy it again |
| 55 | + return deployFn(deployCmd, args) |
| 56 | +} |
0 commit comments