mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
region: server list by host sn
This commit is contained in:
@@ -55,6 +55,8 @@ func init() {
|
||||
|
||||
CdromBoot *bool `help:"filter hosts list by cdrom_boot=true|false"`
|
||||
|
||||
Sn string `help:"find host by sn"`
|
||||
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&HostListOptions{}, "host-list", "List hosts", func(s *mcclient.ClientSession, opts *HostListOptions) error {
|
||||
@@ -76,6 +78,9 @@ func init() {
|
||||
if len(opts.Uuid) > 0 {
|
||||
params.Add(jsonutils.NewString(opts.Uuid), "uuid")
|
||||
}
|
||||
if len(opts.Sn) > 0 {
|
||||
params.Add(jsonutils.NewString(opts.Sn), "sn")
|
||||
}
|
||||
result, err := modules.Hosts.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -80,6 +80,8 @@ type ServerListInput struct {
|
||||
ResourceType string `json:"resource_type"`
|
||||
// 返回开启主备机功能的主机
|
||||
GetBackupGuestsOnHost *bool `json:"get_backup_guests_on_host"`
|
||||
// 根据宿主机 SN 过滤
|
||||
HostSn string `json:"host_sn"`
|
||||
}
|
||||
|
||||
func (input *ServerListInput) AfterUnmarshal() {
|
||||
|
||||
@@ -448,6 +448,13 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ
|
||||
}
|
||||
}
|
||||
|
||||
hostSNFilter := query.HostSn
|
||||
if len(hostSNFilter) > 0 {
|
||||
hosts := HostManager.Query().SubQuery()
|
||||
sq := hosts.Query(hosts.Field("id")).Filter(sqlchemy.Equals(hosts.Field("sn"), hostSNFilter)).SubQuery()
|
||||
q = q.In("host_id", sq)
|
||||
}
|
||||
|
||||
orderByHost := query.OrderByHost
|
||||
if orderByHost == "asc" {
|
||||
hosts := HostManager.Query().SubQuery()
|
||||
|
||||
@@ -50,6 +50,7 @@ type ServerListOptions struct {
|
||||
UsableServerForEip string `help:"Eip id or name"`
|
||||
WithoutUserMeta *bool `help:"Show Servers without user metadata"`
|
||||
Group string `help:"Instance Group ID or Name"`
|
||||
HostSn string `help:"Host SN"`
|
||||
|
||||
ResourceType string `help:"Resource type" choices:"shared|prepaid|dedicated"`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user