Exemplo n.º 1
0
function buildVSMigratePlan($new_vs_id, $vs_id_list)
{
    $ret = array('properties' => array('vsconfig' => '', 'rsconfig' => ''), 'ports' => array(), 'vips' => array(), 'triplets' => array(), 'messages' => array());
    $config_stat = array('vsconfig' => array(), 'rsconfig' => array());
    $gt = array();
    // grouped triplets
    foreach ($vs_id_list as $vs_id) {
        $vsinfo = spotEntity('ipv4vs', $vs_id);
        // create nesessary vips and ports
        if ($vsinfo['proto'] != 'MARK') {
            $vip_key = $vsinfo['vip_bin'];
            $port_key = $vsinfo['proto'] . '-' . $vsinfo['vport'];
            $ret['vips'][$vip_key] = array('vip' => $vsinfo['vip_bin'], 'vsconfig' => '', 'rsconfig' => '');
            $ret['ports'][$port_key] = array('proto' => $vsinfo['proto'], 'vport' => $vsinfo['vport'], 'vsconfig' => '', 'rsconfig' => '');
        } else {
            $vip_key = '';
            $mark = implode('', unpack('N', $vsinfo['vip_bin']));
            $port_key = $vsinfo['proto'] . '-' . $mark;
            $ret['ports'][$port_key] = array('proto' => $vsinfo['proto'], 'vport' => $mark, 'vsconfig' => '', 'rsconfig' => '');
        }
        // fill triplets
        foreach (SLBTriplet::getTriplets($vsinfo) as $triplet) {
            $tr_key = $triplet->lb['id'] . '-' . $triplet->rs['id'];
            if (!isset($ret['triplets'][$tr_key])) {
                $ret['triplets'][$tr_key] = array('object_id' => $triplet->lb['id'], 'rspool_id' => $triplet->rs['id'], 'vs_id' => $new_vs_id, 'vips' => array(), 'ports' => array());
            }
            $configs = array('vsconfig' => tokenizeConfig($triplet->vs['vsconfig'] . "\n" . $triplet->slb['vsconfig']), 'rsconfig' => tokenizeConfig($triplet->vs['rsconfig'] . "\n" . $triplet->slb['rsconfig']));
            if ($vsinfo['proto'] != 'MARK') {
                if (!isset($ret['triplets'][$tr_key]['ports'][$port_key])) {
                    $ret['triplets'][$tr_key]['ports'][$port_key] = array('proto' => $vsinfo['proto'], 'vport' => $vsinfo['vport'], 'vsconfig' => '', 'rsconfig' => '');
                }
                if (!isset($ret['triplets'][$tr_key]['vips'][$vip_key])) {
                    $ret['triplets'][$tr_key]['vips'][$vip_key] = array('vip' => $vsinfo['vip_bin'], 'prio' => NULL, 'vsconfig' => '', 'rsconfig' => '');
                }
                if ('' != $triplet->slb['prio']) {
                    $ret['triplets'][$tr_key]['vips'][$vip_key]['prio'] = $triplet->slb['prio'];
                }
            } else {
                $ret['triplets'][$tr_key]['ports'][$port_key] = array('proto' => $vsinfo['proto'], 'vport' => $mark, 'vsconfig' => '', 'rsconfig' => '');
            }
            $old_tr_key = $tr_key . '-' . $vip_key . '-' . $port_key;
            $gt['all'][$old_tr_key] = $triplet;
            $gt['ports'][$port_key][$old_tr_key] = $triplet;
            $gt['vips'][$vip_key][$old_tr_key] = $triplet;
            $gt['vip_links'][$tr_key][$vip_key][$old_tr_key] = $triplet;
            $gt['port_links'][$tr_key][$port_key][$old_tr_key] = $triplet;
            foreach ($configs as $conf_type => $list) {
                foreach ($list as $line) {
                    $config_stat[$conf_type][$line][$old_tr_key] = $triplet;
                }
            }
        }
    }
    // reduce common config lines and move them from $config_stat into $ret
    foreach ($config_stat as $conf_type => $stat) {
        foreach ($stat as $line => $used_in_triplets) {
            $added_to_triplets = array();
            $wrong_triplets = array();
            if (!array_sub($gt['all'], $used_in_triplets)) {
                // line used in all triplets
                concatConfig($ret['properties'][$conf_type], $line);
                continue;
            }
            foreach ($gt['ports'] as $port_key => $port_triplets) {
                $diff = array_sub($port_triplets, $used_in_triplets);
                if (count($diff) < count($port_triplets) / 2) {
                    // line used in most triplets of this port
                    $added_to_triplets += $port_triplets;
                    $wrong_triplets += $diff;
                    concatConfig($ret['ports'][$port_key][$conf_type], $line);
                }
            }
            foreach ($gt['vips'] as $vip_key => $vip_triplets) {
                if (!array_sub($vip_triplets, $used_in_triplets)) {
                    if (count($vip_triplets) == count(array_sub($vip_triplets, $added_to_triplets))) {
                        // if none of the $vip_triplets are in $added_to_triplets,
                        // line used in all triplets of this vip
                        $added_to_triplets += $vip_triplets;
                        concatConfig($ret['vips'][$vip_key][$conf_type], $line);
                    }
                }
            }
            foreach ($used_in_triplets as $old_tr_key => $triplet) {
                if (isset($added_to_triplets[$old_tr_key])) {
                    continue;
                }
                $tr_key = $triplet->lb['id'] . '-' . $triplet->rs['id'];
                if ($triplet->vs['proto'] != 'MARK') {
                    $vip_key = $triplet->vs['vip_bin'];
                    $port_key = $triplet->vs['proto'] . '-' . $triplet->vs['vport'];
                } else {
                    $vip_key = '';
                    $port_key = $triplet->vs['proto'] . '-' . implode('', unpack('N', $triplet->vs['vip_bin']));
                }
                // if all the triplets for a given port contain line, add it to the ports' config
                if (!array_sub($gt['port_links'][$tr_key][$port_key], $used_in_triplets)) {
                    if (count($gt['port_links'][$tr_key][$port_key]) == count(array_sub($gt['port_links'][$tr_key][$port_key], $added_to_triplets))) {
                        $added_to_triplets += $gt['port_links'][$tr_key][$port_key];
                        concatConfig($ret['triplets'][$tr_key]['ports'][$port_key][$conf_type], $line);
                    }
                }
                // if all the triplets for a given vip contain line, add it to the vips' config
                if ($vip_key != '') {
                    if (!array_sub($gt['vip_links'][$tr_key][$vip_key], $used_in_triplets)) {
                        if (count($gt['vip_links'][$tr_key][$vip_key]) == count(array_sub($gt['vip_links'][$tr_key][$vip_key], $added_to_triplets))) {
                            $added_to_triplets += $gt['vip_links'][$tr_key][$vip_key];
                            concatConfig($ret['triplets'][$tr_key]['vips'][$vip_key][$conf_type], $line);
                        }
                    }
                }
            }
            // check for failed-to-insert lines
            foreach (array_sub($used_in_triplets, $added_to_triplets) as $old_tr_key => $unused_triplet) {
                $ret['messages'][$old_tr_key][] = "Failed to add {$conf_type} line '{$line}'";
            }
            foreach ($wrong_triplets as $old_tr_key => $triplet) {
                $ret['messages'][$old_tr_key][] = "Added {$conf_type} line '{$line}'";
            }
        }
    }
    // for $line
    return $ret;
}
function renderSLBTripletsEdit($cell)
{
    list($realm1, $realm2) = array_values(array_diff(array('object', 'ipv4vs', 'ipv4rspool'), array($cell['realm'])));
    if (getConfigVar('ADDNEW_AT_TOP') == 'yes') {
        callHook('renderNewSLBItemForm', $realm1, $realm2);
    }
    $triplets = SLBTriplet::getTriplets($cell);
    if (count($triplets)) {
        $cells = array();
        foreach ($triplets[0]->display_cells as $field) {
            $cells[] = $triplets[0]->{$field};
        }
        startPortlet('Manage existing (' . count($triplets) . ')');
        echo "<table cellspacing=0 cellpadding=5 align=center class=cooltable>\n";
        global $nextorder;
        $order = 'odd';
        foreach ($triplets as $slb) {
            $cells = array();
            foreach ($slb->display_cells as $field) {
                $cells[] = $slb->{$field};
            }
            $ids = array('object_id' => $slb->lb['id'], 'vs_id' => $slb->vs['id'], 'pool_id' => $slb->rs['id']);
            $del_params = $ids;
            $del_params['op'] = 'delLB';
            printOpFormIntro('updLB', $ids);
            echo "<tr valign=top class=row_{$order}><td rowspan=2 class=tdright valign=middle>";
            echo getOpLink($del_params, '', 'DELETE', 'Unconfigure');
            echo "</td><td class=tdleft valign=bottom>";
            renderSLBEntityCell($cells[0]);
            echo "</td><td>VS config &darr;<br><textarea name=vsconfig rows=5 cols=70>" . stringForTextarea($slb->slb['vsconfig']) . "</textarea></td>";
            echo '<td class=tdleft rowspan=2 valign=middle>';
            printImageHREF('SAVE', 'Save changes', TRUE);
            echo "</td>";
            echo "</tr><tr class=row_{$order}><td class=tdleft valign=top>";
            renderSLBEntityCell($cells[1]);
            echo '</td><td>';
            echo "<textarea name=rsconfig rows=5 cols=70>" . stringForTextarea($slb->slb['rsconfig']) . "</textarea><br>RS config &uarr;";
            echo "<div style='float:left; margin-top:10px'><label><input name=prio type=text size=10 value=\"" . htmlspecialchars($slb->slb['prio']) . "\"> &larr; Priority</label></div>";
            echo '</td></tr></form>';
            $order = $nextorder[$order];
        }
        echo "</table>\n";
        finishPortlet();
    }
    if (getConfigVar('ADDNEW_AT_TOP') != 'yes') {
        callHook('renderNewSLBItemForm', $realm1, $realm2);
    }
}
Exemplo n.º 3
0
function buildEntityLVSConfig($cell)
{
    $ret = "#\n#\n# This configuration has been generated automatically by RackTables\n#\n#\n";
    // slbv2
    if ($cell['realm'] != 'ipv4vs') {
        $ret .= generateSLBConfig2(getTriplets($cell));
    }
    // slbv1
    if ($cell['realm'] != 'ipvs') {
        $ret .= generateSLBConfig(SLBTriplet::getTriplets($cell));
    }
    return $ret;
}
Exemplo n.º 4
0
function buildEntityLVSConfig($cell)
{
    $newconfig = "#\n#\n# This configuration has been generated automatically by RackTables\n#\n#\n";
    foreach (SLBTriplet::getTriplets($cell) as $slb) {
        $newconfig .= $slb->generateConfig();
    }
    return $newconfig;
}