mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
report host stat
This commit is contained in:
@@ -50,7 +50,7 @@ type IBridgeDriver interface {
|
||||
SetupBridgeDev() error
|
||||
SetupInterface() error
|
||||
PersistentMac() error
|
||||
DisableDHCPClient() error
|
||||
DisableDHCPClient() (bool, error)
|
||||
|
||||
GenerateIfupScripts(scriptPath string, nic jsonutils.JSONObject) error
|
||||
GenerateIfdownScripts(scriptPath string, nic jsonutils.JSONObject) error
|
||||
@@ -330,33 +330,33 @@ func (d *SBaseBridgeDriver) WarmupConfig() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *SBaseBridgeDriver) DisableDHCPClient() error {
|
||||
func (d *SBaseBridgeDriver) DisableDHCPClient() (bool, error) {
|
||||
if d.inter != nil {
|
||||
filename := fmt.Sprintf("/var/run/dhclient-%s.pid", d.inter.String())
|
||||
if !fileutils2.Exists(filename) {
|
||||
return nil
|
||||
return false, nil
|
||||
}
|
||||
s, err := fileutils2.FileGetContents(filename)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get dhclient pid")
|
||||
return false, errors.Wrap(err, "get dhclient pid")
|
||||
}
|
||||
pid, err := strconv.Atoi(strings.TrimSpace(s))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "convert pid str to int")
|
||||
return false, errors.Wrap(err, "convert pid str to int")
|
||||
}
|
||||
if fileutils2.Exists(fmt.Sprintf("/proc/%d/cmdline", pid)) {
|
||||
cmdline, err := fileutils2.FileGetContents(fmt.Sprintf("/proc/%d/cmdline", pid))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get proc cmdline")
|
||||
return false, errors.Wrap(err, "get proc cmdline")
|
||||
}
|
||||
if strings.Contains(cmdline, "dhclient") {
|
||||
// kill process
|
||||
p, _ := os.FindProcess(pid)
|
||||
return p.Kill()
|
||||
return true, p.Kill()
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func NewDriver(bridgeDriver, bridge, inter, ip string) (IBridgeDriver, error) {
|
||||
|
||||
@@ -86,7 +86,9 @@ type SHostInfo struct {
|
||||
CloudregionId string
|
||||
ZoneManagerUri string
|
||||
|
||||
FullName string
|
||||
FullName string
|
||||
SysError map[string]string
|
||||
SysWarning map[string]string
|
||||
}
|
||||
|
||||
func (h *SHostInfo) GetIsolatedDeviceManager() *isolated_device.IsolatedDeviceManager {
|
||||
@@ -627,6 +629,9 @@ func (h *SHostInfo) detectSyssoftwareInfo() error {
|
||||
return err
|
||||
}
|
||||
h.detectOvsVersion()
|
||||
if err := h.detectOvsKOVersion(); err != nil {
|
||||
h.SysError["openvswitch"] = err.Error()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -667,6 +672,21 @@ func (h *SHostInfo) detectOvsVersion() {
|
||||
}
|
||||
}
|
||||
|
||||
func (h *SHostInfo) detectOvsKOVersion() error {
|
||||
output, err := procutils.NewRemoteCommandAsFarAsPossible("modinfo", "openvswitch").Output()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "modinfo openvswitch")
|
||||
}
|
||||
lines := strings.Split(string(output), "\n")
|
||||
for i := 0; i < len(lines); i++ {
|
||||
if strings.HasPrefix(lines[i], "version:") {
|
||||
log.Infof("kernel module openvswitch %s", lines[i])
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errors.Errorf("kernel module openvswitch paramters version not found, is kernel version correct ??")
|
||||
}
|
||||
|
||||
func (h *SHostInfo) GetMasterNicIpAndMask() (string, int) {
|
||||
log.Errorf("MasterNic %#v", h.MasterNic)
|
||||
if h.MasterNic != nil {
|
||||
@@ -976,8 +996,11 @@ func (h *SHostInfo) updateHostMetadata(hostname string) error {
|
||||
OnKubernetes: onK8s,
|
||||
Hostname: hostname,
|
||||
}
|
||||
data := meta.JSON(meta)
|
||||
data.Set("__sys_error", jsonutils.Marshal(h.SysError))
|
||||
data.Set("__sys_warning", jsonutils.Marshal(h.SysWarning))
|
||||
|
||||
_, err := modules.Hosts.SetMetadata(h.GetSession(), h.HostId, meta.JSON(meta))
|
||||
_, err := modules.Hosts.SetMetadata(h.GetSession(), h.HostId, data)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1055,6 +1078,14 @@ func (h *SHostInfo) PutHostOffline() {
|
||||
}
|
||||
|
||||
func (h *SHostInfo) PutHostOnline() error {
|
||||
if len(h.SysError) > 0 {
|
||||
log.Fatalf("Can't put host online, unless resolve these problem %v", h.SysError)
|
||||
}
|
||||
|
||||
if len(h.SysWarning) > 0 {
|
||||
log.Warningf("Host have some hidden problem %v", h.SysWarning)
|
||||
}
|
||||
|
||||
data := jsonutils.NewDict()
|
||||
if options.HostOptions.EnableHealthChecker && len(options.HostOptions.EtcdEndpoints) > 0 {
|
||||
_, err := host_health.InitHostHealthManager(h.HostId, h.onHostDown)
|
||||
@@ -1622,6 +1653,8 @@ func NewHostInfo() (*SHostInfo, error) {
|
||||
|
||||
res.Nics = make([]*SNIC, 0)
|
||||
res.IsRegistered = make(chan struct{})
|
||||
res.SysError = make(map[string]string)
|
||||
res.SysWarning = make(map[string]string)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -349,8 +349,10 @@ func NewNIC(desc string) (*SNIC, error) {
|
||||
if err := nic.BridgeDev.PersistentMac(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := nic.BridgeDev.DisableDHCPClient(); err != nil {
|
||||
if isDHCP, err := nic.BridgeDev.DisableDHCPClient(); err != nil {
|
||||
return nil, errors.Wrap(err, "disable dhcp client")
|
||||
} else if isDHCP {
|
||||
Instance().SysWarning["dhcp"] = "dhcp client is enabled before host agent start, please disable it"
|
||||
}
|
||||
|
||||
var dhcpRelay []string
|
||||
|
||||
Reference in New Issue
Block a user