aboutsummaryrefslogtreecommitdiff
path: root/utils/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'utils/main.go')
-rw-r--r--utils/main.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/utils/main.go b/utils/main.go
new file mode 100644
index 0000000..32f9682
--- /dev/null
+++ b/utils/main.go
@@ -0,0 +1,50 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ Ipam "utils/ipam"
+ "utils/networks"
+ "utils/routers"
+)
+
+func main() {
+ 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
+}