diff --git a/README.md b/README.md index 03229feac9d450b8b5500f39b76d859416f13ef7..08bb2db38d81dc96a0b692b976badde7c17078d8 100644 --- a/README.md +++ b/README.md @@ -38,12 +38,26 @@ The PND is the single source of truth within a network. Its state is held and ma Any device directly configured by `goSDN` # Installing -You can install `goSDN` locally using the `go get` command. Since the repository and some dependencies are not publicly available you have to modify your git config first: +You can install the latest release of `goSDN` locally using the `go get` command. Since the repository and some dependencies are not publicly available you have to modify your git config first: ```sh > git config --global url."git@code.fbi.h-da.de:".insteadOf "https://code.fbi.h-da.de" > go get code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn ``` -Now you can start `goSDN` locally using the `gosdn` command or [use the CLI](#using-the-cli) to interact with a running `goSDN` instance. + +To install the development version you need to clone the repo and use `go install` to build and install the binary: +```sh +# If you haven't cloned the repo yet +> git config --global url."git@code.fbi.h-da.de:".insteadOf "https://code.fbi.h-da.de" +> cd $GOPATH/src +> git clone git@code.fbi.h-da.de:cocsn/gosdn.git + +# checkout the develop branch (or any other branch) +> cd $GOPATH/src/code.fbi.h-da.de/cocsn/gosdn +> git checkout develop +> go install ./cmd/gosdn +``` + +Now you can start `goSDN` locally using the `gosdn` command or [use the CLI](#using-the-cli) to interact with a running `goSDN` instance. # Getting Started ## k8s diff --git a/cli/http.go b/cli/http.go index 9707fc9abd31d19a6a6e397cc6c55a2e1a7c76f7..746c4a45146a882d827ef4b58526a5e06e4ef9a3 100644 --- a/cli/http.go +++ b/cli/http.go @@ -43,7 +43,9 @@ func HTTPGet(apiEndpoint, f string, args ...string) error { viper.Set("CLI_PND", pnd) viper.Set("CLI_SBI", sbi) err := viper.WriteConfig() - log.Error(err) + if err != nil { + log.Error(err) + } default: fmt.Println(string(bytes)) } diff --git a/cmd/addDevice.go b/cmd/addDevice.go index 27ef369d7225278292619bf6f315df92eeed3eb2..95180504c5828c06dce7cbb713a204e3acd9275b 100644 --- a/cmd/addDevice.go +++ b/cmd/addDevice.go @@ -42,8 +42,8 @@ var addDeviceCmd = &cobra.Command{ Short: "adds a device to the controller", Long: `Adds a device to the controller. - Device address and user credentials need to be provided - if they diverge from the default credentials.`, +Device address and user credentials need to be provided +if they diverge from the default credentials.`, RunE: func(cmd *cobra.Command, args []string) error { return cli.HTTPGet( apiEndpoint, diff --git a/cmd/capabilities.go b/cmd/capabilities.go index 770435109ca6da0654478e7ed7b8ddfd428502ac..437f6f25f83b62616fd72c918bd78ee45ad82fbb 100644 --- a/cmd/capabilities.go +++ b/cmd/capabilities.go @@ -41,7 +41,7 @@ var capabilitiesCmd = &cobra.Command{ Use: "capabilities", Short: "capabilities request", Long: `Sends a gNMI Capabilities request to the specified target - and prints the supported models to stdout.`, +and prints the supported models to stdout.`, RunE: func(cmd *cobra.Command, args []string) error { return cli.Capabilities(username, password, address) }, diff --git a/cmd/cli.go b/cmd/cli.go index cefb842df9bbb0100d178c72b7c7a0d66c0a91d7..320c17ca84c17bafde8a2fa350e9d67e98465fb2 100644 --- a/cmd/cli.go +++ b/cmd/cli.go @@ -44,7 +44,7 @@ var cliCmd = &cobra.Command{ Use: "cli", Short: "initialises the cli", Long: `Initialises the CLI. The first PND UUID and SBI UUID - are written to the config file for subsequent requests.`, +are written to the config file for subsequent requests.`, RunE: func(cmd *cobra.Command, args []string) error { return cli.HTTPGet(apiEndpoint, "init") }, @@ -53,6 +53,6 @@ var cliCmd = &cobra.Command{ func init() { rootCmd.AddCommand(cliCmd) - cliCmd.PersistentFlags().StringVar(&apiEndpoint, "api-endpoint", "http://gosdn-develop.apps.ocp.fbi.h-da.de/api", "address of the target") + cliCmd.PersistentFlags().StringVar(&apiEndpoint, "controller", "http://gosdn-develop.apps.ocp.fbi.h-da.de/api", "address of the controller") } diff --git a/cmd/cliSet.go b/cmd/cliSet.go index 2d57f5f8669ac16b1136da0bc0c1b07e48acbfd9..9a79c630bed30d80c0d8438224edc42f084ff14d 100644 --- a/cmd/cliSet.go +++ b/cmd/cliSet.go @@ -42,7 +42,7 @@ var cliSetCmd = &cobra.Command{ Args: cobra.ExactArgs(2), Short: "set a value on a device", Long: `Set a path value for a given device. Only one path and - only one value supported for now`, +only one value supported for now`, RunE: func(cmd *cobra.Command, args []string) error { return cli.HTTPGet( apiEndpoint, @@ -60,5 +60,5 @@ var cliSetCmd = &cobra.Command{ func init() { cliCmd.AddCommand(cliSetCmd) - cliCmd.Flags().StringVar(&uuid, "uuid", "", "uuid of the requested device") + cliSetCmd.Flags().StringVar(&uuid, "uuid", "", "uuid of the requested device") } diff --git a/cmd/get.go b/cmd/get.go index 671f5d814097c4b5f87869209aa6efd3be2e3881..d200f3a08d4d8116e4168886dbde25427f99fa36 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -41,7 +41,7 @@ var getCmd = &cobra.Command{ Use: "gosdn get", Short: "get request", Long: `Sends a gNMI Get request to the specified target and - prints the response to stdout`, +prints the response to stdout`, RunE: func(cmd *cobra.Command, args []string) error { _, err := cli.Get(address, username, password, args...) return err diff --git a/cmd/getDevice.go b/cmd/getDevice.go index e166719f4e1e8c967f6a7f6456a06407858eef4f..2daf934073e6f69dc0f8b55971aa747c9eccec13 100644 --- a/cmd/getDevice.go +++ b/cmd/getDevice.go @@ -43,7 +43,7 @@ var getDeviceCmd = &cobra.Command{ Short: "gets device information from the controller", Long: `Gets device information from the controller. - Device UUID needs to be specified as positional argument.`, +Device UUID needs to be specified as positional argument.`, RunE: func(cmd *cobra.Command, args []string) error { return cli.HTTPGet( apiEndpoint, diff --git a/cmd/init.go b/cmd/init.go index c939c2131669f64158d724e7462f03f9df0b02d4..6a4b3e9bab78477c71efc80a075b3855b1a3265d 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -42,7 +42,7 @@ var initCmd = &cobra.Command{ Short: "initialise SBI and PND", Long: `Initialise SBI and PND and saves values to config file. - Same as invoking "gosdn cli" without any arguments`, +Same as invoking "gosdn cli" without any arguments`, RunE: func(cmd *cobra.Command, args []string) error { return cli.HTTPGet(apiEndpoint, "init") }, diff --git a/cmd/request.go b/cmd/request.go index 59edc0c5ea1766ef719cda528bd16b74790df3b4..54dd12becaad214a2d19f36d9da6a0a2cf7ac174 100644 --- a/cmd/request.go +++ b/cmd/request.go @@ -43,7 +43,7 @@ var requestCmd = &cobra.Command{ Short: "requests a path from a specified device on the controller", Long: `Requests a path from a specified device on the controller. - The request path is passed as positional argument.`, +The request path is passed as positional argument.`, RunE: func(cmd *cobra.Command, args []string) error { return cli.HTTPGet( apiEndpoint, @@ -59,5 +59,5 @@ var requestCmd = &cobra.Command{ func init() { cliCmd.AddCommand(requestCmd) - cliCmd.Flags().StringVar(&uuid, "uuid", "", "uuid of the requested device") + requestCmd.Flags().StringVar(&uuid, "uuid", "", "uuid of the requested device") } diff --git a/cmd/requestAll.go b/cmd/requestAll.go index b4eb4650c4f53f890eac0915b823d3f76355661c..11234826ed412ed507e9711b7b4af84b379c856e 100644 --- a/cmd/requestAll.go +++ b/cmd/requestAll.go @@ -42,9 +42,9 @@ var requestAllCmd = &cobra.Command{ Args: cobra.ExactArgs(1), Short: "requests specified path from all devices on the controller", Long: `Requests a path from all devices on the controller known by - the controller. +the controller. - The request path is passed as positional argument.`, +The request path is passed as positional argument.`, RunE: func(cmd *cobra.Command, args []string) error { return cli.HTTPGet( apiEndpoint, diff --git a/cmd/root.go b/cmd/root.go index daf7afe31b57355a7adae5334f63b1ce84b4c269..61b1e153fba0a4294eb7a18ff2538186739d5143 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -56,7 +56,7 @@ var rootCmd = &cobra.Command{ Use: "gosdn", Short: "starts the gosdn controller", Long: `Starts the gosdn controller and listens on port 8080 - for REST API calls.`, +for REST API calls.`, RunE: func(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -79,7 +79,7 @@ func init() { rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./configs/gosdn.toml)") rootCmd.PersistentFlags().StringVarP(&username, "username", "u", "admin", "username for a gnmi resource") rootCmd.PersistentFlags().StringVarP(&password, "password", "p", "arista", "password for a gnmi resource") - rootCmd.PersistentFlags().StringVarP(&address, "address", "a", "ceos-cocsn.apps.ocp.fbi.h-da.de:6030", "address to a gnmi resource") + rootCmd.PersistentFlags().StringVarP(&address, "address", "a", "ceos-cocsn.apps.ocp.fbi.h-da.de:6030", "address of a gnmi target") rootCmd.PersistentFlags().StringVarP(&loglevel, "log-level", "l", "", "log level 'debug' or 'trace'") rootCmd.Flags().StringVar(&grpcPort, "grpc-port", "55055", "port for gRPC NBI") @@ -108,7 +108,10 @@ func initConfig() { cliPnd = viper.GetString("CLI_PND") cliSbi = viper.GetString("CLI_SBI") - loglevel = viper.GetString("GOSDN_LOG") + ll := viper.GetString("GOSDN_LOG") + if ll != "" { + loglevel = ll + } log.SetReportCaller(true) switch loglevel { case "trace": diff --git a/cmd/set.go b/cmd/set.go index 0f2b758cd13d23c428a83b6c24cccbe33b56b244..486d9f594a7942d25aa690d5e4b970eb96816624 100644 --- a/cmd/set.go +++ b/cmd/set.go @@ -43,7 +43,7 @@ var setCmd = &cobra.Command{ Use: "set", Short: "set request", Long: `Sends a gNMI Set request to the specified target. Only one - request per invocation supported.`, +request per invocation supported.`, RunE: func(cmd *cobra.Command, args []string) error { return cli.Set(address, username, password, typ, args...) }, diff --git a/cmd/subscribe.go b/cmd/subscribe.go index eac7b4518f6e4409759a4f01a037a7b78b893025..a641b7fb4f4abffebd4e6848ae5cf6343644d276 100644 --- a/cmd/subscribe.go +++ b/cmd/subscribe.go @@ -45,7 +45,7 @@ var subscribeCmd = &cobra.Command{ Short: "subscribe to target", Long: `Starts a gNMI subscriber requesting the specified paths on the target and logs the response to stdout. - Only 'stream' mode with 'sample' operation supported.`, +Only 'stream' mode with 'sample' operation supported.`, RunE: func(cmd *cobra.Command, args []string) error { return cli.Subscribe(address, username, password, sampleInterval, heartbeatInterval, args...) }, diff --git a/go.mod b/go.mod index 0ff00d4c822ef6682a5da308969cd95a71eb9751..9822234c73e01a5119746554b44198af1da233b9 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/openconfig/gnmi v0.0.0-20200617225440-d2b4e6a45802 github.com/openconfig/goyang v0.2.3 github.com/openconfig/ygot v0.10.0 - github.com/sirupsen/logrus v1.4.2 + github.com/sirupsen/logrus v1.7.0 github.com/spf13/cobra v1.1.1 github.com/spf13/viper v1.7.1 github.com/stretchr/testify v1.6.1 diff --git a/go.sum b/go.sum index 1a42253423ce3a13303668e00677ea278d69350d..df1bca3a02416ecdb2b8129aa30f24d7ceea3832 100644 --- a/go.sum +++ b/go.sum @@ -260,7 +260,6 @@ github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgo github.com/klauspost/pgzip v1.2.4/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= github.com/klauspost/reedsolomon v1.9.3/go.mod h1:CwCi+NUr9pqSVktrkN+Ondf06rkhYZ/pcNv7fu+8Un4= -github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= @@ -379,8 +378,9 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= -github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM= +github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs= github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= @@ -545,6 +545,7 @@ golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/nucleus/http.go b/nucleus/http.go index c4419fb7906b1b0d094725cc122db3c47ee12c68..f350858c8d52b0b9a75ee4d4f642ac764a2b9d35 100644 --- a/nucleus/http.go +++ b/nucleus/http.go @@ -61,24 +61,37 @@ func httpHandler(writer http.ResponseWriter, request *http.Request) { return } + var hasPnd bool + var hasSbi bool + id, err := uuid.Parse(query.Get("uuid")) if err != nil { - log.Error(err) + if err.Error() != "invalid UUID length: 0" { + log.Error(err) + } } pid, err := uuid.Parse(query.Get("pnd")) if err != nil { - log.Error(err) + if err.Error() != "invalid UUID length: 0" { + log.Error(err) + } + } else { + hasPnd = true } sid, err := uuid.Parse(query.Get("sbi")) if err != nil { - log.Error(err) + if err.Error() != "invalid UUID length: 0" { + log.Error(err) + } + } else { + hasSbi = true } var pnd PrincipalNetworkDomain var sbi SouthboundInterface - if query.Get("q") != "init" && query.Get("q") != "getIDs" { + if hasSbi && hasPnd { pnd, err = c.pndc.get(pid) if err != nil { log.Error(err)