diff --git a/pkg/appsrv/appsrv.go b/pkg/appsrv/appsrv.go index c3b3cebf12..d9865a6d61 100644 --- a/pkg/appsrv/appsrv.go +++ b/pkg/appsrv/appsrv.go @@ -245,7 +245,7 @@ func (app *Application) defaultHandle(w http.ResponseWriter, r *http.Request, ri if ok { fw := newResponseWriterChannel(w) worker := make(chan *SWorker) - to := hand.processTimeout + to := hand.FetchProcessTimeout(r) if to == 0 { to = app.processTimeout } diff --git a/pkg/appsrv/handlerinfo.go b/pkg/appsrv/handlerinfo.go index ccca71da48..1163d95f2a 100644 --- a/pkg/appsrv/handlerinfo.go +++ b/pkg/appsrv/handlerinfo.go @@ -41,6 +41,14 @@ type SHandlerInfo struct { skipLog bool } +func (this *SHandlerInfo) FetchProcessTimeout(r *http.Request) time.Duration { + if r.Method == http.MethodGet && r.Header.Get("X-Export-Keys") == "true" { + return time.Hour * 2 + } else { + return this.processTimeout + } +} + func (this *SHandlerInfo) GetName(params map[string]string) string { if len(this.name) > 0 { return this.name diff --git a/pkg/cloudcommon/db/db_dispatcher.go b/pkg/cloudcommon/db/db_dispatcher.go index 880e4a7047..e05b5b3ceb 100644 --- a/pkg/cloudcommon/db/db_dispatcher.go +++ b/pkg/cloudcommon/db/db_dispatcher.go @@ -476,6 +476,12 @@ func ListItems(manager IModelManager, ctx context.Context, userCred mcclient.Tok limit = maxLimit } + // export data only + exportLimit, err := query.Int("export_limit") + if query.Contains("export_keys") && err == nil { + limit = exportLimit + } + var primaryCol sqlchemy.IColumnSpec primaryCols := manager.TableSpec().PrimaryColumns() if len(primaryCols) == 1 { diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 7bb189ee79..0ee5d2b42e 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -1550,6 +1550,13 @@ func (manager *SGuestManager) ListItemExportKeys(ctx context.Context, q *sqlchem q.AppendField(eipsSubQuery.Field("ip_addr", "eip")) } + if utils.IsInStringArray("host", keys) { + hostQuery := HostManager.Query("id", "name").GroupBy("id") + hostSubQuery := hostQuery.SubQuery() + q.LeftJoin(hostSubQuery, sqlchemy.Equals(q.Field("host_id"), hostSubQuery.Field("id"))) + q.AppendField(hostSubQuery.Field("name", "host")) + } + // host_id as filter key if utils.IsInStringArray("region", keys) { zoneQuery := ZoneManager.Query("id", "cloudregion_id").SubQuery() @@ -1589,6 +1596,9 @@ func (manager *SGuestManager) GetExportExtraKeys(ctx context.Context, query json if disk, ok := rowMap["disk_size"]; ok { res.Set("disk", jsonutils.NewString(disk)) } + if host, ok := rowMap["host"]; ok && len(host) > 0 { + res.Set("host", jsonutils.NewString(host)) + } if region, ok := rowMap["region"]; ok && len(region) > 0 { res.Set("region", jsonutils.NewString(region)) }