Skip to content

Commit

Permalink
Support OwnerUsers filter in Hypervisor.ListVMs SRPC method.
Browse files Browse the repository at this point in the history
  • Loading branch information
rgooch committed Feb 14, 2019
1 parent 4239249 commit bbc6d77
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion hypervisor/httpd/listVMs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions hypervisor/manager/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 15 additions & 3 deletions hypervisor/manager/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion hypervisor/rpcd/listVMs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bbc6d77

Please sign in to comment.