1
0
mirror of https://github.com/rancher/os.git synced 2025-09-08 10:11:46 +00:00

Move around code for better clarity

This commit is contained in:
Darren Shepherd
2018-09-15 21:55:26 -07:00
committed by niusmallnan
parent 2f50b7b178
commit 1f50386828
112 changed files with 992 additions and 859 deletions

View File

@@ -0,0 +1,49 @@
package modules
import (
"bufio"
"os"
"os/exec"
"strings"
"github.com/rancher/os/config"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/util"
)
func LoadModules(cfg *config.CloudConfig) (*config.CloudConfig, error) {
mounted := map[string]bool{}
f, err := os.Open("/proc/modules")
if err != nil {
return cfg, err
}
defer f.Close()
reader := bufio.NewScanner(f)
for reader.Scan() {
mounted[strings.SplitN(reader.Text(), " ", 2)[0]] = true
}
if util.GetHypervisor() == "hyperv" {
cfg.Rancher.Modules = append(cfg.Rancher.Modules, "hv_utils")
}
for _, module := range cfg.Rancher.Modules {
if mounted[module] {
continue
}
log.Debugf("Loading module %s", module)
// split module and module parameters
cmdParam := strings.SplitN(module, " ", -1)
cmd := exec.Command("modprobe", cmdParam...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Errorf("Could not load module %s, err %v", module, err)
}
}
return cfg, reader.Err()
}