mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-06-02 05:52:00 +08:00
fix(region): add cloud_env filter for cachedimages (#23190)
This commit is contained in:
@@ -99,4 +99,7 @@ type CachedimageListInput struct {
|
||||
|
||||
// valid cachedimage
|
||||
Valid bool `json:"valid"`
|
||||
|
||||
// enum: [public, private]
|
||||
CloudEnv string `json:"cloud_env"`
|
||||
}
|
||||
|
||||
@@ -1017,7 +1017,7 @@ func GetTagValueCountMap(
|
||||
}
|
||||
objSubQ = objSubQ.AppendField(sumFieldQ)
|
||||
|
||||
objSubQ.DebugQuery2("GetTagValueCountMap objSubQ")
|
||||
// objSubQ.DebugQuery2("GetTagValueCountMap objSubQ")
|
||||
|
||||
q := objSubQ.SubQuery().Query()
|
||||
q = q.AppendField(sqlchemy.SUM(tagValueCountKey, q.Field("_sub_count_")))
|
||||
@@ -1040,7 +1040,7 @@ func GetTagValueCountMap(
|
||||
}
|
||||
q = q.GroupBy(groupBy...)
|
||||
|
||||
q.DebugQuery2("GetTagValueCountMap")
|
||||
// q.DebugQuery2("GetTagValueCountMap")
|
||||
|
||||
valueMap, err := q.AllStringMap()
|
||||
if err != nil {
|
||||
|
||||
@@ -1404,7 +1404,7 @@ func (manager *STaskManager) migrateObjectInfo() error {
|
||||
q = q.Filter(sqlchemy.IsNull(taskObj.Field("task_id")))
|
||||
q = q.Asc("created_at")
|
||||
|
||||
q.DebugQuery2("migrateObjectInfo")
|
||||
// q.DebugQuery2("migrateObjectInfo")
|
||||
|
||||
rows, err := q.Rows()
|
||||
if err != nil {
|
||||
|
||||
@@ -912,6 +912,26 @@ func (manager *SCachedimageManager) ListItemFilter(
|
||||
if len(query.CloudproviderId) > 0 {
|
||||
storagesQ = storagesQ.In("manager_id", query.CloudproviderId)
|
||||
}
|
||||
if len(query.CloudEnv) > 0 {
|
||||
switch query.CloudEnv {
|
||||
case api.CLOUD_ENV_PUBLIC_CLOUD:
|
||||
pubQ := CloudproviderManager.GetPublicProviderIdsQuery()
|
||||
storagesQ = storagesQ.In("manager_id", pubQ)
|
||||
case api.CLOUD_ENV_PRIVATE_CLOUD:
|
||||
privQ := CloudproviderManager.GetPrivateProviderIdsQuery()
|
||||
storagesQ = storagesQ.In("manager_id", privQ)
|
||||
case api.CLOUD_ENV_ON_PREMISE:
|
||||
storagesQ = storagesQ.IsNullOrEmpty("manager_id")
|
||||
case api.CLOUD_ENV_PRIVATE_ON_PREMISE:
|
||||
privQ := CloudproviderManager.GetPrivateProviderIdsQuery()
|
||||
storagesQ = storagesQ.Filter(
|
||||
sqlchemy.OR(
|
||||
sqlchemy.In(storagesQ.Field("manager_id"), privQ),
|
||||
sqlchemy.IsNullOrEmpty(storagesQ.Field("manager_id")),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
if len(query.HostSchedtagId) > 0 {
|
||||
hostschedtags := HostschedtagManager.Query("host_id").Equals("schedtag_id", query.HostSchedtagId)
|
||||
hoststorages := HoststorageManager.Query("storage_id").In("host_id", hostschedtags.Distinct().SubQuery())
|
||||
|
||||
@@ -23,7 +23,9 @@ import (
|
||||
"yunion.io/x/pkg/gotypes"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/compute/options"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
"yunion.io/x/onecloud/pkg/util/yunionmeta"
|
||||
)
|
||||
|
||||
@@ -153,6 +155,7 @@ func (self *SCloudimage) syncWithImage(ctx context.Context, userCred mcclient.To
|
||||
|
||||
skuUrl := region.getMetaUrl(meta.ImageBase, image.GetGlobalId())
|
||||
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
obj, err := db.FetchByExternalId(CachedimageManager, image.GetGlobalId())
|
||||
if err != nil {
|
||||
if errors.Cause(err) != sql.ErrNoRows {
|
||||
@@ -168,7 +171,7 @@ func (self *SCloudimage) syncWithImage(ctx context.Context, userCred mcclient.To
|
||||
}
|
||||
|
||||
cachedImage.IsPublic = true
|
||||
cachedImage.ProjectId = "system"
|
||||
cachedImage.ProjectId = s.GetProjectId()
|
||||
err = CachedimageManager.TableSpec().Insert(ctx, cachedImage)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Insert cachedimage")
|
||||
@@ -176,18 +179,23 @@ func (self *SCloudimage) syncWithImage(ctx context.Context, userCred mcclient.To
|
||||
return nil
|
||||
}
|
||||
cachedImage := obj.(*SCachedimage)
|
||||
if gotypes.IsNil(cachedImage.Info) {
|
||||
err = meta.Get(skuUrl, &image)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Get")
|
||||
}
|
||||
_, err := db.Update(cachedImage, func() error {
|
||||
_, err = db.Update(cachedImage, func() error {
|
||||
if gotypes.IsNil(cachedImage.Info) {
|
||||
err = meta.Get(skuUrl, &image)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Get")
|
||||
}
|
||||
cachedImage.Info = image.Info
|
||||
cachedImage.Size = image.Size
|
||||
cachedImage.UEFI = image.UEFI
|
||||
return nil
|
||||
})
|
||||
return err
|
||||
}
|
||||
if cachedImage.ProjectId == "system" {
|
||||
cachedImage.ProjectId = s.GetProjectId()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Update cachedimage")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/compute/options"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
"yunion.io/x/onecloud/pkg/util/yunionmeta"
|
||||
)
|
||||
@@ -1264,7 +1265,8 @@ func (self *SCloudregion) newCloudimage(ctx context.Context, userCred mcclient.T
|
||||
}
|
||||
|
||||
image.IsPublic = true
|
||||
image.ProjectId = "system"
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
image.ProjectId = s.GetProjectId()
|
||||
err = CachedimageManager.TableSpec().Insert(ctx, image)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Insert cachedimage")
|
||||
|
||||
Reference in New Issue
Block a user