mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
fix(host): catch init error
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
package hostman
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
execlient "yunion.io/x/executor/client"
|
||||
"yunion.io/x/log"
|
||||
|
||||
@@ -77,7 +79,12 @@ func (host *SHostService) RunService() {
|
||||
|
||||
hostInstance := hostinfo.Instance()
|
||||
if err := hostInstance.Init(); err != nil {
|
||||
log.Fatalf("Host instance init error: %v", err)
|
||||
log.Errorf("Host instance init error: %v", err)
|
||||
for {
|
||||
// to catch error
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
// log.Fatalf("Host instance init error: %v", err)
|
||||
}
|
||||
|
||||
app_common.InitAuth(&options.HostOptions.CommonOptions, func() {
|
||||
|
||||
@@ -198,9 +198,7 @@ func (h *SHostInfo) Init() error {
|
||||
}
|
||||
|
||||
if err := hostbridge.Prepare(options.HostOptions.BridgeDriver); err != nil {
|
||||
err := errors.Errorf("Prepare host bridge %q error: %v", options.HostOptions.BridgeDriver, err)
|
||||
log.Errorln(err)
|
||||
return err
|
||||
return errors.Wrapf(err, "Prepare host bridge %q", options.HostOptions.BridgeDriver)
|
||||
}
|
||||
|
||||
log.Infof("Start parseConfig")
|
||||
@@ -302,7 +300,7 @@ func (h *SHostInfo) parseConfig() error {
|
||||
if len(options.HostOptions.Networks) == 0 {
|
||||
netConf, err := h.generateLocalNetworkConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "generateLocalNetworkConfig")
|
||||
}
|
||||
log.Infof("Generate network config %s", netConf)
|
||||
options.HostOptions.Networks = []string{netConf}
|
||||
@@ -319,13 +317,13 @@ func (h *SHostInfo) parseConfig() error {
|
||||
for _, n := range options.HostOptions.Networks {
|
||||
nic, err := NewNIC(n)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrapf(err, "NewNIC %s", n)
|
||||
}
|
||||
h.Nics = append(h.Nics, nic)
|
||||
}
|
||||
for i := 0; i < len(h.Nics); i++ {
|
||||
if err := h.Nics[i].SetupDhcpRelay(); err != nil {
|
||||
return err
|
||||
return errors.Wrapf(err, "SetupDhcpRelay %s/%s/%s", h.Nics[i].Inter, h.Nics[i].Bridge, h.Nics[i].Ip)
|
||||
}
|
||||
}
|
||||
if len(options.HostOptions.ListenInterface) > 0 {
|
||||
|
||||
@@ -274,27 +274,24 @@ func NewNIC(desc string) (*SNIC, error) {
|
||||
nic.BridgeDev, err = hostbridge.NewDriver(options.HostOptions.BridgeDriver,
|
||||
nic.Bridge, nic.Inter, nic.Ip)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return nil, err
|
||||
return nil, errors.Wrapf(err, "hostbridge.NewDriver driver: %s, bridge: %s, interface: %s, ip: %s", options.HostOptions.BridgeDriver, nic.Bridge, nic.Inter, nic.Ip)
|
||||
}
|
||||
|
||||
confirm, err := nic.BridgeDev.ConfirmToConfig()
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return nil, err
|
||||
return nil, errors.Wrapf(err, "nic.BridgeDev.ConfirmToConfig %#v", nic.BridgeDev)
|
||||
}
|
||||
if !confirm {
|
||||
log.Infof("Not confirm to configuration")
|
||||
if err = nic.BridgeDev.Setup(nic.BridgeDev); err != nil {
|
||||
log.Errorln(err)
|
||||
return nil, err
|
||||
return nil, errors.Wrapf(err, "nic.BridgeDev.Setup %v", nic.BridgeDev)
|
||||
}
|
||||
time.Sleep(time.Second * 1)
|
||||
} else {
|
||||
log.Infof("Confirm to configuration!!")
|
||||
}
|
||||
if err := nic.BridgeDev.PersistentConfig(); err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrapf(err, "nic.BridgeDev.PersistentConfig %v", nic.BridgeDev)
|
||||
}
|
||||
if isDHCP, err := nic.BridgeDev.DisableDHCPClient(); err != nil {
|
||||
return nil, errors.Wrap(err, "disable dhcp client")
|
||||
|
||||
Reference in New Issue
Block a user