Added constants for release version and device types, added diagnostics.GetReleaseVersion
parent
162665b115
commit
ef994a1002
|
@ -1,7 +1,18 @@
|
||||||
package diagnostics
|
package diagnostics
|
||||||
|
|
||||||
|
type ReleaseVersion string
|
||||||
|
|
||||||
var Version string
|
var Version string
|
||||||
|
|
||||||
var Commit string
|
var Commit string
|
||||||
|
|
||||||
var BuildDate string
|
var BuildDate string
|
||||||
|
|
||||||
|
const (
|
||||||
|
DEV_VERSION ReleaseVersion = "dev"
|
||||||
|
PROD_VERSION ReleaseVersion = "prod"
|
||||||
|
CLOUD_VERSION ReleaseVersion = "cloud"
|
||||||
|
OTHER_VERSION ReleaseVersion = "other"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetReleaseVersion() ReleaseVersion {
|
||||||
|
return ReleaseVersion(Version)
|
||||||
|
}
|
||||||
|
|
|
@ -6,24 +6,25 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/edgebox-iot/edgeboxctl/internal/diagnostics"
|
||||||
"github.com/edgebox-iot/edgeboxctl/internal/utils"
|
"github.com/edgebox-iot/edgeboxctl/internal/utils"
|
||||||
"github.com/shirou/gopsutil/disk"
|
"github.com/shirou/gopsutil/disk"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Device : Struct representing a storage device in the system
|
// Device : Struct representing a storage device in the system
|
||||||
type Device struct {
|
type Device struct {
|
||||||
ID string `json:"id"`
|
ID DeviceIdentifier `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Size string `json:"size"`
|
Size string `json:"size"`
|
||||||
InUse bool `json:"in_use"`
|
InUse bool `json:"in_use"`
|
||||||
MainDevice bool `json:"main_device"`
|
MainDevice bool `json:"main_device"`
|
||||||
MAJ string `json:"maj"`
|
MAJ string `json:"maj"`
|
||||||
MIN string `json:"min"`
|
MIN string `json:"min"`
|
||||||
RM string `json:"rm"`
|
RM string `json:"rm"`
|
||||||
RO string `json:"ro"`
|
RO string `json:"ro"`
|
||||||
Partitions []Partition `json:"partitions"`
|
Partitions []Partition `json:"partitions"`
|
||||||
Status DeviceStatus `json:"status"`
|
Status DeviceStatus `json:"status"`
|
||||||
UsageStat UsageStat `json:"usage_stat"`
|
UsageStat UsageStat `json:"usage_stat"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeviceStatus : Struct representing possible storage device statuses (code + description)
|
// DeviceStatus : Struct representing possible storage device statuses (code + description)
|
||||||
|
@ -66,8 +67,27 @@ type Partition struct {
|
||||||
UsageStat UsageStat `json:"usage_stat"`
|
UsageStat UsageStat `json:"usage_stat"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DeviceIdentifier string
|
||||||
|
|
||||||
|
const (
|
||||||
|
DISK_TYPE_SDA DeviceIdentifier = "sda"
|
||||||
|
DISK_TYPE_MCBLK DeviceIdentifier = "mmcblk0"
|
||||||
|
DISK_TYPE_VDA DeviceIdentifier = "vda"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetDeviceIdentifier(release_version diagnostics.ReleaseVersion) DeviceIdentifier {
|
||||||
|
switch release_version {
|
||||||
|
case diagnostics.CLOUD_VERSION:
|
||||||
|
return DISK_TYPE_VDA
|
||||||
|
case diagnostics.PROD_VERSION:
|
||||||
|
return DISK_TYPE_MCBLK
|
||||||
|
}
|
||||||
|
|
||||||
|
return DISK_TYPE_SDA
|
||||||
|
}
|
||||||
|
|
||||||
// GetDevices : Returns a list of all available sotrage devices in structs filled with information
|
// GetDevices : Returns a list of all available sotrage devices in structs filled with information
|
||||||
func GetDevices(release_version string) []Device {
|
func GetDevices(release_version diagnostics.ReleaseVersion) []Device {
|
||||||
|
|
||||||
var devices []Device
|
var devices []Device
|
||||||
|
|
||||||
|
@ -80,15 +100,7 @@ func GetDevices(release_version string) []Device {
|
||||||
firstDevice := true
|
firstDevice := true
|
||||||
currentDeviceInUseFlag := false
|
currentDeviceInUseFlag := false
|
||||||
|
|
||||||
mainDiskID := "sda"
|
mainDiskID := GetDeviceIdentifier(release_version)
|
||||||
|
|
||||||
if release_version == "dev" {
|
|
||||||
mainDiskID = "sda"
|
|
||||||
} else if release_version == "prod" {
|
|
||||||
mainDiskID = "mmcblk0"
|
|
||||||
} else if release_version == "cloud" {
|
|
||||||
mainDiskID = "vda"
|
|
||||||
}
|
|
||||||
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
// 1 Device is represented here. Extract words in order for filling a Device struct
|
// 1 Device is represented here. Extract words in order for filling a Device struct
|
||||||
|
@ -130,7 +142,7 @@ func GetDevices(release_version string) []Device {
|
||||||
mainDevice := false
|
mainDevice := false
|
||||||
|
|
||||||
device := Device{
|
device := Device{
|
||||||
ID: deviceRawInfo[0],
|
ID: DeviceIdentifier(deviceRawInfo[0]),
|
||||||
Name: deviceRawInfo[0],
|
Name: deviceRawInfo[0],
|
||||||
Size: deviceRawInfo[3],
|
Size: deviceRawInfo[3],
|
||||||
MainDevice: mainDevice,
|
MainDevice: mainDevice,
|
||||||
|
|
|
@ -121,7 +121,7 @@ func ExecuteTask(task Task) Task {
|
||||||
log.Fatal(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if diagnostics.Version == "dev" {
|
if diagnostics.GetReleaseVersion() == diagnostics.DEV_VERSION {
|
||||||
log.Printf("Dev environemnt. Not executing tasks.")
|
log.Printf("Dev environemnt. Not executing tasks.")
|
||||||
} else {
|
} else {
|
||||||
log.Println("Task: " + task.Task)
|
log.Println("Task: " + task.Task)
|
||||||
|
@ -287,7 +287,7 @@ func ExecuteSchedules(tick int) {
|
||||||
// })
|
// })
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if diagnostics.Version == "cloud" {
|
if diagnostics.GetReleaseVersion() == diagnostics.CLOUD_VERSION {
|
||||||
log.Println("Setting up cloud version options (name, email, api token)")
|
log.Println("Setting up cloud version options (name, email, api token)")
|
||||||
taskSetupCloudOptions()
|
taskSetupCloudOptions()
|
||||||
}
|
}
|
||||||
|
@ -451,7 +451,7 @@ func taskGetSystemUptime() string {
|
||||||
func taskGetStorageDevices() string {
|
func taskGetStorageDevices() string {
|
||||||
fmt.Println("Executing taskGetStorageDevices")
|
fmt.Println("Executing taskGetStorageDevices")
|
||||||
|
|
||||||
devices := storage.GetDevices(diagnostics.Version)
|
devices := storage.GetDevices(diagnostics.GetReleaseVersion())
|
||||||
devicesJSON, _ := json.Marshal(devices)
|
devicesJSON, _ := json.Marshal(devices)
|
||||||
|
|
||||||
utils.WriteOption("STORAGE_DEVICES_LIST", string(devicesJSON))
|
utils.WriteOption("STORAGE_DEVICES_LIST", string(devicesJSON))
|
||||||
|
|
Loading…
Reference in New Issue