Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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:
storeName: fmt.Sprintf("device-store-%s.json", pndUUID.String()),
sbiStore: sbiStore,
}
case store.Memory:
store := NewGenericStore[device.Device]()
return &store
default:
return nil
}
}