Merge pull request #4134 from swordqiu/hotfix/qj-esxi-fix-20191213-misc

fix: misc esxi bugfix 20191213
This commit is contained in:
yunion-ci-robot
2019-12-13 12:57:59 +08:00
committed by GitHub
3 changed files with 22 additions and 7 deletions
+5 -2
View File
@@ -60,9 +60,12 @@ func (dc *SDatacenter) scanHosts() error {
if err != nil {
return errors.Wrap(err, "dc.manager.scanMObjects")
}
dc.ihosts = make([]cloudprovider.ICloudHost, len(hosts))
dc.ihosts = make([]cloudprovider.ICloudHost, 0)
for i := 0; i < len(hosts); i += 1 {
dc.ihosts[i] = NewHost(dc.manager, &hosts[i], dc)
h := NewHost(dc.manager, &hosts[i], dc)
if h != nil {
dc.ihosts = append(dc.ihosts, h)
}
}
}
return nil
+8
View File
@@ -92,6 +92,10 @@ type SHost struct {
}
func NewHost(manager *SESXiClient, host *mo.HostSystem, dc *SDatacenter) *SHost {
if host.Config == nil {
log.Errorf("empty host config %s", host.Name)
return nil
}
return &SHost{SManagedObject: newManagedObject(manager, host, dc)}
}
@@ -308,6 +312,10 @@ func (self *SHost) getNicInfo() []SHostNicInfo {
func (self *SHost) fetchNicInfo() []SHostNicInfo {
moHost := self.getHostSystem()
if moHost.Config == nil || moHost.Config.Network == nil {
return nil
}
nicInfoList := make([]SHostNicInfo, 0)
for i, nic := range moHost.Config.Network.Pnic {
+9 -5
View File
@@ -206,16 +206,16 @@ func (cli *SESXiClient) scanMObjects(folder types.ManagedObjectReference, props
v, err := m.CreateContainerView(cli.context, folder, []string{resType}, true)
if err != nil {
log.Fatalf("%s", err)
return err
log.Errorf("m.CreateContainerView for type %s props %s fail: %s", resType, props, err)
return errors.Wrapf(err, "m.CreateContainerView %s", resType)
}
defer v.Destroy(cli.context)
err = v.Retrieve(cli.context, []string{resType}, props, dst)
if err != nil {
log.Fatalf("%s", err)
return err
log.Errorf("v.Retrieve for type %s props %s fail: %s", resType, props, err)
return errors.Wrapf(err, "v.Retrieve %s", resType)
}
return nil
@@ -315,7 +315,11 @@ func (cli *SESXiClient) FindHostByIp(hostIp string) (*SHost, error) {
return nil, err
}
return NewHost(cli, &host, nil), nil
h := NewHost(cli, &host, nil)
if h == nil {
return nil, errors.Wrap(errors.ErrInvalidStatus, "empty host mo")
}
return h, nil
}
func (cli *SESXiClient) acquireCloneTicket() (string, error) {