Snap (Ubuntu package management)

Install
sudo apt install -y snapd

CLI
snap find
snap install

Configure proxy
sudo mkdir -p /etc/systemd/system/snapd.service.d/
echo -e '[Service]\nEnvironment="http_proxy=http://proxy.example.com:3128/"' | sudo tee /etc/systemd/system/snapd.service.d/http-proxy.conf
echo -e '[Service]\nEnvironment="https_proxy=http://proxy.example.com:3128/"' | sudo tee /etc/systemd/system/snapd.service.d/https-proxy.conf
sudo systemctl daemon-reload
sudo systemctl restart snapd

# debug proxy
systemctl show snapd | grep proxy

OpenStack: Application credentials

Create applications credentials
openstack application credential create admin --role admin --expiration $(date -I -d '+1 month')T23:59:59 -c id -c secret #-f value

Configure clouds.yml
# ~/.config/openstack/clouds.yaml
clouds:
dev-app:
auth_type: "v3applicationcredential"
auth:
auth_url: https://keystone.example.com/v3
application_credential_id: "b9275fc5b3aadceeb407fbe941427425"
application_credential_secret: "HqfdfKk3q63xrnIZgdkizePfv1s27aYPBTrbiMKFNdrOU1JpdjfR0KSyomS4A01vSdxjkE9MzPuM4dVG7emWuA"

Open vSwitch (OVS)

Create
ovs-vsctl -- --may-exist add-port br-int o-hm0 -- \
set Interface o-hm0 type=internal -- \
set Interface o-hm0 external-ids:iface-status=active -- \
set Interface o-hm0 external-ids:attached-mac=${CTL_HOST_MAC} -- \
set Interface o-hm0 external-ids:iface-id=${PORT_ID} -- \
set Interface o-hm0 external-ids:skip_cleanup=true

Delete
ovs-vsctl -- del-port br-int o-hm0

Create port
openvswitch_vswitchd ovs-vsctl -- --may-exist add-port br-int my-port1 -- \
set Interface o-hm0 type=internal -- \

OpenStack: Glance (Image)

Deaktivate image
IMAGE_NAME="Ubuntu 14.04"
openstack image list --status active --name "${IMAGE_NAME}" -c ID -f value | xargs openstack image set --deactivate --private
openstack image list --status active

List the images
openstack image list

Delete all images
for IMAGE in $(openstack image list -c ID -f value); do
openstack image set --unprotected ${IMAGE}
openstack image delete ${IMAGE}
done

Delete image
IMAGE_NAME="Ubuntu 16.04"
openstack image set --unprotected ${IMAGE_NAME}

OpenStack: Live migrate VM to another OpenStack hypervisor

VM=foo-u1804

# list all vms on a hypervisor
openstack server list --all --status ACTIVE --host com1.example.com

# get current hypervisor
openstack server show ${VM} -c OS-EXT-SRV-ATTR:host -f value

# list avaiable hypervisors
openstack host list -c "Host Name" -c Service -f value | grep compute | cut -d" " -f1

# migrate VM
openstack server migrate ${VM} --live ${TARGET_COMPUTE_NODE} --wait

# get state
openstack server show ${VM} -c name -c OS-EXT-SRV-ATTR:host -c status -f value | paste - - -

# migrate all VMs
openstack server list --all --host ${OS_NODE}

Ansible Redfish module

# redfish_facts module
Documentation: https://docs.ansible.com/ansible/latest/modules/redfish_facts_module.html
Git: https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/remote_management/redfish/redfish_facts.py
local: /usr/lib/python2.7/dist-packages/ansible/modules/remote_management/redfish/redfish_facts.py

# redfish_utils library
Git: https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/redfish_utils.py
local: /usr/lib/python2.7/dist-packages/ansible/module_utils/redfish_utils.py

#!/usr/bin/env ansible-playbook

---
- hosts: localhost
vars:

Migrate LXC container to LXD (with ZFS storage)

CONTAINER_NAME=www

lxc-stop -n ${CONTAINER_NAME}
lxc init ubuntu:18.04 ${CONTAINER_NAME} -c security.privileged=true -c boot.autostart=true
#lxc stop ${CONTAINER_NAME}
#lxc config set ${CONTAINER_NAME} boot.autostart true
zfs mount tank/lxd/containers/${CONTAINER_NAME}
mv /var/lib/lxd/containers/${CONTAINER_NAME}/rootfs{,.org}
rsync -av --numeric-ids /var/lib/lxc/${CONTAINER_NAME}/rootfs /var/lib/lxd/containers/${CONTAINER_NAME}/
mv /var/lib/lxd/containers/${CONTAINER_NAME}/rootfs/dev{,.org}

OpenStack: Octavia LoadBalancer (LBaaS)

Create Amphora image
sudo apt install -y python-pip git qemu qemu-utils debootstrap kpartx
sudo pip install diskimage-builder
git clone https://review.openstack.org/p/openstack/octavia
cd octavia
sudo ./diskimage-create/diskimage-create.sh -d bionic -t raw
chmod a+r ./amphora-x64-haproxy.raw

Upload Amphora image
#openstack image create --container-format bare --disk-format qcow2 --private --file amphora-x64-haproxy.qcow2 --tag amphora amphora