Skip to content

Commit

Permalink
Set Target after network/storage lookup (from Incus) (#14420)
Browse files Browse the repository at this point in the history
In LXD init, if the `--storage` or `--network` flags are provided the
CLI will check the storage pool or network exists before setting up a
device on the instance config. When targeting a cluster group this would
lead to calls like `GET /1.0/storage-pools/foo?target=@bar` which
doesn't make sense.

This commit (cherry-picked from Incus) moves setting the cluster group
target to after those lookups.

I've added tests have checked that they fail before this change and pass
afterwards.
  • Loading branch information
tomponline authored Nov 11, 2024
2 parents 45ae32b + 0111b79 commit 35ff15e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions lxc/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ func (c *cmdInit) create(conf *config.Config, args []string, launch bool) (lxd.I
return nil, "", err
}

if c.flagTarget != "" {
d = d.UseTarget(c.flagTarget)
}

// Overwrite profiles.
if c.flagProfile != nil {
profiles = c.flagProfile
Expand Down Expand Up @@ -264,6 +260,11 @@ func (c *cmdInit) create(conf *config.Config, args []string, launch bool) (lxd.I
instanceDBType = api.InstanceTypeVM
}

// Set the target if provided.
if c.flagTarget != "" {
d = d.UseTarget(c.flagTarget)
}

// Setup instance creation request
req := api.InstancesPost{
Name: name,
Expand Down
8 changes: 4 additions & 4 deletions test/suites/clustering.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3660,12 +3660,12 @@ EOF
lxc init testimage cluster:c1
lxc info cluster:c1 | grep -q "Location: node1"

# c2 should go to node2
lxc init testimage cluster:c2 --target=@blah
# c2 should go to node2. Additionally it should be possible to specify the network.
lxc init testimage cluster:c2 --target=@blah --network "${bridge}"
lxc info cluster:c2 | grep -q "Location: node2"

# c3 should go to node2 again
lxc init testimage cluster:c3 --target=@blah
# c3 should go to node2 again. Additionally it should be possible to specify the storage pool.
lxc init testimage cluster:c3 --target=@blah --storage data
lxc info cluster:c3 | grep -q "Location: node2"

# Direct targeting of node2 should work
Expand Down

0 comments on commit 35ff15e

Please sign in to comment.