Skip to content
Snippets Groups Projects
Commit 82d5eb42 authored by Fabian Seidl's avatar Fabian Seidl Committed by Fabian Seidl
Browse files

updated api/grpc according to other api changes

parent f2e745bb
No related branches found
No related tags found
1 merge request!238Stfaseid http refactor
...@@ -36,11 +36,11 @@ func Init(addr string) error { ...@@ -36,11 +36,11 @@ func Init(addr string) error {
pid := resp.Pnd[0].Id pid := resp.Pnd[0].Id
viper.Set("CLI_PND", pid) viper.Set("CLI_PND", pid)
log.Infof("PND: %v", pid) log.Infof("PND: %v", pid)
if len(resp.Pnd[0].Sbi) != 0 { // if len(resp.Pnd[0].Sbi) != 0 {
sbi := resp.Pnd[0].Sbi[0].Id // sbi := resp.Pnd[0].Sbi[0].Id
viper.Set("CLI_SBI", sbi) // viper.Set("CLI_SBI", sbi)
log.Infof("SBI: %v", sbi) // log.Infof("SBI: %v", sbi)
} // }
} }
return viper.WriteConfig() return viper.WriteConfig()
} }
...@@ -55,29 +55,28 @@ func GetIds(addr string) ([]*ppb.PrincipalNetworkDomain, error) { ...@@ -55,29 +55,28 @@ func GetIds(addr string) ([]*ppb.PrincipalNetworkDomain, error) {
return resp.Pnd, nil 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...) coreClient, err := nbi.CoreClient(addr, dialOptions...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
req := &pb.GetRequest{ req := &pb.GetPndListRequest{
Timestamp: time.Now().UnixNano(), 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 // AddPnd takes a name, description and SBI UUID to create a new
// PrincipalNetworkDomain on the controller // 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...) coreClient, err := nbi.CoreClient(addr, dialOptions...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
ctx := context.Background() ctx := context.Background()
req := &pb.SetRequest{ req := &pb.CreatePndListRequest{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
Pnd: []*pb.SetPnd{ Pnd: []*pb.PndCreateProperties{
{ {
Name: name, Name: name,
Description: description, Description: description,
...@@ -86,13 +85,12 @@ func AddPnd(addr, name, description, sbi string) (*pb.SetResponse, error) { ...@@ -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 // GetPnd requests one PrincipalNetworkDomain from the
// controller. To request all PrincipalNetworkDomains without providing // controller.
// names or UUIDs use GetIds() func GetPnd(addr string, args ...string) (*pb.GetPndResponse, error) {
func GetPnd(addr string, args ...string) (*pb.GetResponse, error) {
coreClient, err := nbi.CoreClient(addr, dialOptions...) coreClient, err := nbi.CoreClient(addr, dialOptions...)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -101,40 +99,52 @@ func GetPnd(addr string, args ...string) (*pb.GetResponse, error) { ...@@ -101,40 +99,52 @@ func GetPnd(addr string, args ...string) (*pb.GetResponse, error) {
return nil, errors.New("not enough arguments") return nil, errors.New("not enough arguments")
} }
ctx := context.Background() ctx := context.Background()
req := &pb.GetRequest{ req := &pb.GetPndRequest{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
Pid: args, 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 // 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() ctx := context.Background()
client, err := nbi.PndClient(addr, dialOptions...) client, err := nbi.PndClient(addr, dialOptions...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
req := &ppb.GetRequest{ req := &ppb.GetChangeListRequest{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
Request: &ppb.GetRequest_Change{ Pid: pnd,
Change: &ppb.GetChange{
All: true,
},
},
Pid: pnd,
} }
return client.Get(ctx, req) return client.GetChangeList(ctx, req)
} }
// commit sends a commit request for one or multiple changes to the // commit sends a commit request for one or multiple changes to the
// controller. // 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)) changes := make([]*ppb.SetChange, len(cuids))
for i, arg := range cuids { for i, arg := range cuids {
changes[i] = &ppb.SetChange{ changes[i] = &ppb.SetChange{
Cuid: arg, Cuid: arg,
Op: ppb.SetChange_COMMIT, Op: ppb.Operation_OPERATION_COMMIT,
} }
} }
return commitConfirm(addr, pnd, changes) return commitConfirm(addr, pnd, changes)
...@@ -142,40 +152,40 @@ func commit(addr, pnd string, cuids ...string) (*ppb.SetResponse, error) { ...@@ -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 // confirm sends a confirm request for one or multiple changes to the
// controller // 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)) changes := make([]*ppb.SetChange, len(cuids))
for i, arg := range cuids { for i, arg := range cuids {
changes[i] = &ppb.SetChange{ changes[i] = &ppb.SetChange{
Cuid: arg, Cuid: arg,
Op: ppb.SetChange_CONFIRM, Op: ppb.Operation_OPERATION_CONFIRM,
} }
} }
return commitConfirm(addr, pnd, changes) 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() ctx := context.Background()
client, err := nbi.PndClient(addr, dialOptions...) client, err := nbi.PndClient(addr, dialOptions...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
req := &ppb.SetRequest{ req := &ppb.SetChangeListRequest{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
Change: changes, Change: changes,
Pid: pnd, 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. // 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. // 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...) pndClient, err := nbi.PndClient(addr, dialOptions...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
req := &ppb.SetRequest{ req := &ppb.SetOndListRequest{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
Ond: []*ppb.SetOnd{ Ond: []*ppb.SetOnd{
{ {
...@@ -197,80 +207,85 @@ func addDevice(addr, deviceName string, opt *tpb.TransportOption, sid, pid uuid. ...@@ -197,80 +207,85 @@ func addDevice(addr, deviceName string, opt *tpb.TransportOption, sid, pid uuid.
default: default:
} }
ctx := context.Background() 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 // PrincipalNetworkDomain from the controller. If no device identifier
// is provided, all devices are requested. // is provided, an error is thrown.
func getDevice(addr, pid string, did ...string) (*ppb.GetResponse, error) { func getDevice(addr, pid string, did ...string) (*ppb.GetOndResponse, error) {
pndClient, err := nbi.PndClient(addr, dialOptions...) pndClient, err := nbi.PndClient(addr, dialOptions...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var all bool
if len(did) == 0 { if len(did) == 0 {
all = true return nil, err
} }
req := &ppb.GetRequest{ req := &ppb.GetOndRequest{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
Request: &ppb.GetRequest_Ond{ Did: did,
Ond: &ppb.GetOnd{ Pid: pid,
All: all,
Did: did,
},
},
Pid: pid,
} }
ctx := context.Background() 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...) pndClient, err := nbi.PndClient(addr, dialOptions...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
req := &ppb.GetRequest{ req := &ppb.GetOndListRequest{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
Request: &ppb.GetRequest_Path{ Pid: pid,
Path: &ppb.GetPath{ }
Did: did, ctx := context.Background()
Path: path, return pndClient.GetOndList(ctx, req)
}, }
},
Pid: pid, 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() 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...) pndClient, err := nbi.PndClient(addr, dialOptions...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
req := &ppb.DeleteRequest{ req := &ppb.DeleteOndRequest{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
Type: ppb.DeleteRequest_OND, Did: did,
Uuid: did,
Pid: pid, Pid: pid,
} }
ctx := context.Background() ctx := context.Background()
return pndClient.Delete(ctx, req) return pndClient.DeleteOnd(ctx, req)
} }
// change creates a ChangeRequest for the specified OND. ApiOperations are // change creates a ChangeRequest for the specified OND. ApiOperations are
// used to specify the type of the change (update, replace, delete as specified // 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) // 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. // 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{ req := &ppb.ChangeRequest{
Id: did, Did: did,
Path: path, Path: path,
Value: value, Value: value,
ApiOp: op, ApiOp: op,
...@@ -278,16 +293,16 @@ func changeRequest(addr, did, pid, path, value string, op ppb.ApiOperation) (*pp ...@@ -278,16 +293,16 @@ func changeRequest(addr, did, pid, path, value string, op ppb.ApiOperation) (*pp
return sendChangeRequest(addr, pid, req) 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...) pndClient, err := nbi.PndClient(addr, dialOptions...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
ctx := context.Background() ctx := context.Background()
r := &ppb.SetRequest{ r := &ppb.SetPathListRequest{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
ChangeRequest: []*ppb.ChangeRequest{req}, ChangeRequest: []*ppb.ChangeRequest{req},
Pid: pid, Pid: pid,
} }
return pndClient.Set(ctx, r) return pndClient.SetPathList(ctx, r)
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment