Friday, March 14, 2008

VMware Automation Part 2

Eureka! I found it. So now I can automate the vmware-config.pl part of the installation. It turns out that VMware Server keeps a database of sorts in /etc/vmware/locations. This is created during the vmware-install.pl run. If you append "answer EULA_AGREED yes" (without the quotes) to the locations file, it will not present you with the EULA. Here is the complete code. Again, please comment.

#!/usr/bin/python
########################################################################
#vmwareInstall.py
#
#This will automatically complete the vmware-install.pl for a VMware
# Server 1.0.4. After that runs, the script hand over the
# vmware-config.pl to you. At some point, I'll rework this to
# complete the other half of it as well
#
#Author: Mike Dunphy <mdunphy AT spu DOT edu>
#
# License:
# This Script is hereby placed in the public domain. Anyone
# is encouraged to use or modify it, and distribute modified or
# unmodified copies.
#
# Disclaimer:
# Mike Dunphy takes no responsibility for and will not support your
# use of this script.
########################################################################
import os
import pexpect
import sys

user = 'your username goes here'
EULA = "answer EULA_AGREED yes"
URL = raw_input("Please enter URL for VMware download: ")
os.system('wget -P /home/%s/ %s' % (user,URL)
os.system('tar zxf VMware-server*')

os.chdir('/home/%s/vmware-server-distrib' % user)
p = pexpect.spawn('/home/%s/vmware-server-distrib/vmware-install.pl' % user)
p.expect('/bin]')
p.sendline()
p.expect('/etc]')
p.sendline()
p.expect('/init.d]')
p.sendline()
p.expect('/sbin]')
p.sendline()
p.expect('/vmware]')
p.sendline()
p.expect('yes]')
p.sendline()
p.expect('/man]')
p.sendline()
p.expect('/vmware]')
p.sendline()
p.expect('yes]')
p.sendline()
p.expect('yes]')
p.sendline('yes')
p.close(force=True)

os.system('echo %s >> /etc/vmware/locations' % EULA)
p2 = pexpect.spawn('/usr/bin/vmware-config.pl')
p2.expect('/icons]')
p2.sendline()
p2.expect('/applications]')
p2.sendline()
p2.expect('/pixmaps]')
p2.sendline()
p2.expect('yes]')
p2.sendline()
p2.expect('/include]')
p2.sendline()
p2.expect('yes]')
p2.sendline()
p2.expect('yes]')
p2.sendline()
p2.expect('yes]')
p2.sendline()
p2.expect('no]')
p2.sendline()
p2.expect('yes]')
p2.sendline()
p2.expect('yes]')
p2.sendline()
p2.expect('no]')
p2.sendline()
p2.expect('902]')
p2.sendline()
p2.expect('Machines]')
p2.sendline('/VMs')
p2.expect('yes]')
p2.sendline()
p2.expect('cancel:')
p2.sendline('Enter your serial')
sys.exit(0)

No comments: