VMware

Jonathan Marrott's VM Scripting Blog

A swell blog containing some of the scripts I have written for VM management.

22 Posts 1 2 Previous Next
0

Session Keeper

Posted by froboy Mar 27, 2008

Here's a script that will create a session, save it to a session file and keep it alive. If at any time the session is terminated, the script will create a new session and new session file.

Usage: SessionKeeper.pl --server <servername> --file <session_filename_to_be_saved>

0 Comments Permalink
0

List DCs and Clusters

Posted by froboy Jan 22, 2008

These two scripts are both designed for enumeration of objects. The cluster specific script will also enumerate HA properties about that cluster.

Usage:
listdcs.pl --server lewvc --username <username> --password <password>
listdcclusters.pl --server lewvc --username <username> --password <password> --datacenter <DC Name>

0 Comments Permalink
7

List All VMs (Updated)

Posted by froboy Jan 22, 2008

These scripts will list all vms registered with Virtual Center or a specific Datacenter object.

Usage: listdcvms.pl --server <VC Server> --username <username> --password <password> --datacenter <DC Name>
Usage: listallvms.pl --server <VC Server> --username <username> --password <password>

7 Comments Permalink
0

Additional Blog, etc.

Posted by froboy Jan 18, 2008

Since this particular blog is dedicated to VMWare and scripting, I have created a more general tech blog. This blog will also contain some VMWare info that is not scripting related. Initially it contains notes from the recent ESX training I went through. If you have been through the Install and Configure training and are preparing for your VCP exam, these notes will prove very helpful. I just passed my VCP exam today with a 91%. That was lower than I wanted, but I did hurry through it in about 30 min. I am sure that I glazed over some questions.

You can find it at:
My Tech Blog

0 Comments Permalink
0

Firewall - XML Changes (Updated)

Posted by froboy Jan 18, 2008

I decided that I didn't like changing the firewall by executing esxcfg-firewall all the time. So I edited the appropriate XML file to include the nececssary ports for TSM and VMM (HP) agent. This is different for ESX 3.0.x and 3.5. One word of caution: In ESX 3.5 if you add a service to services.xml and it exists in another XML file. You can render your system inaccessible.

ESX 3.5
Service - TSM
Location - ibmTSM.xml

<!-- Firewall configuration information for IBM TSM -->
<ConfigRoot>
<service>
<id>TSM</id>
<rule id='0000'>
<direction>inbound</direction>
<protocol>tcp</protocol>
<port type='dst'>1500</port>
<flags>-m state --state NEW</flags>
</rule>
<rule id='0001'>
<direction>outbound</direction>
<protocol>tcp</protocol>
<port type='dst'>1500</port>
<flags>-m state --state NEW</flags>
</rule>
<rule id='0002'>
<direction>inbound</direction>
<protocol>tcp</protocol>
<port type='dst'>
<begin>1581</begin>
<end>1583</end>
</port>
<flags>-m state --state NEW</flags>
</rule>
<rule id='0003'>
<direction>outbound</direction>
<protocol>tcp</protocol>
<port type='dst'>
<begin>1581</begin>
<end>1583</end>
</port>
<flags>-m state --state NEW</flags>
</rule>
</service>
</ConfigRoot>

ESX 3.0.x
Service - TSM
Location - services.xml
<service id='0023'>
<id>TSM</id>
<rule id='0000'>
<direction>inbound</direction>
<protocol>tcp</protocol>
<port type='dst'>1500</port>
<flags>-m state --state NEW</flags>
</rule>
<rule id='0001'>
<direction>outbound</direction>
<protocol>tcp</protocol>
<port type='dst'>1500</port>
<flags>-m state --state NEW</flags>
</rule>
<rule id='0002'>
<direction>inbound</direction>
<protocol>tcp</protocol>
<port type='dst'>
<begin>1581</begin>
<end>1583</end>
</port>
<flags>-m state --state NEW</flags>
</rule>
<rule id='0003'>
<direction>outbound</direction>
<protocol>tcp</protocol>
<port type='dst'>
<begin>1581</begin>
<end>1583</end>
</port>
<flags>-m state --state NEW</flags>
</rule>
</service>

Service - VMM
Location - services.xml
Note: We discontinued use of VMM do to VM reboots.

