openstack

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}

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

OpenStack: Cleanup project objects

# Delete VM
openstack server list --project=test-project --os-cloud=dev
openstack server delete test-project-vm

# Delete floating IP
openstack floating ip list --project=test-project --os-cloud=dev
openstack floating ip delete 1.2.3.4

# Delete router
openstack router list --project=test-project --os-cloud=dev
openstack subnet list --project=test-project --os-cloud=dev
openstack router remove subnet test-project-router test-project-subnet
openstack router delete test-project-router

# Delete subnet
openstack subnet list --project=test-project --os-cloud=dev

OpenStack: Cloud management with Ansible

Ansible OpenStack modules
https://docs.ansible.com/ansible/latest/search.html?q=os_

Ansible OpenStack module repository
https://github.com/ansible/ansible/tree/devel/lib/ansible/modules/cloud/openstack

# Fix; To utilize this module, the installed version ofthe shade library MUST be >=1.8.0
wget http://mirrors.kernel.org/ubuntu/pool/universe/p/python-shade/python-shade_1.30.0-2_all.deb -O /tmp/python-shade_1.30.0-2_all.deb
sudo dpkg -i /tmp/python-shade_1.30.0-2_all.deb

OpenStack multi cloud / user configurattion

Configure connections
# ~/.config/openstack/clouds.yaml
clouds:
admin-dev:
auth:
auth_url: http://keystone-admin.dev.example.com:35357/v3
project_name: admin
username: admin
user_domain_name: Default
project_domain_name: Default
interface: internal
foo-stage:
auth:
auth_url: http://api.stage.example.com:35357
project_name: fooproject
username: foo
user_domain_name: foodom
project_domain_name: foodom

Configure passwords
# ~/.config/openstack/secure.yaml
clouds:

OpenStack: Install OpenStack CLI client (OSC)

release notes for openstack client tools
# installed
pip list | grep python-openstackclient
python-openstackclient 3.16.2

# available (for rocky release)
https://docs.openstack.org/releasenotes/python-openstackclient/rocky.html
https://github.com/openstack/python-magnumclient/releases

# install rocky client versions
pip install -U \
gnocchiclient \
"pankoclient<0.6.0" \
"python-barbicanclient<4.8.0" \
"python-cinderclient<4.0.1" \
python-cloudkittyclient \
"python-glanceclient<2.14.0" \
"python-heatclient<1.17.0" \

OpenStack: Regenerate kolla password file

OS_ENV=dev

rm /etc/kolla/passwords.yml
cp /etc/kolla/config/passwords-${OS_ENV}.yml /etc/kolla/passwords.yml

# marge new password / reorder passwords
# kolla-genpwd -p /etc/kolla/passwords.yml
# cp /etc/kolla/passwords.yml /etc/kolla/config/passwords-${OS_ENV}.yml

cat /etc/kolla/config/passwords-${OS_ENV}.yml | cut -d" " -f1 > /etc/kolla/passwords.yml
kolla-genpwd -p /etc/kolla/passwords.yml
mv /etc/kolla/passwords.yml /etc/kolla/config/passwords-${OS_ENV}.yml
ln -s /etc/kolla/config/passwords-${OS_ENV}.yml /etc/kolla/passwords.yml

Links