mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
fix: add lb and group ip address usage
This commit is contained in:
@@ -142,6 +142,7 @@ func init() {
|
||||
type ImageUsageOptions struct {
|
||||
Project string `help:"check image usage of a project"`
|
||||
Domain string `help:"check image usage of a domain"`
|
||||
Scope string `help:"query scope" choices:"project|domain|system"`
|
||||
}
|
||||
R(&ImageUsageOptions{}, "image-usage", "Show general usage of images", func(s *mcclient.ClientSession, args *ImageUsageOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
@@ -150,6 +151,9 @@ func init() {
|
||||
} else if args.Domain != "" {
|
||||
params.Add(jsonutils.NewString(args.Domain), "domain")
|
||||
}
|
||||
if args.Scope != "" {
|
||||
params.Add(jsonutils.NewString(args.Scope), "scope")
|
||||
}
|
||||
result, err := modules.Images.GetUsage(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -361,6 +361,18 @@ func (manager *SWireManager) totalCountQ(rangeObj db.IStandaloneModel, hostTypes
|
||||
sqlchemy.COUNT("rnic_count"),
|
||||
)
|
||||
|
||||
groupNics := GroupnetworkManager.Query().SubQuery()
|
||||
grpNicSQ := groupNics.Query(
|
||||
groupNics.Field("network_id"),
|
||||
sqlchemy.COUNT("grpnic_count"),
|
||||
).GroupBy(groupNics.Field("network_id")).SubQuery()
|
||||
|
||||
lbNics := LoadbalancernetworkManager.Query().SubQuery()
|
||||
lbNicSQ := lbNics.Query(
|
||||
lbNics.Field("network_id"),
|
||||
sqlchemy.COUNT("lbnic_count"),
|
||||
).GroupBy(lbNics.Field("network_id")).SubQuery()
|
||||
|
||||
gNicSQ := gNicQ.GroupBy(gNics.Field("network_id")).SubQuery()
|
||||
hNicSQ := hNicQ.GroupBy(hNics.Field("network_id")).SubQuery()
|
||||
revSQ := revQ.GroupBy(revIps.Field("network_id")).SubQuery()
|
||||
@@ -371,10 +383,15 @@ func (manager *SWireManager) totalCountQ(rangeObj db.IStandaloneModel, hostTypes
|
||||
sqlchemy.COUNT("id").Label("net_count"),
|
||||
sqlchemy.SUM("gnic_count", gNicQ.Field("gnic_count")),
|
||||
sqlchemy.SUM("hnic_count", hNicQ.Field("hnic_count")),
|
||||
sqlchemy.SUM("rev_count", revQ.Field("rnic_count")))
|
||||
sqlchemy.SUM("rev_count", revQ.Field("rnic_count")),
|
||||
sqlchemy.SUM("grpnic_count", grpNicSQ.Field("grpnic_count")),
|
||||
sqlchemy.SUM("lbnic_count", lbNicSQ.Field("lbnic_count")),
|
||||
)
|
||||
netQ = netQ.LeftJoin(gNicSQ, sqlchemy.Equals(gNicSQ.Field("network_id"), networks.Field("id")))
|
||||
netQ = netQ.LeftJoin(hNicSQ, sqlchemy.Equals(hNicSQ.Field("network_id"), networks.Field("id")))
|
||||
netQ = netQ.LeftJoin(revSQ, sqlchemy.Equals(revSQ.Field("network_id"), networks.Field("id")))
|
||||
netQ = netQ.LeftJoin(grpNicSQ, sqlchemy.Equals(grpNicSQ.Field("network_id"), networks.Field("id")))
|
||||
netQ = netQ.LeftJoin(lbNicSQ, sqlchemy.Equals(lbNicSQ.Field("network_id"), networks.Field("id")))
|
||||
netQ = netQ.GroupBy(networks.Field("wire_id"))
|
||||
netSQ := netQ.SubQuery()
|
||||
|
||||
@@ -385,6 +402,8 @@ func (manager *SWireManager) totalCountQ(rangeObj db.IStandaloneModel, hostTypes
|
||||
sqlchemy.SUM("guest_nic_count", netSQ.Field("gnic_count")),
|
||||
sqlchemy.SUM("host_nic_count", netSQ.Field("hnic_count")),
|
||||
sqlchemy.SUM("reserved_count", netSQ.Field("rev_count")),
|
||||
sqlchemy.SUM("group_nic_count", netSQ.Field("grpnic_count")),
|
||||
sqlchemy.SUM("lb_nic_count", netSQ.Field("lbnic_count")),
|
||||
)
|
||||
q = q.LeftJoin(netSQ, sqlchemy.Equals(wires.Field("id"), netSQ.Field("wire_id")))
|
||||
|
||||
@@ -434,6 +453,12 @@ type WiresCountStat struct {
|
||||
GuestNicCount int
|
||||
HostNicCount int
|
||||
ReservedCount int
|
||||
GroupNicCount int
|
||||
LbNicCount int
|
||||
}
|
||||
|
||||
func (wstat WiresCountStat) NicCount() int {
|
||||
return wstat.GuestNicCount + wstat.HostNicCount + wstat.ReservedCount + wstat.GroupNicCount + wstat.LbNicCount
|
||||
}
|
||||
|
||||
func (manager *SWireManager) TotalCount(rangeObj db.IStandaloneModel, hostTypes []string, providers []string, cloudEnv string) WiresCountStat {
|
||||
|
||||
@@ -461,6 +461,9 @@ func WireUsage(rangeObj db.IStandaloneModel, hostTypes []string, providers []str
|
||||
count["all.nics.guest"] = result.GuestNicCount
|
||||
count["all.nics.host"] = result.HostNicCount
|
||||
count["all.nics.reserve"] = result.ReservedCount
|
||||
count["all.nics.group"] = result.GroupNicCount
|
||||
count["all.nics.lb"] = result.LbNicCount
|
||||
count["all.nics"] = result.NicCount()
|
||||
return count
|
||||
}
|
||||
|
||||
@@ -606,6 +609,7 @@ func EipUsage(scope rbacutils.TRbacScope, ownerId mcclient.IIdentityProvider, ra
|
||||
count[getKey(projectId, "eip.public_ip")] = eipUsage.PublicIPCount
|
||||
count[getKey(projectId, "eip.floating_ip")] = eipUsage.EIPCount
|
||||
count[getKey(projectId, "eip.floating_ip.used")] = eipUsage.EIPUsedCount
|
||||
count[getKey(projectId, "eip.used")] = eipUsage.EIPUsedCount + eipUsage.PublicIPCount
|
||||
return count
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user