Skip to content

Instantly share code, notes, and snippets.

View djoreilly's full-sized avatar

Darragh O'Reilly djoreilly

View GitHub Profile
@djoreilly
djoreilly / meta_svr.py
Last active May 17, 2023 08:04
Metadata server to allow booting cloud-init images on Libvirt
"""
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 February 21, 2019 17:18
Pretty print an OpenStack Olso messaging packet capture
'''
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 16:26
Convert json to yaml
#!/usr/bin/env python3
import sys, json, yaml
yaml.dump(json.loads(sys.stdin.read()), sys.stdout, default_flow_style=False)
@djoreilly
djoreilly / j2-render.py
Created March 27, 2018 11:30
Render Jinja2 template
#!/usr/bin/python
import sys
import yaml
import jinja2
if len(sys.argv) != 3:
print "Usage: %s yaml template" % sys.argv[0]
sys.exit(1)
@djoreilly
djoreilly / bgpd.conf
Last active August 28, 2023 15:14 — forked from heri16/bgpd.conf
AWS VPC VPN StrongSwan Virtual Tunnel Interface (VTI)
#@ /etc/quagga/bgpd.conf (Centos & Ubuntu)
hostname <Local OS hostname>
password <Any random phrase>
enable password <Any random phrase>
!
log file /var/log/quagga/bgpd
!debug bgp events
!debug bgp zebra
debug bgp updates
@djoreilly
djoreilly / stack.yaml
Created February 16, 2018 18:12
Cloudformation example
AWSTemplateFormatVersion: 2010-09-09
# aws cloudformation create-stack --stack-name test-stack --template-body file://stack.yaml
# aws cloudformation describe-stacks --stack-name test-stack
# aws cloudformation describe-stack-events --stack-name test-stack
# aws cloudformation update-stack --stack-name test-stack --template-body file://stack.yaml
Description: VPC, SGs, instances
Parameters:
@djoreilly
djoreilly / mk_ansible_inv.py
Last active June 19, 2018 15:31
Builds an Ansible inventory file with RHOS overcloud nodes.
#!/usr/bin/python
'''
Builds an Ansible inventory file with RHOS overcloud nodes.
On director:
source ~/stackrc
./mk_ansible_inv.py >hosts
ansible all -i hosts -m shell -a "/usr/sbin/ip -4 a"
ansible controllers -i hosts -m shell -a "uptime"
TODO add storage and ceph nodes
@djoreilly
djoreilly / random_mac.py
Created November 30, 2017 10:44
Generates a random mac address with real OUI
import random
# wget http://standards-oui.ieee.org/oui.txt
OUI_FILE = 'oui.txt'
SEP = ':'
with open(OUI_FILE) as f:
lines = f.readlines()
while True:
@djoreilly
djoreilly / ovs-cheat.md
Last active March 15, 2024 13:02
OVS cheat sheet

DB

ovs-vsctl list open_vswitch
ovs-vsctl list interface
ovs-vsctl list interface vxlan-ac000344
ovs-vsctl --columns=options list interface vxlan-ac000344
ovs-vsctl --columns=ofport,name list Interface
ovs-vsctl --columns=ofport,name --format=table list Interface
ovs-vsctl -f csv --no-heading --columns=_uuid list controller
ovs-vsctl -f csv --no-heading -d bare --columns=other_config list port
@djoreilly
djoreilly / multicast-openstack.md
Last active December 29, 2023 07:06
Multicast on OpenStack

Multicast on OpenStack

The following works with Neutron VLAN provider networks, and requires configuration on the physical switches. Multicast works on br-int because the ML2 OVS driver/agent uses OVS in standalone mode (no external controller). The packets on br-int hit the NORMAL flow action, and so get treated by the ovs-vswitchd code that does IGMP snooping (when enabled). All IGMP packets are sent to the slow path (userspace ovs-vswitchd).

The following will not work on Neutron tunnel backed networks (VxLAN, GRE), as the neutron-openvswitch-agent hardcodes flows on br-tun that treats multicast the same as broadcasts and the NORMAL action is not used.

+----------------------------+      +----------------------------+
|      +----+    +----+      |      |      +----+    +----+      |
|      | VM |    | VM |      |      |      | VM |    | VM |      |
|      +-+--+    +--+-+      |      |      +-+--+    +--+-+      |