fix(region): cloudpods hypervisor (#20561)

This commit is contained in:
屈轩
2024-06-18 15:38:36 +08:00
committed by GitHub
parent f343dc1530
commit c4c5532e37
4 changed files with 26 additions and 9 deletions
+20 -7
View File
@@ -159,6 +159,9 @@ type StorageInfos struct {
StorageTypes3 map[string]map[string]*SimpleStorageInfo `json:",allowempty"`
DataStorageTypes2 map[string][]string `json:",allowempty"`
DataStorageTypes3 map[string]map[string]*SimpleStorageInfo `json:",allowempty"`
SystemStorageTypes map[string]map[string]map[string]*SimpleStorageInfo `json:",allowempty"`
DataStorageTypes map[string]map[string]map[string]*SimpleStorageInfo `json:",allowempty"`
}
func GetDiskCapabilities(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, region *SCloudregion, zone *SZone) (SCapabilities, error) {
@@ -726,6 +729,9 @@ func getStorageTypes(
StorageTypes3: map[string]map[string]*SimpleStorageInfo{},
DataStorageTypes2: map[string][]string{},
DataStorageTypes3: map[string]map[string]*SimpleStorageInfo{},
SystemStorageTypes: map[string]map[string]map[string]*SimpleStorageInfo{},
DataStorageTypes: map[string]map[string]map[string]*SimpleStorageInfo{},
}
var (
addStorageInfo = func(storage *StorageInfo, simpleStorage *SimpleStorageInfo) {
@@ -738,24 +744,29 @@ func getStorageTypes(
simpleStorage.Storages = append(simpleStorage.Storages, sStorage{Id: storage.Id, Name: storage.Name})
}
setStorageInfos = func(hostDriver IHostDriver, storageType string, storage *StorageInfo,
storageInfos map[string]map[string]*SimpleStorageInfo) bool {
var notFound bool
storageInfos map[string]map[string]*SimpleStorageInfo) {
sfs, ok := storageInfos[hostDriver.GetHypervisor()]
if !ok {
sfs = make(map[string]*SimpleStorageInfo)
notFound = true
}
simpleStorage, ok := sfs[storageType]
if !ok {
notFound = true
simpleStorage = &SimpleStorageInfo{Storages: []sStorage{}}
}
if !utils.IsInStringArray(hostDriver.GetProvider(), api.PUBLIC_CLOUD_PROVIDERS) {
addStorageInfo(storage, simpleStorage)
sfs[storageType] = simpleStorage
storageInfos[hostDriver.GetHypervisor()] = sfs
}
return notFound
sfs[storageType] = simpleStorage
storageInfos[hostDriver.GetHypervisor()] = sfs
}
setStorageInfos2 = func(hostDriver IHostDriver, storageType string, storage *StorageInfo,
storageInfos2 map[string]map[string]map[string]*SimpleStorageInfo) {
_, ok := storageInfos2[hostDriver.GetProvider()]
if !ok {
storageInfos2[hostDriver.GetProvider()] = make(map[string]map[string]*SimpleStorageInfo)
}
setStorageInfos(hostDriver, storageType, storage, storageInfos2[hostDriver.GetProvider()])
}
)
@@ -806,8 +817,10 @@ func getStorageTypes(
// set hypervisor storage types and infos
if storage.IsSysDiskStore {
setStorageInfos(hostDriver, storageType, &storage, ret.StorageTypes3)
setStorageInfos2(hostDriver, storageType, &storage, ret.SystemStorageTypes)
}
setStorageInfos(hostDriver, storageType, &storage, ret.DataStorageTypes3)
setStorageInfos2(hostDriver, storageType, &storage, ret.DataStorageTypes)
}
}
+1 -1
View File
@@ -5906,7 +5906,7 @@ func (manager *SHostManager) PingDetectionTask(ctx context.Context, userCred mcc
deadline := time.Now().Add(-1 * time.Duration(options.Options.HostOfflineMaxSeconds) * time.Second)
q := manager.Query().Equals("host_status", api.HOST_ONLINE).
Equals("host_type", api.HOST_TYPE_HYPERVISOR)
Equals("host_type", api.HOST_TYPE_HYPERVISOR).IsNullOrEmpty("manager_id")
q = q.Filter(sqlchemy.OR(sqlchemy.IsNull(q.Field("last_ping_at")),
sqlchemy.LT(q.Field("last_ping_at"), deadline)))
+4 -1
View File
@@ -15,6 +15,8 @@
package cloudpods
import (
"fmt"
"yunion.io/x/cloudmux/pkg/cloudprovider"
"yunion.io/x/cloudmux/pkg/multicloud"
"yunion.io/x/jsonutils"
@@ -270,7 +272,7 @@ func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error
}
func (host *SHost) CreateVM(opts *cloudprovider.SManagedVMCreateConfig) (cloudprovider.ICloudVM, error) {
hypervisor := api.HOST_TYPE_HYPERVISOR
hypervisor := api.HYPERVISOR_KVM
if host.HostType == api.HOST_TYPE_ESXI {
hypervisor = api.HYPERVISOR_ESXI
}
@@ -338,6 +340,7 @@ func (region *SRegion) GetHosts(zoneId string) ([]SHost, error) {
if len(zoneId) > 0 {
params["zone_id"] = zoneId
}
params["filter"] = fmt.Sprintf("host_type.in('hypervisor', 'baremetal')")
ret := []SHost{}
err := region.list(&modules.Hosts, params, &ret)
if err != nil {
+1
View File
@@ -486,6 +486,7 @@ func (self *SRegion) GetInstances(hostId string) ([]SInstance, error) {
if len(hostId) > 0 {
params["host_id"] = hostId
}
params["filter"] = fmt.Sprintf("hypervisor.in('kvm', 'baremetal')")
ret := []SInstance{}
return ret, self.list(&modules.Servers, params, &ret)
}