Skip to content

Instantly share code, notes, and snippets.

@thieman
Created April 16, 2014 00:13
Show Gist options
  • Save thieman/10791765 to your computer and use it in GitHub Desktop.
Save thieman/10791765 to your computer and use it in GitHub Desktop.
Automatic Server Names in S3
# Example of how to generate a node name on Amazon EC2
# This calls out to the "magic" IP that can give you your EC2 metadata
IPNAME=`curl -s http://169.254.169.254/latest/meta-data/hostname | cut -d '.' -f1 | cut -d '-' -f1-2 --complement | tr '-' '.' | xargs -I {} python ip_to_name.py {}`
RETVAL=$?
if [ $RETVAL -ne 0 ]
then
# fallback to internal IP if ip-to-name breaks
IPNAME=`ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1 }' | tr '.' '-'`
fi
echo "node_name \"$IPNAME\"" >> /etc/chef/client.rb
#!/usr/bin/env python
import sys
import random
phonemes = ['BA', 'BE', 'BI', 'BLA', 'BLE', 'BLI', 'BLO', 'BLU', 'BLY', 'BO', 'BRA', 'BRE', 'BRI', 'BRO', 'BRU', 'BRY', 'BU', 'BY', 'CHA', 'CHE', 'CHI', 'CHO', 'CHU', 'CHY', 'DA', 'DE', 'DI', 'DO', 'DRA', 'DRE', 'DRI', 'DRO', 'DRU', 'DRY', 'DU', 'DY', 'FA', 'FE', 'FI', 'FLA', 'FLE', 'FLI', 'FLO', 'FLU', 'FLY', 'FO', 'FRA', 'FRE', 'FRI', 'FRO', 'FRU', 'FRY', 'FU', 'FY', 'GA', 'GE', 'GI', 'GLA', 'GLE', 'GLI', 'GLO', 'GLU', 'GLY', 'GO', 'GRA', 'GRE', 'GRI', 'GRO', 'GRU', 'GRY', 'GU', 'GY', 'HA', 'HE', 'HI', 'HO', 'HU', 'HY', 'JA', 'JE', 'JI', 'JO', 'JU', 'JY', 'KA', 'KE', 'KI', 'KLA', 'KLE', 'KLI', 'KLO', 'KLU', 'KLY', 'KO', 'KRA', 'KRE', 'KRI', 'KRO', 'KRU', 'KRY', 'KU', 'KY', 'LA', 'LE', 'LI', 'LO', 'LU', 'LY', 'MA', 'ME', 'MI', 'MO', 'MU', 'MY', 'NA', 'NE', 'NI', 'NO', 'NU', 'NY', 'PA', 'PE', 'PI', 'PLA', 'PLE', 'PLI', 'PLO', 'PLU', 'PLY', 'PO', 'PRA', 'PRE', 'PRI', 'PRO', 'PRU', 'PRY', 'PU', 'PY', 'QUA', 'QUE', 'QUI', 'QUO', 'QUU', 'QUY', 'RA', 'RE', 'RI', 'RO', 'RU', 'RY', 'SA', 'SE', 'SHA', 'SHE', 'SHI', 'SHO', 'SHU', 'SHY', 'SI', 'SKA', 'SKE', 'SKI', 'SKO', 'SKU', 'SLA', 'SLE', 'SLI', 'SLO', 'SLU', 'SLY', 'SMA', 'SME', 'SMI', 'SMO', 'SMU', 'SMY', 'SNA', 'SNE', 'SNI', 'SNO', 'SNU', 'SNY', 'SO', 'SPA', 'SPE', 'SPI', 'SPO', 'SPU', 'SPY', 'SRI', 'STA', 'STE', 'STI', 'STO', 'STU', 'STY', 'SU', 'SWA', 'SWE', 'SWI', 'SWO', 'SWU', 'SWY', 'SY', 'TA', 'TE', 'THA', 'THE', 'THI', 'THO', 'THU', 'THY', 'TI', 'TO', 'TRA', 'TRE', 'TRI', 'TRU', 'TRY', 'TU', 'TY', 'VA', 'VE', 'VI', 'VO', 'VRA', 'VRE', 'VRI', 'VRO', 'VRU', 'VRY', 'VU', 'VY', 'WA', 'WE', 'WI', 'WO', 'WU', 'WY', 'YA', 'YE', 'YI', 'YO', 'YU', 'ZA', 'ZE', 'ZHA', 'ZHE', 'ZHI', 'ZHO', 'ZHU', 'ZHY', 'ZI', 'ZO', 'ZU', 'ZY']
words = ['arm', 'ask', 'ass', 'bad', 'bank', 'beam', 'bear', 'bed', 'beer', 'beg', 'bet', 'big', 'bike', 'bled', 'blue', 'boat', 'bog', 'bold', 'bong', 'book', 'boot', 'bop', 'boss', 'box', 'buck', 'bud', 'bum', 'bus', 'can', 'car', 'care', 'carp', 'cart', 'case', 'cash', 'cat', 'char', 'chip', 'clog', 'cloy', 'clue', 'cod', 'code', 'cold', 'cost', 'cow', 'crop', 'crow', 'crud', 'cub', 'cup', 'cut', 'dad', 'dark', 'dart', 'deck', 'dim', 'dirt', 'disk', 'dog', 'dub', 'duck', 'duct', 'dude', 'duke', 'dump', 'eel', 'egg', 'elm', 'end', 'etch', 'face', 'fact', 'fast', 'fear', 'fen', 'fish', 'flag', 'flak', 'fled', 'flux', 'fly', 'foe', 'fold', 'ford', 'fork', 'fuel', 'funk', 'gag', 'gain', 'game', 'gimp', 'git', 'goon', 'grog', 'gum', 'gunk', 'ham', 'hat', 'heap', 'heck', 'held', 'help', 'hem', 'herd', 'hid', 'hike', 'hip', 'hobo', 'hold', 'hop', 'hub', 'hue', 'hug', 'hut', 'jet', 'jig', 'joke', 'juke', 'key', 'kick', 'king', 'kiss', 'kite', 'land', 'last', 'leaf', 'lid', 'line', 'link', 'lion', 'lord', 'lose', 'love', 'mace', 'mad', 'man', 'map', 'mask', 'math', 'mead', 'mill', 'mime', 'mod', 'moo', 'moon', 'mug', 'myth', 'nag', 'neck', 'need', 'nerd', 'nerf', 'nit', 'nope', 'now', 'oat', 'ode', 'ouch', 'pal', 'pay', 'perk', 'pig', 'pink', 'plow', 'pod', 'pond', 'poof', 'pope', 'post', 'prep', 'punk', 'pure', 'rad', 'raft', 'raid', 'ramp', 'rant', 'rap', 'rat', 'rate', 'rend', 'rest', 'rib', 'rice', 'rip', 'rock', 'roof', 'rot', 'ruby', 'rude', 'rug', 'rush', 'sad', 'safe', 'sap', 'scum', 'seal', 'seat', 'shed', 'ship', 'shut', 'side', 'silk', 'sit', 'ski', 'sky', 'slab', 'slam', 'sled', 'sly', 'snap', 'snow', 'soap', 'sod', 'soon', 'spa', 'spud', 'spun', 'star', 'stat', 'tame', 'tan', 'tank', 'thin', 'tool', 'tree', 'trim', 'true', 'tub', 'turf', 'tusk', 'ugly', 'urge', 'var', 'vex', 'vim', 'void', 'vow', 'wig', 'wind', 'with', 'wolf', 'wood', 'wub', 'yak', 'yam', 'yaw', 'yay', 'yolo', 'yup', 'zag', 'zig', 'zing', 'zip', 'zone']
USE_LIST = words
def main(address):
print '-'.join([USE_LIST[int(piece)].lower() for piece in address.split('.')])
if __name__ == '__main__':
if len(sys.argv) != 2:
raise ValueError('Expects a single arg of a full or partial IP address, e.g. 62.43.255')
main(sys.argv[1].strip())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment