mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
Merge pull request #255 in YUNIONIO/onecloud from ~QUXUAN/onecloud:hotfix/qx-cloudprovider-sum-guest to release/2.1.0
* commit '873724b1fbdef79890367951896768b24fd849e7': cloudprovider返回虚机数量信息
This commit is contained in:
@@ -70,6 +70,11 @@ func (self *SCloudprovider) ValidateDeleteCondition(ctx context.Context) error {
|
||||
return self.SEnabledStatusStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) GetGuestCount() int {
|
||||
sq := HostManager.Query("id").Equals("manager_id", self.Id)
|
||||
return GuestManager.Query().In("host_id", sq).Count()
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) GetHostCount() int {
|
||||
return HostManager.Query().Equals("manager_id", self.Id).Count()
|
||||
}
|
||||
@@ -396,11 +401,12 @@ func (manager *SCloudproviderManager) FetchCloudproviderByIdOrName(providerId st
|
||||
}
|
||||
|
||||
type SCloudproviderUsage struct {
|
||||
GuestCount int
|
||||
HostCount int
|
||||
VpcCount int
|
||||
StorageCount int
|
||||
StorageCacheCount int
|
||||
EipCount int
|
||||
EipCount int
|
||||
}
|
||||
|
||||
func (usage *SCloudproviderUsage) isEmpty() bool {
|
||||
@@ -424,6 +430,7 @@ func (usage *SCloudproviderUsage) isEmpty() bool {
|
||||
|
||||
func (self *SCloudprovider) getUsage() *SCloudproviderUsage {
|
||||
usage := SCloudproviderUsage{}
|
||||
usage.GuestCount = self.GetGuestCount()
|
||||
usage.HostCount = self.GetHostCount()
|
||||
usage.VpcCount = self.getVpcCount()
|
||||
usage.StorageCount = self.getStorageCount()
|
||||
|
||||
@@ -6,7 +6,9 @@ var (
|
||||
|
||||
func init() {
|
||||
Cloudproviders = NewComputeManager("cloudprovider", "cloudproviders",
|
||||
[]string{"ID", "Name", "Enabled", "Status", "Access_url", "Account", "Last_sync", "Provider"},
|
||||
[]string{"ID", "Name", "Enabled", "Status", "Access_url", "Account",
|
||||
"Last_sync", "Provider", "guest_count", "host_count", "vpc_count",
|
||||
"storage_count", "storage_cache_count", "eip_count"},
|
||||
[]string{})
|
||||
|
||||
registerCompute(&Cloudproviders)
|
||||
|
||||
Reference in New Issue
Block a user