From fa783ea9b7b100f8ea75c124acec8ce961e38611 Mon Sep 17 00:00:00 2001 From: phamt Date: Sat, 9 Feb 2013 05:24:21 +0000 Subject: [PATCH] Synch up code that was fixed in 2.8 to trunk. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@15128 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/zvmUtils.pm | 48 +++++++ xCAT-UI/js/configure/users.js | 6 +- xCAT-UI/js/custom/esx.js | 9 ++ xCAT-UI/js/custom/kvm.js | 9 ++ xCAT-UI/js/custom/zvm.js | 10 +- xCAT-UI/js/custom/zvmUtils.js | 8 +- xCAT-UI/js/nodes/nodes.js | 186 +++++++++++++--------------- xCAT-UI/js/service/service.js | 42 +++---- xCAT-UI/js/ui.js | 14 +-- xCAT-UI/lib/cmd.php | 6 +- xCAT-UI/lib/zCmd.php | 6 +- xCAT-server/lib/xcat/plugins/zvm.pm | 185 ++++++++++++++++----------- 12 files changed, 314 insertions(+), 215 deletions(-) diff --git a/perl-xCAT/xCAT/zvmUtils.pm b/perl-xCAT/xCAT/zvmUtils.pm index 373a5afde..012920688 100644 --- a/perl-xCAT/xCAT/zvmUtils.pm +++ b/perl-xCAT/xCAT/zvmUtils.pm @@ -2125,6 +2125,7 @@ sub querySSI { Description : Execute a remote command Arguments : User (root or non-root) Node + Command to execute Returns : Output returned from executing command Example : my $out = xCAT::zvmUtils->rExecute($user, $node, $cmd); @@ -2146,4 +2147,51 @@ sub rExecute { $cmd = "'" . $cmd . "'"; $out = `ssh $user\@$node "$sudo sh -c $cmd"`; return $out; +} + +#------------------------------------------------------- + +=head3 getUsedFcpDevices + + Description : Get a list of used FCP devices in the zFCP pools + Arguments : User (root or non-root) + zHCP + Returns : List of known FCP devices + Example : my %devices = xCAT::zvmUtils->getUsedFcpDevices($user, $zhcp); + +=cut + +#------------------------------------------------------- +sub getUsedFcpDevices { + my ( $class, $user, $hcp ) = @_; + + # Directory where zFCP pools are + my $pool = "/var/opt/zhcp/zfcp"; + + my $sudo = "sudo"; + if ($user eq "root") { + $sudo = ""; + } + + # Grep the pools for used or allocated zFCP devices + my %usedDevices; + my @args; + my @devices = split("\n", `ssh $user\@$hcp "$sudo cat $pool/*.conf" | egrep -i "used|allocated"`); + foreach (@devices) { + @args = split(",", $_); + + # Sample pool configuration file: + # #status,wwpn,lun,size,range,owner,channel,tag + # used,1000000000000000,2000000000000110,8g,3B00-3B3F,ihost1,1a23,$root_device$ + # free,1000000000000000,2000000000000111,,3B00-3B3F,,, + # free,1230000000000000,2000000000000112,,3B00-3B3F,,, + $args[6] = xCAT::zvmUtils->trimStr($args[6]); + + # Push used or allocated devices into hash + if ($args[6]) { + $usedDevices{uc($args[6])} = 1; + } + } + + return %usedDevices; } \ No newline at end of file diff --git a/xCAT-UI/js/configure/users.js b/xCAT-UI/js/configure/users.js index 3781df970..dda52524a 100644 --- a/xCAT-UI/js/configure/users.js +++ b/xCAT-UI/js/configure/users.js @@ -323,7 +323,7 @@ function openCreateUserDialog(data) { data : { cmd : 'webrun', tgt : '', - args : 'policy|' + priority + '|' + args, + args : 'policy||' + priority + '||' + args, msg : dialogId }, @@ -337,7 +337,7 @@ function openCreateUserDialog(data) { data : { cmd : 'webrun', tgt : '', - args : 'passwd|' + usrName + '|' + password, + args : 'passwd||' + usrName + '||' + password, msg : dialogId }, @@ -455,7 +455,7 @@ function openDeleteUserDialog(users) { data : { cmd : 'webrun', tgt : '', - args : 'deleteuser|' + users, + args : 'deleteuser||' + users, msg : dialogId }, success : updatePanel diff --git a/xCAT-UI/js/custom/esx.js b/xCAT-UI/js/custom/esx.js index 92b084c90..33f686a59 100644 --- a/xCAT-UI/js/custom/esx.js +++ b/xCAT-UI/js/custom/esx.js @@ -70,6 +70,15 @@ esxPlugin.prototype.loadConfigPage = function(tabId) { profileLnk.trigger('click'); }; +/** + * Migrate node + * + * @param node Node to migrate + */ +esxPlugin.prototype.loadMigratePage = function(node) { + openDialog('info', 'Not yet supported'); +}; + /** * Clone node (service page) * diff --git a/xCAT-UI/js/custom/kvm.js b/xCAT-UI/js/custom/kvm.js index 1f2ca89b1..4add9688d 100644 --- a/xCAT-UI/js/custom/kvm.js +++ b/xCAT-UI/js/custom/kvm.js @@ -68,6 +68,15 @@ kvmPlugin.prototype.loadConfigPage = function(tabId) { profileLnk.trigger('click'); }; +/** + * Migrate node + * + * @param node Node to migrate + */ +kvmPlugin.prototype.loadMigratePage = function(node) { + openDialog('info', 'Not yet supported'); +}; + /** * Clone node (service page) * diff --git a/xCAT-UI/js/custom/zvm.js b/xCAT-UI/js/custom/zvm.js index 015b050b2..7ef7030d4 100644 --- a/xCAT-UI/js/custom/zvm.js +++ b/xCAT-UI/js/custom/zvm.js @@ -953,6 +953,8 @@ zvmPlugin.prototype.loadInventory = function(data) { var tabId = args[0].replace('out=', ''); // Get node var node = args[1].replace('node=', ''); + // Clear any existing cookie + $.cookie(node + 'processes', null); // Remove loader $('#' + tabId).find('img').remove(); @@ -2394,18 +2396,16 @@ zvmPlugin.prototype.loadMigratePage = function(tgtNode) { if (maxQuiesce.val() <= 0) { args = args + "max_quiesce=NOLIMIT;"; } else { - args = args + "'max_quiesce=" + maxQuiesce.val() + "';"; + args = args + "max_quiesce=" + maxQuiesce.val() + ";"; } // Append force argument if ($("input[name=force]:checked").length > 0) { args = args + "'force=" $("input[name=force]:checked").each(function() { - args = args + $(this).val() + ' '; + args += $(this).val() + ' '; }); - args = args + "';"; - } else { - args = args + ";"; + args += "';"; } var statBarId = 'migrateStatusBar' + inst; diff --git a/xCAT-UI/js/custom/zvmUtils.js b/xCAT-UI/js/custom/zvmUtils.js index 5df11d311..259819919 100644 --- a/xCAT-UI/js/custom/zvmUtils.js +++ b/xCAT-UI/js/custom/zvmUtils.js @@ -779,7 +779,7 @@ function updateZNodeStatus(data) { var statBarId = node + 'StatusBar'; // Write ajax response to status bar - var prg = writeRsp(rsp, '[A-Za-z0-9._-]+:'); + var prg = writeRsp(rsp, node + ': '); $('#' + statBarId).find('div').append(prg); } @@ -1993,7 +1993,7 @@ function openAddScsi2SystemDialog(hcp) { data : { cmd : 'chhypervisor', tgt : hcp, - args : "--addscsi|" + num + "|" + pathArray + "|" + option + "|" + persist, + args : "--addscsi||" + num + "||" + pathArray + "||" + option + "||" + persist, msg : dialogId }, @@ -2707,7 +2707,7 @@ function removeZfcp(node, address, wwpn, lun) { data : { cmd : 'chvm', tgt : node, - args : '--removezfcp;' + address + ';' + wwpn + ';' + lun, + args : '--removezfcp||' + address + '||' + wwpn + '||' + lun, msg : node }, @@ -3624,7 +3624,7 @@ function openAddZfcp2PoolDialog() { data : { cmd : 'chvm', tgt : tgtHcp, - args : '--addzfcp2pool|' + tgtPool + '|' + tgtStatus + '|"' + tgtPortName + '"|' + tgtUnitNo + '|' + tgtSize + "| " + tgtRange + '|' + tgtOwner, + args : '--addzfcp2pool||' + tgtPool + '||' + tgtStatus + '||"' + tgtPortName + '"||' + tgtUnitNo + '||' + tgtSize + '||' + tgtRange + '||' + tgtOwner, msg : dialogId }, diff --git a/xCAT-UI/js/nodes/nodes.js b/xCAT-UI/js/nodes/nodes.js index 074d5d520..76b16a7f7 100644 --- a/xCAT-UI/js/nodes/nodes.js +++ b/xCAT-UI/js/nodes/nodes.js @@ -418,24 +418,24 @@ function mkAddNodeLink() { var plugin; switch(mgt) { - case "kvm": - plugin = new kvmPlugin(); - break; - case "esx": - plugin = new esxPlugin(); - break; - case "blade": - plugin = new bladePlugin(); - break; - case "hmc": - plugin = new hmcPlugin(); - break; - case "ipmi": - plugin = new ipmiPlugin(); - break; - case "zvm": - plugin = new zvmPlugin(); - break; + case "kvm": + plugin = new kvmPlugin(); + break; + case "esx": + plugin = new esxPlugin(); + break; + case "blade": + plugin = new bladePlugin(); + break; + case "hmc": + plugin = new hmcPlugin(); + break; + case "ipmi": + plugin = new ipmiPlugin(); + break; + case "zvm": + plugin = new zvmPlugin(); + break; } plugin.addNode(); @@ -686,24 +686,15 @@ function loadNodes(data) { // Create an instance of the plugin var plugin; switch(mgt) { - case "blade": - plugin = new bladePlugin(); - break; - case "fsp": - plugin = new fspPlugin(); - break; - case "hmc": - plugin = new hmcPlugin(); - break; - case "ipmi": - plugin = new ipmiPlugin(); - break; - case "ivm": - plugin = new ivmPlugin(); - break; - case "zvm": - plugin = new zvmPlugin(); - break; + case "kvm": + plugin = new kvmPlugin(); + break; + case "esx": + plugin = new esxPlugin(); + break; + case "zvm": + plugin = new zvmPlugin(); + break; } plugin.loadClonePage(tgtNodes[i]); @@ -741,34 +732,35 @@ function loadNodes(data) { var migrateLnk = $('Migrate'); migrateLnk.click(function() { var tgtNodes = getNodesChecked(nodesTableId).split(','); + var mgt = "", tmp = ""; for (var i in tgtNodes) { - var mgt = getNodeAttr(tgtNodes[i], 'mgt'); - - // Create an instance of the plugin - var plugin; - switch(mgt) { - case "blade": - plugin = new bladePlugin(); - break; - case "fsp": - plugin = new fspPlugin(); - break; - case "hmc": - plugin = new hmcPlugin(); - break; - case "ipmi": - plugin = new ipmiPlugin(); - break; - case "ivm": - plugin = new ivmPlugin(); - break; - case "zvm": - plugin = new zvmPlugin(); - break; + tmp = getNodeAttr(tgtNodes[i], 'mgt'); + if (!mgt) { + mgt = tmp + } else { + if (tmp != mgt) { + openDialog('warn', "You can pick only one type (mgt) of node to migrate!"); + return; + } } - - plugin.loadMigratePage(tgtNodes[i]); } + + // Create an instance of the plugin + var plugin; + switch(mgt) { + // Only hypervisors support migration + case "kvm": + plugin = new kvmPlugin(); + break; + case "esx": + plugin = new esxPlugin(); + break; + case "zvm": + plugin = new zvmPlugin(); + break; + } + + plugin.loadMigratePage(tgtNodes); }); // Update @@ -854,24 +846,24 @@ function loadNodes(data) { // Create an instance of the plugin var plugin; switch(mgt) { - case "blade": - plugin = new bladePlugin(); - break; - case "fsp": - plugin = new fspPlugin(); - break; - case "hmc": - plugin = new hmcPlugin(); - break; - case "ipmi": - plugin = new ipmiPlugin(); - break; - case "ivm": - plugin = new ivmPlugin(); - break; - case "zvm": - plugin = new zvmPlugin(); - break; + case "kvm": + plugin = new kvmPlugin(); + break; + case "esx": + plugin = new esxPlugin(); + break; + case "blade": + plugin = new bladePlugin(); + break; + case "hmc": + plugin = new hmcPlugin(); + break; + case "ipmi": + plugin = new ipmiPlugin(); + break; + case "zvm": + plugin = new zvmPlugin(); + break; } plugin.loadLogPage(tgtNodes[i]); @@ -1635,24 +1627,24 @@ function loadNode(e) { // Create an instance of the plugin var plugin; switch(mgt) { - case "blade": - plugin = new bladePlugin(); - break; - case "fsp": - plugin = new fspPlugin(); - break; - case "hmc": - plugin = new hmcPlugin(); - break; - case "ipmi": - plugin = new ipmiPlugin(); - break; - case "ivm": - plugin = new ivmPlugin(); - break; - case "zvm": - plugin = new zvmPlugin(); - break; + case "kvm": + plugin = new kvmPlugin(); + break; + case "esx": + plugin = new esxPlugin(); + break; + case "blade": + plugin = new bladePlugin(); + break; + case "hmc": + plugin = new hmcPlugin(); + break; + case "ipmi": + plugin = new ipmiPlugin(); + break; + case "zvm": + plugin = new zvmPlugin(); + break; } // Get tab area where a new tab will be inserted diff --git a/xCAT-UI/js/service/service.js b/xCAT-UI/js/service/service.js index e40140014..13da1083c 100644 --- a/xCAT-UI/js/service/service.js +++ b/xCAT-UI/js/service/service.js @@ -858,18 +858,15 @@ function loadNode(e) { // Create an instance of the plugin var plugin; switch (mgt) { - case "blade": - plugin = new bladePlugin(); - break; - case "hmc": - plugin = new hmcPlugin(); - break; - case "ipmi": - plugin = new ipmiPlugin(); - break; - case "zvm": - plugin = new zvmPlugin(); - break; + case "kvm": + plugin = new kvmPlugin(); + break; + case "esx": + plugin = new esxPlugin(); + break; + case "zvm": + plugin = new zvmPlugin(); + break; } // Select tab @@ -1317,18 +1314,15 @@ function cloneNode(tgtNodes) { // Create an instance of the plugin var plugin; switch (hw) { - case "blade": - plugin = new bladePlugin(); - break; - case "hmc": - plugin = new hmcPlugin(); - break; - case "ipmi": - plugin = new ipmiPlugin(); - break; - case "zvm": - plugin = new zvmPlugin(); - break; + case "kvm": + plugin = new kvmPlugin(); + break; + case "esx": + plugin = new esxPlugin(); + break; + case "zvm": + plugin = new zvmPlugin(); + break; } // Clone node diff --git a/xCAT-UI/js/ui.js b/xCAT-UI/js/ui.js index 6d1450914..10996f56d 100644 --- a/xCAT-UI/js/ui.js +++ b/xCAT-UI/js/ui.js @@ -676,21 +676,21 @@ function writeRsp(rsp, pattern) { * @param msg Message to show */ function openDialog(type, msg) { - var msgDialog; + var msgDialog = $('
'); + var title = ""; if (type == "warn") { // Create warning message - msgDialog = $('
' - + '

' + msg + '

' - + '
'); + msgDialog.append(createWarnBar(msg)); + title = "Warning"; } else { // Create info message - msgDialog = $('
' - + '

' + msg + '

' - +'
'); + msgDialog.append(createInfoBar(msg)); + title = "Info"; } // Open dialog msgDialog.dialog({ + title: title, modal: true, close: function(){ $(this).remove(); diff --git a/xCAT-UI/lib/cmd.php b/xCAT-UI/lib/cmd.php index eb3741775..f63f83000 100644 --- a/xCAT-UI/lib/cmd.php +++ b/xCAT-UI/lib/cmd.php @@ -41,14 +41,14 @@ if (isset($_GET["cmd"])) { } // If no $args are given, set $args_array to NULL - // Separators used are: | or ; + // Separators used are: || or ; $args_array = array(); if ($args) { // If $args contains multiple arguments, split it into an array - if (strpos($args, "|")) { + if (strpos($args, "||")) { // Split the arguments into an array $args_array = array(); - $args_array = explode("|", $args); + $args_array = explode("||", $args); } else if (strpos($args, ";")) { // Split the arguments into an array $args_array = array(); diff --git a/xCAT-UI/lib/zCmd.php b/xCAT-UI/lib/zCmd.php index 7bdf07b81..c2a21eebf 100644 --- a/xCAT-UI/lib/zCmd.php +++ b/xCAT-UI/lib/zCmd.php @@ -45,11 +45,11 @@ if (isset($_GET["cmd"])) { } // If $args contains multiple arguments, split it into an array - // Separators used are: | or ; - if (strpos($args, "|")) { + // Separators used are: || or ; + if (strpos($args, "||")) { // Split the arguments into an array $arr = array(); - $arr = explode("|", $args); + $arr = explode("||", $args); } else if (strpos($args, ";")) { // Split the arguments into an array $arr = array(); diff --git a/xCAT-server/lib/xcat/plugins/zvm.pm b/xCAT-server/lib/xcat/plugins/zvm.pm index 4062375cc..845e273ed 100644 --- a/xCAT-server/lib/xcat/plugins/zvm.pm +++ b/xCAT-server/lib/xcat/plugins/zvm.pm @@ -138,6 +138,9 @@ sub process_request { # Directory where executables are on zHCP $::DIR = "/opt/zhcp/bin"; + # Directory where system config is on zHCP + $::SYSCONF = "/opt/zhcp/conf"; + # Directory where zFCP disk pools are on zHCP $::ZFCPPOOL = "/var/opt/zhcp/zfcp"; @@ -1105,6 +1108,8 @@ sub changeVM { my $min; my $max; if ($device =~ m/auto/i) { + my %usedDevices = xCAT::zvmUtils->getUsedFcpDevices($::SUDOER, $hcp); + if ($device =~ m/,/i) { @ranges = split(';', $range); } else { @@ -1138,7 +1143,12 @@ sub changeVM { ($min, $max) = split('-', $_); if (hex($device) >= hex($min) && hex($device) <= hex($max)) { $found = 1; - last; + $device = uc($device); + + # Used found zFCP channel if not in use or allocated + if (!$usedDevices{$device}) { + last; + } } } } @@ -1200,22 +1210,50 @@ sub changeVM { # SLES 11: /etc/udev/rules.d/51-zfcp* my $tmp; if ( $os =~ m/sles10/i ) { - $out = `ssh $::SUDOER\@$node "$::SUDO zfcp_host_configure 0.0.$device 1"`; - $out = `ssh $::SUDOER\@$node "$::SUDO zfcp_disk_configure 0.0.$device $wwpn $lun 1"`; + $out = `ssh $::SUDOER\@$node "$::SUDO /sbin/zfcp_host_configure 0.0.$device 1"`; + if ($out) { + xCAT::zvmUtils->printLn($callback, "$node: $out"); + } + + $out = `ssh $::SUDOER\@$node "$::SUDO /sbin/zfcp_disk_configure 0.0.$device $wwpn $lun 1"`; if ($out) { xCAT::zvmUtils->printLn($callback, "$node: $out"); } $out = xCAT::zvmUtils->rExecute($::SUDOER, $node, "echo 0x$wwpn:0x$lun >> /etc/sysconfig/hardware/hwcfg-zfcp-bus-ccw-0.0.$device"); - } elsif ( $os =~ m/sles11/i ) { - $out = `ssh $::SUDOER\@$node "$::SUDO zfcp_disk_configure 0.0.$device $wwpn $lun 1"`; + } elsif ( $os =~ m/sles11/i ) { + $out = `ssh $::SUDOER\@$node "$::SUDO /sbin/zfcp_host_configure 0.0.$device 1"`; if ($out) { xCAT::zvmUtils->printLn($callback, "$node: $out"); } - $tmp = "'ACTION==\"add\", KERNEL==\"rport-*\", ATTR{port_name}==\"0x$wwpn\", SUBSYSTEMS==\"ccw\", KERNELS==\"0.0.$device\", ATTR{[ccw/0.0.$device]0x$wwpn/unit_add}=\"0x$lun\"'"; - $tmp = xCAT::zvmUtils->replaceStr($tmp, '"', '\\"'); - $out = xCAT::zvmUtils->rExecute($::SUDOER, $node, "echo $tmp >> /etc/udev/rules.d/51-zfcp-0.0.$device.rules"); + $out = `ssh $::SUDOER\@$node "$::SUDO /sbin/zfcp_disk_configure 0.0.$device $wwpn $lun 1"`; + if ($out) { + xCAT::zvmUtils->printLn($callback, "$node: $out"); + } + + # Configure zFCP device to be persistent + $out = `ssh $::SUDOER\@$node "$::SUDO touch /etc/udev/rules.d/51-zfcp-0.0.$device.rules"`; + + # Check if the file already contains the zFCP channel + $out = `ssh $::SUDOER\@$node "$::SUDO cat /etc/udev/rules.d/51-zfcp-0.0.$device.rules" | egrep -i "ccw/0.0.$device]online"`; + if (!$out) { + $tmp = "'ACTION==\"add\", SUBSYSTEM==\"ccw\", KERNEL==\"0.0.$device\", IMPORT{program}=\"collect 0.0.$device \%k 0.0.$device zfcp\"'"; + $tmp = xCAT::zvmUtils->replaceStr($tmp, '"', '\\"'); + $out = `ssh $::SUDOER\@$node "echo $tmp | $::SUDO tee -a /etc/udev/rules.d/51-zfcp-0.0.$device.rules"`; + + $tmp = "'ACTION==\"add\", SUBSYSTEM==\"drivers\", KERNEL==\"zfcp\", IMPORT{program}=\"collect 0.0.$device \%k 0.0.$device zfcp\"'"; + $tmp = xCAT::zvmUtils->replaceStr($tmp, '"', '\\"'); + $out = `ssh $::SUDOER\@$node "echo $tmp | $::SUDO tee -a /etc/udev/rules.d/51-zfcp-0.0.$device.rules"`; + + $tmp = "'ACTION==\"add\", ENV{COLLECT_0.0.$device}==\"0\", ATTR{[ccw/0.0.$device]online}=\"1\"'"; + $tmp = xCAT::zvmUtils->replaceStr($tmp, '"', '\\"'); + $out = `ssh $::SUDOER\@$node "echo $tmp | $::SUDO tee -a /etc/udev/rules.d/51-zfcp-0.0.$device.rules"`; + } + + $tmp = "'ACTION==\"add\", KERNEL==\"rport-*\", ATTR{port_name}==\"0x$wwpn\", SUBSYSTEMS==\"ccw\", KERNELS==\"0.0.$device\", ATTR{[ccw/0.0.$device]0x$wwpn/unit_add}=\"0x$lun\"'"; + $tmp = xCAT::zvmUtils->replaceStr($tmp, '"', '\\"'); + $out = `ssh $::SUDOER\@$node "echo $tmp | $::SUDO tee -a /etc/udev/rules.d/51-zfcp-0.0.$device.rules"`; } elsif ( $os =~ m/rhel/i ) { $out = xCAT::zvmUtils->rExecute($::SUDOER, $node, "echo \"0.0.$device 0x$wwpn 0x$lun\" >> /etc/zfcp.conf"); @@ -2874,71 +2912,80 @@ sub makeVM { $macId = xCAT::zvmUtils->replaceStr( $macId, ":", "" ); $macId = substr( $macId, 6 ); } else { + my $prefix; + if (`ssh -o ConnectTimeout=5 $::SUDOER\@$hcp "$::SUDO test -f $::SYSCONF/userprefix && echo Exists"`) { + $prefix = `ssh -o ConnectTimeout=5 $::SUDOER\@$hcp "$::SUDO cat $::SYSCONF/userprefix"`; + $prefix =~ s/\s*$//; + $prefix =~ s/^\s*//; + } # Get zHCP MAC address # The MAC address prefix is the same for all network devices - $out = `ssh -o ConnectTimeout=5 $::SUDOER\@$hcp "/sbin/modprobe vmcp"`; - $out = `ssh -o ConnectTimeout=5 $::SUDOER\@$hcp "$::SUDO /sbin/vmcp q v nic" | grep "MAC:"`; - if ($out) { - @lines = split( "\n", $out ); - @words = split( " ", $lines[0] ); - - # Extract MAC prefix - my $prefix = $words[1]; - $prefix = xCAT::zvmUtils->replaceStr( $prefix, "-", "" ); - $prefix = substr( $prefix, 0, 6 ); - - # Generate MAC address - my $mac; - while ($generateNew) { - - # If no MACID is found, get one - $macId = xCAT::zvmUtils->getMacID($::SUDOER, $hcp); - if ( !$macId ) { - xCAT::zvmUtils->printLn( $callback, "$node: (Error) Could not generate MACID" ); - return; - } - - # Create MAC address - $mac = $prefix . $macId; - - # If length is less than 12, append a zero - if ( length($mac) != 12 ) { - $mac = "0" . $mac; - } - - # Format MAC address - $mac = - substr( $mac, 0, 2 ) . ":" - . substr( $mac, 2, 2 ) . ":" - . substr( $mac, 4, 2 ) . ":" - . substr( $mac, 6, 2 ) . ":" - . substr( $mac, 8, 2 ) . ":" - . substr( $mac, 10, 2 ); - - # Check 'mac' table for MAC address - my $tab = xCAT::Table->new( 'mac', -create => 1, -autocommit => 0 ); - my @entries = $tab->getAllAttribsWhere( "mac = '" . $mac . "'", 'node' ); - - # If MAC address exists - if (@entries) { - # Generate new MACID - $out = xCAT::zvmUtils->generateMacId($::SUDOER, $hcp); - $generateNew = 1; - } else { - $generateNew = 0; - - # Save MAC address in 'mac' table - xCAT::zvmUtils->setNodeProp( 'mac', $node, 'mac', $mac ); - - # Generate new MACID - $out = xCAT::zvmUtils->generateMacId($::SUDOER, $hcp); - } - } # End of while ($generateNew) - } else { - xCAT::zvmUtils->printLn( $callback, "$node: (Error) Could not find the MAC address of the zHCP" ); - xCAT::zvmUtils->printLn( $callback, "$node: (Solution) Verify that the node's zHCP($hcp) is correct, the node is online, and the SSH keys are setup for the zHCP" ); + if (!$prefix) { + $out = `ssh -o ConnectTimeout=5 $::SUDOER\@$hcp "/sbin/modprobe vmcp"`; + $out = `ssh -o ConnectTimeout=5 $::SUDOER\@$hcp "$::SUDO /sbin/vmcp q v nic" | grep "MAC:"`; + if ($out) { + @lines = split( "\n", $out ); + @words = split( " ", $lines[0] ); + + # Extract MAC prefix + $prefix = $words[1]; + $prefix = xCAT::zvmUtils->replaceStr( $prefix, "-", "" ); + $prefix = substr( $prefix, 0, 6 ); + } else { + xCAT::zvmUtils->printLn( $callback, "$node: (Error) Could not find the MAC address of the zHCP" ); + xCAT::zvmUtils->printLn( $callback, "$node: (Solution) Verify that the node's zHCP($hcp) is correct, the node is online, and the SSH keys are setup for the zHCP" ); + return; + } } + + # Generate MAC address + my $mac; + while ($generateNew) { + + # If no MACID is found, get one + $macId = xCAT::zvmUtils->getMacID($::SUDOER, $hcp); + if ( !$macId ) { + xCAT::zvmUtils->printLn( $callback, "$node: (Error) Could not generate MACID" ); + return; + } + + # Create MAC address + $mac = $prefix . $macId; + + # If length is less than 12, append a zero + if ( length($mac) != 12 ) { + $mac = "0" . $mac; + } + + # Format MAC address + $mac = + substr( $mac, 0, 2 ) . ":" + . substr( $mac, 2, 2 ) . ":" + . substr( $mac, 4, 2 ) . ":" + . substr( $mac, 6, 2 ) . ":" + . substr( $mac, 8, 2 ) . ":" + . substr( $mac, 10, 2 ); + + # Check 'mac' table for MAC address + my $tab = xCAT::Table->new( 'mac', -create => 1, -autocommit => 0 ); + my @entries = $tab->getAllAttribsWhere( "mac = '" . $mac . "'", 'node' ); + + # If MAC address exists + if (@entries) { + # Generate new MACID + $out = xCAT::zvmUtils->generateMacId($::SUDOER, $hcp); + $generateNew = 1; + } else { + $generateNew = 0; + + # Save MAC address in 'mac' table + xCAT::zvmUtils->setNodeProp( 'mac', $node, 'mac', $mac ); + + # Generate new MACID + $out = xCAT::zvmUtils->generateMacId($::SUDOER, $hcp); + } + } # End of while ($generateNew) } # Create virtual server