Created
March 21, 2014 13:10
-
-
Save GregSutcliffe/9685853 to your computer and use it in GitHub Desktop.
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) | |
bundle exec bin/hammer host delete --name "${2}.sapphire.elysium.emeraldreverie.org" | |
exit 0 | |
;; | |
# Actual host creation stuff | |
squeeze) | |
image="debian-squeeze-6.0.0-3-amd64.qcow2" | |
;; | |
precise) | |
image="ubuntu-precise-12.04.0-1-amd64.qcow2" | |
;; | |
centos) | |
image="centos.img" | |
;; | |
*) | |
image="debian-wheezy-7.0.0-3-amd64.qcow2" | |
;; | |
esac | |
# Use a random number for the hostname | |
rng=$(( 100+( $(od -An -N2 -i /dev/random) )%(1023+1) )) | |
# Get an ip from the proxy | |
ip=$(curl -sk http://localhost:8443/dhcp/192.168.122.0/unused_ip |cut -d':' -f2|tr -d '"}') | |
bundle exec bin/hammer host create \ | |
--name "${1}${rng}" \ | |
--hostgroup-id 49 \ | |
--subnet-id 1 \ | |
--ip "${ip}" \ | |
--compute-resource-id 3 \ | |
--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" \ | |
--provision_method image | |
echo "${1}${rng}" on "${ip}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment