mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #404 from Zexi/bugfix/capability-account
fix: capability 接口没有考虑 cloudaccount 的禁用情况
This commit is contained in:
@@ -72,7 +72,7 @@ func getRegionZoneSubq(region *SCloudregion) *sqlchemy.SSubQuery {
|
||||
}
|
||||
|
||||
func getHypervisors(region *SCloudregion, zone *SZone) []string {
|
||||
q := HostManager.Query("host_type")
|
||||
q := HostManager.Query("host_type", "manager_id")
|
||||
if region != nil {
|
||||
subq := getRegionZoneSubq(region)
|
||||
q = q.Filter(sqlchemy.In(q.Field("zone_id"), subq))
|
||||
@@ -92,8 +92,9 @@ func getHypervisors(region *SCloudregion, zone *SZone) []string {
|
||||
hypervisors := make([]string, 0)
|
||||
for rows.Next() {
|
||||
var hostType string
|
||||
rows.Scan(&hostType)
|
||||
if len(hostType) > 0 {
|
||||
var managerId string
|
||||
rows.Scan(&hostType, &managerId)
|
||||
if len(hostType) > 0 && IsProviderAccountEnabled(managerId) {
|
||||
hypervisors = append(hypervisors, HOSTTYPE_HYPERVISOR[hostType])
|
||||
}
|
||||
}
|
||||
@@ -101,7 +102,7 @@ func getHypervisors(region *SCloudregion, zone *SZone) []string {
|
||||
}
|
||||
|
||||
func getResourceTypes(region *SCloudregion, zone *SZone) []string {
|
||||
q := HostManager.Query("resource_type")
|
||||
q := HostManager.Query("resource_type", "manager_id")
|
||||
if region != nil {
|
||||
subq := getRegionZoneSubq(region)
|
||||
q = q.Filter(sqlchemy.In(q.Field("zone_id"), subq))
|
||||
@@ -120,8 +121,9 @@ func getResourceTypes(region *SCloudregion, zone *SZone) []string {
|
||||
resourceTypes := make([]string, 0)
|
||||
for rows.Next() {
|
||||
var resType string
|
||||
rows.Scan(&resType)
|
||||
if len(resType) > 0 {
|
||||
var managerId string
|
||||
rows.Scan(&resType, &managerId)
|
||||
if len(resType) > 0 && IsProviderAccountEnabled(managerId) {
|
||||
resourceTypes = append(resourceTypes, resType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -600,6 +600,28 @@ func (manager *SCloudproviderManager) FetchCloudproviderById(providerId string)
|
||||
return providerObj.(*SCloudprovider)
|
||||
}
|
||||
|
||||
func IsProviderAccountEnabled(providerId string) bool {
|
||||
if len(providerId) == 0 {
|
||||
return true
|
||||
}
|
||||
return CloudproviderManager.IsProviderAccountEnabled(providerId)
|
||||
}
|
||||
|
||||
func (manager *SCloudproviderManager) IsProviderAccountEnabled(providerId string) bool {
|
||||
providerObj := manager.FetchCloudproviderById(providerId)
|
||||
if providerObj == nil {
|
||||
return false
|
||||
}
|
||||
if !providerObj.Enabled {
|
||||
return false
|
||||
}
|
||||
account := providerObj.GetCloudaccount()
|
||||
if account == nil {
|
||||
return false
|
||||
}
|
||||
return account.Enabled
|
||||
}
|
||||
|
||||
func (manager *SCloudproviderManager) FetchCloudproviderByIdOrName(providerId string) *SCloudprovider {
|
||||
providerObj, err := manager.FetchByIdOrName(nil, providerId)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user