Skip to content
Snippets Groups Projects
Commit 2fbf71a3 authored by Fabian Seidl's avatar Fabian Seidl
Browse files

fix adding subscriptions

parent 1856c2c0
No related branches found
No related tags found
No related merge requests found
Pipeline #228785 passed
......@@ -46,10 +46,10 @@ var subAddCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
spinner, _ := pterm.DefaultSpinner.Start("Adding subscription")
// TODO: add option to provide sub options??
// Note: Currently, doesn't support providing options/paths.
_, err := api.Add(createContextWithAuthorization(), viper.GetString("controllerAPIEndpoint"), mneUUID, nil)
if err != nil {
pterm.Error.Println(err)
spinner.Fail(err)
return
}
spinner.Success()
......
......@@ -138,22 +138,26 @@ func (s *SubManagementServer) Add(ctx context.Context, request *subpb.AddRequest
}, err
}
var paths [][]string
for _, path := range request.Subscription.Paths {
var elems []string
for _, elem := range path.Elem {
elems = append(elems, elem)
var gNMISubScribeOptions *gnmi.SubscribeOptions
if request.Subscription != nil {
var paths [][]string
for _, path := range request.Subscription.Paths {
var elems []string
for _, elem := range path.Elem {
elems = append(elems, elem)
}
paths = append(paths, elems)
}
paths = append(paths, elems)
}
err = s.networkElementWatchter.SubscribeToNetworkElementWithID(mneID,
&gnmi.SubscribeOptions{
gNMISubScribeOptions = &gnmi.SubscribeOptions{
Mode: request.Subscription.SubscribeOptions.GnmiMode,
StreamMode: request.Subscription.SubscribeOptions.GnmiStreamMode,
SampleInterval: request.Subscription.SubscribeOptions.SampleInterval,
Paths: paths,
},
}
}
err = s.networkElementWatchter.SubscribeToNetworkElementWithID(mneID,
gNMISubScribeOptions,
)
if err != nil {
return &subpb.AddResponse{
......
......@@ -108,6 +108,14 @@ func (n *NetworkElementWatcher) SubscribeToNetworkElement(mne networkelement.Net
// SubscribeToNetworkElementWithID subscribes to the network element matching the provided ID according to provided SubscribeOptions.
// SubscribeOptions can be nil. Use nil for a fixed, pre-defined set of gNMI subscription options (streaming in sample mode each second).
func (n *NetworkElementWatcher) SubscribeToNetworkElementWithID(mneID uuid.UUID, opts *gnmi.SubscribeOptions) error {
if opts == nil {
opts = &gnmi.SubscribeOptions{
Mode: gNMISubscribeMode,
StreamMode: gNMIStreamMode,
SampleInterval: subscribeSampleInterval,
}
}
mne, err := n.mneService.Get(store.Query{ID: mneID})
if err != nil {
log.Error(err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment