mirror of
https://gitlab.com/arm-research/smarter/smarter-device-manager.git
synced 2024-11-25 20:14:05 +00:00
Merge branch 'dev' into 'master'
Fix access to files on subdirectorties on /dev See merge request arm-research/smarter/smarter-device-manager!15
This commit is contained in:
commit
ab97aba78f
@ -17,6 +17,10 @@ The smarter-device-manager starts by reading a YAML configuration file. This con
|
|||||||
nummaxdevices: 10
|
nummaxdevices: 10
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Devices in subdirectories have the slash replaced with underscore in the
|
||||||
|
resource name, due to kubernetes naming restrictions: e.g. `/dev/net/tun`
|
||||||
|
becomes `smarter-devices/net_tun`.
|
||||||
|
|
||||||
The default config file provided will enable most of the devices available on a Raspberry Pi (vers 1-4) or equivalent boards. I2C, SPI, video devices, sound and others would be enabled. The config file can be replaced using a configmap to enable or disable access to different devices, like accelerators, GPUs, etc.
|
The default config file provided will enable most of the devices available on a Raspberry Pi (vers 1-4) or equivalent boards. I2C, SPI, video devices, sound and others would be enabled. The config file can be replaced using a configmap to enable or disable access to different devices, like accelerators, GPUs, etc.
|
||||||
|
|
||||||
The node will show the devices it recognizes as resources in the node object in Kubernetes. The example below shows a raspberry PI.
|
The node will show the devices it recognizes as resources in the node object in Kubernetes. The example below shows a raspberry PI.
|
||||||
|
41
main.go
41
main.go
@ -56,17 +56,33 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readDevDirectory(dirToList string) (files []string, err error) {
|
func readDevDirectory(dirToList string) (files []string, err error) {
|
||||||
f, err := os.Open(dirToList)
|
var foundFiles []string
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
files, err = f.Readdirnames(-1)
|
|
||||||
f.Close()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return files, nil
|
f, err := os.Open(dirToList)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
files, err = f.Readdirnames(-1)
|
||||||
|
if err != nil {
|
||||||
|
f.Close()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
for _, subDir := range files {
|
||||||
|
foundFiles = append(foundFiles, subDir)
|
||||||
|
filesDir, err := readDevDirectory(dirToList+"/"+subDir)
|
||||||
|
if err == nil {
|
||||||
|
for _, fileName := range filesDir {
|
||||||
|
foundFiles = append(foundFiles, subDir+"/"+fileName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return foundFiles, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func sanitizeName(path string) string {
|
||||||
|
return strings.Replace(path, "/", "_" ,-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func findDevicesPattern(listDevices []string, pattern string) ([]string,error) {
|
func findDevicesPattern(listDevices []string, pattern string) ([]string,error) {
|
||||||
@ -151,9 +167,10 @@ func main() {
|
|||||||
if len(foundDevices) > 0 {
|
if len(foundDevices) > 0 {
|
||||||
for _, deviceToCreate := range foundDevices {
|
for _, deviceToCreate := range foundDevices {
|
||||||
var newDevice DeviceInstance
|
var newDevice DeviceInstance
|
||||||
|
deviceSafeName := sanitizeName(deviceToCreate)
|
||||||
newDevice.deviceType = deviceFileType
|
newDevice.deviceType = deviceFileType
|
||||||
newDevice.deviceName = "smarter-devices/" + deviceToCreate
|
newDevice.deviceName = "smarter-devices/" + deviceSafeName
|
||||||
newDevice.socketName = pluginapi.DevicePluginPath + "smarter-" + deviceToCreate + ".sock"
|
newDevice.socketName = pluginapi.DevicePluginPath + "smarter-" + deviceSafeName + ".sock"
|
||||||
newDevice.deviceFile = "/dev/" + deviceToCreate
|
newDevice.deviceFile = "/dev/" + deviceToCreate
|
||||||
newDevice.numDevices = deviceToTest.NumMaxDevices
|
newDevice.numDevices = deviceToTest.NumMaxDevices
|
||||||
listDevicesAvailable = append(listDevicesAvailable, newDevice)
|
listDevicesAvailable = append(listDevicesAvailable, newDevice)
|
||||||
|
Loading…
Reference in New Issue
Block a user