Skip to content
Snippets Groups Projects
Commit d5c5efbd authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

cli documentation

parent 5cdce8ca
Branches
Tags
1 merge request!90Develop
...@@ -9,11 +9,13 @@ import ( ...@@ -9,11 +9,13 @@ import (
"strings" "strings"
) )
func Capabilities() error { // Capabilities sends a gNMI Capabilities request to the specified target
// and prints the supported models to stdout
func Capabilities(a, u , p string) error {
cfg := gnmi.Config{ cfg := gnmi.Config{
Addr: "portainer.danet.fbi.h-da.de:6030", Addr: a,
Username: "admin", Username: u,
Password: "arista", Password: p,
Encoding: gpb.Encoding_JSON_IETF, Encoding: gpb.Encoding_JSON_IETF,
} }
opts := &nucleus.GnmiTransportOptions{Config: cfg} opts := &nucleus.GnmiTransportOptions{Config: cfg}
......
...@@ -3,54 +3,31 @@ package cli ...@@ -3,54 +3,31 @@ package cli
import ( import (
"code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi" "code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi"
"code.fbi.h-da.de/cocsn/gosdn/nucleus" "code.fbi.h-da.de/cocsn/gosdn/nucleus"
"github.com/google/uuid" "context"
gpb "github.com/openconfig/gnmi/proto/gnmi" gpb "github.com/openconfig/gnmi/proto/gnmi"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
/* // Get sends a gNMI Get request to the specified target and prints the response to stdout
Simple gnmi request program. Use with cauton and leaf paths only. func Get(a, u, p string, args...string) error {
Bootstrapping of pnd, device and transport simplified not idiomatic
*/
func Get() error {
sbi := &nucleus.OpenConfig{} sbi := &nucleus.OpenConfig{}
opts := &nucleus.GnmiTransportOptions{ opts := &nucleus.GnmiTransportOptions{
Config: gnmi.Config{ Config: gnmi.Config{
Addr: "portainer.danet.fbi.h-da.de:6030", Addr: a,
Username: "admin", Username: u,
Password: "arista", Password: p,
Encoding: gpb.Encoding_JSON_IETF, Encoding: gpb.Encoding_JSON_IETF,
}, },
SetNode: sbi.SetNode(), SetNode: sbi.SetNode(),
} }
device, err := nucleus.NewDevice(sbi, opts) t, err := nucleus.NewGnmiTransport(opts)
if err != nil { if err != nil {
return err return err
} }
pnd, err := nucleus.NewPND("openconfig", "test description", uuid.New(), sbi) resp, err := t.Get(context.Background(), args...)
if err != nil { if err != nil {
return err return err
} }
if err := pnd.AddDevice(device); err != nil { log.Info(resp)
return err
}
p := []string{"/interfaces/interface"}
errors := 0
for _, path := range p {
err := pnd.RequestAll(path)
if err != nil {
log.Debug(err)
errors++
break
}
}
percentage := float64(errors) / float64(len(p)) * 100.0
if errors != 0 {
log.Error("%v errors", errors)
log.Error("%v percent failed", percentage)
}
return nil return nil
} }
...@@ -6,11 +6,11 @@ import ( ...@@ -6,11 +6,11 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
var schema *ytypes.Schema var testSchema *ytypes.Schema
func init(){ func init(){
var err error var err error
schema, err = model.Schema() testSchema, err = model.Schema()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
func PathTraversal() error { func PathTraversal() error {
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)
paths, err := path.ParseSchema(schema, "device") paths, err := path.ParseSchema(testSchema, "device")
if err != nil { if err != nil {
return err return err
} }
......
...@@ -6,20 +6,16 @@ import ( ...@@ -6,20 +6,16 @@ import (
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util/proto" "code.fbi.h-da.de/cocsn/gosdn/nucleus/util/proto"
"context" "context"
pb "google.golang.org/protobuf/proto" pb "google.golang.org/protobuf/proto"
"os"
) )
func Set() error { // Set sends a gNMI Set request to the specified target. Only one
a := os.Getenv("GOSDN_TEST_ENDPOINT") // request per invocation supported.
if a == "" { func Set(a, u, p, typ string, args ...string) error {
a = "portainer.danet.fbi.h-da.de:6030"
}
opts := &nucleus.GnmiTransportOptions{ opts := &nucleus.GnmiTransportOptions{
Config: gnmi.Config{ Config: gnmi.Config{
Addr: a, Addr: a,
Username: "admin", Username: u,
Password: "arista", Password: p,
}, },
} }
t, err := nucleus.NewGnmiTransport(opts) t, err := nucleus.NewGnmiTransport(opts)
...@@ -27,21 +23,18 @@ func Set() error { ...@@ -27,21 +23,18 @@ func Set() error {
return err return err
} }
reqs := []interface{}{ path := gnmi.SplitPath(args[0])
req := []interface{}{
&gnmi.Operation{ &gnmi.Operation{
Type: "update", Type: typ,
Origin: "", Origin: "",
Target: "", Target: "",
Path: []string{ Path: path,
"system", Val: args[1],
"config",
"hostname",
},
Val: "ceos3000",
}, },
} }
resp, err := t.Set(context.Background(), reqs...) resp, err := t.Set(context.Background(), req...)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"code.fbi.h-da.de/cocsn/gosdn/nucleus" "code.fbi.h-da.de/cocsn/gosdn/nucleus"
"context" "context"
"fmt" "fmt"
"github.com/google/uuid"
gpb "github.com/openconfig/gnmi/proto/gnmi" gpb "github.com/openconfig/gnmi/proto/gnmi"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"os" "os"
...@@ -13,46 +12,38 @@ import ( ...@@ -13,46 +12,38 @@ import (
"syscall" "syscall"
"time" "time"
) )
// Subscribe starts a gNMI subscriber requersting the specified paths on the target and
func Subscribe() error{ // logs the response to stdout. Only 'stream' mode with 'sample' operation supported.
func Subscribe(a, u, p string, sample, heartbeat int64, args...string) error{
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)
sbi := &nucleus.OpenConfig{} sbi := &nucleus.OpenConfig{}
tOpts := &nucleus.GnmiTransportOptions{
device, err := nucleus.NewDevice(sbi, Config: gnmi.Config{
&nucleus.GnmiTransportOptions{ Addr: a,
Config: gnmi.Config{ Username: u,
Addr: "portainer.danet.fbi.h-da.de:6030", Password: p,
Username: "admin", Encoding: gpb.Encoding_JSON_IETF,
Password: "arista", },
Encoding: gpb.Encoding_JSON_IETF, SetNode: sbi.SetNode(),
}, RespChan: make(chan *gpb.SubscribeResponse),
SetNode: sbi.SetNode(),
RespChan: make(chan *gpb.SubscribeResponse),
})
if err != nil {
return err
} }
pnd, err := nucleus.NewPND("openconfig", "a simple openconfig PND", uuid.New(), sbi)
device, err := nucleus.NewDevice(sbi,tOpts)
if err != nil { if err != nil {
return err return err
} }
if err := pnd.AddDevice(device); err != nil {
return err
}
paths := []string{"/interfaces/interface/name"}
opts := &gnmi.SubscribeOptions{ opts := &gnmi.SubscribeOptions{
UpdatesOnly: false, UpdatesOnly: false,
Prefix: "", Prefix: "",
Mode: "stream", Mode: "stream",
StreamMode: "sample", StreamMode: "sample",
SampleInterval: uint64(10 * time.Second.Nanoseconds()), SampleInterval: uint64(sample * time.Second.Nanoseconds()),
SuppressRedundant: false, SuppressRedundant: false,
HeartbeatInterval: uint64(time.Second.Nanoseconds()), HeartbeatInterval: uint64(heartbeat * time.Second.Nanoseconds()),
Paths: gnmi.SplitPaths(paths), Paths: gnmi.SplitPaths(args),
Origin: "", Origin: "",
Target: "portainer.danet.fbi.h-da.de:6030", Target: a,
} }
done := make(chan os.Signal, 1) done := make(chan os.Signal, 1)
signal.Notify(done, syscall.SIGILL, syscall.SIGTERM) signal.Notify(done, syscall.SIGILL, syscall.SIGTERM)
......
...@@ -2,12 +2,12 @@ package cli ...@@ -2,12 +2,12 @@ package cli
import ( import (
"code.fbi.h-da.de/cocsn/gosdn/forks/google/gnmi" "code.fbi.h-da.de/cocsn/gosdn/forks/google/gnmi"
"code.fbi.h-da.de/cocsn/gosdn/forks/google/gnmi/modeldata" oc "code.fbi.h-da.de/cocsn/yang-models/generated/openconfig"
oc "code.fbi.h-da.de/cocsn/yang-models/generated/arista"
"context" "context"
"flag"
"github.com/google/gnxi/utils/credentials" "github.com/google/gnxi/utils/credentials"
pb "github.com/openconfig/gnmi/proto/gnmi" pb "github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/goyang/pkg/yang"
"github.com/openconfig/ygot/util"
"github.com/openconfig/ygot/ygot" "github.com/openconfig/ygot/ygot"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"google.golang.org/grpc" "google.golang.org/grpc"
...@@ -18,10 +18,6 @@ import ( ...@@ -18,10 +18,6 @@ import (
"reflect" "reflect"
) )
var (
bindAddr = flag.String("bind_address", ":9339", "Bind to address:port or just :port")
)
type server struct { type server struct {
*gnmi.Server *gnmi.Server
} }
...@@ -65,10 +61,20 @@ func (s *server) Set(ctx context.Context, req *pb.SetRequest) (*pb.SetResponse, ...@@ -65,10 +61,20 @@ func (s *server) Set(ctx context.Context, req *pb.SetRequest) (*pb.SetResponse,
} }
*/ */
func Target() error { // Target starts a gNMI target listening on the specified port.
func Target(bindAddr string) error {
entries := make([]*yang.Entry, 0)
for _,e := range oc.SchemaTree {
entries = append(entries, e)
}
modelData, err := util.FindModelData(entries)
if err != nil {
return err
}
// Google stuff from here // Google stuff from here
model := gnmi.NewModel(modeldata.ModelData, model := gnmi.NewModel(
modelData,
reflect.TypeOf((*oc.Device)(nil)), reflect.TypeOf((*oc.Device)(nil)),
oc.SchemaTree["Device"], oc.SchemaTree["Device"],
oc.Unmarshal, oc.Unmarshal,
...@@ -84,8 +90,8 @@ func Target() error { ...@@ -84,8 +90,8 @@ func Target() error {
pb.RegisterGNMIServer(g, s) pb.RegisterGNMIServer(g, s)
reflection.Register(g) reflection.Register(g)
log.Infof("starting to listen on %s", *bindAddr) log.Infof("starting to listen on %s", bindAddr)
listen, err := net.Listen("tcp", *bindAddr) listen, err := net.Listen("tcp", bindAddr)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
) )
func LeafPaths() error { func LeafPaths() error {
for _,v := range schema.SchemaTree { for _,v := range testSchema.SchemaTree {
entry, err := util.FindLeafRefSchema(v, "/interface/") entry, err := util.FindLeafRefSchema(v, "/interface/")
if err != nil { if err != nil {
log.Error(err) log.Error(err)
......
...@@ -38,15 +38,11 @@ import ( ...@@ -38,15 +38,11 @@ import (
// capabilitiesCmd represents the capabilities command // capabilitiesCmd represents the capabilities command
var capabilitiesCmd = &cobra.Command{ var capabilitiesCmd = &cobra.Command{
Use: "capabilities", Use: "capabilities",
Short: "A brief description of your command", Short: "capabilities request",
Long: `A longer description that spans multiple lines and likely contains examples Long: `Sends a gNMI Capabilities request to the specified target
and usage of using your command. For example: // and prints the supported models to stdout.`,
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.Capabilities() return cli.Capabilities(username, password, address)
}, },
} }
......
...@@ -37,29 +37,14 @@ import ( ...@@ -37,29 +37,14 @@ import (
// getCmd represents the get command // getCmd represents the get command
var getCmd = &cobra.Command{ var getCmd = &cobra.Command{
Use: "get", Use: "gosdn get",
Short: "A brief description of your command", Short: "get request",
Long: `A longer description that spans multiple lines and likely contains examples Long: `Sends a gNMI Get request to the specified target and prints the response to stdout`,
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.Get() return cli.Get(address, username, password, args...)
}, },
} }
func init() { func init() {
rootCmd.AddCommand(getCmd) rootCmd.AddCommand(getCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// getCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// getCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
} }
...@@ -31,35 +31,20 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -31,35 +31,20 @@ POSSIBILITY OF SUCH DAMAGE.
package cmd package cmd
import ( import (
"code.fbi.h-da.de/cocsn/gosdn/cli" "errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// legacyCmd represents the legacy command // legacyCmd represents the legacy command
var legacyCmd = &cobra.Command{ var legacyCmd = &cobra.Command{
Use: "legacy", Use: "legacy",
Short: "A brief description of your command", Short: "multiple ygot utils - not yet implemented",
Long: `A longer description that spans multiple lines and likely contains examples Long: ``,
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.PathTraversal() return errors.New("not implemented")
}, },
} }
func init() { func init() {
pathCmd.AddCommand(legacyCmd) pathCmd.AddCommand(legacyCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// legacyCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// legacyCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
} }
...@@ -38,28 +38,13 @@ import ( ...@@ -38,28 +38,13 @@ import (
// pathCmd represents the path command // pathCmd represents the path command
var pathCmd = &cobra.Command{ var pathCmd = &cobra.Command{
Use: "path", Use: "path",
Short: "A brief description of your command", Short: "multiple ygot utils - not yet implemented",
Long: `A longer description that spans multiple lines and likely contains examples Long: ``,
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("path needs either [ygot] or [legacy] command") return errors.New("not implemented")
}, },
} }
func init() { func init() {
rootCmd.AddCommand(pathCmd) rootCmd.AddCommand(pathCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// pathCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// pathCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
} }
...@@ -31,8 +31,9 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -31,8 +31,9 @@ POSSIBILITY OF SUCH DAMAGE.
package cmd package cmd
import ( import (
"code.fbi.h-da.de/cocsn/gosdn/cli" "code.fbi.h-da.de/cocsn/gosdn/nucleus"
"fmt" "fmt"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"os" "os"
...@@ -41,20 +42,19 @@ import ( ...@@ -41,20 +42,19 @@ import (
var cfgFile string var cfgFile string
var username string
var password string
var address string
// rootCmd represents the base command when called without any subcommands // rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
Use: "gosdn", Use: "gosdn",
Short: "A brief description of your application", Short: "starts the gosdn controller",
Long: `A longer description that spans multiple lines and likely contains Long: `Set GOSDN_DEBUG environment variable to enalbe debug logging.`,
examples and usage of using your application. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.Gosdn() rc := make(chan bool)
return nucleus.StartAndRun(rc)
}, },
} }
...@@ -75,11 +75,9 @@ func init() { ...@@ -75,11 +75,9 @@ func init() {
// will be global for your application. // will be global for your application.
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./configs/gosdn.toml)") 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")
// Cobra also supports local flags, which will only run rootCmd.PersistentFlags().StringVarP(&username, "address", "a", "ceos-cocsn.apps.ocp.fbi.h-da.de:6030", "address to a gnmi resource")
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
} }
...@@ -99,5 +97,8 @@ func initConfig() { ...@@ -99,5 +97,8 @@ func initConfig() {
if err := viper.ReadInConfig(); err == nil { if err := viper.ReadInConfig(); err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed()) fmt.Println("Using config file:", viper.ConfigFileUsed())
} }
if viper.IsSet("GOSDN_DEBUG") {
log.SetLevel(log.DebugLevel)
}
} }
...@@ -35,31 +35,22 @@ import ( ...@@ -35,31 +35,22 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var typ string
// setCmd represents the set command // setCmd represents the set command
var setCmd = &cobra.Command{ var setCmd = &cobra.Command{
Use: "set", Use: "set",
Short: "A brief description of your command", Short: "set request",
Long: `A longer description that spans multiple lines and likely contains examples Long: `Sends a gNMI Set request to the specified target. Only one
and usage of using your command. For example: request per invocation supported.`,
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.Set() return cli.Set(address, username, password, typ, args...)
}, },
} }
func init() { func init() {
rootCmd.AddCommand(setCmd) rootCmd.AddCommand(setCmd)
// Here you will define your flags and configuration settings. setCmd.Flags().StringVarP(&typ, "type", "t", "update", "Type of the set request. " +
"Possible values: 'update', 'replace', and 'delete'")
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// setCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// setCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
} }
...@@ -35,31 +35,24 @@ import ( ...@@ -35,31 +35,24 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var sampleInterval int64
var heartbeatInterval int64
// subscribeCmd represents the subscribe command // subscribeCmd represents the subscribe command
var subscribeCmd = &cobra.Command{ var subscribeCmd = &cobra.Command{
Use: "subscribe", Use: "subscribe",
Short: "A brief description of your command", Short: "subscribe to target",
Long: `A longer description that spans multiple lines and likely contains examples Long: `Starts a gNMI subscriber requersting the specified paths on the target and logs the response to stdout.
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications. Only 'stream' mode with 'sample' operation supported.`,
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.Subscribe() return cli.Subscribe(address, username, password, sampleInterval, heartbeatInterval, args...)
}, },
} }
func init() { func init() {
rootCmd.AddCommand(subscribeCmd) rootCmd.AddCommand(subscribeCmd)
// Here you will define your flags and configuration settings. subscribeCmd.Flags().Int64Var(&sampleInterval, "sample-rate", 5, "Sample rate per second.")
subscribeCmd.Flags().Int64Var(&heartbeatInterval, "heartbeat-rate", 1, "Heartbeat rate per second.")
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// subscribeCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// subscribeCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
} }
...@@ -36,31 +36,20 @@ import ( ...@@ -36,31 +36,20 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var bindAddr string
// targetCmd represents the target command // targetCmd represents the target command
var targetCmd = &cobra.Command{ var targetCmd = &cobra.Command{
Use: "target", Use: "target",
Short: "A brief description of your command", Short: "start gnmi target",
Long: `A longer description that spans multiple lines and likely contains examples Long: `Starts a gNMI target listening on the specified port.`,
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.Target() return cli.Target(bindAddr)
}, },
} }
func init() { func init() {
rootCmd.AddCommand(targetCmd) rootCmd.AddCommand(targetCmd)
// Here you will define your flags and configuration settings. targetCmd.Flags().StringVar(&bindAddr, "bind-address", ":9339", "listen address of the target: [address]:port")
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// targetCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// targetCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
} }
...@@ -31,35 +31,20 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -31,35 +31,20 @@ POSSIBILITY OF SUCH DAMAGE.
package cmd package cmd
import ( import (
"code.fbi.h-da.de/cocsn/gosdn/cli" "errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// utilCmd represents the util command // utilCmd represents the util command
var utilCmd = &cobra.Command{ var utilCmd = &cobra.Command{
Use: "util", Use: "util",
Short: "A brief description of your command", Short: "multiple ygot utils - not yet implemented",
Long: `A longer description that spans multiple lines and likely contains examples Long: ``,
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.LeafPaths() return errors.New("not implemented")
}, },
} }
func init() { func init() {
ygotCmd.AddCommand(utilCmd) ygotCmd.AddCommand(utilCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// utilCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// utilCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
} }
...@@ -39,13 +39,8 @@ import ( ...@@ -39,13 +39,8 @@ import (
// ygotCmd represents the ygot command // ygotCmd represents the ygot command
var ygotCmd = &cobra.Command{ var ygotCmd = &cobra.Command{
Use: "ygot", Use: "ygot",
Short: "A brief description of your command", Short: "multiple ygot utils - not yet implemented",
Long: `A longer description that spans multiple lines and likely contains examples Long: ``,
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("not implemented") return errors.New("not implemented")
}, },
...@@ -53,14 +48,4 @@ to quickly create a Cobra application.`, ...@@ -53,14 +48,4 @@ to quickly create a Cobra application.`,
func init() { func init() {
rootCmd.AddCommand(ygotCmd) rootCmd.AddCommand(ygotCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// ygotCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// ygotCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
} }
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
//StartAndRun is used to start the core of the controller and any auxiliary services. //StartAndRun starts the gosdn core and auxiliary services.
func StartAndRun(IsRunningChannel chan bool) error { func StartAndRun(IsRunningChannel chan bool) error {
log.Info("This is the network superintendent...") log.Info("This is the network superintendent...")
log.Info("Starting my ducks") log.Info("Starting my ducks")
...@@ -16,7 +16,6 @@ func StartAndRun(IsRunningChannel chan bool) error { ...@@ -16,7 +16,6 @@ func StartAndRun(IsRunningChannel chan bool) error {
if err := core.Initialize(IsRunningChannel); err != nil { if err := core.Initialize(IsRunningChannel); err != nil {
return err return err
} }
// Start the GRCP CLI
go core.Shutdown() go core.Shutdown()
log.Info("and ready for take off") log.Info("and ready for take off")
......
...@@ -2,9 +2,10 @@ package test ...@@ -2,9 +2,10 @@ package test
import ( import (
"code.fbi.h-da.de/cocsn/gosdn/forks/google/gnmi" "code.fbi.h-da.de/cocsn/gosdn/forks/google/gnmi"
"code.fbi.h-da.de/cocsn/gosdn/forks/google/gnmi/modeldata"
oc "code.fbi.h-da.de/cocsn/yang-models/generated/arista" oc "code.fbi.h-da.de/cocsn/yang-models/generated/arista"
pb "github.com/openconfig/gnmi/proto/gnmi" pb "github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/goyang/pkg/yang"
"github.com/openconfig/ygot/util"
"github.com/openconfig/ygot/ygot" "github.com/openconfig/ygot/ygot"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"google.golang.org/grpc" "google.golang.org/grpc"
...@@ -62,8 +63,19 @@ func GnmiTarget(stop chan bool, bindAddr string) error { ...@@ -62,8 +63,19 @@ func GnmiTarget(stop chan bool, bindAddr string) error {
bindAddr = "localhost:13371" bindAddr = "localhost:13371"
} }
entries := make([]*yang.Entry, 0)
for _,e := range oc.SchemaTree {
entries = append(entries, e)
}
modelData, err := util.FindModelData(entries)
if err != nil {
return err
}
// Google stuff from here // Google stuff from here
model := gnmi.NewModel(modeldata.ModelData, model := gnmi.NewModel(
modelData,
reflect.TypeOf((*oc.Device)(nil)), reflect.TypeOf((*oc.Device)(nil)),
oc.SchemaTree["Device"], oc.SchemaTree["Device"],
oc.Unmarshal, oc.Unmarshal,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment