增加:guests支持with_eip=true和without_eip=true两个过滤条件

This commit is contained in:
Qiu Jian
2018-09-12 02:02:06 +08:00
parent a1b67853de
commit 9a8d0e77a9
2 changed files with 16 additions and 0 deletions
+14
View File
@@ -316,6 +316,20 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ
q = q.In("host_id", sq)
}
withEip, _ := queryDict.GetString("with_eip")
withoutEip, _ := queryDict.GetString("without_eip")
if len(withEip) > 0 || len(withoutEip) > 0 {
eips := ElasticipManager.Query().SubQuery()
sq := eips.Query(eips.Field("associate_id")).Equals("associate_type", EIP_ASSOCIATE_TYPE_SERVER)
sq = sq.IsNotNull("associate_id").IsNotEmpty("associate_id")
if utils.ToBool(withEip) {
q = q.In("id", sq)
} else if utils.ToBool(withoutEip) {
q = q.NotIn("id", sq)
}
}
gpu, _ := queryDict.GetString("gpu")
if len(gpu) != 0 {
isodev := IsolatedDeviceManager.Query().SubQuery()
+2
View File
@@ -21,6 +21,8 @@ type ServerListOptions struct {
Hypervisor string `help:"Show server of hypervisor" choices:"kvm|esxi|container|baremetal|aliyun"`
Manager string `help:"Show servers imported from manager"`
Region string `help:"Show servers in cloudregion"`
WithEip *bool `help:"Show Servers with EIP"`
WithoutEip *bool `help:"Show Servers without EIP"`
BaseListOptions
}