feat(clustertool): extract IPs without talhelper
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package talassist
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/truecharts/public/clustertool/pkg/helper"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// NodeIPConfig represents a simplified YAML structure to only parse node IP addresses
|
||||
type NodeIPConfig struct {
|
||||
Nodes []struct {
|
||||
IPAddress string `yaml:"ipAddress"`
|
||||
} `yaml:"nodes"`
|
||||
}
|
||||
|
||||
// LoadNodeIPs loads the list of IP addresses in nodes[].ipAddress from talconfig.yaml
|
||||
func LoadNodeIPs() error {
|
||||
// Read the YAML file
|
||||
data, err := ioutil.ReadFile(helper.TalConfigFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Unmarshal only the IP addresses from the YAML
|
||||
var config NodeIPConfig
|
||||
if err := yaml.Unmarshal(data, &config); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Extract the IP addresses into a list
|
||||
for _, node := range config.Nodes {
|
||||
ipAddresses = append(ipAddresses, node.IPAddress)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package talassist
|
||||
|
||||
var (
|
||||
ipAddresses = []string{}
|
||||
)
|
||||
Reference in New Issue
Block a user