Skip to content

Instantly share code, notes, and snippets.

View mevansam's full-sized avatar

Mevan Samaratunga mevansam

  • AppBricks
  • Boston, USA
View GitHub Profile
@mevansam
mevansam / sync_dir
Last active May 24, 2017 07:27
Synchronize a local path with a remote path
#!/bin/bash
if [[ $# -ne 5 ]]; then
echo -e "\nUsage: sync [SSH KEY PATH] [SSH_USER] [REMOTE HOST] [LOCAL DIR/FILE] [REMOTE DIR/FILE]\n"
exit 1
fi
if [[ ! -e $4 ]]; then
echo -e "\nError: '$4' does not exist."
exit 1
# This Vagrant file shoud default to VirtualBox
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox'
# Install bosh cli in jumpbox - This script will be skipped if the pre-provisioned box is used
bosh_cli_install_script = <<SCRIPT
set -x
# Proxy server #.#.#.#:# if any
PROXY=""
#!/bin/bash
[ "$1" = "-d" ] && debug=on || debug=off
# Make working directory
export wrkdir=/tmp/wrkdir.$$
mkdir -p ${wrkdir}
# Clean up function
clean_up()
{
@mevansam
mevansam / gist:8f0bcb0f7b991d30de8e
Last active August 29, 2015 14:20
Run basic VM and volume tests on an OpenStack cluster
#!/bin/bash
if [ -z $1 ] || [ -z $2 ]; then
echo -e "\nusage: ./ostest.sh <start> <end> [ <image> <user> <key_pair> <private_network> <public_network> ]\n"
echo -e " Runs tests numbered from <start> to <end>. Arguments <image>, <user>, <key_pair>,"
echo -e " <private_network> and <public_network> are optional but must provided as one. If"
echo -e " they are not provided then 'cirros-0.3.3', 'cirros', '$(whoami)' 'private01' and "
echo -e " 'public01' will be used.\n"
exit 1
fi
@mevansam
mevansam / gist:f50159ef7295f4bb1a0f
Last active August 29, 2015 14:20
VagrantFile for VMware vSphere 6 ESX Hypervisor with vCenter Server VM
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.define "esx" do |esx|
esx.vm.box = "mevansam/vmware-esxi6-vc"
esx.vm.hostname = "esxbox"
esx.vm.synced_folder ".", "/vagrant", disabled: true
@mevansam
mevansam / gist:7bd8298e3e5316008108
Last active August 29, 2015 14:11
Re-enabling VBox networks if disabled by VPN tools
#!/bin/bash
for device in $(VBoxManage list hostonlyifs | awk '/^Name:/ { print $2 }'); do \
ipaddress=$(VBoxManage list hostonlyifs | grep -A 3 "$device" | awk '/IPAddress:/ { print $2 }'); \
VBoxManage hostonlyif ipconfig $device --ip $ipaddress; \
sudo ifconfig $device down; \
sudo ifconfig $device up; \
echo "Restarted $device with ip $ipaddress."; \
done
@mevansam
mevansam / gist:d0d517ea321c6b199e55
Last active August 29, 2015 14:11
Sample OpenStack openrc file for an OpenStack sandbox
# COMMON OPENSTACK ENVS
export OS_USERNAME=admin
export OS_PASSWORD=0p3n5tack
export OS_TENANT_NAME=admin
export OS_AUTH_URL=https://192.168.60.200:5000/v2.0
export OS_REGION_NAME=kvm_vbox
export SERVICE_ENDPOINT="https://192.168.60.200:35357/v2.0"
export SERVICE_TOKEN=0c4a1365e0bbb7e2e02543a2b932cfed
@mevansam
mevansam / gist:2b8ee9e248d1b5082552
Last active August 29, 2015 14:11
Configure an OpenStack installation with a Sample Network and Security Group and Key
#!/bin/bash
set -x
if [ ! -e "openrc" ]; then
echo "Unable to find an 'openrc' with the openstack environment."
exit 1
fi
source openrc
@mevansam
mevansam / gist:4092474
Last active October 12, 2015 21:57
Ruby method to format a text table that resizes to the screen width
require "set"
require "highline"
#
# Prints a 2-d array as a table formatted to terminal size
#
def print_table(table, format = true, cols = nil)
# Apply column filter
unless cols.nil?