Merge pull request #774 in YUNIONIO/onecloud from ~QUXUAN/onecloud:hotfix/qx-cloudprovider-clean-schedcache to release/2.1.0

* commit 'b50cd5f667142aeb30a1658af129da13b1a62e1e':
  同步完成后清理调度缓存
This commit is contained in:
邱剑
2018-12-17 12:13:35 +08:00
2 changed files with 15 additions and 2 deletions
+14 -2
View File
@@ -8,14 +8,14 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/pkg/util/timeutils"
"yunion.io/x/pkg/utils"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
)
const (
@@ -70,6 +70,18 @@ func (self *SCloudprovider) ValidateDeleteCondition(ctx context.Context) error {
return self.SEnabledStatusStandaloneResourceBase.ValidateDeleteCondition(ctx)
}
func (self *SCloudprovider) CleanSchedCache() {
hosts := []SHost{}
q := HostManager.Query().Equals("manager_id", self.Id)
if err := db.FetchModelObjects(HostManager, q, &hosts); err != nil {
log.Errorf("failed to get hosts for cloudprovider %s error: %v", self.Name, err)
return
}
for _, host := range hosts {
host.ClearSchedDescCache()
}
}
func (self *SCloudprovider) GetGuestCount() int {
sq := HostManager.Query("id").Equals("manager_id", self.Id)
return GuestManager.Query().In("host_id", sq).Count()
@@ -80,6 +80,7 @@ func (self *CloudProviderSyncInfoTask) OnInit(ctx context.Context, obj db.IStand
}
provider.SetStatus(self.UserCred, models.CLOUD_PROVIDER_CONNECTED, "")
provider.CleanSchedCache()
self.SetStageComplete(ctx, nil)
logclient.AddActionLog(provider, getAction(self.Params), body, self.UserCred, true)
}