VM Storage (migration phase)

[], 'SVC' => [] ]; } // Add the LUN to the correct category (VNX or SVC) for its host. $luns_by_hostname[$hostname][$lun['baie']][] = $lun; } // Get the list of cluster hostnames from the LUNs we already fetched. // This avoids an extra database query for clusters. $cluster_hostnames = []; foreach ($luns_by_hostname as $hostname => $luns) { if (str_contains($hostname, '-c1')) { $cluster_hostnames[] = $hostname; } } sort($cluster_hostnames); // Sort them alphabetically // --- STEP 3: RENDERING --- // Now, loop through the prepared data and render the HTML. // Use htmlspecialchars() on all output to prevent XSS attacks. /** * Helper function to render LUNs for a specific host, avoiding duplicates. * This avoids code duplication and handles redundant data from the DB. * @param array $luns The array of LUNs for a specific host. * @param string $type 'VNX' or 'SVC'. * @return string The generated HTML for the table cell. */ function renderLuns(array $luns, string $type): string { $html = ""; return $html; } // Render rows for VMs foreach ($vms as $vm) { echo ""; echo ""; if (str_contains($vm['Owner'], "SYN") || str_contains($vm['Owner'], "MIG")) { echo ""; } else { echo ""; } // --- CORRECTED VHDX RENDERING --- $vhdx_parts = []; if (!empty($vm['VHDXs'])) { // 1. Split the string into an array of individual VHDX entries $vhdx_entries = explode('|', $vm['VHDXs']); foreach ($vhdx_entries as $entry) { // 2. Replace the first comma (after .vhdx) with " : " and add "GB" // The limit parameter '2' ensures we only replace the first occurrence. $formatted_entry = preg_replace('/\.vhdx,/', ' : ', $entry, 1) . 'GB'; $vhdx_parts[] = $formatted_entry; } } // 3. Join all formatted parts with a comma and a space echo ""; if ($vm['WWPNs'] != "") { $hostname = $vm['Name']; $vnx_luns = $luns_by_hostname[$hostname]['VNX'] ?? []; $svc_luns = $luns_by_hostname[$hostname]['SVC'] ?? []; echo renderLuns($vnx_luns, 'VNX'); echo renderLuns($svc_luns, 'SVC'); } else { echo ""; } echo ""; } // Render rows for Clusters foreach ($cluster_hostnames as $hostname) { echo ""; echo ""; echo ""; // Empty cells for Legacy, Destination, VHDX $vnx_luns = $luns_by_hostname[$hostname]['VNX'] ?? []; $svc_luns = $luns_by_hostname[$hostname]['SVC'] ?? []; echo renderLuns($vnx_luns, 'VNX'); echo renderLuns($svc_luns, 'SVC'); echo ""; } ?>
VM Legacy Host Destination Host VHDX Storage VNX Luns SVC Luns
"; $rendered_luns = []; // Array to track what has been rendered if (!empty($luns)) { foreach ($luns as $lun) { $lun_name = ($type === 'VNX' && str_contains($lun['name'], '_')) ? explode("_", $lun['name'])[1] : $lun['name']; $lun_size = $lun['size']; // Create a unique key for this LUN to detect duplicates $unique_key = $lun_name . ':' . $lun_size; // If we have already rendered this exact LUN, skip it if (in_array($unique_key, $rendered_luns)) { continue; } // Render the LUN and add its key to our tracking array $html .= htmlspecialchars($lun_name) . " : " . htmlspecialchars($lun_size) . "GB
\n"; $rendered_luns[] = $unique_key; } } $html .= "
" . htmlspecialchars($vm['Name']) . "" . htmlspecialchars($vm['Owner']) . "" . htmlspecialchars($vm['Owner']) . "" . implode('
', $vhdx_parts) . "
" . htmlspecialchars($hostname) . " (Cluster)