SEBA-580 Add backup commands;
Retrieve server version;
Show available models

Change-Id: I3dc37d6f155661a2635fb4c95cf42b2aa81035e8
diff --git a/commands/version.go b/commands/version.go
index 7f7daf4..9cc8b05 100644
--- a/commands/version.go
+++ b/commands/version.go
@@ -17,7 +17,10 @@
 package commands
 
 import (
+	"context"
+	"github.com/fullstorydev/grpcurl"
 	flags "github.com/jessevdk/go-flags"
+	"github.com/jhump/protoreflect/dynamic"
 	"github.com/opencord/cordctl/cli/version"
 	"github.com/opencord/cordctl/format"
 )
@@ -31,8 +34,18 @@
 	Arch      string `json:"arch"`
 }
 
+type CoreVersionDetails struct {
+	Version       string `json:"version"`
+	PythonVersion string `json:"goversion"`
+	GitCommit     string `json:"gitcommit"`
+	BuildTime     string `json:"buildtime"`
+	Os            string `json:"os"`
+	Arch          string `json:"arch"`
+}
+
 type VersionOutput struct {
-	Client VersionDetails `json:"client"`
+	Client VersionDetails     `json:"client"`
+	Server CoreVersionDetails `json:"server"`
 }
 
 type VersionOpts struct {
@@ -50,6 +63,14 @@
 		Arch:      version.Arch,
 		BuildTime: version.BuildTime,
 	},
+	Server: CoreVersionDetails{
+		Version:       "unknown",
+		PythonVersion: "unknown",
+		GitCommit:     "unknown",
+		Os:            "unknown",
+		Arch:          "unknown",
+		BuildTime:     "unknown",
+	},
 }
 
 func RegisterVersionCommands(parent *flags.Parser) {
@@ -57,14 +78,59 @@
 }
 
 const DefaultFormat = `Client:
- Version        {{.Client.Version}}
- Go version:    {{.Client.GoVersion}}
- Git commit:    {{.Client.GitCommit}}
- Built:         {{.Client.BuildTime}}
- OS/Arch:       {{.Client.Os}}/{{.Client.Arch}}
+ Version         {{.Client.Version}}
+ Go version:     {{.Client.GoVersion}}
+ Git commit:     {{.Client.GitCommit}}
+ Built:          {{.Client.BuildTime}}
+ OS/Arch:        {{.Client.Os}}/{{.Client.Arch}}
+
+Server:
+ Version         {{.Server.Version}}
+ Python version: {{.Server.PythonVersion}}
+ Git commit:     {{.Server.GitCommit}}
+ Built:          {{.Server.BuildTime}}
+ OS/Arch:        {{.Server.Os}}/{{.Server.Arch}}
 `
 
 func (options *VersionOpts) Execute(args []string) error {
+	conn, err := NewConnection()
+	if err != nil {
+		return err
+	}
+	defer conn.Close()
+
+	descriptor, method, err := GetReflectionMethod(conn, "xos.utility.GetVersion")
+	if err != nil {
+		return err
+	}
+
+	ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Grpc.Timeout)
+	defer cancel()
+
+	headers := GenerateHeaders()
+
+	h := &RpcEventHandler{}
+	err = grpcurl.InvokeRPC(ctx, descriptor, conn, method, headers, h, h.GetParams)
+	if err != nil {
+		return err
+	}
+
+	if h.Status != nil && h.Status.Err() != nil {
+		return h.Status.Err()
+	}
+
+	d, err := dynamic.AsDynamicMessage(h.Response)
+	if err != nil {
+		return err
+	}
+
+	versionInfo.Server.Version = d.GetFieldByName("version").(string)
+	versionInfo.Server.PythonVersion = d.GetFieldByName("pythonVersion").(string)
+	versionInfo.Server.GitCommit = d.GetFieldByName("gitCommit").(string)
+	versionInfo.Server.BuildTime = d.GetFieldByName("buildTime").(string)
+	versionInfo.Server.Os = d.GetFieldByName("os").(string)
+	versionInfo.Server.Arch = d.GetFieldByName("arch").(string)
+
 	result := CommandResult{
 		Format:   format.Format(DefaultFormat),
 		OutputAs: toOutputType(options.OutputAs),