Skip to content

Commit

Permalink
Merge pull request #12952 from tomponline/tp-import-devices
Browse files Browse the repository at this point in the history
client: Add API extension check for instance import with device override support
  • Loading branch information
tomponline authored Feb 23, 2024
2 parents 3e1d231 + 471536d commit 30b1ac7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 7 additions & 0 deletions client/lxd_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,13 @@ func (r *ProtocolLXD) CreateInstanceFromBackup(args InstanceBackupArgs) (Operati
}
}

if len(args.Devices) > 0 {
err = r.CheckExtension("import_instance_devices")
if err != nil {
return nil, fmt.Errorf("Cannot use device override: %w", err)
}
}

// Prepare the HTTP request
reqURL, err := r.setQueryAttributes(fmt.Sprintf("%s/1.0%s", r.httpBaseURL.String(), path))
if err != nil {
Expand Down
11 changes: 9 additions & 2 deletions test/suites/container_devices_nic_bridged.sh
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ test_container_devices_nic_bridged() {
lxc copy "${ctName}" foo # Gets new MAC address but IPs still conflict.
! stat "${LXD_DIR}/networks/${brName}/dnsmasq.hosts/foo.eth0" || false
lxc snapshot foo
lxc export foo foo.tar.gz
lxc export foo foo.tar.gz # Export in pristine state for import tests below.
! lxc start foo || false
lxc config device set foo eth0 \
ipv4.address=192.0.2.233 \
Expand Down Expand Up @@ -682,9 +682,16 @@ test_container_devices_nic_bridged() {

# Check MAC conflict detection:
! lxc config device set "${ctName}" eth0 hwaddr="0a:92:a7:0d:b7:c9" || false
lxc delete -f foo

# Test container with conflicting addresses rebuilds DHCP lease if original conflicting instance is removed.
# Test container can be imported with device override to fix conflict.
lxc import foo.tar.gz --device eth0,ipv4.address=192.0.2.233 --device eth0,ipv6.address=2001:db8::3
lxc config device get foo eth0 ipv4.address | grep -Fx '192.0.2.233'
lxc config device get foo eth0 ipv6.address | grep -Fx '2001:db8::3'
lxc start foo
lxc delete -f foo

# Test container with conflicting addresses rebuilds DHCP lease if original conflicting instance is removed.
! stat "${LXD_DIR}/networks/${brName}/dnsmasq.hosts/foo.eth0" || false
lxc import foo.tar.gz
rm foo.tar.gz
Expand Down

0 comments on commit 30b1ac7

Please sign in to comment.