mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #4965 from ioito/hotfix/qx-cloudevent-brand
fix: 公有云日志添加brand字段
This commit is contained in:
@@ -26,6 +26,8 @@ type CloudeventListInput struct {
|
||||
|
||||
compute.ManagedResourceListInput
|
||||
|
||||
Since time.Time
|
||||
Until time.Time
|
||||
// 操作日志起始时间
|
||||
Since time.Time `json:"since"`
|
||||
// 操作日志截止时间
|
||||
Until time.Time `json:"until"`
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ func init() {
|
||||
type SCloudevent struct {
|
||||
db.SModelBase
|
||||
|
||||
Id int64 `primary:"true" auto_increment:"true" list:"user"`
|
||||
Name string `width:"128" charset:"utf8" nullable:"false" index:"true" list:"user"`
|
||||
Service string `width:"64" charset:"utf8" nullable:"true" list:"user"`
|
||||
ResourceType string `width:"64" charset:"utf8" nullable:"true" list:"user"`
|
||||
@@ -63,6 +64,7 @@ type SCloudevent struct {
|
||||
CloudproviderId string `width:"64" charset:"utf8" nullable:"true" list:"user"`
|
||||
Manager string `width:"128" charset:"utf8" nullable:"false" index:"true" list:"user"`
|
||||
Provider string `width:"64" charset:"ascii" nullable:"false" list:"user"`
|
||||
Brand string `width:"64" charset:"ascii" list:"domain"`
|
||||
}
|
||||
|
||||
func (self *SCloudeventManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
@@ -101,6 +103,10 @@ func (manager *SCloudeventManager) ListItemFilter(ctx context.Context, q *sqlche
|
||||
q = q.In("provider", input.Providers)
|
||||
}
|
||||
|
||||
if len(input.Brands) > 0 {
|
||||
q = q.In("brand", input.Brands)
|
||||
}
|
||||
|
||||
if !input.Since.IsZero() {
|
||||
q = q.GT("created_at", input.Since)
|
||||
}
|
||||
@@ -129,6 +135,7 @@ func (manager *SCloudeventManager) SyncCloudevent(ctx context.Context, userCred
|
||||
Success: iEvent.IsSuccess(),
|
||||
Manager: cloudprovider.Name,
|
||||
Provider: cloudprovider.Provider,
|
||||
Brand: cloudprovider.Brand,
|
||||
CloudproviderId: cloudprovider.Id,
|
||||
}
|
||||
|
||||
@@ -151,3 +158,22 @@ func (manager *SCloudeventManager) GetPagingConfig() *db.SPagingConfig {
|
||||
DefaultLimit: 20,
|
||||
}
|
||||
}
|
||||
|
||||
func (manager *SCloudeventManager) InitializeData() error {
|
||||
events := []SCloudevent{}
|
||||
q := manager.Query().IsNullOrEmpty("brand")
|
||||
err := db.FetchModelObjects(manager, q, &events)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := range events {
|
||||
_, err = db.Update(&events[i], func() error {
|
||||
events[i].Brand = events[i].Provider
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -67,12 +67,13 @@ type SCloudprovider struct {
|
||||
Secret string `length:"0" charset:"ascii" nullable:"false" list:"domain"`
|
||||
|
||||
Provider string `width:"64" charset:"ascii" list:"domain"`
|
||||
Brand string `width:"64" charset:"ascii" list:"domain"`
|
||||
}
|
||||
|
||||
func (manager *SCloudproviderManager) GetRegionCloudproviders(ctx context.Context, userCred mcclient.TokenCredential) ([]SCloudprovider, error) {
|
||||
s := session.GetSession(ctx, userCred)
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString("public"), "cloud_env")
|
||||
params.Add(jsonutils.JSONTrue, "details")
|
||||
result, err := modules.Cloudproviders.List(s, params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "modules.Cloudproviders.List")
|
||||
@@ -151,6 +152,7 @@ func (provider *SCloudprovider) syncWithRegionProvider(ctx context.Context, user
|
||||
provider.Status = cloudprovider.Status
|
||||
provider.Secret = cloudprovider.Secret
|
||||
provider.Enabled = cloudprovider.Enabled
|
||||
provider.Brand = cloudprovider.Brand
|
||||
return nil
|
||||
})
|
||||
return err
|
||||
|
||||
@@ -29,6 +29,7 @@ func InitDB() error {
|
||||
db.TenantCacheManager,
|
||||
|
||||
CloudproviderManager,
|
||||
CloudeventManager,
|
||||
} {
|
||||
err := manager.InitializeData()
|
||||
if err != nil {
|
||||
|
||||
@@ -872,6 +872,8 @@ func (self *SCloudprovider) getMoreDetails(ctx context.Context, extra *jsonutils
|
||||
account := self.GetCloudaccount()
|
||||
if account != nil {
|
||||
extra.Add(jsonutils.NewString(account.GetName()), "cloudaccount")
|
||||
// 此字段不能删除,公有云日志同步需要这个字段
|
||||
extra.Add(jsonutils.NewString(account.Brand), "brand")
|
||||
}
|
||||
extra.Set("sync_status2", jsonutils.NewString(self.getSyncStatus2()))
|
||||
capabilities, _ := CloudproviderCapabilityManager.getCapabilities(self.Id)
|
||||
|
||||
Reference in New Issue
Block a user