From a6fd56b6677717273d2312fcc8b08f23632d6b51 Mon Sep 17 00:00:00 2001 From: Pavel Vorobyov Date: Fri, 3 Jul 2020 11:55:29 +0300 Subject: [PATCH] dctree filter --- store/store.go | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/store/store.go b/store/store.go index 2978733..1026bbf 100644 --- a/store/store.go +++ b/store/store.go @@ -202,6 +202,7 @@ func (s *Store) HostList(expr []rune) ([]string, error) { } } } + etoken.hosts = append(etoken.hosts, host) } @@ -216,8 +217,18 @@ func (s *Store) HostList(expr []rune) ([]string, error) { continue } if host.Datacenter.Name != token.DatacenterFilter { - // TODO tree - continue + hostDC := host.Datacenter.Parent + parentMatch := false + for hostDC != nil { + if hostDC.Name == token.DatacenterFilter { + parentMatch = true + break + } + hostDC = hostDC.Parent + } + if !parentMatch { + continue + } } } @@ -265,8 +276,18 @@ func (s *Store) HostList(expr []rune) ([]string, error) { continue } if host.Datacenter.Name != token.DatacenterFilter { - // TODO tree - continue + hostDC := host.Datacenter.Parent + parentMatch := false + for hostDC != nil { + if hostDC.Name == token.DatacenterFilter { + parentMatch = true + break + } + hostDC = hostDC.Parent + } + if !parentMatch { + continue + } } }