mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #11435 from zexi/automated-cherry-pick-of-#11433-upstream-release-3.7
Automated cherry pick of #11433: fix(region,scheduler): baremetal reuse ip
This commit is contained in:
@@ -160,7 +160,7 @@ func (self *SBaremetalGuestDriver) GetNamedNetworkConfiguration(guest *models.SG
|
||||
}
|
||||
reuseAddr := false
|
||||
hn := host.GetAttach2Network(netConfig.Network)
|
||||
if hn != nil && netConfig.Address == "" && options.Options.BaremetalServerReuseHostIp {
|
||||
if hn != nil && options.Options.BaremetalServerReuseHostIp {
|
||||
// try to reuse host network IP address
|
||||
netConfig.Address = hn.IpAddr
|
||||
reuseAddr = true
|
||||
|
||||
+23
-10
@@ -2448,7 +2448,7 @@ func (self *SHost) GetNetinterfacesWithIdAndCredential(netId string, userCred mc
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
if used == 0 && !reserved {
|
||||
if used == 0 && !reserved && !options.Options.BaremetalServerReuseHostIp {
|
||||
return nil, nil
|
||||
}
|
||||
matchNetIfs := make([]SNetInterface, 0)
|
||||
@@ -2866,16 +2866,11 @@ func (self *SHost) getMoreDetails(ctx context.Context, out api.HostDetails, show
|
||||
out.ServerIps = strings.Join(server.GetRealIPs(), ",")
|
||||
}
|
||||
}
|
||||
netifs := self.GetNetInterfaces()
|
||||
if netifs != nil && len(netifs) > 0 {
|
||||
nics := self.GetNics()
|
||||
if nics != nil && len(nics) > 0 {
|
||||
nicInfos := []jsonutils.JSONObject{}
|
||||
for i := 0; i < len(netifs); i += 1 {
|
||||
nicInfo := netifs[i].getBaremetalJsonDesc()
|
||||
if nicInfo == nil {
|
||||
log.Errorf("netif %s get baremetal desc failed", netifs[i].GetId())
|
||||
continue
|
||||
}
|
||||
nicInfos = append(nicInfos, nicInfo)
|
||||
for i := 0; i < len(nics); i += 1 {
|
||||
nicInfos = append(nicInfos, jsonutils.Marshal(nics[i]))
|
||||
}
|
||||
out.NicCount = len(nicInfos)
|
||||
out.NicInfo = nicInfos
|
||||
@@ -5644,6 +5639,24 @@ func (host *SHost) GetIpmiInfo() (types.SIPMIInfo, error) {
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func (host *SHost) GetNics() []*types.SNic {
|
||||
netifs := host.GetNetInterfaces()
|
||||
nicInfos := []*types.SNic{}
|
||||
if netifs != nil && len(netifs) > 0 {
|
||||
for i := 0; i < len(netifs); i += 1 {
|
||||
desc := netifs[i].getBaremetalJsonDesc()
|
||||
if desc == nil {
|
||||
log.Errorf("netif %s get baremetal desc failed", netifs[i].GetId())
|
||||
continue
|
||||
}
|
||||
nicInfo := new(types.SNic)
|
||||
desc.Unmarshal(nicInfo)
|
||||
nicInfos = append(nicInfos, nicInfo)
|
||||
}
|
||||
}
|
||||
return nicInfos
|
||||
}
|
||||
|
||||
func (host *SHost) GetUEFIInfo() (*types.EFIBootMgrInfo, error) {
|
||||
if host.UefiInfo == nil {
|
||||
return nil, nil
|
||||
|
||||
@@ -1051,6 +1051,11 @@ func isValidNetworkInfo(userCred mcclient.TokenCredential, netConfig *api.Networ
|
||||
if netConfig.BwLimit > api.MAX_BANDWIDTH {
|
||||
return httperrors.NewInputParameterError("Bandwidth limit cannot exceed %dMbps", api.MAX_BANDWIDTH)
|
||||
}
|
||||
if net.ServerType == api.NETWORK_TYPE_BAREMETAL {
|
||||
// not check baremetal network free address here
|
||||
// TODO: find better solution ?
|
||||
return nil
|
||||
}
|
||||
freeCnt, err := net.getFreeAddressCount()
|
||||
if err != nil {
|
||||
return httperrors.NewInternalServerError("getFreeAddressCount fail %s", err)
|
||||
|
||||
+14
@@ -57,6 +57,20 @@ func (h baremetalGetter) StorageInfo() []*baremetal.BaremetalStorage {
|
||||
return h.bm.StorageInfo
|
||||
}
|
||||
|
||||
func (h baremetalGetter) GetFreePort(netId string) int {
|
||||
cnt := h.h.GetFreePort(netId)
|
||||
if cnt < 0 {
|
||||
cnt = 0
|
||||
}
|
||||
nics := h.GetNics()
|
||||
for _, nic := range nics {
|
||||
if len(nic.IpAddr) > 0 && nic.NetId == netId {
|
||||
cnt += 1
|
||||
}
|
||||
}
|
||||
return cnt
|
||||
}
|
||||
|
||||
type BaremetalDesc struct {
|
||||
*BaseHostDesc
|
||||
|
||||
|
||||
+15
@@ -52,6 +52,8 @@ type BaseHostDesc struct {
|
||||
InstanceGroups map[string]*api.CandidateGroup `json:"instance_groups"`
|
||||
IpmiInfo types.SIPMIInfo `json:"ipmi_info"`
|
||||
|
||||
Nics []*types.SNic `json:"nics"`
|
||||
|
||||
SharedDomains []string `json:"shared_domains"`
|
||||
PendingUsage map[string]interface{} `json:"pending_usage"`
|
||||
}
|
||||
@@ -227,6 +229,10 @@ func (b baseHostGetter) GetIpmiInfo() types.SIPMIInfo {
|
||||
return b.h.IpmiInfo
|
||||
}
|
||||
|
||||
func (b baseHostGetter) GetNics() []*types.SNic {
|
||||
return b.h.Nics
|
||||
}
|
||||
|
||||
func (b baseHostGetter) GetQuotaKeys(s *api.SchedInfo) computemodels.SComputeResourceKeys {
|
||||
return b.h.getQuotaKeys(s)
|
||||
}
|
||||
@@ -318,6 +324,10 @@ func newBaseHostDesc(b *baseBuilder, host *computemodels.SHost) (*BaseHostDesc,
|
||||
return nil, fmt.Errorf("Fill ipmi info error: %v", err)
|
||||
}
|
||||
|
||||
if err := desc.fillNics(host); err != nil {
|
||||
return nil, fmt.Errorf("Fill nics info error: %v", err)
|
||||
}
|
||||
|
||||
if err := desc.fillIsolatedDevices(b, host); err != nil {
|
||||
return nil, fmt.Errorf("Fill isolated devices error: %v", err)
|
||||
}
|
||||
@@ -619,6 +629,11 @@ func (b *BaseHostDesc) fillIpmiInfo(host *computemodels.SHost) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *BaseHostDesc) fillNics(host *computemodels.SHost) error {
|
||||
b.Nics = host.GetNics()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *BaseHostDesc) GetEnableStatus() string {
|
||||
if h.GetEnabled() {
|
||||
return "enable"
|
||||
|
||||
@@ -106,6 +106,8 @@ type CandidatePropertyGetter interface {
|
||||
|
||||
GetIpmiInfo() types.SIPMIInfo
|
||||
|
||||
GetNics() []*types.SNic
|
||||
|
||||
GetQuotaKeys(s *api.SchedInfo) computemodels.SComputeResourceKeys
|
||||
|
||||
GetPendingUsage() *schedmodels.SPendingUsage
|
||||
|
||||
@@ -193,6 +193,20 @@ func (mr *MockCandidatePropertyGetterMockRecorder) GetIpmiInfo() *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetIpmiInfo", reflect.TypeOf((*MockCandidatePropertyGetter)(nil).GetIpmiInfo))
|
||||
}
|
||||
|
||||
// GetNics mocks base method
|
||||
func (m *MockCandidatePropertyGetter) GetNics() []*types.SNic {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetNics")
|
||||
ret0, _ := ret[0].([]*types.SNic)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetIpmiInfo indicates an expected call of GetIpmiInfo
|
||||
func (mr *MockCandidatePropertyGetterMockRecorder) GetNics() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNics", reflect.TypeOf((*MockCandidatePropertyGetter)(nil).GetNics))
|
||||
}
|
||||
|
||||
// GetIsolatedDevice mocks base method
|
||||
func (m *MockCandidatePropertyGetter) GetIsolatedDevice(arg0 string) *core.IsolatedDeviceDesc {
|
||||
m.ctrl.T.Helper()
|
||||
|
||||
Reference in New Issue
Block a user