Tui 模块开发完成,数据正常写入数据库

This commit is contained in:
2026-03-06 16:33:08 +08:00
parent 3f5e333a4d
commit 8bc4f4fe04
7 changed files with 674 additions and 535 deletions

View File

@@ -201,7 +201,7 @@ func loadConfig() (*ConfigMapping, error) {
if _, err := toml.DecodeFile(cfgfile, configs); err != nil {
if errors.Is(err, os.ErrNotExist) {
// 文件不存在,直接返回默认配置
logger.Infof("Config file %s not exist, use default config", cfgfile)
logger.Debugf("Config file %s not exist, use default config", cfgfile)
return configs, nil
}
// 其他错误,返回错误
@@ -209,7 +209,7 @@ func loadConfig() (*ConfigMapping, error) {
return nil, err
}
logger.Infof("Load config file %s success", cfgfile)
logger.Debugf("Load config file %s success", cfgfile)
return configs, nil
}
@@ -310,7 +310,9 @@ func (m *model) saveConfig() error {
return err
}
logger.Debugf("Result: %v", result)
for _, value := range utils.OutputMaps(result) {
logger.Debugf("%s", value)
}
return nil
}
@@ -433,15 +435,15 @@ func insertDataToDB(result map[string]string) error {
lesArgs := fmt.Sprintf("%s vnc vncip=%s vncpassword=sunhpc", result["boot_args"], result["private_address"])
bootaction := []string{
fmt.Sprintf("insert into bootactions values (1, 'install', '%s', '%s', '%s');",
fmt.Sprintf("insert or replace into bootactions values (1, 'install', '%s', '%s', '%s');",
vmlinuz, initrds, insArgs),
"insert into bootactions values (2, 'os', 'localboot 0', '', '');",
"insert into bootactions values (3, 'memtest', 'kernel memtest', '', '');",
fmt.Sprintf("insert into bootactions values (4, 'install headless', '%s', '%s', '%s');",
"insert or replace into bootactions values (2, 'os', 'localboot 0', '', '');",
"insert or replace into bootactions values (3, 'memtest', 'kernel memtest', '', '');",
fmt.Sprintf("insert or replace into bootactions values (4, 'install headless', '%s', '%s', '%s');",
vmlinuz, initrds, lesArgs),
fmt.Sprintf("insert into bootactions values (5, 'rescue', '%s', '%s', '%s');",
fmt.Sprintf("insert or replace into bootactions values (5, 'rescue', '%s', '%s', '%s');",
vmlinuz, initrds, resArgs),
"insert into bootactions values (6, 'pxeflash', 'kernel memdisk bigraw', 'pxeflash.img', 'keeppxe');",
"insert or replace into bootactions values (6, 'pxeflash', 'kernel memdisk bigraw', 'pxeflash.img', 'keeppxe');",
}
insertData = append(insertData, bootaction...)
@@ -453,42 +455,41 @@ func insertDataToDB(result map[string]string) error {
category := item.Category
catindex := item.Catindex
insertData = append(insertData,
fmt.Sprintf("insert into attributes values ('%s', '%s', '%s', %d, %d);",
fmt.Sprintf("insert or replace into attributes values (NULL, '%s', '%s', '%s', %d, %d);",
key, value, shadow, category, catindex))
}
nodes := []string{
fmt.Sprintf(
"insert into nodes values (1, '%s', '%d', 0, 0, '%s', '%s', '', 'install');",
"insert or replace into nodes values (1, '%s', '2', '%d', 0, 0, '%s', '%s', '', 'install');",
result["private_hostname"],
info.GetSystemInfo().NumCPU,
info.GetSystemInfo().Arch,
info.GetSystemInfo().OS),
fmt.Sprintf(
"insert into networks values (1, 1, '%s', '%s', '%s', '%s', '2');",
result["public_mac"],
result["public_address"],
result["private_hostname"],
result["public_interface"]),
fmt.Sprintf(
"insert into networks values (2, 1, '%s', '%s', '%s', '%s', '1');",
result["private_mac"],
result["private_address"],
result["private_hostname"],
result["private_interface"]),
fmt.Sprintf(
"insert into subnets values (1, 'private', '%s', '%s', '%s', '%s', '1');",
`insert or replace into subnets values (1, 'private', '%s', '%s', '%s', '%s', '1');`,
result["private_domain"],
result["private_network"],
result["private_netmask"],
result["private_mtu"]),
fmt.Sprintf(
"insert into subnets values (2, 'public', '%s', '%s', '%s', '%s', '0');",
`insert or replace into subnets values (2, 'public', '%s', '%s', '%s', '%s', '0');`,
result["public_domain"],
result["public_network"],
result["public_netmask"],
result["public_mtu"]),
fmt.Sprintf(
`insert or replace into networks values (1, 1, '%s', '%s', '%s', '%s', '2', NULL, NULL,NULL,NULL);`,
result["public_mac"],
result["public_address"],
result["private_hostname"],
result["public_interface"]),
fmt.Sprintf(
`insert or replace into networks values (2, 1, '%s', '%s', '%s', '%s', '1', NULL, NULL, NULL, NULL);`,
result["private_mac"],
result["private_address"],
result["private_hostname"],
result["private_interface"]),
}
insertData = append(insertData, nodes...)