Skip to content
Snippets Groups Projects
deviceStore.go 2.21 KiB
Newer Older
  • Learn to ignore specific revisions
  • package nucleus
    
    import (
    	"fmt"
    
    	"code.fbi.h-da.de/danet/gosdn/controller/interfaces/device"
    	"code.fbi.h-da.de/danet/gosdn/controller/interfaces/southbound"
    	"code.fbi.h-da.de/danet/gosdn/controller/store"
    
    	"github.com/google/uuid"
    	log "github.com/sirupsen/logrus"
    )
    
    const (
    	deviceStoreName = "device"
    )
    
    // DeviceStore is used to store Devices
    type DeviceStore struct {
    	storeName string
    	sbiStore  southbound.SbiStore
    }
    
    // LoadedDevice represents a Orchestrated Networking Device that was loaeded
    // by using the Load() method of the DeviceStore.
    type LoadedDevice struct {
    	// DeviceID represents the UUID of the LoadedDevice.
    	DeviceID string `json:"id" bson:"_id,omitempty"`
    	// Name represents the name of the LoadedDevice.
    	Name string `json:"name,omitempty"`
    	// TransportType represent the type of the transport in use of the LoadedDevice.
    	TransportType string `json:"transport_type,omitempty"`
    	// TransportAddress represents the address from which the device can be reached via the transport method.
    	TransportAddress string `json:"transport_address,omitempty"`
    	// TransportUsername is used for authentication via the transport method in use.
    	TransportUsername string `json:"transport_username,omitempty"`
    	// TransportPassword is used for authentication via the transport method in use.
    	TransportPassword   string `json:"transport_password,omitempty"`
    	TransportOptionCsbi bool   `json:"transport_option_csbi,omitempty"`
    	// SBI indicates the southbound interface, which is used by this device as UUID.
    	SBI string `json:"sbi,omitempty"`
    }
    
    // ID returns the ID of the LoadedDevice as UUID.
    func (ld LoadedDevice) ID() uuid.UUID {
    	return uuid.MustParse(ld.DeviceID)
    }
    
    // NewDeviceStore returns a DeviceStore
    func NewDeviceStore(pndUUID uuid.UUID, sbiStore southbound.SbiStore) device.Store {
    	storeMode := store.GetStoreMode()
    	log.Debugf("StoreMode: %s", storeMode)
    
    	switch storeMode {
    	case store.Filesystem:
    		store := NewGenericStore[device.Device]()
    
    		return &store
    	case store.Database:
    
    		return &DatabaseDeviceStore{
    
    			storeName: fmt.Sprintf("device-store-%s.json", pndUUID.String()),
    			sbiStore:  sbiStore,
    		}
    	case store.Memory:
    		store := NewGenericStore[device.Device]()
    
    		return &store
    	default:
    		return nil
    	}
    }