Skip to content

Commit

Permalink
Merge pull request #562 from rgooch/master
Browse files Browse the repository at this point in the history
Support filtering by owner users in vm-control list-vms subcommand.
  • Loading branch information
rgooch committed Feb 14, 2019
2 parents 68098e6 + bbc6d77 commit cba145e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
5 changes: 4 additions & 1 deletion cmd/vm-control/listVMs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
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
3 changes: 2 additions & 1 deletion proto/hypervisor/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ type ImportLocalVmResponse struct {
}

type ListVMsRequest struct {
Sort bool
OwnerUsers []string
Sort bool
}

type ListVMsResponse struct {
Expand Down

0 comments on commit cba145e

Please sign in to comment.