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 }