Sunday, July 19, 2009

VMware Perl toolkit tutorial (3) - variable

1. Scalar variables
Scalar variables hold both strings and numbers. Strings and numbers are inter-changable, but the variables should not start with a number and the variable $_ is special. For example:
$variable1 = 10; or
$variable2 = 'test';

The operations and assignment are the same as C. I found out this on the website, which can help us to understand the operation.
Perl uses all the usual C arithmetic operators:

$a = 1 + 2; # Add 1 and 2 and store in $a
$a = 3 - 4; # Subtract 4 from 3 and store in $a
$a = 5 * 6; # Multiply 5 and 6
$a = 7 / 8; # Divide 7 by 8 to give 0.875
$a = 9 ** 10; # Nine to the power of 10
$a = 5 % 2; # Remainder of 5 divided by 2
++$a; # Increment $a and then return it
$a++; # Return $a and then increment it
--$a; # Decrement $a and then return it
$a--; # Return $a and then decrement it

and for strings Perl has the following among others:

$a = $b . $c; # Concatenate $b and $c
$a = $b x $c; # $b repeated $c times

To assign values Perl includes

$a = $b; # Assign $b to $a
$a += $b; # Add $b to $a
$a -= $b; # Subtract $b from $a
$a .= $b; # Append $b onto $a

2. Array Variable
Array variables are prefixed by an @ symbol. The statement
@variable = ("number1", "number2", "number3");
assigns a three element list to the array variable @variable. To access each item,
$variable[0] will returns number1. Notice that the @ has changed to a $.

Array assignment functions are put and pop. Here are some examples:
push(@array1, "item3", "item4");
push(@array1, ("item3", "item4"));
push(@array1, @array2);
The push function returns the length of the new list.

To remove the last item from a list and return it use the pop function.
$item1 = pop(@array1);
Now $item1 is the last item in @array1 and the @array1 has all the items except item1.
We can also assign an array to a scalar variable.
$item1 = @array1;
assigns the length of @array1

$item1 = "@array1";
turns the list into a string with a space between each element.

Arrays can also be used to make multiple assignments to scalar variables:
($a, $b) = ($c, $d); # Same as $a=$c; $b=$d;
($a, $b) = @food; # $a and $b are the first two
# items of @food.
($a, @somefood) = @food; # $a is the first item of @food
# @somefood is a list of the
# others.

VMware Perl toolkit tutorial (2) - basic programing

With VMware Perl installed, we are ready to write VMware perl script. The file extension for Perl scripts is .pl. There are a few elements every Perl script must contain in order to function.
1. The first line of every VMware Perl script is a commented line directed toward the Perl interpreter.
#!/usr/bin/perl
2. Comments can be inserted into a program with the # symbol, and anything from the # to the end of the line is ignored (with the exception of the first line). The only way to stretch comments over several lines is to use a # on each line.

3. Everything else is a Perl statement which must end with a semicolon, like the last line above.

Now let me give you a example.

#!/usr/local/bin/perl
#
# First VMware Perl
#
print 'Hello world.';


4. When the file is executed Perl first compiles it and then executes that compiled version. So after a short pause for compilation the program should run quite quickly. In order to run the Perl program, after you install the Perl,

A:) you can run the program by: perl program or ./program

B:) You can always run the program with warnings using the command by perl -w program. This will display warnings and other helpful messages before it tries to execute the program.

C:) To run the program with a debugger use the command by perl -d progname

Sunday, July 12, 2009

VMware Perl toolkit tutorial (1) installation

Well, when I first study the vmware perl, it was called VI Perl Toolkit. After the vSphere 4 was released, the name has changed to vSphere SDK for Perl 4.0. When I went through all the installation steps, I found there was no much difference from the older version to the new version.
VMware Perl is just like other perl version, except it has VMware specific components. So don't think it too complicate. Compared to other perl, the grammar, the infrastructure and the standard library should be the same.
The vmware perl toolkit can be installed on a standalone linux box, or as a virtual machine (VIMA). I do not like VIMA since it does not give me the flexibility. I like to install the vmware perl toolkit on standalone linux box, since I can bundle other software with the vmware perl toolkit together.
So, here I will introduce how to install the vmware perl toolkit on linux, or I should say vSphere SDK perl 4.0 in the new release.
1. Supported Linux Platforms
Red Hat Enterprise Linux (RHEL) 5.2 (64 bit)
Red Hat Enterprise Linux (RHEL) 5.2 (32 bit)
SUSE Enterprise Server 10 SP1 32 bit
Ubuntu 8.04 32 bit

2. Preparation:
Download the vSphere SDK for Perl
Check Connectivity, make sure that the connection from your development system
to the target ESX/ESXi or vCenter Server system is working.

