From 9a8d0e77a9794e9b52d8eb2b77ff8a00ec7da42a Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Wed, 12 Sep 2018 02:02:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=EF=BC=9Aguests=E6=94=AF?= =?UTF-8?q?=E6=8C=81with=5Feip=3Dtrue=E5=92=8Cwithout=5Feip=3Dtrue?= =?UTF-8?q?=E4=B8=A4=E4=B8=AA=E8=BF=87=E6=BB=A4=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/compute/models/guests.go | 14 ++++++++++++++ pkg/mcclient/options/servers.go | 2 ++ 2 files changed, 16 insertions(+) diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index f50fa8cc3c..410eee41db 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -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() diff --git a/pkg/mcclient/options/servers.go b/pkg/mcclient/options/servers.go index 3ded557f64..eab469fbf0 100644 --- a/pkg/mcclient/options/servers.go +++ b/pkg/mcclient/options/servers.go @@ -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 }