From 04c55e4fd54fb2dd44ea09e82725959d28f348fa Mon Sep 17 00:00:00 2001
From: Manuel Kieweg <manuel.kieweg@h-da.de>
Date: Wed, 9 Jun 2021 21:19:38 +0200
Subject: [PATCH] .

---
 cli/grpc.go      | 8 +++++---
 cmd/addDevice.go | 5 +++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/cli/grpc.go b/cli/grpc.go
index 1bd0218e0..ca9e4d48c 100644
--- a/cli/grpc.go
+++ b/cli/grpc.go
@@ -9,6 +9,7 @@ import (
 	spb "code.fbi.h-da.de/cocsn/api/go/gosdn/southbound"
 	tpb "code.fbi.h-da.de/cocsn/api/go/gosdn/transport"
 	nbi "code.fbi.h-da.de/cocsn/gosdn/northbound/client"
+	"github.com/google/uuid"
 	log "github.com/sirupsen/logrus"
 	"github.com/spf13/viper"
 
@@ -41,7 +42,7 @@ func Init(addr string) error {
 			log.Infof("SBI: %v", sbi)
 		}
 	}
-	return nil
+	return viper.WriteConfig()
 }
 
 // GetIds requests all UUID information from the controller
@@ -184,7 +185,7 @@ func AddDevice(addr, username, password, sbi, pnd, deviceAddress, deviceName str
 				},
 				DeviceName: deviceName,
 				TransportOption: &tpb.TransportOption{
-					Address:  addr,
+					Address:  deviceAddress,
 					Username: username,
 					Password: password,
 					TransportOption: &tpb.TransportOption_GnmiTransportOption{
@@ -196,7 +197,8 @@ func AddDevice(addr, username, password, sbi, pnd, deviceAddress, deviceName str
 		Pid: pnd,
 	}
 	if sbi == "csbi" {
-		req.Ond[0].Sbi = nil
+		req.Ond[0].Sbi.Id = uuid.Nil.String()
+		req.Ond[0].Sbi.Type = spb.Type_CONTAINERISED
 		req.Ond[0].TransportOption.Csbi = true
 	}
 	ctx := context.Background()
diff --git a/cmd/addDevice.go b/cmd/addDevice.go
index 2304e2214..53e458532 100644
--- a/cmd/addDevice.go
+++ b/cmd/addDevice.go
@@ -47,6 +47,9 @@ var addDeviceCmd = &cobra.Command{
 Device address and user credentials need to be provided
 if they diverge from the default credentials.`,
 	RunE: func(cmd *cobra.Command, args []string) error {
+		if csbi {
+			cliSbi = "csbi"
+		}
 		resp, err := cli.AddDevice(
 			apiEndpoint,
 			username,
@@ -65,9 +68,11 @@ if they diverge from the default credentials.`,
 }
 
 var deviceName string
+var csbi bool
 
 func init() {
 	cliCmd.AddCommand(addDeviceCmd)
 
 	addDeviceCmd.Flags().StringVar(&deviceName, "name", "", "add a device name (optional)")
+	addDeviceCmd.Flags().BoolVar(&csbi, "csbi", false, "add a csbi device")
 }
-- 
GitLab