Skip to content

Commit

Permalink
fix: globalvpc count vpc
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu Xuan committed May 11, 2020
1 parent 1403fae commit b6ec2b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/apis/compute/globalvpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type GlobalVpcDetails struct {
apis.EnabledStatusInfrasResourceBaseDetails

SGlobalVpc

// vpc数量
VpcCount int `json:"vpc_count"`
}

type GlobalVpcResourceInfo struct {
Expand Down
12 changes: 11 additions & 1 deletion pkg/compute/models/globalvpcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,24 @@ func (self *SGlobalVpc) ValidateDeleteCondition(ctx context.Context) error {
return self.SEnabledStatusInfrasResourceBase.ValidateDeleteCondition(ctx)
}

func (self *SGlobalVpc) GetVpcQuery() *sqlchemy.SQuery {
return VpcManager.Query().Equals("globalvpc_id", self.Id)
}

func (self *SGlobalVpc) GetVpcs() ([]SVpc, error) {
vpcs := []SVpc{}
q := VpcManager.Query().Equals("globalvpc_id", self.Id)
q := self.GetVpcQuery()
err := db.FetchModelObjects(VpcManager, q, &vpcs)
if err != nil {
return nil, err
}
return vpcs, nil
}

func (self *SGlobalVpc) GetVpcCount() (int, error) {
return self.GetVpcQuery().CountWithError()
}

func (self *SGlobalVpc) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) (api.GlobalVpcDetails, error) {
return api.GlobalVpcDetails{}, nil
}
Expand All @@ -97,6 +105,8 @@ func (manager *SGlobalVpcManager) FetchCustomizeColumns(
rows[i] = api.GlobalVpcDetails{
EnabledStatusInfrasResourceBaseDetails: stdRows[i],
}
gv := objs[i].(*SGlobalVpc)
rows[i].VpcCount, _ = gv.GetVpcCount()
}
return rows
}
Expand Down

0 comments on commit b6ec2b4

Please sign in to comment.