mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
Merge pull request #397 in YUNIONIO/onecloud from ~WANYAOQI/onecloud:feature/wyq/support-get-export-keys to release/2.2.0
* commit '3151e782e990bdc9a815e64e26613982c72b931b': support export filter
This commit is contained in:
@@ -340,6 +340,12 @@ func query2List(manager IModelManager, ctx context.Context, userCred mcclient.To
|
||||
}
|
||||
jsonDict = getModelExtraDetails(item, ctx, jsonDict)
|
||||
}
|
||||
if query.Contains("export_keys") {
|
||||
exportDict := item.GetExportItems(ctx, userCred, query)
|
||||
if exportDict != nil {
|
||||
jsonDict.Update(exportDict)
|
||||
}
|
||||
}
|
||||
results = append(results, jsonDict)
|
||||
}
|
||||
return results, nil
|
||||
|
||||
@@ -74,6 +74,7 @@ type IModel interface {
|
||||
// get hooks
|
||||
AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool
|
||||
GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict
|
||||
GetExportItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict
|
||||
|
||||
// create hooks
|
||||
CustomizeCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data jsonutils.JSONObject) error
|
||||
|
||||
@@ -180,6 +180,10 @@ func (model *SModelBase) GetCustomizeColumns(ctx context.Context, userCred mccli
|
||||
return jsonutils.NewDict()
|
||||
}
|
||||
|
||||
func (model *SModelBase) GetExportItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
return jsonutils.NewDict()
|
||||
}
|
||||
|
||||
// get hooks
|
||||
func (model *SModelBase) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool {
|
||||
return false
|
||||
|
||||
@@ -1103,6 +1103,20 @@ func (self *SGuest) GetExtraDetails(ctx context.Context, userCred mcclient.Token
|
||||
return self.moreExtraInfo(extra)
|
||||
}
|
||||
|
||||
func (self *SGuest) GetExportItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
exportKeys, _ := query.GetString("export_keys")
|
||||
keys := strings.Split(exportKeys, ",")
|
||||
res := jsonutils.NewDict()
|
||||
if utils.IsInStringArray("os_distribution", keys) {
|
||||
osType := self.GetMetadata("os_distribution", userCred)
|
||||
if len(osType) == 0 {
|
||||
osType = self.OsType
|
||||
}
|
||||
res.Set("os_distribution", jsonutils.NewString(osType))
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (self *SGuest) getNetworksDetails() string {
|
||||
var buf bytes.Buffer
|
||||
for _, nic := range self.GetNetworks() {
|
||||
|
||||
Reference in New Issue
Block a user