mirror of
https://github.com/edgebox-iot/edgeboxctl.git
synced 2026-09-24 05:41:43 +02:00
Storage Module Basis (#13)
* Added storage module, base structs, getDevices() func, taskGetStorageDevices (ticks every 30) * GetDevices now returns a complete description w/ disk partitions * Added InUse flag to Device, fixed logic bugs * Added disk space usage for partitions in use by the system * Cleanup * Added UsageStat and UsageSplit filling for in use devices * Changed value of lsblk block usage output to bytes * Cleanup, small fixes * Added ExecAndGetLines util func * Added explicit detection of disk or part block type, ignoring non-suppoorted devices * Added command line tool dependencies for the project in README file * Added comment to func ExecAndGetLines * Removed GetMySQLDbConnectionDetails() * Added tests to utils module * Fix invalid argument type for Exec family of tests * Removed too much verbosity from utils.GetPath when no env file is available, added new argument (path) to Exec family of funcs * Added new path argument to utils.Exec... test * Fixed TestExec * Added spaces trim to Exec result * Trimming spaces and newlines from result of Exec * Better visibility for test result log of TestExec * Added ExampleExecAndStream test * Added Example tests with failure status for ExecAndStream * Added branch to test for valid key in GetPath * Added missing t.Fail() statements in utils_test.go * Added storage_test.go file, smoke test * TestGetDevices
This commit is contained in:
+40
-3
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/edgebox-iot/edgeboxctl/internal/diagnostics"
|
||||
"github.com/edgebox-iot/edgeboxctl/internal/edgeapps"
|
||||
"github.com/edgebox-iot/edgeboxctl/internal/storage"
|
||||
"github.com/edgebox-iot/edgeboxctl/internal/system"
|
||||
"github.com/edgebox-iot/edgeboxctl/internal/utils"
|
||||
_ "github.com/go-sql-driver/mysql" // Mysql Driver
|
||||
@@ -253,10 +254,16 @@ func ExecuteSchedules(tick int) {
|
||||
uptime := taskGetSystemUptime()
|
||||
log.Println("Uptime is " + uptime + " seconds (" + system.GetUptimeFormatted() + ")")
|
||||
|
||||
log.Println(taskGetStorageDevices())
|
||||
log.Println(taskGetEdgeApps())
|
||||
|
||||
}
|
||||
|
||||
if tick%5 == 0 {
|
||||
// Executing every 5 ticks
|
||||
log.Println(taskGetStorageDevices())
|
||||
}
|
||||
|
||||
if tick%30 == 0 {
|
||||
// Executing every 30 ticks
|
||||
log.Println(taskGetEdgeApps())
|
||||
@@ -277,13 +284,13 @@ func taskSetupTunnel(args taskSetupTunnelArgs) string {
|
||||
fmt.Println("Executing taskSetupTunnel")
|
||||
|
||||
cmdargs := []string{"gen", "--name", args.NodeName, "--token", args.BootnodeToken, args.BootnodeAddress + ":8655", "--prefix", args.AssignedAddress}
|
||||
utils.Exec("tinc-boot", cmdargs)
|
||||
utils.Exec(utils.GetPath("wsPath"), "tinc-boot", cmdargs)
|
||||
|
||||
cmdargs = []string{"start", "tinc@dnet"}
|
||||
utils.Exec("systemctl", cmdargs)
|
||||
utils.Exec(utils.GetPath("wsPath"), "systemctl", cmdargs)
|
||||
|
||||
cmdargs = []string{"enable", "tinc@dnet"}
|
||||
utils.Exec("systemctl", cmdargs)
|
||||
utils.Exec(utils.GetPath("wsPath"), "systemctl", cmdargs)
|
||||
|
||||
output := "OK" // Better check / logging of command execution result.
|
||||
return output
|
||||
@@ -435,3 +442,33 @@ func taskGetSystemUptime() string {
|
||||
return uptime
|
||||
|
||||
}
|
||||
|
||||
func taskGetStorageDevices() string {
|
||||
fmt.Println("Executing taskGetStorageDevices")
|
||||
|
||||
devices := storage.GetDevices()
|
||||
devicesJSON, _ := json.Marshal(devices)
|
||||
|
||||
db, err := sql.Open("sqlite3", utils.GetSQLiteDbConnectionDetails())
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
|
||||
statement, err := db.Prepare("REPLACE into option (name, value, created, updated) VALUES (?, ?, ?, ?);") // Prepare SQL Statement
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
|
||||
formatedDatetime := utils.GetSQLiteFormattedDateTime(time.Now())
|
||||
|
||||
_, err = statement.Exec("STORAGE_DEVICES_LIST", devicesJSON, formatedDatetime, formatedDatetime) // Execute SQL Statement
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
|
||||
db.Close()
|
||||
|
||||
return string(devicesJSON)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user