<service id='0028'>
<id>VmmService</id>
<rule id='0000'>
<direction>inbound</direction>
<protocol>tcp</protocol>
<port type='dst'>
<begin>1124</begin>
<end>1126</end>
</port>
<flags>-m state --state NEW</flags>
</rule>
<rule id='0001'>
<direction>outbound</direction>
<protocol>tcp</protocol>
<port type='dst'>
<begin>1124</begin>
<end>1126</end>
</port>
<flags>-m state --state NEW</flags>
</rule>
</service>

0 Comments Permalink
5

Enable VMotion on VMKernel port

Posted by froboy Jan 18, 2008

This will enable VMotion on a VMKernel port. I am writing this one because it changed between verisons of ESX. This command uses the very useful vimsh.

ESX 3.0.x:
vimsh -n -e "/hostsvc/vmotion/vnic_set portgroup2"
portgroup# - Determined by the order of portgroup creation. The system automatically makes one to begin with.

ESX 3.5:
vimsh -n -e "/hostsvc/vmotion/vnic_set vmk0"
vmk# - Determined by the order of the VMKernel port creation. The first one created is '0'.

5 Comments Permalink
3

Create NFS Mount on ESX (Updated)

Posted by froboy Jan 18, 2008

I like to have a mount on each of my ESX servers to allow for quick installations and centralized scripting for cron jobs.

NFS Mount visible from host and service console:
<Required to have a Service Console and VMKernel port>
This can be accessed from /vmfs/volumes/<datastore>
esxcfg-firewall -e nfsClient
esxcfg-nas -a -o nfsserver.yourdomain.com -s /vol/vm nfs01

Manual mount visible from the service console only:
1. Edit /etc/rc.d/rc.local
2. Add: mount nfsserver.yourdomain.com:/vol/vm /mnt/vm
This will allow it to mount on boot.
3. Execute: mkdir /mnt/vm
4. Execute: chkconfig portmap on
5. Execute: service portmap start
6. Execute: esxcfg-firewall -e nfsClient
7. Execute: mount nfsserver.yourdomain.com:/vol/vm /mnt/vm
This will immediately mount.

3 Comments Permalink
0

DNS - Set Servers (Updated)

Posted by froboy Jan 18, 2008

Simple script to set DNS servers. This sets muplitle DNS servers while kickstart by default only sets one.

Set DNS servers using vimsh:
vimsh -n -e "/hostsvc/net/dns_set --dns-addresses=192.168.0.1,192.168.0.2 --dns-searchdomain=yourdomain.com"

Set DNS servers by manually creating resolv.conf:
cat > /etc/resolv.conf << EOF1

search yourdomain.com
nameserver 192.168.0.4
nameserver 192.168.0.6

EOF1

0 Comments Permalink
0

ESX Friendly Method:
Install IO:Tty -
1. Download Perl-IO-TTY from here
2. Copy to your host or execute from a shared location
3. Execute 'rpm -ivh perl-IO-Tty-1.07-1.el3.rf.i386.rpm'

Install Expect.pm -
1. Download Perl-Expect from here
2. Copy to your host or execute from a shared location
3. Execute 'rpm -ivh perl-Expect-1.21-1.el3.rf.noarch.rpm'

Pain-in-the-butt Method:
You can download these from http://sourceforge.net/projects/expectperl/

The installation itself is pretty simple. IO::Tty needs to be installed first. This installation does not add additional items to run in RAM.

Install IO:Tty -
1. Decompress file.
2. Browse to location of files.
3. Execute perl Makefile.PL
4. Execute make
5. Execute make install

Install Expect.pm -
1. Decompress file.
2. Browse to location of files.
3. Execute perl Makefile.PL
4. Execute make
5. Execute make install

0 Comments Permalink
4

The service console memory should be increased if you are running apps other than the default install. This includes management agents, backups, etc. Here is a simple command that I ran across to accomplish this. It requires a reboot to take effect. I incorporate this in my kickstart script. Don't forget to set your swap partition to be 2x the Service Console memory.

See Current Setting:
The setting shown is in bytes (MB * 1024 * 1024)
vimsh -n -e "/hostsvc/memoryinfo"
serviceConsoleReserved - Current setting
serviceConsoleReservedCfg - Setting after next reboot

Set to 800MB with vimsh:
vimsh -n -e "/hostsvc/memoryinfo 838860800"

