Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/integration-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@ jobs:
- name: Exec Test
run: cd integration-test/exec && ./test.sh

- name: Topo Test
run: cd integration-test/topo && ./test.sh

- name: Remove netns Folder
run: rm -rf /var/run/netns
10 changes: 10 additions & 0 deletions cmd/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ func errPrint(err error) {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}

func errFileNotExist(file string) {
fmt.Printf("File '%s' does not exist\n", file)
os.Exit(1)
}

func errYamlFormat(file string, err error) {
fmt.Printf("Error parsing YAML file '%s': %v\n", file, err)
os.Exit(1)
}
52 changes: 52 additions & 0 deletions cmd/topo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package cmd

import (
"fmt"

"github.com/Alonza0314/nsctl/internal/topo"
"github.com/free-ran-ue/util"
"github.com/spf13/cobra"
)

var topoCmd = &cobra.Command{
Use: "topo <apply|delete> [args]",
Short: "Manage the topology of namespaces and networks",
Long: "Manage the topology of namespaces and networks",
Run: topoFunc,
}

func init() {
nsctlCmd.AddCommand(topoCmd)
}

func topoFunc(cmd *cobra.Command, args []string) {
if len(args) == 0 {
errEmptyAction()
}

if !util.FileExists(args[1]) {
errFileNotExist(args[1])
}

var topoStruct topo.Topology
if err := util.LoadFromYaml(args[1], &topoStruct); err != nil {
errYamlFormat(args[1], err)
}

switch args[0] {
case "apply":
if err := topo.Apply(&topoStruct); err != nil {
errPrint(err)
} else {
fmt.Printf("Topology applied successfully from file: %s\n", args[1])
}
case "delete":
if err := topo.Delete(&topoStruct); err != nil {
errPrint(err)
} else {
fmt.Printf("Topology deleted successfully from file: %s\n", args[1])
}
default:
errFormat(args)
}
}
53 changes: 52 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,64 @@ module github.com/Alonza0314/nsctl
go 1.25.5

require (
github.com/free-ran-ue/util v0.0.3
github.com/pterm/pterm v0.12.83
github.com/spf13/cobra v1.10.2
github.com/vishvananda/netlink v1.3.1
github.com/vishvananda/netns v0.0.5
)

require (
atomicgo.dev/cursor v0.2.0 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/schedule v0.1.0 // indirect
github.com/Alonza0314/logger-go/v2 v2.0.5 // indirect
github.com/bytedance/gopkg v0.1.3 // indirect
github.com/bytedance/sonic v1.15.0 // indirect
github.com/bytedance/sonic/loader v0.5.0 // indirect
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/containerd/console v1.0.5 // indirect
github.com/free-ran-ue/free-ran-ue/v2 v2.3.11 // indirect
github.com/free5gc/aper v1.1.0 // indirect
github.com/free5gc/nas v1.2.2 // indirect
github.com/free5gc/ngap v1.1.2 // indirect
github.com/free5gc/openapi v1.2.3 // indirect
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
github.com/gin-contrib/sse v1.1.0 // indirect
github.com/gin-gonic/gin v1.12.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.30.1 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/goccy/go-yaml v1.19.2 // indirect
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
github.com/gookit/color v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/quic-go/qpack v0.6.0 // indirect
github.com/quic-go/quic-go v0.59.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/pflag v1.0.9 // indirect
golang.org/x/sys v0.10.0 // indirect
github.com/tim-ywliu/nested-logrus-formatter v1.3.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.3.1 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect
golang.org/x/arch v0.22.0 // indirect
golang.org/x/crypto v0.48.0 // indirect
golang.org/x/net v0.51.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/term v0.40.0 // indirect
golang.org/x/text v0.34.0 // indirect
google.golang.org/protobuf v1.36.10 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading
Loading