p. 1
vmware server and vmware player the way forward for virtualization by dennis zimmer a chapter 15 aaaaaaaaaaaaaaaa like vmware player vmware server offers many possibilities that are just a easily recognized at first glance this chapter will take you through a not a number of advanced techniques which may be of great use to you aaaa 15.1 programming interfaces a a through programming interfaces vmware server offers a great variety of a ways to use the product there are three different apis advanced proa gramming interface vmcom vmperl and vmware server c on linux a they are vmperl and vmware server c you can find more information at the a following links a a · vmperl and vmcom api a http www.vmware.com/support/developer a · vmware server c api a http www.vmware.com/pdf/server_c_api_programming.pdf a a you can save a lot of time and work by using scripts for recurring or very a complex tasks this includes for example the creation of multiple virtual a machines or regular backups including a subsequent copy process for ara chiving a vmware server for advanced users three apis available for developers recurring or complex tasks can be automated 221
[close]
p. 2
chapter 15 vmware server for advanced users vmware server provides some commands a the vmware scripting api com perl can be used with every vmware as a server product i will discuss it in detail in the following section a to a use the vmware scripting api it must be installed on the system which will be running the scripts a perl interpreter is already available but evea rything else must be installed separately for example the visual basic ide a integrated development environment a a vmware server already provides some scripts which use the vmware scripta ing a api even the command line commands which are explained later such as vmware-cmd are implemented using this method to highlight a this here is an excerpt from the vmware-cmd script which shows the invoa cation of vmware-cmd l a a sub do_list a my $vms connect_server_local connection to vmserver a my @list $vms registered_vm_names retrieval of vms a if list a my err $errstr $vms get_last_error a if err 0 a print stderr vmcontrol error $err $errstr n a cleanup object s resources a undef $vms a exit err a a a while shift @list a print n output vms a a cleanup object s resources undef $vms a a a in the first line you can see the name of the sub routine which is used to a display a list of all virtual machines registered on a vmware server and to a print them out the second line creates a connection to the vmware server a which is documented in the remark appended with the double slash a a the third line creates an array with reference to the registered virtual maa chines of the connected vmware server within the first if statement the a @list array and the referenced function are checked and if an error occurs a 222
[close]
p. 3
chapter 15 vmware server for advanced users a which is caught by the second if statement then the whole routine exits a with that error number if everything is functioning correctly the while a prints out all virtual machines within the @list array loop a why a am i showing you a script provided by vmware quite simply it is a very a good basis on which to write your own scripts or to extend existing ones with new functions a a when extending the existing vmware scripts be aware that they may be a overwritten with a new version when you upgrade vmware server you can a also download a sample program for visual basic vmcom from the a vmware web site which provides a small administration program minia mui for vmware server a a according to vmware this interface can either be used for automation of a management tasks for the virtual machines or for small applications a which can be run interactively by the user furthermore this interface can a also a even be used to start up and shut down virtual machines as well as for a registering vms on vmware server some of these actions can be run locally a while others can also be run remotely via the vmware server depending a on how they are programmed a figure 15.1 shows the connection structure via both the vmcom and the a vmperl apis the client system determines what connections are possible aaaaaaaaaaaaaa figure 15.1 connection via vmcom or vmperl api a a a customizing vmware scripts can save time 223
[close]
p. 4
chapter 15 vmware server for advanced users the com api can be accessed by many programming languages vmware provides useful documentation for developers virtualcenter offers an additional sdk vmware server provides an enhanced cli a both vmware server with different host operating systems and vmware a server can be accessed via both apis vmcom and vmperl although esx a a windows system supports and can make use of the vmcom api only a a vmware scripting api can be used from perl and also from the well the a known microsoft com interface component object model therefore it is a possible to use the vmware api with all programming languages which a support com these include jscript vbscript and visual basic you can a sample programs in the vmware scripting api installation files and in find a manuals the a a documentation of the programming interfaces for vmware is generally a good and for whatever you are trying to do perhaps someone else in very a community has already had a similar requirement and has created a the a program which you can use if you go and find it for this i can only recoma mend visiting the community forum there you can find a lot of fully proa grammed examples and can receive quick answers to your questions a a you work with virtualcenter the virtual infrastructure sdk can also be if a used this allows centralized access to multiple vmware servers aaaa 15.2 command line a a besides the programming interface for developers it is also possible to a the command line commands with these the required actions can be use a easily with batch or script files for example this allows one to shut run a down and back up all running virtual machines or to shut down the host a system in such a way that the virtual machines don t crash a in a the following section i will address some important command line instructions that you need to be aware of aaaaaaaa 224
[close]
p. 5
chapter 15 vmware server for advanced users a 15.2.1 vmware-cmd a a is by far the most powerful command line program which is provided this a vmware server it can be used to perform actions with the virtual mawith a chines it can also be used with the l parameter on windows vmwarea cmd.bat l to create a list of all virtual machines registered on the host a system a the structure of this list containing the path to the .vmx configuration a file is ideal for use in other scripts for example to start or stop virtual a machines as the following example shows a a example for stopping all virtual machines on linux a a for vm in vmware-cmd l do a vmware-cmd $vm stop trysoft a done a the first line shows the begin of a for loop which executes the command a vmware-cmd l it will run until all given output lines are processed a a the second line is re-running the vmware-cmd command with the current a virtual machine shown within the variable $vm and the arguments stop a stops the vm and trysoft first try to stop through vmware tools and if a that doesn t work kill the vm the hard way a a the last line ends the script note that a for loop is always opened with a for and what has to be executed must be between do and done it a won t execute if you don t close the loop properly a a the general syntax for this command is as follows a a vm based a vmware-cmd
[close]
p. 6
chapter 15 vmware server for advanced users a table 15.1 provides an overview of the cmd options a table 15.1 vmware-cmd options a a option description a -h
[close]
p. 7
chapter 15 vmware server for advanced users table 15.3 vmware-cmd vm options continued a a option a getconfig
[close]
p. 8
chapter 15 vmware server for advanced users vmware-vdiskmanager is the command to manage virtual disk files a table 15.4 provides an overview of the available power mode options a table 15.4 vmware-cmd power mode options a a option settings a soft stop clean shutdown using vmware tools and scripts a start starts the vm and tries to run the start or resume scripts a trysoft stop tries to shut down soft if there is an error the vm switches a off a start tries to start soft changes to hard if there is an error a hard stop power removed for the vm like pulling out the power plug a start starts the virtual machine without scripts a a a 15.2.2 vmware-vdiskmanager a a the name suggests vmware-vdiskmanager is a program for hard disk as a management or more exactly the management of hard disk files with this a program virtual hard disks can be created enlarged or defragged from the a command line a a existing virtual hard disks need to be offline when they are altered this a means that the vm must be switched off and not suspended by the way a virtual drives connected using vmware-mount can also be used as always a when working at the command line filenames with spaces must be given a in quotes to avoid misinterpretation a a example creating an 8 gb ide hard disk a the following script line can be used to create an 8 gb die hard disk opa tion -c a a vmware-vdiskmanager.exe -c -s 8gb -a ide -t 0 hard-disk-file.vmdk a a the option -s let s you configure the hard disk size in sectors kb mb or gb a and the valid values range between 100.0 mb and 950.0 gb the option -a a is used to add the adapter type and the option -t the type of hard disk as a can be seen in table 15.7 aaaa 228
[close]
p. 9
chapter 15 vmware server for advanced users a general syntax of the command is as follows the a vmware-vdiskmanager.exe
[close]
p. 10
chapter 15 vmware server for advanced users free gui for vmwarevdiskmanager virtual disk factory with extended functionality in development a options for configuration of various types of hard disks for the above the a option t are listed in table 15.7 a table 15.7 vmware-diskmanager hard disk type a a option description a0 monolithic dynamically growing hard disk a 1 dynamically growing hard disk divided into 2 gb pieces a 2 monolithic hard disk entire capacity used directly a 3 hard disk divided into 2 gb portions entire capacity used directly a a if a you find that using the command line is too cumbersome but you would still a like to use the functionality of vmware-diskmanager i can recommend the a windows tool by robert petruska and ulli hankeln vmware diskmanager gui it can be found at http petruska.stardock.net/software a vmware a a figure 15.2 shows the graphical interface of vmware-diskmanager aaaaaaaaaaaaaaa figure 15.2 graphical interface of vmware-vdiskmanager a a figure 15.2 in addition an extended version called virtual disk factory a currently in beta with expanded functionality is being developed this a program even allows hard disks to be converted however beware that a when using hard disk files which run on the guest operating system the a alteration of the hard disk type can automatically lead to a blue screen a a 230
[close]
p. 11
chapter 15 vmware server for advanced users a since the operating system no longer correctly recognizes the hard disk a same problem occurs with p2v migration described later in this chapthe a and therefore needs the appropriate tools to remedy it ter a figure 15.3 shows the interface of the virtual disk factory with the added a functionality aaaaaaaaaaaaaaaa figure 15.3 virtual disk factory a a a 15.2.3 vmware-mount a a as a you have already read in relation to vmware-vdiskmanager there is a program called the vmware diskmount utility this is automatically ina stalled together with vmware server unless you have disabled the compoa nent during the installation alternatively you can find a current version a of a the program at http www.vmware.com/download/ws a the a vmware diskmount utility allows to connect vm hard disk files to a desired system as local drives windows or mountpoints linux this means a you a can read or write files on the hard disk without having to start a virtual machine to be able to use vmware diskmount the hard disk file must not a be a in use meaning that a virtual machine must not be accessing it a a a command for mounting virtual disk partitions 231
[close]
p. 12
chapter 15 vmware server for advanced users a example associating drive x to the first partition of a vmdk file a vmware-mount x e vms vm1 vm1-hdd1.vmdk /v:1 a this a line assigns drive x to the file vm1-hdd1.vmdk on drive e:vms/vm1 the option /v is used to identify the partition number of the virtual hard disk a a the a general syntax of this command on windows is as follows a vmware-mount
[close]
p. 13
chapter 15 vmware server for advanced users a perl script must be stopped with ctrl+c to remove the connection to the a mountpoint the a a will have already guessed a graphical interface for windows exists you a created by robert petruska which simplifies the use of the diskmount utila it is shown in figure 15.4 ity aaaaaaaaaaaaaaaaaa figure 15.4 gui for the vmware diskmount utility a figure 15.4 as vmware diskmount makes the hard disk file available as a a local drive you can then access the file system of the .vmdk file the a file a system is emulated by the operating system in the virtual machine and cannot be understood by all systems therefore you cannot access ext3 or a reiserfs from windows without tools similarly on linux systems without a tools you can read windows ntfs partitions but not write to them a a a 15.2.4 vmware-support.vbs a a the a vmware-support script gathers information about the local vmware server os information and program information this script can be a found within the vmware server program directory a a a free gui tool available vmware support uses this support file to help 233
[close]
p. 14
chapter 15 vmware server for advanced users some network sniffing may help too a after the script has been executed it displays the path to a file with the a name vmsupport-date compress and send this file to vmware in order to a get support with the information in this file the official vmware support a may be able to find errors in your configuration or software and thereby a help to resolve your problems a the vmware-support.vbs only runs on microsoft windows whereas on linux a vmware-support is found in the /usr/bin/vm-support directory a a note a if a windows scripting host is deactivated you must first activate it in the registry a a a to a activate it you must change the following registry key with the regedit program a a hkey_local_machine software microsoft windows script host set a settings enabled to 1 a a a 15.2.5 vnetsniffer a a the vnetsniffer program can be very useful in order to find problems with a virtual machines by analyzing traffic on the network it is certainly not as a powerful as other tools such as ethereal but the information displayed a often offers enough details to identify the problem a a figure 15.5 you can see a vnetsniffer example allowing all packets to in a read on the vmnet0 bridge network be aaaaaaaaaaa 234
[close]
p. 15
chapter 15 vmware server for advanced users aaaaaaaaaaaaaa figure 15.5 vnetsniffer output a a first line is the execution of the command the second line shows the the a source and destination ip address the third line shows the outgoing arp a request packet including the mac and ip address of the source and sent a the ip address of the destination with all zeros in the mac address field to a fifth line shows the arp reply including the mac address of the previthe a destination all following lines show the exchange of data between ous a two nodes over tcp the a a program is excellent if you have connection problems and want to this a identify whether they are coming from the network or from one of your a nodes you can use vnetsniffer if you want to find out if packets are reacha the virtual network for example if you are running an ftp server on a ing a on vmnet4 you can try to connect to it while running vnetsniffer /e vm a vmnet4 analysis of the output can determine whether the packets are aca tually reaching the vm if not you are probably dealing with a networking a problem a a the general syntax for using vnetsniffer is as follows a vnetsniffer e vmnet a a option /e shows extended information the vmware network name the a must be provided as the network to be monitored after a basic installaa three virtual networks exist vmnet0 bridge vmnet1 host-only tion a vmnet8 nat and a identify the source of connection problems 235
[close]