Skip to content

Commit

Permalink
lxc/list: Use server-side filtering for list command
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Resztak <[email protected]>
  • Loading branch information
presztak authored and stgraber committed May 13, 2022
1 parent e61d2ef commit 7f5f8fe
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lxc/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,41 +495,45 @@ func (c *cmdList) Run(cmd *cobra.Command, args []string) error {
if needsData && d.HasExtension("container_full") {
// Using the GetInstancesFull shortcut
var cts []api.InstanceFull

serverFilters, clientFilters := getServerSupportedFilters(filters, api.InstanceFull{})
if c.flagAllProjects {
cts, err = d.GetInstancesFullAllProjects(api.InstanceTypeAny)
cts, err = d.GetInstancesFullAllProjectsWithFilter(api.InstanceTypeAny, serverFilters)
} else {
cts, err = d.GetInstancesFull(api.InstanceTypeAny)
cts, err = d.GetInstancesFullWithFilter(api.InstanceTypeAny, serverFilters)
}
if err != nil {
return err
}

return c.showInstances(cts, filters, columns)
return c.showInstances(cts, clientFilters, columns)
}

// Get the list of instances
var cts []api.Instance
var ctslist []api.Instance
serverFilters, clientFilters := getServerSupportedFilters(filters, api.Instance{})

if c.flagAllProjects {
ctslist, err = d.GetInstancesAllProjects(api.InstanceTypeAny)
ctslist, err = d.GetInstancesAllProjectsWithFilter(api.InstanceTypeAny, serverFilters)
} else {
ctslist, err = d.GetInstances(api.InstanceTypeAny)
ctslist, err = d.GetInstancesWithFilter(api.InstanceTypeAny, serverFilters)
}
if err != nil {
return err
}

// Apply filters
for _, cinfo := range ctslist {
if !c.shouldShow(filters, &cinfo, nil, true) {
if !c.shouldShow(clientFilters, &cinfo, nil, true) {
continue
}

cts = append(cts, cinfo)
}

// Fetch any remaining data and render the table
return c.listInstances(conf, d, cts, filters, columns)
return c.listInstances(conf, d, cts, clientFilters, columns)
}

func (c *cmdList) parseColumns(clustered bool) ([]column, bool, error) {
Expand Down

0 comments on commit 7f5f8fe

Please sign in to comment.