Skip to content

Instantly share code, notes, and snippets.

View mbaldessari's full-sized avatar
🏠
Working from home

Michele Baldessari mbaldessari

🏠
Working from home
View GitHub Profile
@mbaldessari
mbaldessari / gist:54a4924daae59063968b
Created May 10, 2014 16:26
Bash implementation of "cd ...."
function cd () {
local -ri n=${#*};
if [ $n -eq 0 -o -d "${!n}" -o "${!n}" == "-" ]; then
builtin cd "$@";
else
local e="s:\.\.\.:../..:g";
builtin cd "${@:1:$n-1}" $(sed -e$e -e$e -e$e <<< "${!n}");
fi
}
#!/usr/bin/python
from __future__ import print_function
import cProfile
from datetime import datetime
import os
import pstats
import resource
import StringIO
@mbaldessari
mbaldessari / ethtool-speed-test.c
Created April 19, 2015 08:08
Get the speed of a network interface via the ethtool interface
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <net/if.h>
#include <ctype.h>
#define ETHTOOL_GSET 0x1
#define SIOCETHTOOL 0x8946
for i in $(nova list |grep Running| awk '{ print $12 }' | cut -f2 -d=); do echo $i; ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null heat-admin@$i "sudo sosreport --batch; sudo chmod 644 /var/tmp/sos*xz"; scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null heat-admin@$i:/var/tmp/sos*xz .; done
#!/bin/bash
# by Damien Ciabrini & Michele Baldessari
# This function takes the resource name as a parameter and returns
# "clone", "master", "primitive" or exits with 1
function get_resource_type() {
local clone_count
local master_count
local primitive_count
local bundle_count
function apply_patch() {
local CHANGE=$1
local REPO=$2
local DIR=$3
# patchset revision is 4th optional argument
if [[ -z ${4-} ]]; then
REF=$(curl -s "https://review.openstack.org/changes/?q=change:$CHANGE&o=CURRENT_REVISION" |tail -n+2|jq -r '.[] | .revisions[.current_revision] | .ref')
else
REF=$(curl -s "https://review.openstack.org/changes/?q=change:$CHANGE&o=ALL_REVISIONS" |tail -n+2| jq -r '.[] | .revisions | to_entries | map(select(.value._number=='$4')) | .[0]|.value.ref')
fi
@mbaldessari
mbaldessari / gist:917c31bc01565f99eb1629d019e5d657
Created December 20, 2017 10:37
Useful TripleO/OSP aliases
ospgrep() {
echo "$*"
grep -E "\s\b(E[rR]{2}:?|alert|Traceback|TRACE|crit|fatal|HANDLER|TASK|PLAY|Unexpected|FAIL|[Ff]ail|denied|non-zero|[Tt]ime[d\s]?out|UNCAUGHT|EXCEPTION|Unknown|[Aa]ssertion|inuse)" $*
}
sprunge() {
if [ -n "$1" ]; then
curl -F 'sprunge=<-' "http://sprunge.us" <"$1"
else
curl -F 'sprunge=<-' "http://sprunge.us"
export OS_PROJECT_DOMAIN_NAME='Default'
export OS_USER_DOMAIN_NAME='Default'
export OS_PROJECT_NAME='admin'
export OS_USERNAME='admin'
export OS_AUTH_URL=http://192.168.24.2:5000/
export OS_AUTH_TYPE='password'
export OS_IDENTITY_API_VERSION='3'
export OS_PASSWORD=$(sudo hiera -c /etc/puppet/hiera.yaml keystone::admin_password)
@mbaldessari
mbaldessari / gist:a60f5c23be2dd201574cbe971d8bd10e
Created February 7, 2019 15:12
Destroy two controllers fully
#!/bin/bash
set -eu
# This only works when ran from the undercloud on an infrared setup
SSH_OPT="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
node0="controller-0"
node1="controller-1"
# Let's kill controller-0 and controller-1 leaving only controller-2 up
from keystoneauth1 import session
from keystoneauth1.identity import v3
from swiftclient.client import Connection
from tripleo_common.utils import swift as swiftutils
_authurl = 'http://192.168.24.1:5000/v3/'
_auth_version = '3'
_user = 'admin'
# (sudo hiera -c /etc/puppet/hiera.yaml keystone::admin_password)
_key = '6aMpWobr5ySX47vwJefUgMGAA'