添加数据到数据库,但无法插入,临时提交保存
This commit is contained in:
@@ -2,9 +2,11 @@ package wizard
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"sunhpc/pkg/database"
|
||||
"sunhpc/pkg/info"
|
||||
"sunhpc/pkg/logger"
|
||||
"sunhpc/pkg/utils"
|
||||
|
||||
@@ -68,6 +70,23 @@ type ConfigMapping struct {
|
||||
} `toml:"private"`
|
||||
}
|
||||
|
||||
type IPMaskInfo struct {
|
||||
NetworkAddress string // 网络地址 192.168.1.0
|
||||
CIDR string // CIDR 格式 192.168.1.0/24
|
||||
IPAddress string // IP 地址 192.168.1.100
|
||||
MacAddress string // MAC 地址 00:11:22:33:44:55
|
||||
Netmask string // 子网掩码 255.255.255.0
|
||||
PrefixLength int // 前缀长度 24
|
||||
}
|
||||
|
||||
type AttrItem struct {
|
||||
Key string
|
||||
Value string
|
||||
Shadow string
|
||||
Category int
|
||||
Catindex int
|
||||
}
|
||||
|
||||
func NewConfigWithDefault() *ConfigMapping {
|
||||
return &ConfigMapping{
|
||||
Title: "Cluster Configuration",
|
||||
@@ -197,32 +216,111 @@ func loadConfig() (*ConfigMapping, error) {
|
||||
// saveConfig 入口函数:保存所有配置到数据库
|
||||
func (m *model) saveConfig() error {
|
||||
|
||||
conn, err := database.GetDB() // 假设database包已实现getDB()获取连接
|
||||
if err != nil {
|
||||
logger.Errorf("Database connection failed: %v", err)
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
m.force = false // 初始化全量覆盖标识
|
||||
|
||||
config, err := loadConfig()
|
||||
c, err := loadConfig()
|
||||
if err != nil {
|
||||
logger.Debugf("[DEBUG] Load config file failed: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
t_value := m.config.PrivateIPAddress
|
||||
c_value := config.Private.PrivateAddress
|
||||
// 合并配置项
|
||||
result := make(map[string]string)
|
||||
|
||||
logger.Debugf("t_value: %s\n", t_value)
|
||||
logger.Debugf("c_value: %s\n", c_value)
|
||||
// base 配置
|
||||
result["country"] = mergeValue(m.config.Country, c.Base.Country)
|
||||
result["state"] = mergeValue(m.config.State, c.Base.State)
|
||||
result["city"] = mergeValue(m.config.City, c.Base.City)
|
||||
result["contact"] = mergeValue(m.config.Contact, c.Base.Contact)
|
||||
result["homepage"] = mergeValue(m.config.HomePage, c.Base.HomePage)
|
||||
result["cluster_name"] = mergeValue(m.config.ClusterName, c.Base.ClusterName)
|
||||
result["license"] = c.Base.License
|
||||
result["distribution"] = c.Base.Distribution
|
||||
result["timezone"] = mergeValue(m.config.Timezone, c.Base.Timezone)
|
||||
result["base_dir"] = c.Base.BaseDir
|
||||
result["work_dir"] = c.Base.WorkDir
|
||||
result["distro_dir"] = mergeValue(m.config.DistroDir, c.Base.DistroDir)
|
||||
result["partition"] = c.Base.Partition
|
||||
|
||||
logger.Debugf("config.Base.ClusterName: %s\n", config.Base.ClusterName)
|
||||
// safe 配置
|
||||
result["safe_port"] = c.Base.SafePort
|
||||
result["safe_dirs"] = c.Base.SafeDirs
|
||||
result["safe_security"] = c.Base.SafeSecurity
|
||||
|
||||
// plugin 配置
|
||||
result["plugin_dirs"] = c.Base.PluginDirs
|
||||
result["plugin_port"] = c.Base.PluginPort
|
||||
|
||||
// monitor 配置
|
||||
result["ganglia_addr"] = c.Base.GangliaAddr
|
||||
|
||||
// public 配置
|
||||
result["public_hostname"] = mergeValue(m.config.PublicHostname, c.Public.PublicHostname)
|
||||
result["public_interface"] = mergeValue(m.config.PublicInterface, c.Public.PublicInterface)
|
||||
result["public_address"] = mergeValue(m.config.PublicIPAddress, c.Public.PublicAddress)
|
||||
result["public_netmask"] = mergeValue(m.config.PublicNetmask, c.Public.PublicNetmask)
|
||||
result["public_gateway"] = mergeValue(m.config.PublicGateway, c.Public.PublicGateway)
|
||||
|
||||
// 获取公网网络信息
|
||||
publicIface := mergeValue(m.config.PublicInterface, c.Public.PublicInterface)
|
||||
publicInfo, err := GetNetworkInfo(
|
||||
publicIface, c.Public.PublicAddress, c.Public.PublicNetmask)
|
||||
if err != nil {
|
||||
logger.Debugf("[DEBUG] Get public interface %s IP mask info failed: %v",
|
||||
publicIface, err)
|
||||
}
|
||||
|
||||
result["public_network"] = publicInfo.NetworkAddress
|
||||
result["public_domain"] = mergeValue(m.config.PublicDomain, c.Public.PublicDomain)
|
||||
|
||||
result["public_cidr"] = mergeValue(c.Public.PublicCIDR, publicInfo.CIDR)
|
||||
result["public_dns"] = c.Public.PublicDNS
|
||||
result["public_mac"] = publicInfo.MacAddress
|
||||
result["public_mtu"] = mergeValue(m.config.PublicMTU, c.Public.PublicMTU)
|
||||
result["public_ntp"] = c.Public.PublicNTP
|
||||
|
||||
// private 配置
|
||||
// 获取内网网络信息
|
||||
privateIface := mergeValue(m.config.PrivateInterface, c.Private.PrivateInterface)
|
||||
privateInfo, err := GetNetworkInfo(
|
||||
privateIface, c.Private.PrivateAddress, c.Private.PrivateNetmask)
|
||||
if err != nil {
|
||||
logger.Debugf("[DEBUG] Get private interface %s IP mask info failed: %v",
|
||||
privateIface, err)
|
||||
}
|
||||
result["private_hostname"] = mergeValue(m.config.PrivateHostname, c.Private.PrivateHostname)
|
||||
result["private_interface"] = mergeValue(m.config.PrivateInterface, c.Private.PrivateInterface)
|
||||
result["private_address"] = mergeValue(m.config.PrivateIPAddress, c.Private.PrivateAddress)
|
||||
result["private_netmask"] = mergeValue(m.config.PrivateNetmask, c.Private.PrivateNetmask)
|
||||
result["private_network"] = privateInfo.NetworkAddress
|
||||
result["private_domain"] = mergeValue(m.config.PrivateDomain, c.Private.PrivateDomain)
|
||||
result["private_cidr"] = mergeValue(c.Private.PrivateCIDR, privateInfo.CIDR)
|
||||
result["private_mac"] = privateInfo.MacAddress
|
||||
result["private_mtu"] = mergeValue(m.config.PrivateMTU, c.Private.PrivateMTU)
|
||||
|
||||
// pxe 配置
|
||||
result["next_server"] = mergeValue(privateInfo.IPAddress, c.Pxelinux.NextServer)
|
||||
result["pxe_filename"] = c.Pxelinux.PxeFilename
|
||||
result["pxelinux_dir"] = c.Pxelinux.PxeLinuxDir
|
||||
result["boot_args"] = c.Pxelinux.BootArgs
|
||||
|
||||
// 插入数据到数据库
|
||||
if err := insertDataToDB(result); err != nil {
|
||||
logger.Debugf("[DEBUG] Insert config data to database failed: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Debugf("Result: %v", result)
|
||||
return nil
|
||||
}
|
||||
|
||||
func mergeValue(tui_value, cfg_value string) string {
|
||||
if tui_value == "" {
|
||||
return cfg_value
|
||||
}
|
||||
return tui_value
|
||||
}
|
||||
|
||||
// 获取系统网络接口
|
||||
func getNetworkInterfaces() []string {
|
||||
// 实现获取系统网络接口的逻辑
|
||||
@@ -247,3 +345,226 @@ func getNetworkInterfaces() []string {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func GetNetworkInfo(iface, ip, mask string) (*IPMaskInfo, error) {
|
||||
|
||||
logger.Debugf("Get Network %s, IP %s, mask %s", iface, ip, mask)
|
||||
|
||||
// 解析IP
|
||||
ipAddr := net.ParseIP(ip)
|
||||
if ipAddr == nil {
|
||||
logger.Debugf("Invalid IP address: %s", ip)
|
||||
return nil, fmt.Errorf("invalid IP address: %s", ip)
|
||||
}
|
||||
|
||||
// 解析子网掩码
|
||||
maskAddr := net.ParseIP(mask)
|
||||
if maskAddr == nil {
|
||||
logger.Debugf("Invalid subnet mask: %s", mask)
|
||||
return nil, fmt.Errorf("invalid subnet mask: %s", mask)
|
||||
}
|
||||
|
||||
// 确保是IPv4地址
|
||||
ipv4 := ipAddr.To4()
|
||||
maskv4 := maskAddr.To4()
|
||||
if ipv4 == nil || maskv4 == nil {
|
||||
logger.Debugf("Only support IPv4 address")
|
||||
return nil, fmt.Errorf("only support IPv4 address")
|
||||
}
|
||||
|
||||
// 计算网络地址 (IP & 子网掩码)
|
||||
network := make([]byte, 4)
|
||||
for i := 0; i < 4; i++ {
|
||||
network[i] = ipv4[i] & maskv4[i]
|
||||
}
|
||||
networkAddr := fmt.Sprintf(
|
||||
"%d.%d.%d.%d", network[0], network[1], network[2], network[3])
|
||||
|
||||
// 计算前缀长度
|
||||
prefixLen := 0
|
||||
for i := 0; i < 4; i++ {
|
||||
for j := 7; j >= 0; j-- {
|
||||
if maskv4[i]&(1<<uint(j)) != 0 {
|
||||
prefixLen++
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 计算CIDR格式
|
||||
cidr := fmt.Sprintf("%s/%d", networkAddr, prefixLen)
|
||||
|
||||
var mac string
|
||||
// 获取Mac地址
|
||||
ifaceName, err := net.InterfaceByName(iface)
|
||||
if err == nil {
|
||||
mac = ifaceName.HardwareAddr.String()
|
||||
if mac == "" {
|
||||
logger.Debugf("Network interface %s has no MAC address", iface)
|
||||
}
|
||||
} else {
|
||||
logger.Debugf("Invalid network interface: %s", iface)
|
||||
mac = ""
|
||||
}
|
||||
|
||||
return &IPMaskInfo{
|
||||
NetworkAddress: networkAddr,
|
||||
CIDR: cidr,
|
||||
IPAddress: ip,
|
||||
MacAddress: mac,
|
||||
Netmask: mask,
|
||||
PrefixLength: prefixLen,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func insertDataToDB(result map[string]string) error {
|
||||
|
||||
insertData := []string{}
|
||||
|
||||
infos := info.GetSystemInfo()
|
||||
|
||||
// initrd 配置
|
||||
bootver := fmt.Sprintf("%s-%s", info.Version, infos.Arch)
|
||||
vmlinuz := fmt.Sprintf("vmlinuz-%s", bootver)
|
||||
initrds := fmt.Sprintf("initrd-%s", bootver)
|
||||
insArgs := fmt.Sprintf("%s inst.ks.sendmac ksdevice=bootif", result["boot_args"])
|
||||
resArgs := fmt.Sprintf("%s rescue", result["boot_args"])
|
||||
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');",
|
||||
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');",
|
||||
vmlinuz, initrds, lesArgs),
|
||||
fmt.Sprintf("insert into bootactions values (5, 'rescue', '%s', '%s', '%s');",
|
||||
vmlinuz, initrds, resArgs),
|
||||
"insert into bootactions values (6, 'pxeflash', 'kernel memdisk bigraw', 'pxeflash.img', 'keeppxe');",
|
||||
}
|
||||
insertData = append(insertData, bootaction...)
|
||||
|
||||
attrs := GetAttrs(result)
|
||||
for _, item := range attrs {
|
||||
key := item.Key
|
||||
value := item.Value
|
||||
shadow := item.Shadow
|
||||
category := item.Category
|
||||
catindex := item.Catindex
|
||||
insertData = append(insertData,
|
||||
fmt.Sprintf("insert into attributes values ('%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');",
|
||||
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');",
|
||||
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');",
|
||||
result["public_domain"],
|
||||
result["public_network"],
|
||||
result["public_netmask"],
|
||||
result["public_mtu"]),
|
||||
}
|
||||
insertData = append(insertData, nodes...)
|
||||
|
||||
if err := database.ExecWithTransaction(insertData); err != nil {
|
||||
logger.Debugf("[DEBUG] Insert config data to database failed: %v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetAttrs(results map[string]string) []AttrItem {
|
||||
attrs := []AttrItem{
|
||||
{Key: "Info_CertificateCountry", Value: results["country"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Info_CertificateState", Value: results["state"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Info_CertificateCity", Value: results["city"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Info_CertificateOrganization", Value: "DLHP", Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Info_Contact", Value: results["contact"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Info_ClusterHostname", Value: results["ClusterHostname"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_WorkDir", Value: results["work_dir"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_DistroDir", Value: results["distro_dir"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_Partition", Value: results["partition"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
|
||||
{Key: "Kickstart_PublicHostname", Value: results["public_hostname"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PublicInterface", Value: results["public_interface"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PublicAddress", Value: results["public_address"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PublicMacAddr", Value: results["public_mac"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PublicNetmask", Value: results["public_netmask"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PublicGateway", Value: results["public_gateway"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PublicNetwork", Value: results["public_network"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PublicDomain", Value: results["public_domain"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PublicCIDR", Value: results["public_cidr"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PublicDNS", Value: results["public_dns"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PublicMTU", Value: results["public_mtu"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PublicNTP", Value: results["public_ntp"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
|
||||
{Key: "Kickstart_PrivateHostname", Value: results["private_hostname"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PrivateInterface", Value: results["private_interface"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PrivateAddress", Value: results["private_address"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PrivateMacAddr", Value: results["private_mac"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PrivateNetmask", Value: results["private_netmask"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PrivateGateway", Value: results["private_gateway"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PrivateNetwork", Value: results["private_network"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PrivateDomain", Value: results["private_domain"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PrivateCIDR", Value: results["private_cidr"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_PrivateMTU", Value: results["private_mtu"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
|
||||
{Key: "Kickstart_Timezone", Value: results["timezone"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_Bootargs", Value: results["boot_args"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_Distribution", Value: results["distribution"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Kickstart_BaseDir", Value: results["base_dir"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
|
||||
{Key: "SafePort", Value: results["safe_port"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "SafeDirs", Value: results["safe_dirs"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "SafeSecurity", Value: results["safe_security"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
|
||||
{Key: "Plugin_dirs", Value: results["plugin_dirs"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Plugin_port", Value: results["plugin_port"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
|
||||
{Key: "Ganglia_addr", Value: results["ganglia_addr"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
|
||||
{Key: "Sunhpc_version", Value: results["sunhpc_version"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
|
||||
{Key: "DHCP_filename", Value: results["pxe_filename"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "DHCP_nextserver", Value: results["next_server"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "Pxelinuxdir", Value: results["pxelinux_dir"], Shadow: "false", Category: 1, Catindex: 1},
|
||||
|
||||
{Key: "Kickstartable", Value: "yes", Shadow: "false", Category: 3, Catindex: 4},
|
||||
{Key: "Kickstartable", Value: "yes", Shadow: "false", Category: 3, Catindex: 5},
|
||||
{Key: "Kickstartable", Value: "yes", Shadow: "false", Category: 3, Catindex: 6},
|
||||
{Key: "Kickstartable", Value: "no", Shadow: "false", Category: 3, Catindex: 7},
|
||||
{Key: "Kickstartable", Value: "no", Shadow: "false", Category: 3, Catindex: 8},
|
||||
{Key: "Kickstartable", Value: "yes", Shadow: "false", Category: 3, Catindex: 9},
|
||||
{Key: "Kickstartable", Value: "yes", Shadow: "false", Category: 3, Catindex: 10},
|
||||
|
||||
{Key: "Managed", Value: "true", Shadow: "false", Category: 1, Catindex: 1},
|
||||
{Key: "OS", Value: "linux", Shadow: "false", Category: 1, Catindex: 1},
|
||||
}
|
||||
return attrs
|
||||
}
|
||||
|
||||
@@ -284,20 +284,23 @@ func (m *model) initPageFocus(page PageType) {
|
||||
"Homepage_input",
|
||||
"ClusterName_input",
|
||||
"Country_input",
|
||||
"Region_input",
|
||||
"State_input",
|
||||
"City_input",
|
||||
"Contact_input",
|
||||
"Timezone_input",
|
||||
"DBPath_input",
|
||||
"Software_input",
|
||||
"DistroDir_input",
|
||||
"next_btn",
|
||||
"prev_btn",
|
||||
}
|
||||
defaultFocusID = "next_btn"
|
||||
case PagePublicNetwork:
|
||||
componentOrder = []string{
|
||||
"PublicHostname_input",
|
||||
"PublicInterface_input",
|
||||
"PublicIPAddress_input",
|
||||
"PublicNetmask_input",
|
||||
"PublicGateway_input",
|
||||
"PublicDomain_input",
|
||||
"PublicMTU_input",
|
||||
"next_btn",
|
||||
"prev_btn",
|
||||
@@ -305,9 +308,11 @@ func (m *model) initPageFocus(page PageType) {
|
||||
defaultFocusID = "next_btn"
|
||||
case PageInternalNetwork:
|
||||
componentOrder = []string{
|
||||
"PrivateHostname_input",
|
||||
"PrivateInterface_input",
|
||||
"PrivateIPAddress_input",
|
||||
"PrivateNetmask_input",
|
||||
"PrivateDomain_input",
|
||||
"PrivateMTU_input",
|
||||
"next_btn",
|
||||
"prev_btn",
|
||||
|
||||
@@ -22,23 +22,29 @@ type Config struct {
|
||||
// 数据接收
|
||||
ClusterName string `json:"cluster_name"`
|
||||
Country string `json:"country"`
|
||||
Region string `json:"region"`
|
||||
State string `json:"state"`
|
||||
City string `json:"city"`
|
||||
Contact string `json:"contact"`
|
||||
Timezone string `json:"timezone"`
|
||||
HomePage string `json:"homepage"`
|
||||
DBAddress string `json:"db_address"`
|
||||
Software string `json:"software"`
|
||||
DistroDir string `json:"distro_dir"`
|
||||
|
||||
// 公网设置
|
||||
PublicHostname string `json:"public_hostname"`
|
||||
PublicInterface string `json:"public_interface"`
|
||||
PublicIPAddress string `json:"ip_address"`
|
||||
PublicNetmask string `json:"netmask"`
|
||||
PublicGateway string `json:"gateway"`
|
||||
PublicDomain string `json:"public_domain"`
|
||||
PublicMTU string `json:"public_mtu"`
|
||||
|
||||
// 内网配置
|
||||
PrivateHostname string `json:"private_hostname"`
|
||||
PrivateInterface string `json:"private_interface"`
|
||||
PrivateIPAddress string `json:"private_ip"`
|
||||
PrivateNetmask string `json:"private_mask"`
|
||||
PrivateDomain string `json:"private_domain"`
|
||||
PrivateMTU string `json:"private_mtu"`
|
||||
|
||||
// DNS 配置
|
||||
@@ -101,18 +107,25 @@ func defaultConfig() Config {
|
||||
License: "This test license is for testing purposes only. Do not use it in production.",
|
||||
ClusterName: "cluster.hpc.org",
|
||||
Country: "China",
|
||||
Region: "Beijing",
|
||||
State: "Beijing",
|
||||
City: "Beijing",
|
||||
Contact: "admin@sunhpc.com",
|
||||
Timezone: "Asia/Shanghai",
|
||||
HomePage: "www.sunhpc.com",
|
||||
DBAddress: "/var/lib/sunhpc/sunhpc.db",
|
||||
Software: "/export/sunhpc",
|
||||
DistroDir: "/export/sunhpc",
|
||||
PublicHostname: "cluster.hpc.org",
|
||||
PublicInterface: defaultPublicInterface,
|
||||
PublicIPAddress: "",
|
||||
PublicNetmask: "",
|
||||
PublicGateway: "",
|
||||
PublicDomain: "hpc.org",
|
||||
PublicMTU: "1500",
|
||||
PrivateHostname: "cluster",
|
||||
PrivateInterface: defaultInternalInterface,
|
||||
PrivateIPAddress: "172.16.9.254",
|
||||
PrivateNetmask: "255.255.255.0",
|
||||
PrivateDomain: "local",
|
||||
PrivateMTU: "1500",
|
||||
DNSPrimary: "8.8.8.8",
|
||||
DNSSecondary: "8.8.4.4",
|
||||
@@ -137,20 +150,23 @@ func initialModel() model {
|
||||
page2Comps["Homepage_input"] = NewTextInput("Homepage", cfg.HomePage)
|
||||
page2Comps["ClusterName_input"] = NewTextInput("ClusterName", cfg.ClusterName)
|
||||
page2Comps["Country_input"] = NewTextInput("Country", cfg.Country)
|
||||
page2Comps["Region_input"] = NewTextInput("Region", cfg.Region)
|
||||
page2Comps["State_input"] = NewTextInput("State", cfg.State)
|
||||
page2Comps["City_input"] = NewTextInput("City", cfg.City)
|
||||
page2Comps["Contact_input"] = NewTextInput("Contact", cfg.Contact)
|
||||
page2Comps["Timezone_input"] = NewTextInput("Timezone", cfg.Timezone)
|
||||
page2Comps["DBPath_input"] = NewTextInput("DBPath", cfg.DBAddress)
|
||||
page2Comps["Software_input"] = NewTextInput("Software", cfg.Software)
|
||||
page2Comps["DistroDir_input"] = NewTextInput("DistroDir", cfg.DistroDir)
|
||||
page2Comps["next_btn"] = NewButton("下一步")
|
||||
page2Comps["prev_btn"] = NewButton("上一步")
|
||||
pageComponents[PageData] = page2Comps
|
||||
|
||||
// ------------------ 页面3:公网网络页面 --------------------
|
||||
page3Comps := make(map[string]Focusable)
|
||||
page3Comps["PublicHostname_input"] = NewTextInput("PublicHostname", cfg.PublicHostname)
|
||||
page3Comps["PublicInterface_input"] = NewTextInput("PublicInterface", cfg.PublicInterface)
|
||||
page3Comps["PublicIPAddress_input"] = NewTextInput("PublicIPAddress", cfg.PublicIPAddress)
|
||||
page3Comps["PublicNetmask_input"] = NewTextInput("PublicNetmask", cfg.PublicNetmask)
|
||||
page3Comps["PublicGateway_input"] = NewTextInput("PublicGateway", cfg.PublicGateway)
|
||||
page3Comps["PublicDomain_input"] = NewTextInput("PublicDomain", cfg.PublicDomain)
|
||||
page3Comps["PublicMTU_input"] = NewTextInput("PublicMTU", cfg.PublicMTU)
|
||||
page3Comps["next_btn"] = NewButton("下一步")
|
||||
page3Comps["prev_btn"] = NewButton("上一步")
|
||||
@@ -158,9 +174,11 @@ func initialModel() model {
|
||||
|
||||
// ------------------ 页面4:内网网络页面 --------------------
|
||||
page4Comps := make(map[string]Focusable)
|
||||
page4Comps["PrivateHostname_input"] = NewTextInput("PrivateHostname", cfg.PrivateHostname)
|
||||
page4Comps["PrivateInterface_input"] = NewTextInput("PrivateInterface", cfg.PrivateInterface)
|
||||
page4Comps["PrivateIPAddress_input"] = NewTextInput("PrivateIPAddress", cfg.PrivateIPAddress)
|
||||
page4Comps["PrivateNetmask_input"] = NewTextInput("PrivateNetmask", cfg.PrivateNetmask)
|
||||
page4Comps["PrivateDomain_input"] = NewTextInput("PrivateDomain", cfg.PrivateDomain)
|
||||
page4Comps["PrivateMTU_input"] = NewTextInput("PrivateMTU", cfg.PrivateMTU)
|
||||
page4Comps["next_btn"] = NewButton("下一步")
|
||||
page4Comps["prev_btn"] = NewButton("上一步")
|
||||
@@ -270,14 +288,16 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.config.ClusterName = comp.Value()
|
||||
case "Country_input":
|
||||
m.config.Country = comp.Value()
|
||||
case "Region_input":
|
||||
m.config.Region = comp.Value()
|
||||
case "State_input":
|
||||
m.config.State = comp.Value()
|
||||
case "City_input":
|
||||
m.config.City = comp.Value()
|
||||
case "Contact_input":
|
||||
m.config.Contact = comp.Value()
|
||||
case "Timezone_input":
|
||||
m.config.Timezone = comp.Value()
|
||||
case "DBPath_input":
|
||||
m.config.DBAddress = comp.Value()
|
||||
case "Software_input":
|
||||
m.config.Software = comp.Value()
|
||||
case "DistroDir_input":
|
||||
m.config.DistroDir = comp.Value()
|
||||
|
||||
// 页3:公网网络
|
||||
case "PublicInterface_input":
|
||||
|
||||
@@ -107,13 +107,15 @@ func renderDataInfoPage(m model) string {
|
||||
split_line,
|
||||
makeRow("Country", pageComps["Country_input"].View()),
|
||||
split_line,
|
||||
makeRow("Region", pageComps["Region_input"].View()),
|
||||
makeRow("State", pageComps["State_input"].View()),
|
||||
split_line,
|
||||
makeRow("City", pageComps["City_input"].View()),
|
||||
split_line,
|
||||
makeRow("Contact", pageComps["Contact_input"].View()),
|
||||
split_line,
|
||||
makeRow("Timezone", pageComps["Timezone_input"].View()),
|
||||
split_line,
|
||||
makeRow("DBPath", pageComps["DBPath_input"].View()),
|
||||
split_line,
|
||||
makeRow("Software", pageComps["Software_input"].View()),
|
||||
makeRow("DistroDir", pageComps["DistroDir_input"].View()),
|
||||
split_line,
|
||||
)
|
||||
|
||||
@@ -143,6 +145,8 @@ func renderPublicNetworkPage(m model) string {
|
||||
|
||||
// 拼接公网网络表单
|
||||
formContent := lipgloss.JoinVertical(lipgloss.Center,
|
||||
split_line,
|
||||
makeRow("PublicHostname", pageComps["PublicHostname_input"].View()),
|
||||
split_line,
|
||||
makeRow("PublicInterface", pageComps["PublicInterface_input"].View()),
|
||||
split_line,
|
||||
@@ -152,6 +156,8 @@ func renderPublicNetworkPage(m model) string {
|
||||
split_line,
|
||||
makeRow("PublicGateway", pageComps["PublicGateway_input"].View()),
|
||||
split_line,
|
||||
makeRow("PublicDomain", pageComps["PublicDomain_input"].View()),
|
||||
split_line,
|
||||
makeRow("PublicMTU", pageComps["PublicMTU_input"].View()),
|
||||
split_line,
|
||||
)
|
||||
@@ -187,6 +193,8 @@ func renderInternalNetworkPage(m model) string {
|
||||
|
||||
// 拼接内网网络表单
|
||||
formContent := lipgloss.JoinVertical(lipgloss.Center,
|
||||
split_line,
|
||||
makeRow("PrivateHostname", pageComps["PrivateHostname_input"].View()),
|
||||
split_line,
|
||||
makeRow("PrivateInterface", pageComps["PrivateInterface_input"].View()),
|
||||
split_line,
|
||||
@@ -194,6 +202,8 @@ func renderInternalNetworkPage(m model) string {
|
||||
split_line,
|
||||
makeRow("PrivateNetmask", pageComps["PrivateNetmask_input"].View()),
|
||||
split_line,
|
||||
makeRow("PrivateDomain", pageComps["PrivateDomain_input"].View()),
|
||||
split_line,
|
||||
makeRow("PrivateMTU", pageComps["PrivateMTU_input"].View()),
|
||||
split_line,
|
||||
)
|
||||
@@ -262,7 +272,11 @@ func renderSummaryPage(m model) string {
|
||||
split_line,
|
||||
makeRow("Country", m.config.Country),
|
||||
split_line,
|
||||
makeRow("Region", m.config.Region),
|
||||
makeRow("State", m.config.State),
|
||||
split_line,
|
||||
makeRow("City", m.config.City),
|
||||
split_line,
|
||||
makeRow("Contact", m.config.Contact),
|
||||
split_line,
|
||||
makeRow("Timezone", m.config.Timezone),
|
||||
split_line,
|
||||
@@ -270,7 +284,7 @@ func renderSummaryPage(m model) string {
|
||||
split_line,
|
||||
makeRow("DBPath", m.config.DBAddress),
|
||||
split_line,
|
||||
makeRow("Software", m.config.Software),
|
||||
makeRow("DistroDir", m.config.DistroDir),
|
||||
split_line,
|
||||
makeRow("PublicInterface", m.config.PublicInterface),
|
||||
split_line,
|
||||
|
||||
Reference in New Issue
Block a user