Created
March 10, 2015 10:03
-
-
Save GregSutcliffe/2c8112199ad64202885e to your computer and use it in GitHub Desktop.
New-host script for hammer - use it like "./new-host wheezy"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script to create a new host quickly | |
cd ~/github/hammer-cli | |
case $1 in | |
# Some shortcuts | |
list) | |
bundle exec bin/hammer host list | |
exit 0 | |
;; | |
delete) | |
if [[ "${2}" =~ \w*\..* ]] ; then | |
# has a dot, use verbatim | |
bundle exec bin/hammer host delete --name "${2}" | |
else | |
# no dot, assume the domain | |
bundle exec bin/hammer host delete --name "${2}.sapphire.elysium.emeraldreverie.org" | |
fi | |
exit 0 | |
;; | |
# Actual host creation stuff | |
squeeze) | |
image="debian-squeeze-6.0.0-3-amd64.qcow2" | |
name="squeeze" | |
os=22 | |
;; | |
precise) | |
image="ubuntu-precise-12.04.0-1-amd64.qcow2" | |
name="precise" | |
os=2 | |
;; | |
centos) | |
image="centos.img" | |
name="centos" | |
os=24 | |
;; | |
trusty) | |
image="ubuntu-trusty-14.04.0-1-amd64.qcow2" | |
name="trusty" | |
os=25 | |
;; | |
*) | |
image="debian-wheezy-7.0.0-3-amd64.qcow2" | |
name="wheezy" | |
os=1 | |
;; | |
esac | |
# Use a random number for the hostname | |
rng=$(( 100+( $(od -An -N2 -i /dev/random) )%(1023+1) )) | |
# Get an ip from the proxy for primary networ (image-based only) | |
ip=$(curl -sk http://localhost:8443/dhcp/192.168.130.0/unused_ip |cut -d':' -f2|tr -d '"}') | |
bundle exec bin/hammer host create \ | |
--name "${name}${rng}" \ | |
--hostgroup-id 2 \ | |
--operatingsystem-id $os \ | |
--subnet-id 1 \ | |
--ip "${ip}" \ | |
--compute-resource-id 1 \ | |
--provision-method image \ | |
--compute-attributes cpus="1",memory="1073741824",start="1",image_id="/home/images/$image" \ | |
--interface="type=network,network=default,model=virtio" \ | |
--volume="capacity=10G,format_type=qcow2,pool_name=ImageHome" | |
# --compute-profile-id 1 \ | |
# --location-id 2 \ | |
# --organization-id 1 \ | |
echo "${name}${rng}" on "${ip}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment