diff --git a/api/grpc.go b/api/grpc.go index b237669d856798a5853bb2ef7201fbde11db5c15..d3a3a6d46032f44a31aa32cbcc8fd4336b12f889 100644 --- a/api/grpc.go +++ b/api/grpc.go @@ -36,11 +36,11 @@ func Init(addr string) error { pid := resp.Pnd[0].Id viper.Set("CLI_PND", pid) log.Infof("PND: %v", pid) - if len(resp.Pnd[0].Sbi) != 0 { - sbi := resp.Pnd[0].Sbi[0].Id - viper.Set("CLI_SBI", sbi) - log.Infof("SBI: %v", sbi) - } + // if len(resp.Pnd[0].Sbi) != 0 { + // sbi := resp.Pnd[0].Sbi[0].Id + // viper.Set("CLI_SBI", sbi) + // log.Infof("SBI: %v", sbi) + // } } return viper.WriteConfig() } @@ -55,29 +55,28 @@ func GetIds(addr string) ([]*ppb.PrincipalNetworkDomain, error) { return resp.Pnd, nil } -func getAllCore(ctx context.Context, addr string) (*pb.GetResponse, error) { +func getAllCore(ctx context.Context, addr string) (*pb.GetPndListResponse, error) { coreClient, err := nbi.CoreClient(addr, dialOptions...) if err != nil { return nil, err } - req := &pb.GetRequest{ + req := &pb.GetPndListRequest{ Timestamp: time.Now().UnixNano(), - All: true, } - return coreClient.Get(ctx, req) + return coreClient.GetPndList(ctx, req) } // AddPnd takes a name, description and SBI UUID to create a new // PrincipalNetworkDomain on the controller -func AddPnd(addr, name, description, sbi string) (*pb.SetResponse, error) { +func AddPnd(addr, name, description, sbi string) (*pb.CreatePndListResponse, error) { coreClient, err := nbi.CoreClient(addr, dialOptions...) if err != nil { return nil, err } ctx := context.Background() - req := &pb.SetRequest{ + req := &pb.CreatePndListRequest{ Timestamp: time.Now().UnixNano(), - Pnd: []*pb.SetPnd{ + Pnd: []*pb.PndCreateProperties{ { Name: name, Description: description, @@ -86,13 +85,12 @@ func AddPnd(addr, name, description, sbi string) (*pb.SetResponse, error) { }, } - return coreClient.Set(ctx, req) + return coreClient.CreatePndList(ctx, req) } -// GetPnd requests one or several PrincipalNetworkDomains from the -// controller. To request all PrincipalNetworkDomains without providing -// names or UUIDs use GetIds() -func GetPnd(addr string, args ...string) (*pb.GetResponse, error) { +// GetPnd requests one PrincipalNetworkDomain from the +// controller. +func GetPnd(addr string, args ...string) (*pb.GetPndResponse, error) { coreClient, err := nbi.CoreClient(addr, dialOptions...) if err != nil { return nil, err @@ -101,40 +99,52 @@ func GetPnd(addr string, args ...string) (*pb.GetResponse, error) { return nil, errors.New("not enough arguments") } ctx := context.Background() - req := &pb.GetRequest{ + req := &pb.GetPndRequest{ Timestamp: time.Now().UnixNano(), Pid: args, } - return coreClient.Get(ctx, req) + return coreClient.GetPnd(ctx, req) +} + +// GetPnds requests all PrincipalNetworkDomains from the +// controller. +func GetPnds(addr string, args ...string) (*pb.GetPndListResponse, error) { + coreClient, err := nbi.CoreClient(addr, dialOptions...) + if err != nil { + return nil, err + } + if len(args) <= 0 { + return nil, errors.New("not enough arguments") + } + ctx := context.Background() + req := &pb.GetPndListRequest{ + Timestamp: time.Now().UnixNano(), + } + return coreClient.GetPndList(ctx, req) } // getChanges requests all pending and unconfirmed changes from the controller -func getChanges(addr, pnd string) (*ppb.GetResponse, error) { +func getChanges(addr, pnd string) (*ppb.GetChangeListResponse, error) { ctx := context.Background() client, err := nbi.PndClient(addr, dialOptions...) if err != nil { return nil, err } - req := &ppb.GetRequest{ + req := &ppb.GetChangeListRequest{ Timestamp: time.Now().UnixNano(), - Request: &ppb.GetRequest_Change{ - Change: &ppb.GetChange{ - All: true, - }, - }, - Pid: pnd, + Pid: pnd, } - return client.Get(ctx, req) + return client.GetChangeList(ctx, req) } // commit sends a commit request for one or multiple changes to the // controller. -func commit(addr, pnd string, cuids ...string) (*ppb.SetResponse, error) { +func commit(addr, pnd string, cuids ...string) (*ppb.SetChangeListResponse, error) { changes := make([]*ppb.SetChange, len(cuids)) for i, arg := range cuids { changes[i] = &ppb.SetChange{ Cuid: arg, - Op: ppb.SetChange_COMMIT, + Op: ppb.Operation_OPERATION_COMMIT, } } return commitConfirm(addr, pnd, changes) @@ -142,40 +152,40 @@ func commit(addr, pnd string, cuids ...string) (*ppb.SetResponse, error) { // confirm sends a confirm request for one or multiple changes to the // controller -func confirm(addr, pnd string, cuids ...string) (*ppb.SetResponse, error) { +func confirm(addr, pnd string, cuids ...string) (*ppb.SetChangeListResponse, error) { changes := make([]*ppb.SetChange, len(cuids)) for i, arg := range cuids { changes[i] = &ppb.SetChange{ Cuid: arg, - Op: ppb.SetChange_CONFIRM, + Op: ppb.Operation_OPERATION_CONFIRM, } } return commitConfirm(addr, pnd, changes) } -func commitConfirm(addr, pnd string, changes []*ppb.SetChange) (*ppb.SetResponse, error) { +func commitConfirm(addr, pnd string, changes []*ppb.SetChange) (*ppb.SetChangeListResponse, error) { ctx := context.Background() client, err := nbi.PndClient(addr, dialOptions...) if err != nil { return nil, err } - req := &ppb.SetRequest{ + req := &ppb.SetChangeListRequest{ Timestamp: time.Now().UnixNano(), Change: changes, Pid: pnd, } - return client.Set(ctx, req) + return client.SetChangeList(ctx, req) } // addDevice adds a new device to the controller. The device name is optional. // If no name is provided a name will be generated upon device creation. -func addDevice(addr, deviceName string, opt *tpb.TransportOption, sid, pid uuid.UUID) (*ppb.SetResponse, error) { +func addDevice(addr, deviceName string, opt *tpb.TransportOption, sid, pid uuid.UUID) (*ppb.SetOndListResponse, error) { pndClient, err := nbi.PndClient(addr, dialOptions...) if err != nil { return nil, err } - req := &ppb.SetRequest{ + req := &ppb.SetOndListRequest{ Timestamp: time.Now().UnixNano(), Ond: []*ppb.SetOnd{ { @@ -197,80 +207,85 @@ func addDevice(addr, deviceName string, opt *tpb.TransportOption, sid, pid uuid. default: } ctx := context.Background() - return pndClient.Set(ctx, req) + return pndClient.SetOndList(ctx, req) } -// getDevice requests one or multiple devices belonging to a given +// getDevice requests one device belonging to a given // PrincipalNetworkDomain from the controller. If no device identifier -// is provided, all devices are requested. -func getDevice(addr, pid string, did ...string) (*ppb.GetResponse, error) { +// is provided, an error is thrown. +func getDevice(addr, pid string, did ...string) (*ppb.GetOndResponse, error) { pndClient, err := nbi.PndClient(addr, dialOptions...) if err != nil { return nil, err } - var all bool if len(did) == 0 { - all = true + return nil, err } - req := &ppb.GetRequest{ + req := &ppb.GetOndRequest{ Timestamp: time.Now().UnixNano(), - Request: &ppb.GetRequest_Ond{ - Ond: &ppb.GetOnd{ - All: all, - Did: did, - }, - }, - Pid: pid, + Did: did, + Pid: pid, } ctx := context.Background() - return pndClient.Get(ctx, req) + return pndClient.GetOnd(ctx, req) } -func getPath(addr, pid, did, path string) (*ppb.GetResponse, error) { +// getDevice requests all devices belonging to a given +// PrincipalNetworkDomain from the controller. +func getDevices(addr, pid string) (*ppb.GetOndListResponse, error) { pndClient, err := nbi.PndClient(addr, dialOptions...) if err != nil { return nil, err } - req := &ppb.GetRequest{ + req := &ppb.GetOndListRequest{ Timestamp: time.Now().UnixNano(), - Request: &ppb.GetRequest_Path{ - Path: &ppb.GetPath{ - Did: did, - Path: path, - }, - }, - Pid: pid, + Pid: pid, + } + ctx := context.Background() + return pndClient.GetOndList(ctx, req) +} + +func getPath(addr, pid, did, path string) (*ppb.GetPathResponse, error) { + pndClient, err := nbi.PndClient(addr, dialOptions...) + if err != nil { + return nil, err + } + + req := &ppb.GetPathRequest{ + Timestamp: time.Now().UnixNano(), + Did: did, + Pid: pid, + Path: path, } ctx := context.Background() - return pndClient.Get(ctx, req) + return pndClient.GetPath(ctx, req) } -func deleteDevice(addr, pid, did string) (*ppb.DeleteResponse, error) { +func deleteDevice(addr, pid, did string) (*ppb.DeleteOndResponse, error) { pndClient, err := nbi.PndClient(addr, dialOptions...) if err != nil { return nil, err } - req := &ppb.DeleteRequest{ + req := &ppb.DeleteOndRequest{ Timestamp: time.Now().UnixNano(), - Type: ppb.DeleteRequest_OND, - Uuid: did, + Did: did, Pid: pid, } ctx := context.Background() - return pndClient.Delete(ctx, req) + return pndClient.DeleteOnd(ctx, req) } // change creates a ChangeRequest for the specified OND. ApiOperations are // used to specify the type of the change (update, replace, delete as specified // in https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-specification.md#34-modifying-state) // For delete operations the value field needs to contain an empty string. -func changeRequest(addr, did, pid, path, value string, op ppb.ApiOperation) (*ppb.SetResponse, error) { +func changeRequest(addr, did, pid, path, value string, op ppb.ApiOperation) (*ppb.SetPathListResponse, error) { req := &ppb.ChangeRequest{ - Id: did, + Did: did, Path: path, Value: value, ApiOp: op, @@ -278,16 +293,16 @@ func changeRequest(addr, did, pid, path, value string, op ppb.ApiOperation) (*pp return sendChangeRequest(addr, pid, req) } -func sendChangeRequest(addr, pid string, req *ppb.ChangeRequest) (*ppb.SetResponse, error) { +func sendChangeRequest(addr, pid string, req *ppb.ChangeRequest) (*ppb.SetPathListResponse, error) { pndClient, err := nbi.PndClient(addr, dialOptions...) if err != nil { return nil, err } ctx := context.Background() - r := &ppb.SetRequest{ + r := &ppb.SetPathListRequest{ Timestamp: time.Now().UnixNano(), ChangeRequest: []*ppb.ChangeRequest{req}, Pid: pid, } - return pndClient.Set(ctx, r) + return pndClient.SetPathList(ctx, r) }