Skip to content

Instantly share code, notes, and snippets.

@ThinGuy
ThinGuy / hp-raid-cfg
Last active November 28, 2023 20:30
Example MaaS Commissioning script to configure HP RAID
#!/bin/bash -x
# --- Start MAAS 1.0 script metadata ---
# name: 00-hp-array-01-config
# type: commissioning
# title: Configure HP Smart Array controllers on HP systems
# description: Configure HP Smart Array Controllers
# script_type: commissioning
# destructive: True
# tags: configure_hba commissioning
# --- End MAAS 1.0 script metadata ---
@ThinGuy
ThinGuy / sshuttle-opts.sh
Created December 2, 2017 01:19
Pass sshuttle ssh options to get around remote hosts whose identification changes often (testt/dev/ops systems)
# It is possible to paas sshuttle common ssh options such as UserKnownHostsFile, StrictHostIPChecking, CheckHostIP etc
# Normal sshuttle command:
sshuttle -r ubuntu@<some-ip>:2222 <remote_subnet(s)/CIDR>
# In the above scenario, for most systems, StrictHostKeyChecking, and all other good security features will be in effect.
# That's normally a good thing, except when it's not. Like when you have to continually clean a known hosts file because
# your testing different build options and the remote host's ECDSA, DSA, RSA <or whatever> keeps changing.
# By making use of the -e option you can control how sshuttle uses ssh. Any option your ssh-client supports can be passed.
@ThinGuy
ThinGuy / group_keys
Created December 9, 2017 04:10
test ssh key file
ssh-dss AAAAB3NzaC1kc3MAAACBALMVi/NkTMQ4tqsT7Rv0DQemW0VJ5FlknNA1dYqzbWGGuayI3mviUwFtcXiZ9R4EsYdo8q0Q4ezA7tCF7qqnYMGv2rmEsV3J7w9LCj7WtM7nnNqAbXQubIiB5cAZTGEV56/j8ReAdgDrJOBduIZIZ3qmgJCGvd6jdswKwnCPj4knAAAAFQDIbt3UDYvrr1CUWeeTsFQNviFMbwAAAIANv3dsGLnNDvUBxmkwHuwMPmhnr+gNOTuk7kVq4nVj96YfNJ08AFOUKjW6+VakoawWwvZaOGSLTnjhgtH8j/M97Glo+BgTjjttnLhWkQNKVkzAEf9S8WDOWgWeqLYDwdsFisHube1bVuHKmBENemgvX9gJ7+CExlfbRaRsPGQpLQAAAIAgDfuo2ZMG78cqaDR6HTGK4m95XdzaJEDj94DsoEf2SCvn0hjb5ksHWz111L7aus/wbdAckaYT+elwtarQjcRoHnQatEoKA0ZYh4WtmfJokQGjIgdu/1bCWBbuiT1cbrRb5v2ZEofxVj3WmCqjNgA3HB7IY099UmbytJN8eMkA6g== bonham@masters.org
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCc4XuxkjSkA7CgA4F+E2lzfiN8ehJLY7Y4LyCbt40eNV/HSiAI2C15/AzlcZcgEdXFA6RABJhodrOv35Q8mYV7gRILbjhbg0nG6B43i0PdgFpuk3/iriRucY6QscIGngmfXJ70qy1DH1HZbex2D456TDZJnugGZBWYlC4LlWpmw+ixCcQhyn46q+NwUiL+vHQq1YjXFLw/+4dHOSFPvsl0KvmCw+PMsKp1z8DEb5INPohVHH5eaqeeQ1BB4zwOHogQOAmWR6Jn7XXZ7Lxzo+LzyR56ldaf+SfISvdCeqhuHqII786VJXePOkkw5KgImbg9XEHad9pn98ixlvTJJMIT bonham@masters.org
ssh-dss AAAAB3
@ThinGuy
ThinGuy / os_functions.sh
Created February 19, 2018 19:04
Basic openstack tests as functions
####OpenStack Test Functions######
#This file should be sourced, not ran
###Prettyfication section####
tstatus() {
RC=$(echo $?)
[[ $RC -eq 0 ]] && { printf '\e[75G\e[1;37m[ \e[1;32mOK\e[1;37m ]\e[0m\n';return $RC; }
[[ $RC -eq 1 ]] && { printf '\e[75G\e[1;37m[\e[1;31mFAIL\e[1;37m]\e[0m\n';return $RC; }
}
@ThinGuy
ThinGuy / juju-landscape-reset
Created February 24, 2018 03:54
Reset landscape-client deployed with juju
for i in $(juju status|awk '/Unit/,/^$/{gsub(/\*/,"");if (/..landscape-client/) print $1}'|sort -uV);do juju ssh $i "sudo landscape-config --silent";done
@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 / 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 / cpu-onliners.sh
Last active April 13, 2022 21:09
One liners for system CPU Usage
#faster
grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}'
#For grep cpu for use with juju (counts machines, then runs command remotely)
for i in $(juju machines|awk '!/lxd/&&!/kvm/&&!/^M/&&!/^$/{print $1}');do printf "Juju Machine $i CPU %%: ";juju ssh $i "grep 'cpu ' /proc/stat | awk '{usage=(\$2+\$4)*100/(\$2+\$4+\$5)} END {print usage \"%\"}'";done 2>/dev/null
#Slower, but better
top -b -n2 -p 1 | fgrep "Cpu(s)" | tail -1 | awk -F'id,' '{ split($1, vs, ","); v=vs[length(vs)]; sub("ex%", "", v); printf "%.1f%%\n", 100 - v }'
@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"]' \