Skip to content
Snippets Groups Projects
pnd.go 1.96 KiB
Newer Older
  • Learn to ignore specific revisions
  • package api
    
    import (
    	"context"
    	"errors"
    	"time"
    
    	pb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/core"
    	nbi "code.fbi.h-da.de/danet/gosdn/controller/northbound/client"
    )
    
    // AddPnd takes a name, description and SBI UUID to create a new
    // PrincipalNetworkDomain on the controller
    func AddPnd(ctx context.Context, addr, name, description, sbi string) (*pb.CreatePndListResponse, error) {
    	coreClient, err := nbi.CoreClient(addr, dialOptions...)
    	if err != nil {
    		return nil, err
    	}
    
    	req := &pb.CreatePndListRequest{
    		Timestamp: time.Now().UnixNano(),
    		Pnd: []*pb.PndCreateProperties{
    			{
    				Name:        name,
    				Description: description,
    				Sbi:         sbi,
    			},
    		},
    	}
    
    	return coreClient.CreatePndList(ctx, req)
    }
    
    // GetPnd requests one PrincipalNetworkDomain from the
    // controller.
    func GetPnd(ctx context.Context, addr string, args ...string) (*pb.GetPndResponse, error) {
    	coreClient, err := nbi.CoreClient(addr, dialOptions...)
    	if err != nil {
    		return nil, err
    	}
    	if len(args) <= 0 {
    		return nil, errors.New("not enough arguments")
    	}
    
    	req := &pb.GetPndRequest{
    		Timestamp: time.Now().UnixNano(),
    		Pid:       args,
    	}
    	return coreClient.GetPnd(ctx, req)
    }
    
    // GetPnds requests all PrincipalNetworkDomains from the
    // controller.
    func GetPnds(ctx context.Context, 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")
    	}
    
    	req := &pb.GetPndListRequest{
    		Timestamp: time.Now().UnixNano(),
    	}
    	return coreClient.GetPndList(ctx, req)
    }
    
    // DeletePnd requests a deletion of the provided PND.
    func DeletePnd(ctx context.Context, addr string, pid string) (*pb.DeletePndResponse, error) {
    	coreClient, err := nbi.CoreClient(addr, dialOptions...)
    	if err != nil {
    		return nil, err
    	}
    
    	req := &pb.DeletePndRequest{
    		Timestamp: time.Now().UnixNano(),
    		Pid:       pid,
    	}
    	return coreClient.DeletePnd(ctx, req)
    }