Skip to content

Instantly share code, notes, and snippets.

View freyes's full-sized avatar
🥑

Felipe Reyes freyes

🥑
View GitHub Profile
@freyes
freyes / os-nova-pause.sh
Last active August 29, 2015 14:05
Pause/unpause all the virtual machines in a OpenStack cloud
#!/bin/bash
#
# Usage:
# ./os-nova-pause.sh pause
#
# Note: remember to define the environment variables used by the openstack clients
# typically this is done sourcing a 'openrc' file (you can download it from horizon)
#
function mod_server {
@freyes
freyes / prepare-vip.sh
Last active August 29, 2015 14:08
Allow a vip to float across ports, this is needed when you configure a vip for corosync
#!/bin/bash -e
# Usage exmaple:
# ./prepare-vip.sh 10.5.0.107 port1,port2,port3 foo_net
#
# This will prepare the vip 10.5.0.107 to be used by machines in ports `port1`, `port2` and `port3`
# in the the next `foo_net`0
PROG=$0
VIP="$1"
PORTS="$2"
PRIV_NET=${3:-"freyes_admin_net"}
@freyes
freyes / lxc-clone-static-ip.sh
Created November 3, 2014 18:44
Patch a machine to use lxcbr0 in bridge mode and assign a static ip to the container
#!/bin/bash
/usr/bin/lxc-clone.real $@
RET=$?
# hostname will be of the form juju-FOO-machine-NUM
X=$(hostname | cut -d'-' -f4) # here we grab NUM
# the 4th argument to lxc-clone is the new container's name that looks like juju-machine-NUM-lxc-CONTAINER_ID
COUNTER=$(echo $4 | cut -d'-' -f 5)
NEW_IP="10.5.${X}0.$(( $COUNTER + 20 ))"
@freyes
freyes / sync-ibus.py
Created December 15, 2014 16:28
keep synced /desktop/ibus/general/preload-engines with /org/gnome/desktop/input-sources/sources
#!/usr/bin/python
from gi.repository import Gtk, Gio, GLib
IBUS_TO_GNOME = {'xkb:us::eng': ('xkbd', 'us'),
'xkb:us:intl:eng': ('xkbd', 'us+intl')}
def on_changed(settings, key):
if key != 'engines-order':
@freyes
freyes / swap.sh
Created December 18, 2014 14:51
This Bash script will display how much swap each process is using, in kB
#! /bin/bash
#
# swap.sh: Shows the swap usage of each process
# Author: Robert Love
# source: http://www.quora.com/How-can-you-determine-what-processes-are-using-swap-space
swap_total=0
for i in /proc/[0-9]*; do
pid=$(echo $i | sed -e 's/\/proc\///g')
swap_pid=$(cat /proc/$pid/smaps |
convertion = [
(1024 ** 5, 'P'),
(1024 ** 4, 'T'),
(1024 ** 3, 'G'),
(1024 ** 2, 'M'),
(1024 ** 1, 'K'),
(1024 ** 0, 'B'),
]
def size_suffix(bytes):
@freyes
freyes / fakevpn
Last active August 29, 2015 14:13
#!/bin/bash
#
# Simple wrapper for sshuttle :)
#
# Felipe Reyes <freyes@tty.cl>
#
PIDFILE=$HOME/.fake-vpn.pid
if [ ! -n "$FAKEVPN_HOST" ]; then
echo "Please define FAKEVPN_HOST environment variable"
@freyes
freyes / bashrc
Created February 26, 2015 15:24
launch ssh-agent and load env variables
# put this in ~/.bashrc
test -f ~/.ssh/agent && source ~/.ssh/agent > /dev/null
if [ "x$SSH_AGENT_PID" != "x" ]; then
kill -0 $SSH_AGENT_PID || ssh-agent -s -a $HOME/.ssh/agent.socket > ~/.ssh/agent
else
ssh-agent -s -a $HOME/.ssh/agent.socket > ~/.ssh/agent
fi
source ~/.ssh/agent > /dev/null
#!/usr/bin/perl -w
# Dependencies:
# sudo apt-get install libxml-xpath-perl libsys-virt-perl
use strict;
use XML::XPath;
use XML::XPath::XMLParser;
use Sys::Virt;
# Open libvirt connection and get the domain.
#!/bin/bash
set -ex
juju run --service percona-cluster "unit-get private-address"
juju run --service percona-cluster "relation-ids cluster"
RID=$(juju run --unit percona-cluster/0 "relation-ids cluster")