3. Installation:
(install OpenSSL library if the linux does not have)
To install the vSphere SDK for Perl
3.1 Untar the vSphere SDK for Perl binary
3.2 Launch the installer: //vmware-install.pl
3.3 When prompted, read the license agreement.
3.4 Specify an installation directory, or press Enter to accept the default, which is /usr/bin.
When the installation process completes: A success message appears. The installer lists different version numbers for required modules. The prompt returns to the shell prompt.
The defaults utility applications and samples sub directories are in the following locations:
Utility applications – /usr/lib/vmware-vcli/apps
Sample scripts – /usr/share/doc/vmware-vcli/samples

4. Uninstall the vSphere SDK for Perl on Linux
In order to uninstall the vSphere SDK for Perl, run the vmware-uninstall-vSphereCLI.pl script:
//bin/vmware-uninstall-vSphereCLI.pl

Saturday, July 11, 2009

VMware Converter Usage

VMware converter is free from VMware (I think not the enterprise version). In the new released vSphere 4, it is bundled with vSphere 4. The VMware converter automate and simplify physical to virtual machine conversions as well as conversions between virtual machine formats. Here is an chart maybe useful.

I use the VMware converter in the following way:
1. physical to virtual (P2V)
When I want to convert a physical machine to a virtual machine, I need to install the converter on the physical box first, and I also need vCenter support.
2. virtual to virtual (V2V different virtual machine format)
some of my friends working on VMware workstation, but I usually work on ESX. When I need their virtual machines, I will use converter to convert from workstation virtual machine to the ESX virtual machine.
3. virtual to virtual (V2V same format, different setting)
I just do not understand why VMware does not allow me to change the virtual machine hard drive size in ESX after I have created a virtual machine. So I have to use VMware Converter to shrink to hard drive size or expand it.

VMware ESX Advance Features

I have to say, I still spend most of my time on ESX3.5 and ESX3.5i, since my old machines do not support the new released ESX4. Usually I use those ESX hosts as a standalone box to do my development. The features I used the most are snapshot, import and export OVF images, create template and clone machines. Even my ESX boxes do not have SAN, I still use vCenter to manage ESX hosts, since the template and clone are only available through vCenter. My structure actually looks like that:


All the standalone machines are managed by my vCenter, and each of those ESX host is operated by its own. The Virtual Machines can transferred from one host to another host, but we have to power off the virtual machines first.

Now I have a chance to access my friend's data center, then I can experience the new features which are listed on the VMware website.

1. VMotion:
I think all other features are based on this one more or less. VMotion enables the migration of running virtual machines from one physical server to another without
service interruption. It is obvious that my previous setting can migrate from one host to another ESX host, but the service has to be interrupted. It allows virtual
machines to move from a heavily loaded server to a lightly loaded one. The effect is a more efficient assignment of resources.


2. VMware DRS
Taking the VMotion capability one step further by adding an intelligent scheduler, VMware DRS enables the system administrator to set resource assignment policies that
reflect business needs and let VMware DRS do the calculation and automatically handle the detailed physical resource assignments. Now I am looking for the API to find out how to define the policy. If I know the API, I can define my own policy.


3. VMware HA
I probably mentioned this in previous post. VMware HA offers a simple and low cost high availability alternative to application clustering. It enables quick restart
of virtual machines on a different physical server within a Cluster automatically should the hosting server fail. The mechanism behind vmware HA, I think is: The agent keeps testing the heart beat of the machines, and make a clone of this machine periodically, but did not put it online. When the heart beat is lost, then powers up the latest cloned virtual machine, and powers off the original one.

VMware vSphere Released

ESX4, ESX4i and vSphere have been released recently to replace ESX3.5 and ESX3.5i and vCenter. The previous ESX35 kernel is similar to Linux AS4 kernel. The new ESX4 is similar to Linux AS5 kernel. I found the new virtual switches are from 1G to 10G.

The upgrade are fairly easy comparing to the upgrade from ESX2 to ESX3. However, there are still some compatible issues. For example, when I tried to use vSphere to manage the ESX35 host, some functions did not work properly. Also, I wrote some VI perl script codes in ESX35 environment, but they do not work properly in new setting.

The new ESX4 release focuses on the 64bit systems. So when I upgrade from ESX35 to ESX4 on my old machines, they are all failed.
I started testing the new release few days ago. I will some comments when I finish the testing.

Monday, March 30, 2009

ESX3i installation

ESX3i will be the main product of VMware in the future. It is high performance, and it is the building block of Virtual Infrastructure 3.Once you have ESX 3i, you can install it on any server that is supported by VMware ESX Server 3i. The installation of ESX3i is very easy.

1. burn an ISO file onto a bootable CD first.

After the black screen, it moved to the yellow screen.

Then, it comes to the welcome screen.

Pressed Enter to Install and pressed F11 to accept the license agreement.

Select the hard drive and Enter.

Next, press F11.

After the installation, Pressed Enter and rebooted the system, and manual eject the CD. Once rebooted, comes to this screen:

Then the installation process is done. now we should configure the network setting.