From bc35d81e79d2b63a61e962c9899ab7667ce92c9d Mon Sep 17 00:00:00 2001 From: Richard Gooch Date: Wed, 13 Feb 2019 07:26:54 -0800 Subject: [PATCH 1/3] Add proto/hypervisor.ListVMsRequest.OwnerUsers field. --- proto/hypervisor/messages.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 { From 4239249c636ae2dfa2327f1623e4daa8561b97b1 Mon Sep 17 00:00:00 2001 From: Richard Gooch Date: Wed, 13 Feb 2019 13:41:18 -0800 Subject: [PATCH 2/3] Specify OwnerUsers in vm-control list-vms subcommand. --- cmd/vm-control/listVMs.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 { From bbc6d77ba63273e03d5d33f8566cd8f0badf460d Mon Sep 17 00:00:00 2001 From: Richard Gooch Date: Thu, 14 Feb 2019 07:08:57 -0800 Subject: [PATCH 3/3] Support OwnerUsers filter in Hypervisor.ListVMs SRPC method. --- hypervisor/httpd/listVMs.go | 2 +- hypervisor/manager/api.go | 4 ++-- hypervisor/manager/vm.go | 18 +++++++++++++++--- hypervisor/rpcd/listVMs.go | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) 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)