Set by manual edit of files:
mv -f /etc/vmware/esx.conf /tmp/esx.conf.bak
sed -e 's/boot\/memSize = \"272\"/boot\/memSize = \"512\"/g' /tmp/esx.conf.bak >> /etc/vmware/esx.conf

mv -f /boot/grub/grub.conf /tmp/grub.conf.bak
sed -e 's/uppermem 277504/uppermem 523264/g' -e 's/mem=272M/mem=512M/g' /tmp/grub.conf.bak >> /boot/grub/grub.conf

If you feel like setting it to the maximum of 800 MB.

mv -f /etc/vmware/esx.conf /tmp/esx.conf.bak
sed -e 's/boot\/memSize = \"272\"/boot\/memSize = \"800\"/g' /tmp/esx.conf.bak >> /etc/vmware/esx.conf

mv -f /boot/grub/grub.conf /tmp/grub.conf.bak
sed -e 's/uppermem 277504/uppermem 818176/g' -e 's/mem=272M/mem=800M/g' /tmp/grub.conf.bak >> /boot/grub/grub.conf

4 Comments Permalink
0

VI Custom Fields

Posted by froboy Jan 7, 2008

I decided to dabble into custom fields. I have scripts to add, remove, rename and set custom fields. I also have a cool script to export your custom fields to a CSV file and vice versa.

Prerequisites:
VI 3.5 (VI API 2.5.0)
Latest VI Perl Toolkit (VMware VI Remote CLI will install this)
Text::CSV_XS (Perl module for CSVs)
Text::CSV::Simple (Perl module for CSVs)

Scripts:
addvifield.pl - Adds Custom Field to VI
cf2csv.pl - Exports Custom Fields to CSV File
csv2cf.pl - Imports CSV File to Custom Fields (Note: Custom Fields must already be created)
readdcfields.pl - Reads all Custom Fields from every VM in a datacenter
readvmfield.pl - Reads a single Custom Fields from a VM
readvmfields.pl - Reads all Custom Fields from a VM
removevifield.pl - Removes a Custom Fields from VI
renamevifield.pl - Renames a Custom Field in VI
setvmfield.pl - Assigns a value to a Custom Field in a VM
setdctools.pl - Reads VMWare Tools Version From Each VM In A Datacenter And Applies It To The Custom Field "Tools Version"

0 Comments Permalink
0

VC Licensing Spreadsheet

Posted by froboy Nov 21, 2007

I put my licensing script into a spreadsheet...

You need to populate your own hostnames and licensing server, but it will query the licensing log against those hostnames.

0 Comments Permalink
1

VC Licensing

Posted by froboy Nov 16, 2007

Do you know which servers have got a hold of your VC licenses? I had a tedious time looking through the log on VC to get an exact count. All of the check in's and out's complicated things to. So here is a script to parse the VC licensing log to see who has what.

Usage:
vclic.vbs /s:<VC License Server>

1 Comments Permalink
0

TSM - Restore VM Images

Posted by froboy Oct 5, 2007

Procedure Overview:

Restore Files
VM Registration
Restore Files:

Browse to http://<servername>:1581
Click 'Restore'
Enter username and password. Press <Enter>
Click 'View' -> 'Display active/inactive files'
Click 'Yes'
Under 'File Level' browse to the location of the guest to restore.
Place a check mark next to the latest versions of: *.vmx, *.vmxf, *.vmdk
Click Restore
VM Registration

Browse to the guest folder
Edit the .vmx file.
Remove the "-00000?" from the 'scsi0:0.fileName' parameter so that it matches the main vmdk file.
Execute: vmware-cmd -s register <path to vmx file>
Power on VM using Virtual Center.
Troubleshooting:

"The system cannot find the file specified" - This is caused by 'scsi0:0.fileName' parameter in the vmx file pointing to an incorrect vmdk file or to the *-00000?.vmdk file

"A file was not found." - Same as "The system cannot find the file specified"

0 Comments Permalink
3

List Snapshots on ESX Host

Posted by froboy Sep 28, 2007

This script will list all snapshots for guests assigned to a specific host.

3 Comments Permalink
1 2 Previous Next
Click to view froboy's profile Member since: Jun 26, 2006

A swell blog containing some of the scripts I have written for VM management.

View froboy's profile

Communities