Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows usage of remote: with lxc network list-allocations and fixes project usage. #12331

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lxc/network_allocations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/spf13/cobra"

lxd "github.com/canonical/lxd/client"
"github.com/canonical/lxd/shared/api"
cli "github.com/canonical/lxd/shared/cmd"
"github.com/canonical/lxd/shared/i18n"
Expand Down Expand Up @@ -52,7 +51,7 @@ func (c *cmdNetworkListAllocations) Command() *cobra.Command {
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G("List network allocations in use"))

// Workaround for subcommand usage errors. See: https://github.com/spf13/cobra/issues/706
cmd.Args = cobra.NoArgs
cmd.Args = cobra.MaximumNArgs(1)
cmd.RunE = c.Run

cmd.Flags().StringVarP(&c.flagFormat, "format", "f", "table", i18n.G("Format (csv|json|table|yaml|compact)")+"``")
Expand All @@ -62,18 +61,19 @@ func (c *cmdNetworkListAllocations) Command() *cobra.Command {
}

func (c *cmdNetworkListAllocations) Run(cmd *cobra.Command, args []string) error {
d, err := lxd.ConnectLXDUnix("", nil)
if err != nil {
return nil
remote := ""
if len(args) > 0 {
remote = args[0]
}

// Check if server is initialized.
_, _, err = d.GetServer()
resources, err := c.global.ParseServers(remote)
if err != nil {
return err
}

addresses, err := d.UseProject(c.flagProject).GetNetworkAllocations(c.flagAllProjects)
resource := resources[0]
server := resource.server.UseProject(c.flagProject)
addresses, err := server.GetNetworkAllocations(c.flagAllProjects)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions test/suites/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ test_network() {
lxc network list-allocations | grep -e "${net_ipv4}" -e "${net_ipv6}"
lxc network list-allocations | grep -e "/1.0/networks/lxdt$$" -e "/1.0/instances/nettest"
lxc network list-allocations | grep -e "${v4_addr}" -e "${v6_addr}"
lxc network list-allocations localhost: | grep -e "${net_ipv4}" -e "${net_ipv6}"
lxc network list-allocations localhost: | grep -e "/1.0/networks/lxdt$$" -e "/1.0/instances/nettest"
lxc network list-allocations localhost: | grep -e "${v4_addr}" -e "${v6_addr}"

lxc delete nettest -f
lxc network delete lxdt$$
Expand Down
Loading