region: server list by host sn

This commit is contained in:
Zexi Li
2020-02-13 21:06:49 +08:00
parent 1ee2038cc5
commit 53184acbce
4 changed files with 15 additions and 0 deletions
+5
View File
@@ -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
+2
View File
@@ -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() {
+7
View File
@@ -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()
+1
View File
@@ -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"`