Skip to content

Instantly share code, notes, and snippets.

@ThinGuy
ThinGuy / remove-os-hypervisors-from DB
Last active February 24, 2018 04:17
Remove Hypervisors from Openstack (mysql) Database (deployed via juju)
export DB_APP=$(juju 2>/dev/null status --format=json|jq 2>/dev/null -r '.applications | to_entries[] |"\(select((.value."charm-name"|startswith("perc")) or .value."charm-name" == "mysql").key)"')
export MYSQL_PW=$(juju 2>/dev/null run --unit ${DB_APP}/0 leader-get |awk 2>/dev/null '/mysql.passwd/{print $2}')
#Create array of Hypervisors with hostnames, virt type and IP
declare -ag OS_COMPUTE_NODES=($(juju ssh mysql/0 "mysql 2>/dev/null -u root -p${MYSQL_PW} -s -N -D nova -e 'SELECT hypervisor_hostname,hypervisor_type,host_ip FROM compute_nodes;'" 2>/dev/null|sed 's/\t/,/g'|sort -uV))
# Print list of hypervisors from above array
for N in ${!OS_COMPUTE_NODES[@]};do printf "\e[2G$(($N+1))\e[0m) ${OS_COMPUTE_NODES[$N]//,/\\t}\n"; done|column -next
@ThinGuy
ThinGuy / cuda_preseeds
Last active February 28, 2018 22:45
Curtin late commands to install cuda drivers
#These commands should go directly under the maas command in the late_commands section in /etc/maas/preseeds/curtin_userdatas
#Spacing matters, copy as is.
nvidia_00_cmd: ["sh", "-c", "echo Blacklist Nouveau and Adding Cuda Drivers."]
nvidia_01_cmd: ["curtin", "in-target", "--", "sh", "-c", "echo", "-en", "blacklist nouveau\noptions nouveau modeset=0\n >> /etc/modeprobe.d/blacklist-nouveau.conf"]
nvidia_02_cmd: ["curtin", "in-target", "--", "sh", "-c", "wget -qO- http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub|apt-key add -"]
nvidia_03_add: ["curtin", "in-target", "--", "add-apt-repository", "-y", "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 /"]
nvidia_04_cmd: ["curtin", "in-target", "--", "sh", "-c", "apt update"]
nvidia_05_cmd: ["curtin", "in-target", "--", "sh", "-c", "DEBIAN_FRONTEND=noninteractive apt install cuda -yq"]
@ThinGuy
ThinGuy / pod-host-xpath-tag
Last active March 6, 2018 05:48
Hypervisor / Pod Host XPATH auto-tagging for MaaS
maas ${MAAS_PROFILE} tags create name=pod-host \
definition='//node[@id="memory" and @class="memory"]/size >= "17179860388" and
//node[@id="cpu" and @class="processor"]/configuration/setting/id="cores" >= 2 and
.//node[@id="cpu"]/capabilities/capability[@id="vmx"] and
.//node[@id="cpu"]/capabilities/capability[@id="aes"] and
.//node[@id="cpu"]/capabilities/capability[@id="ept"] and
.//node[@id="cpu"]/capabilities/capability[@id="vpid"] and
.//node[@id="cpu"]/capabilities/capability[@id="tpr_shadow"] and
.//node[@id="cpu"]/capabilities/capability[@id="flexpriority"] and
.//node[@id="cpu"]/capabilities/capability[@id="vnmi"]' \
@ThinGuy
ThinGuy / ob-os-sanity.sh
Created March 8, 2018 17:55
Openstack OrangeBox Sanity Test
#!/bin/bash
#Script to configure openstack on Orangebox
[[ ${HOSTNAME,,} =~ orangebox ]] && export OB_NUM=$((10#${HOSTNAME:9})) || OB_NUM=20
#Networking Variables - External will be provider, Int will be tenant
export NEUTRON_DNS1="172.27.$((${OB_NUM})).1"
export NEUTRON_DNS2="172.27.$((${OB_NUM}+2)).1"
export NEUTRON_DNS3="172.27.$((${OB_NUM}+3)).254"
@ThinGuy
ThinGuy / add-extra-opm-sites
Last active March 11, 2018 16:15
Add ntp, landscape, and livepatch to maas DNS when OPM is being used (if not totally isolated from internet)
maas admin dnsresources create name=livepatch domain=canonical.com ip_addresses="162.213.33.130 162.213.33.177"
maas admin dnsresources create name=ntp domain=ubuntu.com ip_addresses="91.189.89.199 91.189.94.4 91.189.91.157 91.189.89.198"
maas admin dnsresources create name=landscape domain=canonical.com ip_addresses="91.189.89.90 91.189.89.173"
maas admin dnsresources create name=usn domain=ubuntu.com ip_addresses="162.213.33.205 162.213.33.20 162.213.33.141"
@ThinGuy
ThinGuy / random-ipv6-range.sh
Last active March 16, 2018 13:40
Function to create a range of IPv6 addresses based off a randomly generated MAC address
random-ipv6-range() {
local DESC="\e[1m${FUNCNAME}: Create a sequential range of IP addresses\e[0m\n"
[[ $1 = '--desc' ]] && { printf "${DESC}";return; }
random-ipv6-range_usage() {
printf "\n${DESC}\n"
printf "\e[2GUsage: ${FUNCNAME%%_*} [OPTIONS]\n\n"
printf "\e[2GOptions:\n"
printf "\e[4G -c, --count \e[24GNumber of IPv6 addresses to include in the range\n"
@ThinGuy
ThinGuy / increment-mac.sh
Created March 16, 2018 13:44
Function to increment increment a provide MAC address (or use autogenerated MAC)
increment-mac() {
local DESC="\e[1m${FUNCNAME}: Prints incrementing MAC address numbers\e[0m\n"
[[ $1 = '--desc' ]] && { printf "${DESC}";return; }
increment-mac_usage() {
printf "\n${DESC}\n"
printf "\e[2GUsage: ${FUNCNAME%%_*} [OPTIONS]\n\n"
printf "\e[2GOptions:\n"
printf "\e[4G -c, --count \e[20GNumber of MAC address to print\n"
@ThinGuy
ThinGuy / juju-openstack-upgrade.sh
Created March 22, 2018 00:35
Rolling Openstack Upgrade with Juju
juju-upgrade-openstack() {
export SERIES=xenial
export RELEASE=pike
export CURRENT_MODEL=$(juju models|awk '/*/{gsub(/*/,"");print $1}')
printf "\e[2GGetting list of applications from juju model \"${CURRENT_MODEL}\" \n"
declare -ag JUJU_APPS=($(juju 2>/dev/null status --format=json|jq 2>/dev/null -r '.applications | to_entries[].key'))
printf "%s\n" ${JUJU_APPS[@]}
printf "\e[2GGetting list of openstack applications from juju model \"${CURRENT_MODEL}\" \n"
declare -ag UPGRADE_APPS=($(for APP in ${JUJU_APPS[@]};do [[ -n $(juju 2>/dev/null config ${APP} action-managed-upgrade) ]] && echo ${APP};done))
printf "%s\n" ${UPGRADE_APPS[@]}
@ThinGuy
ThinGuy / fix-deployed-dns-search.sh
Last active April 2, 2018 11:27
Change dns-search paramater laid down by juju
#If populating MAAS DNS with domains, all domains get added to the search order.
#Resolv.conf only supports 6, so if you have more 6 domains entered, nothing after the 6th gets resolved
#Also, juju for some reason is doing an alpha sort on domain, which in most cases (and in the case of http://launchpad.net/opm) puts
#the MAAS domain near the end, which is past the 6th domain.
#This function will go through all machines and containers in a model and set a given search order, or
#if used without arguments will set the maas domain as the only entry in dns-search
fix-deployed-dns-search() {
@ThinGuy
ThinGuy / unicode-spaces.sh
Last active April 4, 2018 12:53
Show difference of unicode spacing options on characters (If you are using a monospace font, this will be a waste of time)
#If you are using a monospace font, this will be a waste of time
unicode-space-test() {
declare -ag SPACE_ARRAY=(
'\u0020|SPACE|Typically 1/4 EM; Adjusted depending on font.'
'\u00A0|NO-BREAK SPACE|As a space; Often not adjusted.'
'\u1680|OGHAM SPACE MARK|Usually not really a space but a dash.'
'\u180E|MONGOLIAN VOWEL SEPARATOR|No width space.'
'\u2000|EN QUAD|1 EN; Fixed-width.'
'\u2001|EM QUAD|1 EM (nominally; the height of the font); Fixed-width.'
'\u2002|EN SPACE|1 EN; Fixed-width.'