Skip to content

cre_vm.sh – script to add a VM to an ESX

by on November 19, 2013
Script mentioned in the post Creating VMs on ESX using scripts and cobbler

#!/bin/bash
#
# cre_vm.sh - script to add a VM to an ESX
# Input:
# ESX - the ESX host (need to have passwordless ssh capabilities to it)
# IP - the IP you want to give the VM
# DS - the data store the VM will reside in
# 
function Usage {
echo "$0 <ESX host> <IP> <datastore>"
exit
} 
ESX=$1
IP=$2
DS=$3
[ -z "$ESX" ] || [ -z "$IP" ] || [ -z "$DS" ] && Usage
NM=h${IP}_CDH

ssh $ESX create_vm.sh -n $NM -d $DS -c 4 -r 8192 -s 16 
sleep 20
MAC=`ssh $ESX grep ethernet0.generatedAddress /vmfs/volumes/${DS}/$NM/$NM.vmx | awk '/ethernet0.generatedAddress =/{gsub(/"/,"");print $3}'`

cobbler_system_add.sh $IP CentOS6-x86_64 $MAC MYVM=`ssh $ESX vim-cmd vmsvc/getallvms 2>/dev/null | awk '/'$NM'/{print $1}'`

ssh $ESX vim-cmd vmsvc/power.on $MYVM
Advertisements

From → Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: