Skip to content

Commit 8597df6

Browse files
carlmontanarihellt
andauthored
Feat/decouple cmd destroy (#2729)
* chore: re-organizing destroy things * refactor: first pass reswizzling cmd/destroy * refactor: moving most of the destroy things into core, WIP * fix: hopefully fully matching filter/all/name setup from before reswizzling, WIP * refactor: remove common package, flatten cmd out, some cleanup on core/destroy * fix: dont let topoPaths be nil * refactor: use the new destroy and name it as such * refactor: handle lab dir removal in deferred func after cleaning clabs * refactor: functional options pattern for clab.List * fix: nil instead of nothing for list opts, use normal clab initializtion for the destroy clone bits * chore: remove dead code * chore: fix bad docstring and typo * fix: only run the defered lab dir destruction if cleanup * chore: fix some linter nits * chore: remove dead code * unshadowing builtin * compare strings by value * give some air for sros tests * mod tidy * rename labels->filters * align func comment name * rename clone->makeCopy maybe not a better name after all :D * cap labDir --------- Co-authored-by: hellt <[email protected]>
1 parent 644ceb5 commit 8597df6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1060
-818
lines changed

cmd/common/common.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

cmd/common/tools.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

cmd/config.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"sync"
77

88
"github.com/spf13/cobra"
9-
"github.com/srl-labs/containerlab/cmd/common"
109
"github.com/srl-labs/containerlab/core"
1110
"github.com/srl-labs/containerlab/core/config"
1211
"github.com/srl-labs/containerlab/core/config/transport"
@@ -60,10 +59,10 @@ func configRun(_ *cobra.Command, args []string) error {
6059
config.DebugCount = debugCount
6160

6261
c, err := core.NewContainerLab(
63-
core.WithTimeout(common.Timeout),
64-
core.WithTopoPath(common.Topo, common.VarsFile),
65-
core.WithNodeFilter(common.NodeFilter),
66-
core.WithDebug(common.Debug),
62+
core.WithTimeout(timeout),
63+
core.WithTopoPath(topoFile, varsFile),
64+
core.WithNodeFilter(nodeFilter),
65+
core.WithDebug(debug),
6766
)
6867
if err != nil {
6968
return err
@@ -158,7 +157,7 @@ func init() {
158157
"comma separated list of nodes to include")
159158
configCmd.Flags().SortFlags = false
160159

161-
configCmd.Flags().StringSliceVarP(&common.NodeFilter, "node-filter", "", []string{},
160+
configCmd.Flags().StringSliceVarP(&nodeFilter, "node-filter", "", []string{},
162161
"comma separated list of nodes to include")
163162

164163
configCmd.AddCommand(configSendCmd)

cmd/config_template.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"github.com/spf13/cobra"
5-
"github.com/srl-labs/containerlab/cmd/common"
65
"github.com/srl-labs/containerlab/core"
76
"github.com/srl-labs/containerlab/core/config"
87
)
@@ -23,9 +22,9 @@ var configTemplateCmd = &cobra.Command{
2322
config.DebugCount = debugCount
2423

2524
c, err := core.NewContainerLab(
26-
core.WithTimeout(common.Timeout),
27-
core.WithTopoPath(common.Topo, common.VarsFile),
28-
core.WithDebug(common.Debug),
25+
core.WithTimeout(timeout),
26+
core.WithTopoPath(topoFile, varsFile),
27+
core.WithDebug(debug),
2928
)
3029
if err != nil {
3130
return err

cmd/deploy.go

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ import (
1212

1313
"github.com/charmbracelet/log"
1414
"github.com/spf13/cobra"
15-
"github.com/srl-labs/containerlab/cmd/common"
16-
"github.com/srl-labs/containerlab/cmd/inspect"
1715
"github.com/srl-labs/containerlab/cmd/version"
1816
"github.com/srl-labs/containerlab/core"
1917
"github.com/srl-labs/containerlab/core/dependency_manager"
20-
"github.com/srl-labs/containerlab/runtime"
18+
containerlabruntime "github.com/srl-labs/containerlab/runtime"
19+
"github.com/srl-labs/containerlab/utils"
2120
)
2221

2322
// name of the container management network.
@@ -56,13 +55,13 @@ var deployCmd = &cobra.Command{
5655
Long: "deploy a lab based defined by means of the topology definition file\nreference: https://containerlab.dev/cmd/deploy/",
5756
Aliases: []string{"dep"},
5857
SilenceUsage: true,
59-
PreRunE: common.CheckAndGetRootPrivs,
58+
PreRunE: utils.CheckAndGetRootPrivs,
6059
RunE: deployFn,
6160
}
6261

6362
func init() {
6463
RootCmd.AddCommand(deployCmd)
65-
deployCmd.Flags().BoolVarP(&common.Graph, "graph", "g", false, "generate topology graph")
64+
deployCmd.Flags().BoolVarP(&graph, "graph", "g", false, "generate topology graph")
6665
deployCmd.Flags().StringVarP(&mgmtNetName, "network", "", "", "management network name")
6766
deployCmd.Flags().IPNetVarP(&mgmtIPv4Subnet, "ipv4-subnet", "4", net.IPNet{}, "management network IPv4 subnet range")
6867
deployCmd.Flags().IPNetVarP(&mgmtIPv6Subnet, "ipv6-subnet", "6", net.IPNet{}, "management network IPv6 subnet range")
@@ -74,7 +73,7 @@ func init() {
7473
deployCmd.Flags().BoolVarP(&skipPostDeploy, "skip-post-deploy", "", false, "skip post deploy action")
7574
deployCmd.Flags().StringVarP(&exportTemplate, "export-template", "",
7675
"", "template file for topology data export")
77-
deployCmd.Flags().StringSliceVarP(&common.NodeFilter, "node-filter", "", []string{},
76+
deployCmd.Flags().StringSliceVarP(&nodeFilter, "node-filter", "", []string{},
7877
"comma separated list of nodes to include")
7978
deployCmd.Flags().BoolVarP(&skipLabDirFileACLs, "skip-labdir-acl", "", false,
8079
"skip the lab directory extended ACLs provisioning")
@@ -94,25 +93,25 @@ func deployFn(cobraCmd *cobra.Command, _ []string) error {
9493
}
9594

9695
opts := []core.ClabOption{
97-
core.WithTimeout(common.Timeout),
98-
core.WithTopoPath(common.Topo, common.VarsFile),
99-
core.WithTopoBackup(common.Topo),
100-
core.WithNodeFilter(common.NodeFilter),
96+
core.WithTimeout(timeout),
97+
core.WithTopoPath(topoFile, varsFile),
98+
core.WithTopoBackup(topoFile),
99+
core.WithNodeFilter(nodeFilter),
101100
core.WithRuntime(
102-
common.Runtime,
103-
&runtime.RuntimeConfig{
104-
Debug: common.Debug,
105-
Timeout: common.Timeout,
106-
GracefulShutdown: common.Graceful,
101+
runtime,
102+
&containerlabruntime.RuntimeConfig{
103+
Debug: debug,
104+
Timeout: timeout,
105+
GracefulShutdown: gracefulShutdown,
107106
},
108107
),
109108
core.WithDependencyManager(dependency_manager.NewDependencyManager()),
110-
core.WithDebug(common.Debug),
109+
core.WithDebug(debug),
111110
}
112111

113112
// process optional settings
114-
if common.Name != "" {
115-
opts = append(opts, core.WithLabName(common.Name))
113+
if labName != "" {
114+
opts = append(opts, core.WithLabName(labName))
116115
}
117116
if labOwner != "" {
118117
opts = append(opts, core.WithLabOwner(labOwner))
@@ -139,7 +138,7 @@ func deployFn(cobraCmd *cobra.Command, _ []string) error {
139138

140139
deploymentOptions.SetExportTemplate(exportTemplate).
141140
SetReconfigure(reconfigure).
142-
SetGraph(common.Graph).
141+
SetGraph(graph).
143142
SetSkipPostDeploy(skipPostDeploy).
144143
SetSkipLabDirFileACLs(skipLabDirFileACLs)
145144

@@ -158,5 +157,5 @@ func deployFn(cobraCmd *cobra.Command, _ []string) error {
158157
m.DisplayNewVersionAvailable(versionCheckContext)
159158

160159
// print table summary
161-
return inspect.PrintContainerInspect(containers, deployFormat)
160+
return PrintContainerInspect(containers, deployFormat)
162161
}

0 commit comments

Comments
 (0)