Skip to content

Commit

Permalink
cleanup unused variables and change Clab.WithRuntime(...) to use *run…
Browse files Browse the repository at this point in the history
…time.RuntimeConfig
  • Loading branch information
steiler committed Jul 8, 2021
1 parent c5fa3ec commit 0d35345
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 39 deletions.
23 changes: 3 additions & 20 deletions clab/clab.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ type CLab struct {
globalRuntime string
Dir *Directory

debug bool
timeout time.Duration
gracefulShutdown bool
timeout time.Duration
}

type Directory struct {
Expand All @@ -44,19 +42,13 @@ type Directory struct {

type ClabOption func(c *CLab)

func WithDebug(d bool) ClabOption {
return func(c *CLab) {
c.debug = d
}
}

func WithTimeout(dur time.Duration) ClabOption {
return func(c *CLab) {
c.timeout = dur
}
}

func WithRuntime(name string, d bool, dur time.Duration, gracefulShutdown bool) ClabOption {
func WithRuntime(name string, rtconfig *runtime.RuntimeConfig) ClabOption {
return func(c *CLab) {
// define runtime name.
// order of preference: cli flag -> env var -> default value of docker
Expand All @@ -73,10 +65,7 @@ func WithRuntime(name string, d bool, dur time.Duration, gracefulShutdown bool)
if rInit, ok := runtime.ContainerRuntimes[name]; ok {
r := rInit()
err := r.Init(
runtime.WithConfig(&runtime.RuntimeConfig{
Timeout: dur,
Debug: d,
}),
runtime.WithConfig(rtconfig),
runtime.WithMgmtNet(c.Config.Mgmt),
)
if err != nil {
Expand Down Expand Up @@ -108,12 +97,6 @@ func WithTopoFile(file string) ClabOption {
}
}

func WithGracefulShutdown(gracefulShutdown bool) ClabOption {
return func(c *CLab) {
c.gracefulShutdown = gracefulShutdown
}
}

// NewContainerLab function defines a new container lab
func NewContainerLab(opts ...ClabOption) (*CLab, error) {
c := &CLab{
Expand Down
1 change: 0 additions & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var configCmd = &cobra.Command{
transport.DebugCount = debugCount

c, err := clab.NewContainerLab(
clab.WithDebug(debug),
clab.WithTimeout(timeout),
clab.WithTopoFile(topo),
)
Expand Down
9 changes: 7 additions & 2 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ var deployCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
var err error
opts := []clab.ClabOption{
clab.WithDebug(debug),
clab.WithTimeout(timeout),
clab.WithTopoFile(topo),
clab.WithRuntime(rt, debug, timeout, graceful),
clab.WithRuntime(rt,
&runtime.RuntimeConfig{
Debug: debug,
Timeout: timeout,
GracefulShutdown: graceful,
},
),
}
c, err := clab.NewContainerLab(opts...)
if err != nil {
Expand Down
10 changes: 7 additions & 3 deletions cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ var destroyCmd = &cobra.Command{
defer cancel()

opts := []clab.ClabOption{
clab.WithDebug(debug),
clab.WithTimeout(timeout),
clab.WithRuntime(rt, debug, timeout, graceful),
clab.WithRuntime(rt,
&runtime.RuntimeConfig{
Debug: debug,
Timeout: timeout,
GracefulShutdown: graceful,
},
),
}

topos := map[string]struct{}{}
Expand Down Expand Up @@ -71,7 +76,6 @@ var destroyCmd = &cobra.Command{
for topo := range topos {
opts := append(opts,
clab.WithTopoFile(topo),
clab.WithGracefulShutdown(graceful),
)
c, err := clab.NewContainerLab(opts...)
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions cmd/disableTxOffload.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/srl-labs/containerlab/clab"
"github.com/srl-labs/containerlab/runtime"
"github.com/srl-labs/containerlab/utils"
)

Expand All @@ -23,9 +24,14 @@ var disableTxOffloadCmd = &cobra.Command{

RunE: func(cmd *cobra.Command, args []string) error {
opts := []clab.ClabOption{
clab.WithDebug(debug),
clab.WithTimeout(timeout),
clab.WithRuntime(rt, debug, timeout, graceful),
clab.WithRuntime(rt,
&runtime.RuntimeConfig{
Debug: debug,
Timeout: timeout,
GracefulShutdown: graceful,
},
),
}
c, err := clab.NewContainerLab(opts...)
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/srl-labs/containerlab/clab"
"github.com/srl-labs/containerlab/runtime"
"github.com/srl-labs/containerlab/types"
)

Expand Down Expand Up @@ -47,10 +48,15 @@ var execCmd = &cobra.Command{
log.Error("format is expected to be either json or plain")
}
opts := []clab.ClabOption{
clab.WithDebug(debug),
clab.WithTimeout(timeout),
clab.WithTopoFile(topo),
clab.WithRuntime(rt, debug, timeout, graceful),
clab.WithRuntime(rt,
&runtime.RuntimeConfig{
Debug: debug,
Timeout: timeout,
GracefulShutdown: graceful,
},
),
}
c, err := clab.NewContainerLab(opts...)
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions cmd/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/srl-labs/containerlab/clab"
"github.com/srl-labs/containerlab/runtime"
"github.com/srl-labs/containerlab/types"
)

Expand Down Expand Up @@ -56,10 +57,15 @@ var graphCmd = &cobra.Command{
var err error

opts := []clab.ClabOption{
clab.WithDebug(debug),
clab.WithTimeout(timeout),
clab.WithTopoFile(topo),
clab.WithRuntime(rt, debug, timeout, graceful),
clab.WithRuntime(rt,
&runtime.RuntimeConfig{
Debug: debug,
Timeout: timeout,
GracefulShutdown: graceful,
},
),
}
c, err := clab.NewContainerLab(opts...)
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/srl-labs/containerlab/clab"
"github.com/srl-labs/containerlab/runtime"
"github.com/srl-labs/containerlab/types"
)

Expand Down Expand Up @@ -51,9 +52,14 @@ var inspectCmd = &cobra.Command{
return
}
opts := []clab.ClabOption{
clab.WithDebug(debug),
clab.WithTimeout(timeout),
clab.WithRuntime(rt, debug, timeout, graceful),
clab.WithRuntime(rt,
&runtime.RuntimeConfig{
Debug: debug,
Timeout: timeout,
GracefulShutdown: graceful,
},
),
}
if topo != "" {
opts = append(opts, clab.WithTopoFile(topo))
Expand Down
10 changes: 8 additions & 2 deletions cmd/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/spf13/cobra"
"github.com/srl-labs/containerlab/clab"
"github.com/srl-labs/containerlab/nodes"
"github.com/srl-labs/containerlab/runtime"
)

// saveCmd represents the save command
Expand All @@ -27,10 +28,15 @@ Refer to the https://containerlab.srlinux.dev/cmd/save/ documentation to see the
return fmt.Errorf("provide topology file path with --topo flag")
}
opts := []clab.ClabOption{
clab.WithDebug(debug),
clab.WithTimeout(timeout),
clab.WithTopoFile(topo),
clab.WithRuntime(rt, debug, timeout, graceful),
clab.WithRuntime(rt,
&runtime.RuntimeConfig{
Debug: debug,
Timeout: timeout,
GracefulShutdown: graceful,
},
),
}
c, err := clab.NewContainerLab(opts...)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion cmd/tools_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ func createCA(cmd *cobra.Command, args []string) error {
`
var err error
opts := []clab.ClabOption{
clab.WithDebug(debug),
clab.WithTimeout(timeout),
}
c, err := clab.NewContainerLab(opts...)
Expand Down
10 changes: 8 additions & 2 deletions cmd/tools_veth.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/srl-labs/containerlab/clab"
"github.com/srl-labs/containerlab/runtime"
"github.com/srl-labs/containerlab/types"
"github.com/srl-labs/containerlab/utils"
)
Expand Down Expand Up @@ -40,9 +41,14 @@ var vethCreateCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
var err error
opts := []clab.ClabOption{
clab.WithDebug(debug),
clab.WithTimeout(timeout),
clab.WithRuntime(rt, debug, timeout, graceful),
clab.WithRuntime(rt,
&runtime.RuntimeConfig{
Debug: debug,
Timeout: timeout,
GracefulShutdown: graceful,
},
),
}
c, err := clab.NewContainerLab(opts...)
if err != nil {
Expand Down

0 comments on commit 0d35345

Please sign in to comment.