diff --git a/pkg/apis/compute/dbinstance_sku.go b/pkg/apis/compute/dbinstance_sku.go new file mode 100644 index 0000000000..3529b3dae3 --- /dev/null +++ b/pkg/apis/compute/dbinstance_sku.go @@ -0,0 +1,23 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package compute + +import "yunion.io/x/onecloud/pkg/apis" + +type DBInstanceSkuDetails struct { + apis.StandaloneResourceDetails + + CloudregionInfo +} diff --git a/pkg/cloudcommon/db/caller.go b/pkg/cloudcommon/db/caller.go index d8b21a7612..47466a1462 100644 --- a/pkg/cloudcommon/db/caller.go +++ b/pkg/cloudcommon/db/caller.go @@ -57,11 +57,10 @@ func call(obj interface{}, fName string, inputs ...interface{}) ([]reflect.Value func callObject(modelVal reflect.Value, fName string, inputs ...interface{}) ([]reflect.Value, error) { funcVal := modelVal.MethodByName(fName) - return callFunc(funcVal, inputs...) + return callFunc(funcVal, fName, inputs...) } -func callFunc(funcVal reflect.Value, inputs ...interface{}) ([]reflect.Value, error) { - fName := funcVal.String() +func callFunc(funcVal reflect.Value, fName string, inputs ...interface{}) ([]reflect.Value, error) { if !funcVal.IsValid() || funcVal.IsNil() { return nil, httperrors.NewActionNotFoundError(fmt.Sprintf("%s method not found", fName)) } diff --git a/pkg/cloudcommon/db/db_dispatcher.go b/pkg/cloudcommon/db/db_dispatcher.go index c48520bdd6..59d899626b 100644 --- a/pkg/cloudcommon/db/db_dispatcher.go +++ b/pkg/cloudcommon/db/db_dispatcher.go @@ -792,12 +792,11 @@ func (dispatcher *DBModelDispatcher) tryGetModelProperty(ctx context.Context, pr return nil, nil } userCred := fetchUserCredential(ctx) - params := []reflect.Value{ - reflect.ValueOf(ctx), - reflect.ValueOf(userCred), - reflect.ValueOf(query), + params := []interface{}{ctx, userCred, query} + outs, err := callFunc(funcValue, allowFuncName, params...) + if err != nil { + return nil, httperrors.NewInternalServerError("reflect call %s fail %s", allowFuncName, err) } - outs := funcValue.Call(params) if len(outs) != 1 { return nil, httperrors.NewInternalServerError("Invald %s return value", funcName) } @@ -806,7 +805,10 @@ func (dispatcher *DBModelDispatcher) tryGetModelProperty(ctx context.Context, pr } funcValue = modelValue.MethodByName(funcName) - outs = funcValue.Call(params) + outs, err = callFunc(funcValue, funcName, params...) + if err != nil { + return nil, httperrors.NewInternalServerError("reflect call %s fail %s", funcName, err) + } if len(outs) != 2 { return nil, httperrors.NewInternalServerError("Invald %s return value", funcName) } @@ -887,7 +889,7 @@ func (dispatcher *DBModelDispatcher) GetSpecific(ctx context.Context, idStr stri return nil, httperrors.NewSpecNotFoundError("%s %s %s not found", dispatcher.Keyword(), idStr, spec) } - outs, err := callFunc(funcValue, params...) + outs, err := callFunc(funcValue, funcName, params...) if err != nil { return nil, err } @@ -905,7 +907,7 @@ func (dispatcher *DBModelDispatcher) GetSpecific(ctx context.Context, idStr stri return nil, httperrors.NewSpecNotFoundError("%s %s %s not found", dispatcher.Keyword(), idStr, spec) } - outs, err := callFunc(funcValue, params...) + outs, err := callFunc(funcValue, funcName, params...) if err != nil { return nil, err } @@ -1470,7 +1472,7 @@ func reflectDispatcherInternal( return nil, httperrors.NewActionNotFoundError(msg) } - outs, err := callFunc(allowFuncValue, params...) + outs, err := callFunc(allowFuncValue, allowFuncName, params...) if err != nil { return nil, err } @@ -1483,7 +1485,7 @@ func reflectDispatcherInternal( } } - outs, err := callFunc(funcValue, params...) + outs, err := callFunc(funcValue, funcName, params...) if err != nil { return nil, err } diff --git a/pkg/compute/models/cloudregionresource.go b/pkg/compute/models/cloudregionresource.go index d3f9c96c73..621f710645 100644 --- a/pkg/compute/models/cloudregionresource.go +++ b/pkg/compute/models/cloudregionresource.go @@ -37,7 +37,7 @@ func (self *SCloudregionResourceBase) GetRegion() *SCloudregion { return region.(*SCloudregion) } -func (self *SCloudregionResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) api.CloudregionInfo { +func (self *SCloudregionResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) api.CloudregionInfo { out := api.CloudregionInfo{} region := self.GetRegion() if region == nil { diff --git a/pkg/compute/models/dbinstance_skus.go b/pkg/compute/models/dbinstance_skus.go index 0302ec0724..4addc565c6 100644 --- a/pkg/compute/models/dbinstance_skus.go +++ b/pkg/compute/models/dbinstance_skus.go @@ -136,6 +136,14 @@ func (manager *SDBInstanceSkuManager) ListItemFilter(ctx context.Context, q *sql return q, nil } +func (self *SDBInstanceSku) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) (api.DBInstanceSkuDetails, error) { + var err error + out := api.DBInstanceSkuDetails{} + out.StandaloneResourceDetails, err = self.SEnabledStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, isList) + out.CloudregionInfo = self.SCloudregionResourceBase.GetExtraDetails(ctx, userCred, query, isList) + return out, err +} + func (manager *SDBInstanceSkuManager) GetDBStringArray(q *sqlchemy.SQuery) ([]string, error) { array := []string{} rows, err := q.Rows() diff --git a/pkg/compute/models/loadbalancerbackendgroups.go b/pkg/compute/models/loadbalancerbackendgroups.go index fd1ba63412..5497716265 100644 --- a/pkg/compute/models/loadbalancerbackendgroups.go +++ b/pkg/compute/models/loadbalancerbackendgroups.go @@ -400,7 +400,7 @@ func (lbbg *SLoadbalancerBackendGroup) GetExtraDetails(ctx context.Context, user return out, err } out.Loadbalancer = lb.GetName() - out.CloudregionInfo = lbbg.SCloudregionResourceBase.GetExtraDetails(ctx, userCred, query) + out.CloudregionInfo = lbbg.SCloudregionResourceBase.GetExtraDetails(ctx, userCred, query, isList) return out, nil } diff --git a/pkg/compute/models/loadbalancerlistenerrules.go b/pkg/compute/models/loadbalancerlistenerrules.go index 9501ed86f6..0ec5031dba 100644 --- a/pkg/compute/models/loadbalancerlistenerrules.go +++ b/pkg/compute/models/loadbalancerlistenerrules.go @@ -505,7 +505,7 @@ func (lbr *SLoadbalancerListenerRule) GetExtraDetails(ctx context.Context, userC if err != nil { return out, err } - out.CloudregionInfo = lbr.SCloudregionResourceBase.GetExtraDetails(ctx, userCred, query) + out.CloudregionInfo = lbr.SCloudregionResourceBase.GetExtraDetails(ctx, userCred, query, isList) if lbr.BackendGroupId == "" { log.Errorf("loadbalancer listener rule %s(%s): empty backend group field", lbr.Name, lbr.Id) return out, nil diff --git a/pkg/compute/models/loadbalancerlisteners.go b/pkg/compute/models/loadbalancerlisteners.go index 0e38ba8380..312fa1a3ef 100644 --- a/pkg/compute/models/loadbalancerlisteners.go +++ b/pkg/compute/models/loadbalancerlisteners.go @@ -445,7 +445,7 @@ func (lblis *SLoadbalancerListener) GetExtraDetails(ctx context.Context, userCre out.OriginCertificateId = cert.CertificateId } } - out.CloudregionInfo = lblis.SCloudregionResourceBase.GetExtraDetails(ctx, userCred, query) + out.CloudregionInfo = lblis.SCloudregionResourceBase.GetExtraDetails(ctx, userCred, query, isList) return out, nil }