From 4ea96848cb564d86802e1e482cd1804d5dfa2f70 Mon Sep 17 00:00:00 2001 From: Qu Xuan Date: Thu, 19 Mar 2020 19:11:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dsecgrouprule-list=2050?= =?UTF-8?q?0=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/apis/compute/secgrouprule.go | 23 ++++++++++++++++++++ pkg/compute/models/secgroupresource.go | 2 +- pkg/compute/models/secgrouprules.go | 30 ++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 pkg/apis/compute/secgrouprule.go diff --git a/pkg/apis/compute/secgrouprule.go b/pkg/apis/compute/secgrouprule.go new file mode 100644 index 0000000000..6b7ba57d42 --- /dev/null +++ b/pkg/apis/compute/secgrouprule.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 SecgroupRuleDetails struct { + apis.ResourceBaseDetails + SSecurityGroupRule + SecurityGroupResourceInfo +} diff --git a/pkg/compute/models/secgroupresource.go b/pkg/compute/models/secgroupresource.go index de69dc15a1..0947c1d5c8 100644 --- a/pkg/compute/models/secgroupresource.go +++ b/pkg/compute/models/secgroupresource.go @@ -103,7 +103,7 @@ func (manager *SSecurityGroupResourceBaseManager) ListItemFilter( return nil, errors.Wrap(err, "SecurityGroupManager.FetchByIdOrName") } } - q = q.Equals("secgroup", secgrpObj.GetId()) + q = q.Equals("secgroup_id", secgrpObj.GetId()) } return q, nil } diff --git a/pkg/compute/models/secgrouprules.go b/pkg/compute/models/secgrouprules.go index 7231c3831c..9ec84ddbfc 100644 --- a/pkg/compute/models/secgrouprules.go +++ b/pkg/compute/models/secgrouprules.go @@ -36,6 +36,7 @@ import ( "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/util/logclient" "yunion.io/x/onecloud/pkg/util/rbacutils" + "yunion.io/x/onecloud/pkg/util/stringutils2" ) type SSecurityGroupRuleManager struct { @@ -195,6 +196,35 @@ func (manager *SSecurityGroupRuleManager) ListItemFilter( return sql, nil } +func (self *SSecurityGroupRule) GetExtraDetails( + ctx context.Context, + userCred mcclient.TokenCredential, + query jsonutils.JSONObject, + isList bool, +) (api.SecgroupRuleDetails, error) { + return api.SecgroupRuleDetails{}, nil +} + +func (manager *SSecurityGroupRuleManager) FetchCustomizeColumns( + ctx context.Context, + userCred mcclient.TokenCredential, + query jsonutils.JSONObject, + objs []interface{}, + fields stringutils2.SSortedStrings, + isList bool, +) []api.SecgroupRuleDetails { + rows := make([]api.SecgroupRuleDetails, len(objs)) + bRows := manager.SResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList) + secRows := manager.SSecurityGroupResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList) + for i := range rows { + rows[i] = api.SecgroupRuleDetails{ + ResourceBaseDetails: bRows[i], + SecurityGroupResourceInfo: secRows[i], + } + } + return rows +} + func (manager *SSecurityGroupRuleManager) OrderByExtraFields( ctx context.Context, q *sqlchemy.SQuery,