Skip to content
Snippets Groups Projects
sbiStore.go 1.09 KiB
Newer Older
  • Learn to ignore specific revisions
  • package nucleus
    
    import (
    	"fmt"
    
    	spb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/southbound"
    	"code.fbi.h-da.de/danet/gosdn/controller/interfaces/southbound"
    	"code.fbi.h-da.de/danet/gosdn/controller/store"
    
    	"github.com/google/uuid"
    )
    
    const (
    	sbiStoreName = "sbi"
    )
    
    // SbiStore is used to store SouthboundInterfaces
    type SbiStore struct {
    	sbiStoreName string
    }
    
    // LoadedSbi represents a Southbound Interface that was loaded by using
    // the Load() method of the SbiStore.
    type LoadedSbi struct {
    	ID   string   `json:"_id" bson:"_id,omitempty"`
    	Type spb.Type `bson:"type"`
    	Path string   `json:"path,omitempty"`
    }
    
    // NewSbiStore returns a sbiStore
    func NewSbiStore(pndUUID uuid.UUID) southbound.SbiStore {
    	storeMode := store.GetStoreMode()
    
    	switch storeMode {
    	case store.Filesystem:
    		store := NewGenericStore[southbound.SouthboundInterface]()
    
    		return &store
    	case store.Database:
    
    		return &DatabaseSbiStore{
    
    			sbiStoreName: fmt.Sprintf("sbi-store-%s.json", pndUUID.String()),
    		}
    	case store.Memory:
    		store := NewGenericStore[southbound.SouthboundInterface]()
    
    		return &store
    	default:
    		return nil
    	}
    }