Skip to content

Instantly share code, notes, and snippets.

@alexejk
Last active May 1, 2018 08:27
Show Gist options
  • Save alexejk/449fc27fc1f17b4b0f9c3e80db28493f to your computer and use it in GitHub Desktop.
Save alexejk/449fc27fc1f17b4b0f9c3e80db28493f to your computer and use it in GitHub Desktop.
LXD: Management notes
#!/bin/bash
# Purpose: Update all lxd vms
# -------------------------------------------------------
# Get the vm list
vms="$(lxc list volatile.last_state.power=RUNNING -c n --format csv)"
# Update each vm
update_vm(){
local vm="$1"
echo "*** [VM: $vm [$(hostname) @ $(date)] ] ***"
ostype=`lxc config get "$vm" image.os `
case "$ostype" in
# APT-based
debian)
;&
ubuntu)
echo "apt-based update"
lxc exec "$vm" apt-get -- -qq update
lxc exec "$vm" apt-get -- -qq -y dist-upgrade
lxc exec "$vm" apt-get -- -qq -y clean
lxc exec "$vm" apt-get -- -qq -y autoclean
;;
#----------
# RPM-based
redhat)
;&
centos)
echo "rpm-based update"
lxc exec "$vm" -- yum update -y
;;
*)
echo "Unknown or unsupported distribution. Check image.os property"
esac
echo "-----------------------------------------------------------------"
}
# Do it
for v in $vms
do
update_vm "$v"
done

Notes about managing LXD

The following list of quick notes about managing LXD is something that I've found a little bit hard to get my head around when moving from LXC to LXD. Documentation for some parts wasn't very obvious and this is just my notes to not forget this info.

Probably for majority of people this is now obvious, but I've just started moving LXC->LXD and scripts are broken for 3.0 version of configuration.

Setting common setting for all containers:

Use profiles & set shared setting there.

lxc profile edit default

Setting container autostart:

lxc config set <container> boot.autostart <true|false>

Static IP for containers:

lxc network attach lxdbr0 <container> eth0 eth0
lxc config device set <container> eth0 ipv4.address <static-ip>

Edit post-migration LXC->LXD container NIC:

lxc config edit <container>
>
...
devices:                   
  eth0:                    
    ipv4.address: <ip>
    name: eth0             
    nictype: bridged       
    parent: lxdbr0         
    type: nic              
...

Disable IPv6 of lxdbr0 network

lxc network set lxdbr0 ipv6.address none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment