diff options
Diffstat (limited to 'utils/main.go')
-rw-r--r-- | utils/main.go | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/utils/main.go b/utils/main.go index af3a4a7..32f9682 100644 --- a/utils/main.go +++ b/utils/main.go @@ -3,13 +3,48 @@ package main import ( "fmt" "os" + Ipam "utils/ipam" "utils/networks" + "utils/routers" ) func main() { - err := networks.RunNetworks() + if len(os.Args) != 3 { + _, _ = fmt.Fprintf(os.Stderr, "Usage: %s IPAM-FILE PICTURE\n", os.Args[0]) + os.Exit(1) + } + + ipam, err := loadIpam() + if err != nil { + return + } + + if os.Args[1] == "networks" { + err = networks.RunNetworks(ipam) + } else if os.Args[1] == "routers" { + err = routers.RunRouters(ipam) + } else { + _, _ = fmt.Fprintf(os.Stderr, "Unknown command: %s\n", os.Args[2]) + os.Exit(1) + } + if err != nil { _, _ = fmt.Fprintf(os.Stderr, "%v\n", err) os.Exit(1) } } + +func loadIpam() (*Ipam.Ipam, error) { + ipamYaml := os.Args[2] + bs, err := os.ReadFile(ipamYaml) + if err != nil { + return nil, err + } + + ipam, err := Ipam.LoadIpam(bs) + if err != nil { + return nil, err + } + + return ipam, nil +} |