Skip to content

Commit

Permalink
Merge branch 'master' of github.com:srl-labs/containerlab into keepmg…
Browse files Browse the repository at this point in the history
…mtnet
  • Loading branch information
steiler committed Jun 18, 2021
2 parents 06cb4ac + eb969db commit aebc47c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 34 deletions.
3 changes: 0 additions & 3 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ var deployCmd = &cobra.Command{
PreRunE: sudoCheck,
RunE: func(cmd *cobra.Command, args []string) error {
var err error
if err = topoSet(); err != nil {
return err
}
opts := []clab.ClabOption{
clab.WithDebug(debug),
clab.WithTimeout(timeout),
Expand Down
36 changes: 13 additions & 23 deletions cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,20 @@ var destroyCmd = &cobra.Command{

switch {
case !all:
{
// stop if not topo file provided and not all labs are requested
// to be deleted
if err = topoSet(); err != nil {
return err
}
topos[topo] = struct{}{}
}
topos[topo] = struct{}{}
case all:
{
c := clab.NewContainerLab(opts...)
// list all containerlab containers
containers, err := c.Runtime.ListContainers(ctx, []*types.GenericFilter{{FilterType: "label", Field: "containerlab", Operator: "exists"}})
if err != nil {
return fmt.Errorf("could not list containers: %v", err)
}
if len(containers) == 0 {
return fmt.Errorf("no containerlab labs were found")
}
// get unique topo files from all labs
for _, cont := range containers {
topos[cont.Labels["clab-topo-file"]] = struct{}{}
}

c := clab.NewContainerLab(opts...)
// list all containerlab containers
containers, err := c.Runtime.ListContainers(ctx, []*types.GenericFilter{{FilterType: "label", Field: "containerlab", Operator: "exists"}})
if err != nil {
return fmt.Errorf("could not list containers: %v", err)
}
if len(containers) == 0 {
return fmt.Errorf("no containerlab labs were found")
}
// get unique topo files from all labs
for _, cont := range containers {
topos[cont.Labels["clab-topo-file"]] = struct{}{}
}
}

Expand Down
8 changes: 0 additions & 8 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&rt, "runtime", "r", "", "container runtime")
}

// returns an error if topo path is not provided
func topoSet() error {
if topo == "" {
return errors.New("path to the topology definition file must be provided with --topo/-t flag")
}
return nil
}

func sudoCheck(cmd *cobra.Command, args []string) error {
id := os.Geteuid()
if id != 0 {
Expand Down

0 comments on commit aebc47c

Please sign in to comment.