OpenStack: Neutron (network)


# search server by port ID
openstack port show -c device_id -f value ${PORT_ID}
openstack show show ${PORT_ID}
openstack router show ${PORT_ID}


# get port ID for OVS interface
openstack port list -c id -f value | grep $(awk '{print substr($OVS_INTERFACE,4,8)}')
# list all port by subnet
openstack port list --fixed-ip subnet=mgmt-dev-net --sort-column Name
# list all devices by network
openstack port list --network mgmt-dev -c device_id -f value
# allow incomming (ingress) SSH for specific IP / subnet
openstack security group rule create default \
    --protocol tcp \
    --dst-port 22 \
# create port without security
openstack port create openstack-net-port1 --network openstack-net --no-security-group --disable-port-security --no-fixed-ip
openstack port set --disable-port-security openstack-net-port1
# get all port by subnet
openstack port list -c ID -f value --fixed-ip subnet=dev-net1
# search ports (filter with json)
openstack port list -c ID -c "Fixed IP Addresses" -f json | jq -r '.[] | select(."Fixed IP Addresses"[].ip_address | startswith("10.11")).ID'

Creat and assign port

KVM: Create Windows 7 VM

Virtio driver

Create VM

sudo qemu-system-x86_64 \
    --enable-kvm \
    -m 4096 \
    -smp cores=2 \
    -drive file=${DISKIMG},if=virtio \
    -net nic,model=virtio \
    -net user \
    -rtc base=localtime,clock=host \
    -usbdevice tablet \
    -soundhw ac97 \
    -cpu host \
    -vga std
    -vga qxl \
    -drive file=${VIRTIMG},index=3,media=cdrom \
    -cdrom ${WIN7IMG} \
    -vga vmware

Docker: HAProxy



  maxconn 4096
  #stats timeout 30s
  log global
  mode http
  option httplog
  option dontlognull
  timeout connect 5000
  timeout client 50000
  timeout server 50000
  log local0
  #option httpchk
frontend frontend1
  bind :80
  mode http
  use_backend backend1
backend backend1
  mode http
  balance roundrobin
  option httpchk GET / HTTP/1.1
  http-check expect status 400
  server www1 check
  server www2 check
  server www3 check
listen stats 
  bind :9000
  mode http
  stats enable
  stats hide-version
  stats realm Haproxy\ Statistics
  stats refresh 60s
  stats show-node
  stats auth haproxy:password
  stats uri /


docker run -d --name haproxy -v /tmp/haproxy:/usr/local/etc/haproxy:ro -p 8080:80 -p 9000:9000 haproxy:latest
docker logs -f  haproxy

LXD: Create container with HTTP(s) proxy

# Create container
lxc launch ubuntu:18.04 ${CONTAINER}
sleep 10
# Deploy SSH key
lxc file push --uid 0 --gid 0 --mode 600 ~/.ssh/ ${CONTAINER}/root/.ssh/authorized_keys
# Configure http(s) proxy inside of container (if set on host)
[ -z ${http_proxy} ] || echo "export http_proxy=$http_proxy" | lxc shell ${CONTAINER} -- tee -a /etc/environment
[ -z ${https_proxy} ] || echo "export https_proxy=$https_proxy" | lxc shell ${CONTAINER} -- tee -a /etc/environment
# Update APT repository
lxc exec ${CONTAINER} -- bash -c ". /etc/environment && apt update"
# Optional: install applications
lxc exec ${CONTAINER} -- bash -c ". /etc/environment && apt install -y haproxy"

YouTube download and convert to mp3

wget -q -O /tmp/youtube-dl
sudo cp /tmp/youtube-dl /usr/local/sbin/
sudo chmod a+x /usr/local/sbin/youtube-dl
# download audio (mp3) only
youtube-dl --extract-audio --audio-format mp3 -o "%(uploader)s/%(title)s.%(ext)s"
# download whole channel starting from 3 months
youtube-dl --extract-audio --audio-format mp3 -o "%(uploader)s/%(upload_date)s_%(title)s.%(ext)s" --dateafter now-3months -v
# update
sudo youtube-dl -U

# output template

Install tftp server

Install tftp server package
sudo apt-get install -y xinetd tftpd tftp

Create xinetd tftp configuration

cat <<EOF> /etc/xinetd.d/tftp
service tftp
protocol        = udp
port            = 69
socket_type     = dgram
wait            = yes
user            = nobody
server          = /usr/sbin/in.tftpd
server_args     = /tftpboot
disable         = no

Create /tftpboot folder

sudo mkdir /tftpboot
sudo chmod -R 777 /tftpboot
sudo chown -R nobody /tftpboot

Restart the xinetd service

sudo service xinetd restart

Testing our tftp server

ip a add dev eth0:1
echo foo > /tftpboot/testfile
get testfile


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