From fbce5a6a000b009ccb8ed40cde3cdbad5e8eecdf Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 28 Oct 2013 16:07:06 -0400 Subject: [PATCH 1/5] Add formatdisk to esx plugin, to be called by mkstorage --- xCAT-server/lib/xcat/plugins/esx.pm | 36 ++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/esx.pm b/xCAT-server/lib/xcat/plugins/esx.pm index 1f4af072e..44bf57902 100644 --- a/xCAT-server/lib/xcat/plugins/esx.pm +++ b/xCAT-server/lib/xcat/plugins/esx.pm @@ -125,6 +125,7 @@ sub handled_commands{ rpower => 'nodehm:power,mgt', rsetboot => 'nodehm:power,mgt', rmigrate => 'nodehm:power,mgt', + formatdisk => "nodetype:os=(esxi.*)", mkvm => 'nodehm:mgt', rmvm => 'nodehm:mgt', clonevm => 'nodehm:mgt', @@ -210,7 +211,7 @@ sub preprocess_request { my $vmtabhash = $vmtab->getNodesAttribs($noderange,['host','migrationdest']); foreach my $node (@$noderange){ - if ($command eq "rmhypervisor" or $command eq 'lsvm' or $command eq 'rshutdown' or $command eq "chhypervisor") { + if ($command eq "rmhypervisor" or $command eq 'lsvm' or $command eq 'rshutdown' or $command eq "chhypervisor" or $command eq "formatdisk") { $hyp_hash{$node}{nodes} = [$node]; } else { my $ent = $vmtabhash->{$node}->[0]; @@ -636,6 +637,8 @@ sub do_cmd { generic_vm_operation(['config.name','runtime.host'],\&setboot,@exargs); } elsif ($command eq 'rinv') { generic_vm_operation(['config.name','config','runtime.host','layoutEx'],\&inv,@exargs); + } elsif ($command eq 'formatdisk') { + generic_hyp_operation(\&formatdisk,@exargs); } elsif ($command eq 'rmhypervisor') { generic_hyp_operation(\&rmhypervisor,@exargs); } elsif ($command eq 'rshutdown') { @@ -2173,6 +2176,37 @@ sub rshutdown_inmaintenance { return; } +sub formatdisk { + my %args = @_; + my $hyp = $args{hyp}; + $hyphash{$hyp}->{hostview} = get_hostview(hypname=>$hyp,conn=>$hyphash{$hyp}->{conn},properties=>['config','configManager']); + @ARGV = @{$args{exargs}}; + my $nid; + my $name; + GetOptions( + 'id=s' => \$nid, + 'name=s' => \$name, + ); + my $hostview = $hyphash{$hyp}->{hostview}; + if (defined $hyphash{$hyp}->{hostview}) { + my $hdss = $hostview->{vim}->get_view(mo_ref=>$hostview->configManager->storageSystem); + $hdss->RescanAllHba(); + my $dss = $hostview->{vim}->get_view(mo_ref=>$hostview->configManager->datastoreSystem); + my $diskList = $dss->QueryAvailableDisksForVmfs(); + foreach my $disk (@$diskList) { + foreach my $id (@{$disk->{descriptor}}) { + if (lc($id->{id}) eq lc('naa.'.$nid)) { + my $options = $dss->QueryVmfsDatastoreCreateOptions(devicePath => $disk->devicePath); + @$options[0]->spec->vmfs->volumeName($name); + my $newDatastore = $dss->CreateVmfsDatastore(spec => @$options[0]->spec ); + } + } + } + + } + return; +} + sub rmhypervisor { my %args = @_; my $hyp = $args{hyp}; From 952ff38ce42385b3797a15bebc128812c597836c Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 28 Oct 2013 16:15:25 -0400 Subject: [PATCH 2/5] Add --format to mkstorage --- xCAT-server/lib/xcat/plugins/svc.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xCAT-server/lib/xcat/plugins/svc.pm b/xCAT-server/lib/xcat/plugins/svc.pm index 98352215b..e3830a975 100644 --- a/xCAT-server/lib/xcat/plugins/svc.pm +++ b/xCAT-server/lib/xcat/plugins/svc.pm @@ -133,12 +133,14 @@ sub mkstorage { my $pool; my $size; my $boot = 0; + my $format = 0; unless (ref $request->{arg}) { die "TODO: usage"; } my $name; @ARGV = @{$request->{arg}}; unless (GetOptions( + 'format' => \$format, 'shared' => \$shared, 'controller=s' => \$controller, 'boot' => \$boot, @@ -183,6 +185,16 @@ sub mkstorage { my %namemap = makehosts($wwns, controller=>$controller, cfg=>$storents); my @names = values %namemap; bindhosts(\@names, $lun, controller=>$controller); + if ($format) { + my %request = ( + node => [$nodes[0]], + command => [ 'formatdisk' ], + arg => [ '--id', $lun->{wwn}, '--name', $lun->{name} ] + ); + use Data::Dumper; + print Dumper($request{arg}); + $dorequest->(\%request, $callback); + } } else { foreach my $node (@nodes) { mkstorage_single(node=>$node, size=>$size, pool=>$pool, From 3664f1d5c3290b988581864303fefe9bfd7e4ac6 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 28 Oct 2013 20:26:40 -0400 Subject: [PATCH 3/5] Implement rescansan in esx.pm and wire up svc.pm to issue rescansan --- xCAT-server/lib/xcat/plugins/esx.pm | 21 ++++++++++++++++----- xCAT-server/lib/xcat/plugins/svc.pm | 9 ++++++--- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/esx.pm b/xCAT-server/lib/xcat/plugins/esx.pm index 44bf57902..168fa6515 100644 --- a/xCAT-server/lib/xcat/plugins/esx.pm +++ b/xCAT-server/lib/xcat/plugins/esx.pm @@ -126,6 +126,7 @@ sub handled_commands{ rsetboot => 'nodehm:power,mgt', rmigrate => 'nodehm:power,mgt', formatdisk => "nodetype:os=(esxi.*)", + rescansan => "nodetype:os=(esxi.*)", mkvm => 'nodehm:mgt', rmvm => 'nodehm:mgt', clonevm => 'nodehm:mgt', @@ -211,7 +212,7 @@ sub preprocess_request { my $vmtabhash = $vmtab->getNodesAttribs($noderange,['host','migrationdest']); foreach my $node (@$noderange){ - if ($command eq "rmhypervisor" or $command eq 'lsvm' or $command eq 'rshutdown' or $command eq "chhypervisor" or $command eq "formatdisk") { + if ($command eq "rmhypervisor" or $command eq 'lsvm' or $command eq 'rshutdown' or $command eq "chhypervisor" or $command eq "formatdisk" or $command eq 'rescansan') { $hyp_hash{$node}{nodes} = [$node]; } else { my $ent = $vmtabhash->{$node}->[0]; @@ -320,6 +321,7 @@ sub process_request { if ($request->{_xcat_authname}->[0]) { $requester=$request->{_xcat_authname}->[0]; } + %vcenterhash = ();#A data structure to reflect the state of vcenter connectivity to hypervisors my $level = shift; my $distname = undef; my $arch = undef; @@ -639,6 +641,8 @@ sub do_cmd { generic_vm_operation(['config.name','config','runtime.host','layoutEx'],\&inv,@exargs); } elsif ($command eq 'formatdisk') { generic_hyp_operation(\&formatdisk,@exargs); + } elsif ($command eq 'rescansan') { + generic_hyp_operation(\&rescansan,@exargs); } elsif ($command eq 'rmhypervisor') { generic_hyp_operation(\&rmhypervisor,@exargs); } elsif ($command eq 'rshutdown') { @@ -2176,6 +2180,17 @@ sub rshutdown_inmaintenance { return; } +sub rescansan { + my %args = @_; + my $hyp = $args{hyp}; + my $hostview = get_hostview(hypname=>$hyp,conn=>$hyphash{$hyp}->{conn},properties=>['config','configManager']); + if (defined $hostview) { + my $hdss = $hostview->{vim}->get_view(mo_ref=>$hostview->configManager->storageSystem); + $hdss->RescanAllHba(); + $hdss->RescanVmfs(); + } +} + sub formatdisk { my %args = @_; my $hyp = $args{hyp}; @@ -4959,7 +4974,6 @@ sub cpNetbootImages { chdir($tmpDir); xCAT::SvrUtils::sendmsg("extracting netboot files from OS image. This may take about a minute or two...hopefully you have ~1GB free in your /tmp dir\n", $output_handler); my $cmd = "tar zxf $srcDir/image.tgz"; - print "\n$cmd\n"; if(system($cmd)){ xCAT::SvrUtils::sendmsg([1,"Unable to extract $srcDir/image.tgz\n"], $output_handler); } @@ -4971,13 +4985,11 @@ sub cpNetbootImages { # now we need to get partition 5 which has the installation goods in it. my $scmd = "fdisk -lu $tmpDir/usr/lib/vmware/installer/*dd 2>&1 | grep dd5 | awk '{print \$2}'"; - print "running: $scmd\n"; my $sector = `$scmd`; chomp($sector); my $offset = $sector * 512; mkdir "/mnt/xcat"; my $mntcmd = "mount $tmpDir/usr/lib/vmware/installer/*dd /mnt/xcat -o loop,offset=$offset"; - print "$mntcmd\n"; if(system($mntcmd)){ xCAT::SvrUtils::sendmsg([1,"unable to mount partition 5 of the ESX netboot image to /mnt/xcat"], $output_handler); return; @@ -4999,7 +5011,6 @@ sub cpNetbootImages { } chdir("/tmp"); system("umount /mnt/xcat"); - print "tempDir: $tmpDir\n"; system("rm -rf $tmpDir"); } elsif (-r "$srcDir/cim.vgz" and -r "$srcDir/vmkernel.gz" and -r "$srcDir/vmkboot.gz" and -r "$srcDir/sys.vgz") { use File::Basename; diff --git a/xCAT-server/lib/xcat/plugins/svc.pm b/xCAT-server/lib/xcat/plugins/svc.pm index e3830a975..c807b87ba 100644 --- a/xCAT-server/lib/xcat/plugins/svc.pm +++ b/xCAT-server/lib/xcat/plugins/svc.pm @@ -185,14 +185,17 @@ sub mkstorage { my %namemap = makehosts($wwns, controller=>$controller, cfg=>$storents); my @names = values %namemap; bindhosts(\@names, $lun, controller=>$controller); - if ($format) { + if ($format) { my %request = ( node => [$nodes[0]], command => [ 'formatdisk' ], arg => [ '--id', $lun->{wwn}, '--name', $lun->{name} ] ); - use Data::Dumper; - print Dumper($request{arg}); + $dorequest->(\%request, $callback); + %request = ( + node => \@nodes, + command => [ 'rescansan' ], + ); $dorequest->(\%request, $callback); } } else { From cac2677c1cfe4c3936a037c1a36994043153ae56 Mon Sep 17 00:00:00 2001 From: ligc Date: Tue, 29 Oct 2013 10:48:31 +0800 Subject: [PATCH 4/5] temp fix for bug 3792: multiple nics in the same subnet, use the first nic that in the subnet for dhcp --- xCAT-server/lib/xcat/plugins/dhcp.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) mode change 100644 => 100755 xCAT-server/lib/xcat/plugins/dhcp.pm diff --git a/xCAT-server/lib/xcat/plugins/dhcp.pm b/xCAT-server/lib/xcat/plugins/dhcp.pm old mode 100644 new mode 100755 index 46963a50e..90f3b55db --- a/xCAT-server/lib/xcat/plugins/dhcp.pm +++ b/xCAT-server/lib/xcat/plugins/dhcp.pm @@ -1998,6 +1998,11 @@ sub addnet if ($ent[0] eq $net and $ent[2] eq $mask) { $nic = $ent[1]; + # The first nic that matches the network, + # what will happen if there are more than one nics in the same subnet, + # and we want to use the second nic as the dhcp interfaces? + # this is a TODO + last; } } #print " add $net $mask under $nic\n"; @@ -2014,6 +2019,13 @@ sub addnet } unless ($dhcpconf[$idx] =~ /\} # $nic nic_end\n/) { + $callback->( + { + error => + ["Could not add the subnet $net/$mask for nic $nic into $dhcpconffile."], + errorcode => [1] + } + ); return 1; #TODO: this is an error condition } } From 0eb918b7bdfb0e4f6d510c612466baf05db3cc76 Mon Sep 17 00:00:00 2001 From: lissav Date: Tue, 29 Oct 2013 11:08:40 -0400 Subject: [PATCH 5/5] 3865,3864 --- xCAT-server/sbin/xcatsnap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xCAT-server/sbin/xcatsnap b/xCAT-server/sbin/xcatsnap index 500f62b06..64f8b07de 100755 --- a/xCAT-server/sbin/xcatsnap +++ b/xCAT-server/sbin/xcatsnap @@ -102,7 +102,7 @@ sub run_cmd { print "\n\tExecuting: $Command \n"; eval { local $SIG{ALRM} = sub { die "Timeout\n" }; - alarm 60; + alarm 600; @output = `$Command`; alarm 0; }; @@ -238,7 +238,7 @@ sub snap_it { "ls $installdir","/usr/bin/crontab -l", "find /tftpboot -size -32k","ls -lR $xcatroot", "arp -a","ps -edlf","ps -aux","ulimit -a","df -k", - "cat /etc/issue","lsxcatd -a"); + "cat /etc/issue","lsxcatd -a","cat /proc/meminfo", "cat /proc/cpuinfo"); } foreach my $item (@Commands_array) { $Command = $item;