From 045c7ba250baf837c8e703fb784ad4dc45ccc38f Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Mon, 13 Jun 2011 17:30:48 +0000 Subject: [PATCH] -Have rinv -t attempt to resync vm.storage/vm.cfgstore in xCAT table in VMware case git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@9799 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/esx.pm | 58 ++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/esx.pm b/xCAT-server/lib/xcat/plugins/esx.pm index 556b23880..dc7581cf1 100644 --- a/xCAT-server/lib/xcat/plugins/esx.pm +++ b/xCAT-server/lib/xcat/plugins/esx.pm @@ -543,7 +543,7 @@ sub do_cmd { } elsif ($command eq 'rsetboot') { generic_vm_operation(['config.name','runtime.host'],\&setboot,@exargs); } elsif ($command eq 'rinv') { - generic_vm_operation(['config.name','config','runtime.host'],\&inv,@exargs); + generic_vm_operation(['config.name','config','runtime.host','layoutEx'],\&inv,@exargs); } elsif ($command eq 'rmhypervisor') { generic_hyp_operation(\&rmhypervisor,@exargs); } elsif ($command eq 'rshutdown') { @@ -618,17 +618,18 @@ sub inv { xCAT::SvrUtils::sendmsg("CPUs: $cpuCount", $output_handler,$node); my $memory = $vmview->config->hardware->memoryMB; xCAT::SvrUtils::sendmsg("Memory: $memory MB", $output_handler,$node); + my %updatehash = ( cpus => $cpuCount, memory=>$memory); - if($tableUpdate){ - my $vm=xCAT::Table->new('vm',-create=>1); - $vm->setNodeAttribs($node,{cpus=>$cpuCount, memory=>$memory}); - } my $devices = $vmview->config->hardware->device; my $label; my $size; my $fileName; my $device; + if ($tableUpdate and $hyp) { + validate_datastore_prereqs([$node],$hyp); #need datastoremaps to verify names... + } + my %vmstorageurls; foreach $device (@$devices) { $label = $device->deviceInfo->label; @@ -645,10 +646,46 @@ sub inv { } } }); + #if ($tableUpdate) { + # $fileName =~ /\[([^\]]+)\]/; + # $vmstorageurls{$hyphash{$hyp}->{datastoreurlmap}->{$1}}=1; + #} } elsif ($label =~ /Network/) { xCAT::SvrUtils::sendmsg("$label: ".$device->macAddress, $output_handler,$node); } } + if ($tableUpdate) { + my $cfgdatastore; + foreach (@{$vmview->layoutEx->file}) { + if ($_->type eq 'config') { + $_->name =~ /\[([^\]]+)\]/; + $cfgdatastore = $hyphash{$hyp}->{datastoreurlmap}->{$1}; + last; + } + } + my $cfgkey; + if ($tablecfg{vm}->{$node}->[0]->{cfgstore}) { #check the config file explicitly, ignore the rest + $cfgkey='cfgstore'; + } elsif ($tablecfg{vm}->{$node}->[0]->{storage}) { #check the config file explicitly, ignore the rest + $cfgkey='storage'; + } + $tablecfg{vm}->{$node}->[0]->{$cfgkey} =~ m!nfs://([^/]+)/!; + my $tablecfgserver =$1; + my $cfgserver = inet_aton($tablecfgserver); + if ($cfgserver) { + $cfgserver = inet_ntoa($cfgserver); #get the IP address (TODO: really need to wrap getaddrinfo this handily... + my $cfgurl = $tablecfg{vm}->{$node}->[0]->{$cfgkey}; + $cfgurl =~ s/$tablecfgserver/$cfgserver/; + if ($cfgurl ne $cfgdatastore) { + $updatehash{$cfgkey} = $cfgdatastore; + } + } + } + if($tableUpdate){ + my $vm=xCAT::Table->new('vm',-create=>1); + $vm->setNodeAttribs($node,\%updatehash); + } + } @@ -3490,11 +3527,13 @@ sub refreshclusterdatastoremap { # xCAT::SvrUtils::sendmsg([1,"Unable to resolve VMware specified host '".$dsv->info->nas->remoteHost."' to an address, problems may occur"], $output_handler); # } $clusterhash{$cluster}->{datastoremap}->{"nfs://".$mnthost.$dsv->info->nas->remotePath}=$dsv->info->name; + $clusterhash{$cluster}->{datastoreurlmap}->{$dsv->info->name} = "nfs://".$mnthost.$dsv->info->nas->remotePath; #save off a suitable URL if needed $clusterhash{$cluster}->{datastorerefmap}->{"nfs://".$mnthost.$dsv->info->nas->remotePath}=$_; } #TODO: care about SMB }elsif(defined $dsv->info->{vmfs}){ my $name = $dsv->info->vmfs->name; $clusterhash{$cluster}->{datastoremap}->{"vmfs://".$name} = $dsv->info->name; + $clusterhash{$cluster}->{datastoreurlmap}->{$dsv->info->name} = "vmfs://".$name; $clusterhash{$cluster}->{datasotrerefmap}->{"vmfs://".$name} = $_; } } @@ -3530,11 +3569,13 @@ sub validate_datastore_prereqs { xCAT::SvrUtils::sendmsg([1,"Unable to resolve VMware specified host '".$dsv->info->nas->remoteHost."' to an address, problems may occur"], $output_handler); } $hyphash{$hyp}->{datastoremap}->{"nfs://".$mnthost.$dsv->info->nas->remotePath}=$dsv->info->name; + $hyphash{$hyp}->{datastoreurlmap}->{$dsv->info->name} = "nfs://".$mnthost.$dsv->info->nas->remotePath; $hyphash{$hyp}->{datastorerefmap}->{"nfs://".$mnthost.$dsv->info->nas->remotePath}=$_; } #TODO: care about SMB }elsif(defined $dsv->info->{vmfs}){ my $name = $dsv->info->vmfs->name; $hyphash{$hyp}->{datastoremap}->{"vmfs://".$name} = $dsv->info->name; + $hyphash{$hyp}->{datastoreurlmap}->{$dsv->info->name} = "vmfs://".$name; $hyphash{$hyp}->{datastorerefmap}->{"vmfs://".$name} = $_; } } @@ -3568,6 +3609,7 @@ sub validate_datastore_prereqs { unless ($hyphash{$hyp}->{datastoremap}->{$uri}) { #If not already there, must mount it $refresh_names=1; ($hyphash{$hyp}->{datastoremap}->{$uri},$hyphash{$hyp}->{datastorerefmap}->{$uri})=mount_nfs_datastore($hostview,$location); + $hyphash{$hyp}->{datastoreurlmap}->{$hyphash{$hyp}->{datastoremap}->{$uri}} = $uri; } }elsif($method =~ /vmfs/){ (my $name, undef) = split /\//,$location,2; @@ -3578,6 +3620,7 @@ sub validate_datastore_prereqs { $refresh_names=1; ($hyphash{$hyp}->{datastoremap}->{$uri},$hyphash{$hyp}->{datastorerefmap}->{$uri})=create_vmfs_datastore($hostview,$name,$hyp); unless($hyphash{hyp}->{datastoremap}->{$uri}){ return 0; } + $hyphash{$hyp}->{datastoreurlmap}->{$hyphash{$hyp}->{datastoremap}->{$uri}} = $uri; } }else{ xCAT::SvrUtils::sendmsg([1,": $method is unsupported at this time (nfs would be)"], $output_handler,$node); @@ -3617,7 +3660,8 @@ sub validate_datastore_prereqs { $refresh_names=1; ($hyphash{$hyp}->{datastoremap}->{$uri},$hyphash{$hyp}->{datastorerefmap}->{$uri})=mount_nfs_datastore($hostview,$location); } - $hyphash{$hyp}->{datastoremap}->{$origurl}=$hyphash{$hyp}->{datastoremap}->{$uri}; + $hyphash{$hyp}->{datastoreurlmap}->{$hyphash{$hyp}->{datastoremap}->{$uri}} = $uri; + $hyphash{$hyp}->{datastoremap}->{$origurl}=$hyphash{$hyp}->{datastoremap}->{$uri}; #we track both the uri xCAT expected and the one vCenter actually ended up with $hyphash{$hyp}->{datastorerefmap}->{$origurl}=$hyphash{$hyp}->{datastorerefmap}->{$uri}; }elsif($method =~ /vmfs/){ (my $name, undef) = split /\//,$location,2; @@ -3628,6 +3672,7 @@ sub validate_datastore_prereqs { ($hyphash{$hyp}->{datastoremap}->{$uri},$hyphash{$hyp}->{datastorerefmap}->{$uri})=create_vmfs_datastore($hostview,$name,$hyp); unless($hyphash{hyp}->{datastoremap}->{$uri}){ return 0; } } + $hyphash{$hyp}->{datastoreurlmap}->{$hyphash{$hyp}->{datastoremap}->{$uri}} = $uri; $hyphash{$hyp}->{datastoremap}->{$origurl}=$hyphash{$hyp}->{datastoremap}->{$uri}; $hyphash{$hyp}->{datastorerefmap}->{$origurl}=$hyphash{$hyp}->{datastorerefmap}->{$uri}; }else{ @@ -3657,6 +3702,7 @@ sub validate_datastore_prereqs { xCAT::SvrUtils::sendmsg([1,"Unable to resolve VMware specified host '".$dsv->info->nas->remoteHost."' to an address, problems may occur"], $output_handler); } $hyphash{$hyp}->{datastoremap}->{"nfs://".$mnthost.$dsv->info->nas->remotePath}=$dsv->info->name; + $hyphash{$hyp}->{datastoreurlmap}->{$dsv->info->name} = "nfs://".$mnthost.$dsv->info->nas->remotePath; $hyphash{$hyp}->{datastorerefmap}->{"nfs://".$mnthost.$dsv->info->nas->remotePath}=$_; } #TODO: care about SMB } #TODO: care about VMFS