Skip to content

Commit

Permalink
fix(region): cloudpods hypervisor (#20561)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito authored Jun 18, 2024
1 parent f343dc1 commit c4c5532
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
27 changes: 20 additions & 7 deletions pkg/compute/models/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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()])
}
)

Expand Down Expand Up @@ -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)
}

}
Expand Down
2 changes: 1 addition & 1 deletion pkg/compute/models/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
5 changes: 4 additions & 1 deletion pkg/mcclient/cloudpods/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package cloudpods

import (
"fmt"

"yunion.io/x/cloudmux/pkg/cloudprovider"
"yunion.io/x/cloudmux/pkg/multicloud"
"yunion.io/x/jsonutils"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/mcclient/cloudpods/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit c4c5532

Please sign in to comment.