Skip to content.

TalkBMC

Sections
You are here: Home » Blog Archive » Ron Michael » Open for Mainframe » How VMLMAT could handle a Re-IPaddress Project

How VMLMAT could handle a Re-IPaddress Project How VMLMAT could handle a Re-IPaddress Project

Document Actions
Take some code and do more. In this case, create a feature called RE-IP
Steve Carl in his blog mentioned how VMLMAT could RE-IP z/VM virtual machines running z/Linux. Something at one point I needed it to do for us at BMC.

VMLMAT's main design was to manage z/VM virtual machines by allowing the user to provision a z/Linux image onto their machine. It does this by using a prior backup of some z/Linux image and then just restoring this image. VMLMAT will change the personality of the restore to match the requirements of the new machine. Specifically, VMLAT changes the Hostname and IPaddress after the backup tarfile has been restored.
However, it was realized that this natural cloning processs whereby the hostname and IPaddress is modified to the new machine  could be used to just Re-IP a machine without the need to do an actual backup and restore process. I will explain this process to you.

First, lets look at a quick logic review of a typical provisioning using backup and restore.

A restore of a backup image must be performed in order to provision. In this case and for clarity, we will provision "NEWLNX" from a backup of "OLDLNX" 
To see how this process works for a typical restore request:

Lets look at an excerpt from a Bourne shell script called CHANGE which contains lines of code to edit the  z/Linux  configuration once it has been untarred onto the new VM:

# Redhat support

if [  -e "sysconfig/network-scripts/ifcfg-eth0" ]; then                                          
sed -f /tmp/change.input sysconfig/network-scripts/ifcfg-eth0 > /tmp/work
cp /tmp/work sysconfig/network-scripts/ifcfg-eth0 
fi 

As you can see it uses the SED  command to edit and requires the use of a change.input file which was built by a php script called BKGEN.
This BKGEN script runs on the copy server via crontab every minute to check for a request. If one is found, then it will process it and build the change input file, call BKCLONE script which will call the CHANGE script.

Excerpt of BKGEN code:
#lets setup the change file for changing the hostname and IP address
$prfile = "/tmp/change.input";
$fh = fopen($prfile, 'w');
$nl = "\n";
$strdata =  "/" . $ohost . "/s/" . $ohost . "/" . $hostname . "/g" . $nl;
fwrite($fh, $strdata);
$strdata =  "/" . $oip . "/s/" . $oip . "/" . $hip . "/g" . $nl;
fwrite($fh, $strdata);
fclose($fh);

This change file contains the subsitution strings needed by SED. Inorder to obtain these variables to build the change input file, an earlier request was filled out by the user from the webserver and this request file was placed on the copyserver's request queue. The old host name OHOST and old ipaddress OIP variable was stored when the backup was made. In this case, the backup "OLDLNX" html form file contains the following key items:

<input type="hidden" name="ohost" value="OLDLNX">
<input type="hidden" name="oip" value="172.30.31.1">
 ...
<p><a name="#comments"></a><a name="#bottom"></a><form method="post" action="submit.php" name="form" >

The web server routine SUBMIT.PHP takes this information and creates a request record on the copy server for the restore, and later, the copy server php script BKGEN will process this request.
The SUBMIT.PHP script does  a lookup of the user requested hostname "LNXNEW"  from DNS and put the IPaddress  into the request record as well. This address becomes the host ip HIP variable needed by BKGEN to build the change.input file.

To allow RE-IP of a VM, I decided to make a few changes to the code base.
First, the request could be coded so that BKGEN knew that this was just a RE-IP. In other words,  don't do an actual backup/restore process, and just run the CHANGE script.
I did this by creating a new parmfile variable called REIP to signal BKGEN and BKCLONE scripts.
I edited BKGEN to also build into the change file a few more substitution strings so that I could change other networking values like netmask, gateway etc. The code would only do this if I was the user submitting the request (note this following edit is not in the current V1R1M0 of VMLMAT).

BKGEN replacement code excerpt: 

$nl = "\n";
 if ( $reipid != strtoupper($userid)) { 
$strdata =  "/" . $ohost . "/s/" . $ohost . "/" . $hostname . "/g" . $nl;
fwrite($fh, $strdata);
$strdata =  "/" . $oip . "/s/" . $oip . "/" . $hip . "/g" . $nl;
fwrite($fh, $strdata);
} else {
$strdata =  "/" . $ohost . "/s/" . $ohost . "/" . $hostname . "/g" . $nl;
fwrite($fh, $strdata);
$strdata =  "/" . $oip . "/s/" . $oip . "/" . $hip . "/g" . $nl;
fwrite($fh, $strdata);
# some hard coded requirements for this specific re-ip needed by us.
$strdata =  "/172.30.0.0/s/172.30.0.0/172.30.164.0/g" . $nl;
fwrite($fh, $strdata);
$strdata =  "/172.30.255.255/s/172.30.255.255/172.30.167.255/g" . $nl;
fwrite($fh, $strdata);
$strdata =  "/255.255.0.0/s/255.255.0.0/255.255.252.0/g" . $nl;
fwrite($fh, $strdata);
$strdata =  "/172.30.0.253/s/172.30.0.253/172.30.167.253/g" . $nl;
fwrite($fh, $strdata);
}

Here I  have a variable called Re-IP id, REIPID, and if that matched the userid on the request record then perform the additional actions of modifying netmask etc if needed.
In our case, we did need to change these values. So in the above example, if I submitted the request, the code didn't do the normal processing of the IF statement, but instead, did the ELSE actions of additional substitutions for the SED commands and hardwire in the new netmask and other values.

VMLMAT as released in V1R1M0 does support RE-IP and does have the support code defined.

The procedure is to set this  REIPID value in parmfile to yourself.

PARMFILE:
# reip is the switch that tells vmlmat that you want the sysadmin to have the privilege
# to re-ip a machine by submitting a restore request from a standard image but only
# perform the change function inorder to re-ip the virtual machine. No restore will be done.
# this switch must say yes and the reipid must specify an authorized userid to perform this
# function.
# default no
- reip no
- reipid dummy

In this case, you change REIP to yes and REIPID to your own userid.
Then add the above code to BKGEN if you need to change netmask or other networking values. Otherwise VMLMAT as provided in V1R1M0 will just change Hostname and IPaddress.


When you submit a request to do a user backup the VM, say LNXNEW, it will only create the HTML form file and not do an actual backup. The important thing is it will save the OHOST and OIP values. Then you change your DNS entry for the VM to your new IPaddress. Next , when you restore LNXNEW (html form file) to the same hostname, it will not do the actual restore but only run the CHANGE script using OHOST and OIP and the current HOSTNAME and the new HIP value. The CHANGE script will do the rest for you. So the process can be as simple as requesting a few backups and restores by the system admin who modified the parmfile for RE-IP.

Enjoy the feature if you ever need it. It sure saved me time when I had to do over a hundred z/Linux machines!

VMLMAT is found here: http://vmlmat.sourceforge.net

 


_____
tags:
Tuesday, October 28, 2008  |  Permalink |  Comments (0)
 

Powered by Plone

This site conforms to the following standards: