juin 29 2011

HPVM disk physical/virtual mapping script

Tag: Scripts,UnixUggla @ 17 h 02 min

This is a short script to create a physical (host)/virtual (guest) map.
This is a basic script written quickly, that was used to simplify data migration operations. So improvements welcomed.

    Requirements :

  • script must be run from host. (not guest)
  • ssh must be allowed using keys (no passwd) to all guests.
  • hpvmstatus command must be available from path.


use strict;
use warnings;
use Data::Dumper;

my @hpvmstatus=`hpvmstatus`;
my @vms;
my $vm;

my %vm_data;

foreach(@hpvmstatus) {
        ($vm)=$_ =~ /^(.+)\s+[0-9]+\sHPUX\s+On/;
        if (defined($vm)){
                $vm =~ s/\s+//g;
                push (@vms,$vm);

foreach $vm (@vms){
        my @hpvmstatus_vm=`hpvmstatus -P $vm`;

                #Device  Adaptor    Bus Dev Ftn Tgt Lun Storage   Device
                #======= ========== === === === === === ========= =========================
                #disk    avio_stor    0   2   0   0   0 disk      /dev/rdisk/disk17

                (my $ftn,my $tgt,my $lun,my $disk)=$_ =~ /^disk\s+avio_stor\s+\d+\s+\d+\s+(\d+)\s+(\d+)\s+(\d+)\s+disk\s+(.+)$/;

                if (defined($ftn)){

                #Convert tgt to the good legacy device
                my $tgtconv=sprintf("%02X",$tgt);
                my $tgtconv_part1;
                my $tgtconv_part2;



                $vm_data{$vm}->{$disk}->{"legacy"}="c\\dt".$tgtconv_part2."d".$tgtconv_part1; # Don't know how the instance number is defined (cX) so use a more gereric regexp

foreach $vm (@vms){
        my @ioscan=`ssh -q -o stricthostkeychecking=no -o batchmode=yes root\@$vm \"ioscan -m dsf\"`;

                my $regex=$vm_data{$vm}->{$_}->{"legacy"}."\$";
                my @vdisk=grep(/$regex/,@ioscan);
                my $vdisk_str=join(",",@vdisk);

# Debuging purpose
#print Dumper(\%vm_data);

foreach $vm (@vms){