Skip to content

Instantly share code, notes, and snippets.

Avatar

Darragh O'Reilly djoreilly

View GitHub Profile
@djoreilly
djoreilly / pp-iptables.py
Last active Mar 26, 2021
Pretty print iptables output. Align columns and strip out comments.
View pp-iptables.py
#!/usr/bin/python3
import re
import sys
from tabulate import tabulate
comments_re = re.compile(r'/\*.*\/')
in_chain, eof = False, False
headers, table = [], []
@djoreilly
djoreilly / metadata-server.go
Last active Mar 1, 2021
Allows Libvirt VMs with cloud-init to get users public ssh key
View metadata-server.go
package main
import (
"flag"
"io"
"io/ioutil"
"log"
"net/http"
"os/user"
"path/filepath"
@djoreilly
djoreilly / send-vxlan-loop.py
Last active Mar 1, 2021
Reproduce OVS v2.7 memory leak
View send-vxlan-loop.py
# send vxlan pkts from netns to ovs on same host
# keep changing the src mac so learn action creates/updates 1000 flows
# ip netns exec ns1 ./send-vxlan-loop.py
import time
from scapy.all import *
# https://home.regit.org/2014/04/speeding-up-scapy-packets-sending/
sock = conf.L2socket(iface='veth-ns')
@djoreilly
djoreilly / ovs-sort-flows.py
Created Jan 19, 2021
Sort and tabulate the output of ovs-ofctl dump-flows
View ovs-sort-flows.py
'''
Make the output of ovs-ofctl dump-flows more readable
'''
import re
import sys
from tabulate import tabulate
PAT = re.compile("^ cookie.*table=(\d+), n_packets=(\d+).+ priority=(\d+),*(.*) actions=(.+)")
if len(sys.argv) == 2:
@djoreilly
djoreilly / mk-vxlan.sh
Created Feb 17, 2020
Linux VxLAN performance test setup script
View mk-vxlan.sh
#!/bin/bash
set -xe
# $0 host dev remote_ip
# host is 1 or 2
# on vmA
# ./mk-vx.sh 1 ens3 10.10.10.9
# on vmB
# ./mk-vx.sh 2 ens3 10.10.10.15
@djoreilly
djoreilly / dump-vm-neutron-info.py
Created Jan 15, 2020
Gather neutron info for VM connectivity problems
View dump-vm-neutron-info.py
"""
Script to gather neutron info for vm connectivity problems.
Gets the vm's ports, networks, subnets, security groups
and router, external networks and floatingips.
source .openrc admin
python dump-vm-neutrn-info.py VM_ID
"""
import sys
import os_client_config
View find_slow_boot.py
# Search nova-compute.log for ports that took a long time
# to receive the network-vif-plugged- event from neutron.
# python find_slow_boot.py /var/log/nov/nova-compute.log | sort -k 3
import datetime
import re
import sys
if len(sys.argv) == 2:
log_file = sys.argv[1]
@djoreilly
djoreilly / meta_svr.py
Last active Jan 18, 2021
Metadata server to allow booting cloud-init images on Libvirt
View meta_svr.py
"""
Server to answer requests from Libvirt VMs to http://169.254.169.254/
Cloud images usually don't have a preset user/password, and this is needed to add a ssh pub key to .ssh/authorized_hosts.
Change SSH_PUB_KEY path below.
pip install bottle
sudo ip address add 169.254.169.254 dev virbr0
open firewall
-A ufw-user-input -s 192.168.122.0/24 -d 169.254.169.254/32 -i virbr0 -p tcp -m tcp --dport 80 -j ACCEPT
@djoreilly
djoreilly / read-rabbit-cap.py
Last active Feb 21, 2019
Pretty print an OpenStack Olso messaging packet capture
View read-rabbit-cap.py
'''
Pretty print an OpenStack Oslo messaging packet capture.
tcpdump -ni ethX tcp port 5672 -w rabbit.cap
python read-rabbit-cap.py rabbit.cap
python read-rabbit-cap.py rabbit.cap | grep -v context
'''
import json
@djoreilly
djoreilly / json2yaml.py
Created May 17, 2018
Convert json to yaml
View json2yaml.py
#!/usr/bin/env python3
import sys, json, yaml
yaml.dump(json.loads(sys.stdin.read()), sys.stdout, default_flow_style=False)