mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #5420 from swordqiu/automated-cherry-pick-of-#5419-upstream-release-3.1
Automated cherry pick of #5419: fix: fail to find esxi admin vnic, use vnic with default IPv4 route
This commit is contained in:
@@ -313,7 +313,7 @@ func findHostNicByMac(nicInfoList []SHostNicInfo, mac string) *SHostNicInfo {
|
||||
}
|
||||
|
||||
func (self *SHost) getAdminNic() *SHostNicInfo {
|
||||
nics := self.getNicInfo()
|
||||
nics := self.getNicInfo(false)
|
||||
for i := 0; i < len(nics); i += 1 {
|
||||
if nics[i].NicType == api.NIC_TYPE_ADMIN {
|
||||
return &nics[i]
|
||||
@@ -327,20 +327,24 @@ func (self *SHost) getAdminNic() *SHostNicInfo {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHost) getNicInfo() []SHostNicInfo {
|
||||
func (self *SHost) getNicInfo(debug bool) []SHostNicInfo {
|
||||
if self.nicInfo == nil {
|
||||
self.nicInfo = self.fetchNicInfo()
|
||||
self.nicInfo = self.fetchNicInfo(debug)
|
||||
}
|
||||
return self.nicInfo
|
||||
}
|
||||
|
||||
func (self *SHost) fetchNicInfo() []SHostNicInfo {
|
||||
func (self *SHost) fetchNicInfo(debug bool) []SHostNicInfo {
|
||||
moHost := self.getHostSystem()
|
||||
|
||||
if moHost.Config == nil || moHost.Config.Network == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if debug {
|
||||
log.Debugf("%s", jsonutils.Marshal(moHost.Config.Network).PrettyString())
|
||||
}
|
||||
|
||||
nicInfoList := make([]SHostNicInfo, 0)
|
||||
|
||||
for i, nic := range moHost.Config.Network.Pnic {
|
||||
@@ -388,6 +392,29 @@ func (self *SHost) fetchNicInfo() []SHostNicInfo {
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(pnic.IpAddr) == 0 {
|
||||
// find default route vnic
|
||||
defRouteDev := make([]string, 0)
|
||||
for _, r := range moHost.Config.Network.RouteTableInfo.IpRoute {
|
||||
if r.Network == "0.0.0.0" && r.PrefixLength == 0 {
|
||||
// default route
|
||||
defRouteDev = append(defRouteDev, r.DeviceName)
|
||||
}
|
||||
}
|
||||
if len(defRouteDev) == 1 {
|
||||
for _, nic := range vnics {
|
||||
if nic.Device == defRouteDev[0] {
|
||||
pnic.NicType = api.NIC_TYPE_ADMIN
|
||||
pnic.IpAddr = nic.Spec.Ip.IpAddress
|
||||
pnic.LinkUp = true
|
||||
pnic.Mtu = nic.Spec.Mtu
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.Errorf("find default route interfaces fail: %s", defRouteDev)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nicInfoList
|
||||
@@ -1020,7 +1047,11 @@ func (host *SHost) isVersion50() bool {
|
||||
}
|
||||
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
nics := host.getNicInfo()
|
||||
return host.GetIHostNicsInternal(false)
|
||||
}
|
||||
|
||||
func (host *SHost) GetIHostNicsInternal(debug bool) ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
nics := host.getNicInfo(debug)
|
||||
inics := make([]cloudprovider.ICloudHostNetInterface, len(nics))
|
||||
for i := 0; i < len(nics); i += 1 {
|
||||
inics[i] = &nics[i]
|
||||
|
||||
@@ -38,6 +38,8 @@ func init() {
|
||||
|
||||
type HostShowOptions struct {
|
||||
IP string `help:"Host IP"`
|
||||
|
||||
Debug bool `help:"show debug info"`
|
||||
}
|
||||
shellutils.R(&HostShowOptions{}, "host-show", "Show details of a host by IP", func(cli *esxi.SESXiClient, args *HostShowOptions) error {
|
||||
host, err := cli.FindHostByIp(args.IP)
|
||||
@@ -66,7 +68,7 @@ func init() {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
nics, err := host.GetIHostNics()
|
||||
nics, err := host.GetIHostNicsInternal(args.Debug)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user