OpenStack: VPNaaS (VPN)

openstack vpn service list -c ID -f value |
    xargs -L1 openstack vpn service show
openstack vpn ipsec site connection list -c ID -f value |
    xargs -L1 openstack vpn ipsec site connection show

Check VPN peer address

PRIVATE_PEER_ADDRESSES=$(openstack vpn ipsec site connection list -c "Peer Address" -f value | egrep "^10.|^172.|^192.")
    CONNECTION_ID=$(openstack vpn ipsec site connection list | grep ${PRIVATE_PEER_ADDRESSE} | cut -d" " -f2)
    openstack vpn ipsec site connection show ${CONNECTION_ID}
    VPN_SERVICE_ID=$(openstack vpn ipsec site connection show ${CONNECTION_ID} -c "VPN Service" -f value)
    openstack vpn service show ${VPN_SERVICE_ID}
    PROJECT_ID=$(openstack vpn service show ${VPN_SERVICE_ID} -c project_id -f value)
    openstack project show ${PROJECT_ID}


OpenStack: Volume

# List your volumes
openstack volume list
openstack volume type list --public --long
openstack volume backend pool list
cinder --os-volume-api-version 3.50 attachment-delete <attachment_id>
openstack volume set --non-bootable <VOLUME_ID>

Search for multiple volume attachment ids

OpenStack: rescue / recovery system

Download rescure iso

Create rescure system

openstack image create systemrescuecd \
  --file grml64-small_2020.06.iso \
  --disk-format iso \
  --container-format bare \
  --min-ram 512 \
  --property hw_cdrom_bus=scsi
# show image
openstack image list --name systemrescuecd

Attach rescure system

openstack server rescue --image systemrescuecd ${SERVER_ID}

# Login to VM console and fix issues
Detach rescure system

openstack server unrescue ${SERVER_ID}


OpenStack: User

Debug user
openstack user list
openstack user show USER_ID
openstack domain show DOMAIN_ID
openstack project list --user USER_ID
openstack role assignment list --names --user USER_ID

Add role
openstack role add --user USER_ID --project PROJECT_ID creator

LXD: Move / copy container to remote host

Configure LXD
# new server (,
lxc config set core.https_address
lxc config set core.trust_password pass1234

# old server (,
lxc config set core.https_address
lxc remote add

Migrate container
# old server
#lxc config show ${CONTAINER}
lxc stop ${CONTAINER}
lxc config set ${CONTAINER} boot.autostart false
lxc snapshot ${CONTAINER}

# move whole container
# lxc move ${CONTAINER}${CONTAINER} --verbose

OpenStack: Extend public IP range

Show subnet details
openstack subnet list --network public
openstack subnet show public-

Modify database
DB_PASS=$(grep neutron_database_password /etc/kolla/passwords.yml | cut -d " " -f2)
mysql -h --password=${DB_PASS} -P 6033 -u neutron -D neutron
select * from neutron.subnets where cidr like '10.0.0%';
update subnets set cidr='' WHERE cidr = '';

# update subnet name
openstack subnet set --name public- public-

# extend allocation-pool

OpenStack: server (VM)

# List instances / VMs
openstack server list
openstack server list -c ID -c Name -c Status -c Networks -c Host --long

openstack server create foo-vm1 \
--image "Ubuntu 18.04" \
--flavor m1.small \
--key-name foo-key \
--network foo-net

# delete instance
openstack server delete "vm-u1804"
# list all servers from all projects
openstack server list --all-projects --os-cloud=stage-admin
# get IDs only from server
openstack server list --os-cloud=dev-foo -c ID -f value
# get all servers using windows images

Nginx: Log client ip behind NAT with http_x_forwarded_for (X-Forwarded-For Header)

Use nginx real_ip module
nginx -V | grep with-http_realip_module
# /etc/nginx/nginx.conf
http {
# set_real_ip_from;
set_real_ip_from x.x.x.x/x; # LB subnet
real_ip_header X-Forwarded-For;

Option 2: customize log_format
cat /etc/nginx/nginx.conf
log_format main '$http_x_forwarded_for - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"';
access_log /var/log/nginx/access.log main;

Reload Nginx configuration