diff --git a/applications/venv-manager/main.go b/applications/venv-manager/main.go index 182f5d9fc6361f2bd3743d2c88aa9432313a85d8..2c4a887fc7186f55283799a96610a35b8b793707 100644 --- a/applications/venv-manager/main.go +++ b/applications/venv-manager/main.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "os" + "strings" venvmanager "code.fbi.h-da.de/danet/gosdn/applications/venv-manager/venv-manager" "google.golang.org/grpc" @@ -30,6 +31,8 @@ func main() { } flag.Parse() + customContainerRegistryURL = ensureLastCharIsSlash(customContainerRegistryURL) + fmt.Println("I will try to connect to goSDN located at", dialConnectionURL) venvManager := venvmanager.NewVenvManager(dialConnectionURL, dialOption, yamlFilepath, customContainerRegistryURL) @@ -50,3 +53,15 @@ func main() { } os.Exit(0) } + +func ensureLastCharIsSlash(inputString string) string { + if len(inputString) == 0 { + return inputString + } + + if strings.HasSuffix(inputString, "/") { + return inputString + } + + return inputString + "/" +} diff --git a/applications/venv-manager/node/node.go b/applications/venv-manager/node/node.go index 42e067cec3fb7f5ddd7d537e48a39f0eaa76b580..a7e8dd3809ceb98607e066cfca1c6220da32d651 100644 --- a/applications/venv-manager/node/node.go +++ b/applications/venv-manager/node/node.go @@ -23,14 +23,19 @@ func (n Node) GetID() string { // FillAllFields fills all remaining fields of object with data from YangData. func (n *Node) FillAllFields(containerRegistryURL string) { - // make switch case here to differentialte between linux, arista, etc - - // err = *&n.YangData.System.State. + // Works if linux and our gnmi target is used. + softwareVersion := n.YangData.System.State.SoftwareVersion + if softwareVersion != nil { + n.Kind = "linux" + n.Image = containerRegistryURL + *softwareVersion + return + } // specific to arista regex := regexp.MustCompile(`[0-9]+\.[0-9]+\.[0-9][A-Z]`) dockerTag := string(regex.FindAll([]byte(*n.YangData.Lldp.Config.SystemDescription), 1)[0]) + // If it's not linux with our gnmi target and not arista, we don't support it. if len(dockerTag) == 0 { n.Kind = "couldn't detect kind" n.Image = "couldn't detect image" @@ -39,5 +44,4 @@ func (n *Node) FillAllFields(containerRegistryURL string) { n.Kind = "ceos" n.Image = containerRegistryURL + n.Kind + ":" + dockerTag - } diff --git a/applications/venv-manager/venv-manager/venv-manager.go b/applications/venv-manager/venv-manager/venv-manager.go index 151eadf6d450659e5f5c3704697b0bb445eed443..66afb9f1ee10f96467eb58cf1a7a04d686df6e3e 100644 --- a/applications/venv-manager/venv-manager/venv-manager.go +++ b/applications/venv-manager/venv-manager/venv-manager.go @@ -215,7 +215,7 @@ func (v *VenvManager) getAndAddMoreData(topologyData *topology.GoSdnTopology) (* // Create 'root' path to be able to load the whole model from the store. path, err := ygot.StringToPath("/", ygot.StructuredPath) if err != nil { - panic(err) + return nil, err } // just to load model data into goSDN to have newest data available for get request