Skip to content

Commit

Permalink
implement delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
severindellsperger committed Jan 5, 2024
1 parent cae95ef commit f57eb60
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions cmd/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cmd

import (
"github.com/hawkv6/clab-telemetry-linker/pkg/command"
"github.com/hawkv6/clab-telemetry-linker/pkg/config"
"github.com/hawkv6/clab-telemetry-linker/pkg/helpers"
"github.com/hawkv6/clab-telemetry-linker/pkg/impairments"
"github.com/spf13/cobra"
)

var deleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete impairments on a containerlab interface",
Run: func(cmd *cobra.Command, args []string) {
err, defaultConfig := config.NewDefaultConfig()
if err != nil {
log.Fatalf("Error creating config: %v\n", err)
}
helper := helpers.NewDefaultHelper()
command := command.NewDefaultSetCommand(Node, Interface, defaultConfig.GetValue(helper.GetDefaultClabNameKey()))
manager := impairments.NewDefaultSetter(defaultConfig, Node, Interface, helper, command)
// Delete is setting all values to 0
handleError(manager.SetDelay(0), manager, "Error setting delay")
handleError(manager.SetJitter(0), manager, "Error setting jitter")
handleError(manager.SetLoss(0), manager, "Error setting loss")
handleError(manager.SetRate(0), manager, "Error setting rate")
handleError(manager.ApplyImpairments(), manager, "Error applying impairments")
handleError(manager.WriteConfig(), manager, "Error writing config")
},
}

func init() {
rootCmd.AddCommand(deleteCmd)
deleteCmd.Flags().StringVarP(&Node, "node", "n", "", "node to delete the impairments from ")
deleteCmd.Flags().StringVarP(&Interface, "interface", "i", "", "interface to delete the impairments from")
markRequiredFlags(deleteCmd, []string{"node", "interface"})
}

0 comments on commit f57eb60

Please sign in to comment.