diff --git a/cmd/vm-control/listVMs.go b/cmd/vm-control/listVMs.go index 72c27613..39d6fefa 100644 --- a/cmd/vm-control/listVMs.go +++ b/cmd/vm-control/listVMs.go @@ -82,7 +82,10 @@ func listVMsOnHypervisor(hypervisor string, logger log.DebugLogger) error { return err } defer client.Close() - request := hyper_proto.ListVMsRequest{true} + request := hyper_proto.ListVMsRequest{ + OwnerUsers: ownerUsers, + Sort: true, + } var reply hyper_proto.ListVMsResponse err = client.RequestReply("Hypervisor.ListVMs", request, &reply) if err != nil { diff --git a/hypervisor/httpd/listVMs.go b/hypervisor/httpd/listVMs.go index aef1d8da..3d7c4b3d 100644 --- a/hypervisor/httpd/listVMs.go +++ b/hypervisor/httpd/listVMs.go @@ -16,7 +16,7 @@ func (s state) listVMsHandler(w http.ResponseWriter, req *http.Request) { parsedQuery := url.ParseQuery(req.URL) writer := bufio.NewWriter(w) defer writer.Flush() - ipAddrs := s.manager.ListVMs(true) + ipAddrs := s.manager.ListVMs(nil, true) matchState := parsedQuery.Table["state"] if parsedQuery.OutputType() == url.OutputTypeText && matchState == "" { for _, ipAddr := range ipAddrs { diff --git a/hypervisor/manager/api.go b/hypervisor/manager/api.go index f8ca37aa..b3e2f25c 100644 --- a/hypervisor/manager/api.go +++ b/hypervisor/manager/api.go @@ -233,8 +233,8 @@ func (m *Manager) ListSubnets(doSort bool) []proto.Subnet { return m.listSubnets(doSort) } -func (m *Manager) ListVMs(doSort bool) []string { - return m.listVMs(doSort) +func (m *Manager) ListVMs(ownerUsers []string, doSort bool) []string { + return m.listVMs(ownerUsers, doSort) } func (m *Manager) ListVolumeDirectories() []string { diff --git a/hypervisor/manager/vm.go b/hypervisor/manager/vm.go index 0372f100..85536e5e 100644 --- a/hypervisor/manager/vm.go +++ b/hypervisor/manager/vm.go @@ -1027,11 +1027,23 @@ func (m *Manager) importLocalVm(authInfo *srpc.AuthInformation, return nil } -func (m *Manager) listVMs(doSort bool) []string { +func (m *Manager) listVMs(ownerUsers []string, doSort bool) []string { m.mutex.RLock() ipAddrs := make([]string, 0, len(m.vms)) - for ipAddr := range m.vms { - ipAddrs = append(ipAddrs, ipAddr) + for ipAddr, vm := range m.vms { + include := true + if len(ownerUsers) > 0 { + include = false + for _, ownerUser := range ownerUsers { + if _, ok := vm.ownerUsers[ownerUser]; ok { + include = true + break + } + } + } + if include { + ipAddrs = append(ipAddrs, ipAddr) + } } m.mutex.RUnlock() if doSort { diff --git a/hypervisor/rpcd/listVMs.go b/hypervisor/rpcd/listVMs.go index 81439687..0404873a 100644 --- a/hypervisor/rpcd/listVMs.go +++ b/hypervisor/rpcd/listVMs.go @@ -10,7 +10,7 @@ import ( func (t *srpcType) ListVMs(conn *srpc.Conn, request hypervisor.ListVMsRequest, reply *hypervisor.ListVMsResponse) error { - ipAddressStrings := t.manager.ListVMs(request.Sort) + ipAddressStrings := t.manager.ListVMs(request.OwnerUsers, request.Sort) ipAddresses := make([]net.IP, 0, len(ipAddressStrings)) for _, ipAddressString := range ipAddressStrings { ipAddress := net.ParseIP(ipAddressString) diff --git a/proto/hypervisor/messages.go b/proto/hypervisor/messages.go index 1421e19c..7ed7b36f 100644 --- a/proto/hypervisor/messages.go +++ b/proto/hypervisor/messages.go @@ -252,7 +252,8 @@ type ImportLocalVmResponse struct { } type ListVMsRequest struct { - Sort bool + OwnerUsers []string + Sort bool } type ListVMsResponse struct {