VOL-1674 - add version reporting information

Change-Id: Ie6cc244c66077467d371ffb3506ea0f4e817c197
diff --git a/ro_core/config/config.go b/ro_core/config/config.go
index b7906f2..030134b 100644
--- a/ro_core/config/config.go
+++ b/ro_core/config/config.go
@@ -36,6 +36,7 @@
 	default_KVTxnKeyDelTime       = 60
 	default_LogLevel              = 0
 	default_Banner                = false
+	default_DisplayVersionOnly    = false
 	default_CoreTopic             = "rocore"
 	default_ROCoreEndpoint        = "rocore"
 	default_ROCoreKey             = "pki/voltha.key"
@@ -59,6 +60,7 @@
 	CoreTopic           string
 	LogLevel            int
 	Banner              bool
+	DisplayVersionOnly  bool
 	ROCoreKey           string
 	ROCoreCert          string
 	ROCoreCA            string
@@ -84,6 +86,7 @@
 		CoreTopic:           default_CoreTopic,
 		LogLevel:            default_LogLevel,
 		Banner:              default_Banner,
+		DisplayVersionOnly:  default_DisplayVersionOnly,
 		ROCoreKey:           default_ROCoreKey,
 		ROCoreCert:          default_ROCoreCert,
 		ROCoreCA:            default_ROCoreCA,
@@ -133,6 +136,9 @@
 	help = fmt.Sprintf("Show startup banner log lines")
 	flag.BoolVar(&cf.Banner, "banner", default_Banner, help)
 
+	help = fmt.Sprintf("Show version information and exit")
+	flag.BoolVar(&cf.DisplayVersionOnly, "version", default_DisplayVersionOnly, help)
+
 	flag.Parse()
 
 	containerName := getContainerInfo()
diff --git a/ro_core/core/model_proxy_manager.go b/ro_core/core/model_proxy_manager.go
index 60295c0..5613475 100644
--- a/ro_core/core/model_proxy_manager.go
+++ b/ro_core/core/model_proxy_manager.go
@@ -17,7 +17,9 @@
 
 import (
 	"context"
+	"encoding/json"
 	"github.com/opencord/voltha-go/common/log"
+	"github.com/opencord/voltha-go/common/version"
 	"github.com/opencord/voltha-go/db/model"
 	"github.com/opencord/voltha-protos/go/voltha"
 	"google.golang.org/grpc/codes"
@@ -73,11 +75,22 @@
 func (mpMgr *ModelProxyManager) GetVoltha(ctx context.Context) (*voltha.Voltha, error) {
 	log.Debug("GetVoltha")
 
-	// TODO: Need to retrieve VOLTHA core information, for now return empty
-	// value
+	/*
+	 * For now, encode all the version information into a JSON object and
+	 * pass that back as "version" so the client can get all the
+	 * information associated with the version. Long term the API should
+	 * better accomidate this, but for now this will work.
+	 */
+	data, err := json.Marshal(&version.VersionInfo)
+	info := version.VersionInfo.Version
+	if err != nil {
+		log.Warnf("Unable to encode version information as JSON: %s", err.Error())
+	} else {
+		info = string(data)
+	}
+
 	return &voltha.Voltha{
-		// TODO: hardcoded for now until ldflags are supported
-		Version: "2.1.0-dev",
+		Version: info,
 	}, nil
 }
 
diff --git a/ro_core/main.go b/ro_core/main.go
index 97015d4..2313fd3 100644
--- a/ro_core/main.go
+++ b/ro_core/main.go
@@ -21,6 +21,7 @@
 	"fmt"
 	grpcserver "github.com/opencord/voltha-go/common/grpc"
 	"github.com/opencord/voltha-go/common/log"
+	"github.com/opencord/voltha-go/common/version"
 	"github.com/opencord/voltha-go/db/kvstore"
 	"github.com/opencord/voltha-go/ro_core/config"
 	c "github.com/opencord/voltha-go/ro_core/core"
@@ -159,13 +160,19 @@
 }
 
 func printBanner() {
-	fmt.Println("                                            ")
-	fmt.Println(" ______        ______                       ")
-	fmt.Println("|  _ \\ \\      / / ___|___  _ __ ___       ")
-	fmt.Println("| |_) \\ \\ /\\ / / |   / _ \\| '__/ _ \\   ")
-	fmt.Println("|  _ < \\ V  V /| |__| (_) | | |  __/       ")
-	fmt.Println("|_| \\_\\ \\_/\\_/  \\____\\___/|_|  \\___| ")
-	fmt.Println("                                            ")
+	fmt.Println()
+	fmt.Println(" ____   ___   ____               ")
+	fmt.Println("|  _ \\ / _ \\ / ___|___  _ __ ___ ")
+	fmt.Println("| |_) | | | | |   / _ \\| '__/ _ \\")
+	fmt.Println("|  _ <| |_| | |__| (_) | | |  __/")
+	fmt.Println("|_| \\_\\\\___/ \\____\\___/|_|  \\___|")
+	fmt.Println()
+
+}
+
+func printVersion() {
+	fmt.Println("VOLTHA Read-Only Core")
+	fmt.Println(version.VersionInfo.String("  "))
 }
 
 func main() {
@@ -190,6 +197,12 @@
 
 	defer log.CleanUp()
 
+	// Print verison / build information and exit
+	if cf.DisplayVersionOnly {
+		printVersion()
+		return
+	}
+
 	// Print banner if specified
 	if cf.Banner {
 		printBanner()