Skip to content
Snippets Groups Projects
Commit a64c843d authored by Malte Bauch's avatar Malte Bauch
Browse files

Add GetFlattenedOndList to api

parent a61dc8e0
Branches
No related tags found
2 merge requests!352Draft: Resolve "Structs like LoadedDevice, LoadedSbi, LoadedRole, LoadedUser are never passed as pointer",!347Resolve "Requesting information from the Controller via NBI takes very long"
Pipeline #109078 failed
......@@ -75,7 +75,8 @@ func (p *PndAdapter) GetDevice(ctx context.Context, identifier string) (*ppb.Get
}
// GetDevices requests all devices belonging to the PrincipalNetworkDomain
// attached to this adapter.
// attached to this adapter. The requested devices also contain their config
// information as gNMI notifications.
func (p *PndAdapter) GetDevices(ctx context.Context) (*ppb.GetOndListResponse, error) {
resp, err := api.GetDevices(ctx, p.endpoint, p.id.String())
if err != nil {
......@@ -84,6 +85,17 @@ func (p *PndAdapter) GetDevices(ctx context.Context) (*ppb.GetOndListResponse, e
return resp, nil
}
// GetFlattenedDevices requests all devices belonging to the PrincipalNetworkDomain
// attached to this adapter. The devices do not contain the config information
// as gNMI notifications.
func (p *PndAdapter) GetFlattenedDevices(ctx context.Context) (*ppb.GetFlattenedOndListResponse, error) {
resp, err := api.GetFlattenedDevices(ctx, p.endpoint, p.id.String())
if err != nil {
return nil, err
}
return resp, nil
}
// RemoveDevice removes a device from the controller
func (p *PndAdapter) RemoveDevice(ctx context.Context, did uuid.UUID) (*ppb.DeleteOndResponse, error) {
resp, err := api.DeleteDevice(ctx, p.endpoint, p.id.String(), did.String())
......
......@@ -47,7 +47,7 @@ var deviceListCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
spinner, _ := pterm.DefaultSpinner.Start("Fetching data from controller")
resp, err := pndAdapter.GetDevices(createContextWithAuthorization())
resp, err := pndAdapter.GetFlattenedDevices(createContextWithAuthorization())
if err != nil {
spinner.Fail(err)
return err
......
......@@ -240,7 +240,7 @@ func completionBasedOnCmd(c *PromptCompleter, cmd *cobra.Command, inputSplit []s
// the result is converted into a prompt.Suggest slice.
func getDevices() ([]prompt.Suggest, error) {
spinner, _ := pterm.DefaultSpinner.Start("Fetching devices from controller.")
resp, err := pndAdapter.GetDevices(createContextWithAuthorization())
resp, err := pndAdapter.GetFlattenedDevices(createContextWithAuthorization())
if err != nil {
spinner.Fail(err)
return []prompt.Suggest{}, err
......
......@@ -135,6 +135,22 @@ func GetDevices(ctx context.Context, addr, pid string) (*ppb.GetOndListResponse,
return pndClient.GetOndList(ctx, req)
}
// GetDevices requests all devices belonging to a given
// PrincipalNetworkDomain from the controller.
func GetFlattenedDevices(ctx context.Context, addr, pid string) (*ppb.GetFlattenedOndListResponse, error) {
pndClient, err := nbi.PndClient(addr, dialOptions...)
if err != nil {
return nil, err
}
req := &ppb.GetOndListRequest{
Timestamp: time.Now().UnixNano(),
Pid: pid,
}
return pndClient.GetFlattenedOndList(ctx, req)
}
// GetPath requests a specific path
func GetPath(ctx context.Context, addr, pid, did, path string) (*ppb.GetPathResponse, error) {
pndClient, err := nbi.PndClient(addr, dialOptions...)
......
......@@ -196,6 +196,7 @@ func ensureDefaultRoleExists() error {
"/gosdn.rbac.RoleService/DeleteRoles",
"/gosdn.pnd.PndService/GetOnd",
"/gosdn.pnd.PndService/GetOndList",
"/gosdn.pnd.PndService/GetFlattenedOndList",
"/gosdn.pnd.PndService/GetSbi",
"/gosdn.pnd.PndService/GetSbiList",
"/gosdn.pnd.PndService/GetPath",
......
......@@ -114,6 +114,47 @@ func (p PndServer) GetOndList(ctx context.Context, request *ppb.GetOndListReques
}, nil
}
// GetOndList returns a list of existing onds
func (p PndServer) GetFlattenedOndList(ctx context.Context, request *ppb.GetOndListRequest) (*ppb.GetFlattenedOndListResponse, error) {
labels := prometheus.Labels{"service": "pnd", "rpc": "get"}
start := metrics.StartHook(labels, grpcRequestsTotal)
defer metrics.FinishHook(labels, start, grpcRequestDurationSecondsTotal, grpcRequestDurationSeconds)
pid, err := uuid.Parse(request.Pid)
if err != nil {
return nil, handleRPCError(labels, err)
}
pnd, err := p.pndStore.Get(store.Query{ID: pid})
if err != nil {
log.Error(err)
return nil, status.Errorf(codes.Aborted, "%v", err)
}
onds := pnd.Devices()
ondsBySpecificPath := make([]*ppb.FlattenedOrchestratedNetworkingDevice, len(onds))
for i, ond := range onds {
ondFlattened := &ppb.FlattenedOrchestratedNetworkingDevice{
Id: ond.ID().String(),
Name: ond.Name(),
Sbi: &spb.SouthboundInterface{
Id: ond.SBI().ID().String(),
Type: ond.SBI().Type(),
},
}
ondsBySpecificPath[i] = ondFlattened
}
return &ppb.GetFlattenedOndListResponse{
Timestamp: time.Now().UnixNano(),
Pnd: &ppb.PrincipalNetworkDomain{
Id: pnd.ID().String(),
Name: pnd.GetName(),
Description: pnd.GetDescription(),
},
Ond: ondsBySpecificPath,
}, nil
}
func fillOndBySpecificPath(pnd networkdomain.NetworkDomain, d device.Device, path string) (*ppb.OrchestratedNetworkingDevice, error) {
gnmiPath, err := ygot.StringToStructuredPath(path)
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment