Esempio n. 1
0
function renderObject8021QSync($object_id)
{
    $vswitch = getVLANSwitchInfo($object_id);
    $object = spotEntity('object', $object_id);
    try {
        $R = getRunning8021QConfig($object_id);
    } catch (Exception $re) {
        showWarning('Device configuration unavailable:<br>' . $re->getMessage());
        return;
    }
    $D = getStored8021QConfig($vswitch['object_id'], 'desired');
    $C = getStored8021QConfig($vswitch['object_id'], 'cached');
    $plan = apply8021QOrder($vswitch['template_id'], get8021QSyncOptions($vswitch, $D, $C, $R['portdata']));
    $maxdecisions = 0;
    foreach ($plan as $port) {
        if ($port['status'] == 'delete_conflict' or $port['status'] == 'merge_conflict' or $port['status'] == 'add_conflict' or $port['status'] == 'martian_conflict') {
            $maxdecisions++;
        }
    }
    if (isset($_REQUEST['hl_port_id'])) {
        assertUIntArg('hl_port_id');
        $hl_port_id = intval($_REQUEST['hl_port_id']);
        $hl_port_name = NULL;
        addAutoScrollScript("port-{$hl_port_id}");
        amplifyCell($object);
        foreach ($object['ports'] as $port) {
            if (mb_strlen($port['name']) && $port['id'] == $hl_port_id) {
                $hl_port_name = $port['name'];
                break;
            }
        }
    }
    echo '<table border=0 class=objectview cellspacing=0 cellpadding=0>';
    echo '<tr><td class=pcleft width="50%">';
    startPortlet('schedule');
    echo '<table border=0 cellspacing=0 cellpadding=3 align=center>';
    // FIXME: sort rows newest event last
    $rows = array();
    if (!considerConfiguredConstraint($object, 'SYNC_802Q_LISTSRC')) {
        $rows['auto sync'] = '<span class="trerror">disabled by operator</span>';
    }
    $rows['last local change'] = $vswitch['last_change'] . ' (' . $vswitch['last_change_age'] . ' ago)';
    $rows['device out of sync'] = $vswitch['out_of_sync'];
    if ($vswitch['out_of_sync'] == 'no') {
        $rows['last sync session with device'] = $vswitch['last_push_finished'] . ' (' . $vswitch['last_push_age'] . ' ago, lasted ' . $vswitch['last_push_lasted'] . ')';
    }
    if ($vswitch['last_errno']) {
        $rows['failed'] = $vswitch['last_error_ts'] . ' (' . strerror8021Q($vswitch['last_errno']) . ')';
    }
    if (NULL !== ($new_rows = callHook('alter8021qSyncSummaryItems', $rows))) {
        $rows = $new_rows;
    }
    foreach ($rows as $th => $td) {
        echo "<tr><th width='50%' class=tdright>{$th}:</th><td class=tdleft colspan=2>{$td}</td></tr>";
    }
    echo '<tr><th class=tdright>run now:</th><td class=tdcenter>';
    printOpFormIntro('exec8021QPull');
    echo getImageHREF('prev', 'pull remote changes in', TRUE, 101) . '</form></td><td class=tdcenter>';
    if ($maxdecisions) {
        echo getImageHREF('COMMIT gray', 'cannot push due to version conflict(s)');
    } else {
        printOpFormIntro('exec8021QPush');
        echo getImageHREF('COMMIT', 'push local changes out', TRUE, 102) . '</form>';
    }
    echo '</td></tr>';
    echo '</table>';
    finishPortlet();
    startPortlet('preview legend');
    echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>';
    echo '<tr><th>status</th><th width="50%">color code</th></tr>';
    echo '<tr><td class=tdright>with template role:</td><td class=trbusy>&nbsp;</td></tr>';
    echo '<tr><td class=tdright>without template role:</td><td>&nbsp;</td></tr>';
    echo '<tr><td class=tdright>new data:</td><td class=trok>&nbsp;</td></tr>';
    echo '<tr><td class=tdright>warnings in new data:</td><td class=trwarning>&nbsp;</td></tr>';
    echo '<tr><td class=tdright>fatal errors in new data:</td><td class=trerror>&nbsp;</td></tr>';
    echo '<tr><td class=tdright>deleted data:</td><td class=trnull>&nbsp;</td></tr>';
    echo '</table>';
    finishPortlet();
    echo '</td><td class=pcright>';
    startPortlet('preview/resolve');
    switchportInfoJS($object_id);
    // load JS code to make portnames interactive
    // initialize one of three popups: we've got data already
    $port_config = addslashes(json_encode(formatPortConfigHints($object_id, $R)));
    addJS(<<<END
\$(document).ready(function(){
\tvar confData = \$.parseJSON('{$port_config}');
\tapplyConfData(confData);
\tvar menuItem = \$('.context-menu-item.itemname-conf');
\tmenuItem.addClass(\$.contextMenu.disabledItemClassName);
\tsetItemIcon(menuItem[0], 'ok');
});
END
, TRUE);
    echo '<table cellspacing=0 cellpadding=5 align=center class=widetable width="100%">';
    if ($maxdecisions) {
        echo '<tr><th colspan=2>&nbsp;</th><th colspan=3>discard</th><th>&nbsp;</th></tr>';
    }
    echo '<tr valign=top><th>port</th><th width="40%">last&nbsp;saved&nbsp;version</th>';
    if ($maxdecisions) {
        addJS('js/racktables.js');
        printOpFormIntro('resolve8021QConflicts', array('mutex_rev' => $vswitch['mutex_rev']));
        foreach (array('left', 'asis', 'right') as $pos) {
            echo "<th class=tdcenter><input type=radio name=column_radio value={$pos} " . "onclick=\"checkColumnOfRadios('i_', {$maxdecisions}, '_{$pos}')\"></th>";
        }
    }
    echo '<th width="40%">running&nbsp;version</th></tr>';
    $rownum = 0;
    $plan = sortPortList($plan);
    $domvlans = array_keys(getDomainVLANs($vswitch['domain_id']));
    $default_port = array('mode' => 'access', 'allowed' => array(VLAN_DFL_ID), 'native' => VLAN_DFL_ID);
    foreach ($plan as $port_name => $item) {
        $trclass = $left_extra = $right_extra = $left_text = $right_text = '';
        $radio_attrs = array();
        switch ($item['status']) {
            case 'ok_to_delete':
                $left_text = serializeVLANPack($item['left']);
                $right_text = 'none';
                $left_extra = ' trnull';
                $right_extra = ' trok';
                // no confirmation is necessary
                break;
            case 'delete_conflict':
                $trclass = 'trbusy';
                $left_extra = ' trerror';
                // can be fixed on request
                $right_extra = ' trnull';
                $left_text = formatVLANPackDiff($item['lastseen'], $item['left']);
                $right_text = '&nbsp;';
                $radio_attrs = array('left' => '', 'asis' => ' checked', 'right' => ' disabled');
                // dummy setting to suppress warnings in resolve8021QConflicts()
                $item['right'] = $default_port;
                break;
            case 'add_conflict':
                $trclass = 'trbusy';
                $right_extra = ' trerror';
                $left_text = '&nbsp;';
                $right_text = serializeVLANPack($item['right']);
                break;
            case 'ok_to_add':
                $trclass = 'trbusy';
                $right_extra = ' trok';
                $left_text = '&nbsp;';
                $right_text = serializeVLANPack($item['right']);
                break;
            case 'ok_to_merge':
                $trclass = 'trbusy';
                $left_extra = ' trok';
                $right_extra = ' trok';
                // fall through
            // fall through
            case 'in_sync':
                $trclass = 'trbusy';
                $left_text = $right_text = serializeVLANPack($item['both']);
                break;
            case 'ok_to_pull':
                // at least one of the sides is not in the default state
                $trclass = 'trbusy';
                $right_extra = ' trok';
                $left_text = serializeVLANPack($item['left']);
                $right_text = serializeVLANPack($item['right']);
                break;
            case 'ok_to_push':
                $trclass = ' trbusy';
                $left_extra = ' trok';
                $left_text = formatVLANPackDiff($C[$port_name], $item['left']);
                $right_text = serializeVLANPack($item['right']);
                break;
            case 'merge_conflict':
                $trclass = 'trbusy';
                $left_extra = ' trerror';
                $right_extra = ' trerror';
                $left_text = formatVLANPackDiff($C[$port_name], $item['left']);
                $right_text = serializeVLANPack($item['right']);
                // enable, but consider each option independently
                // Don't accept running VLANs not in domain, and
                // don't offer anything, that VST will deny.
                // Consider domain and template constraints.
                $radio_attrs = array('left' => '', 'asis' => ' checked', 'right' => '');
                if (!acceptable8021QConfig($item['right']) or count(array_diff($item['right']['allowed'], $domvlans)) or !goodModeForVSTRole($item['right']['mode'], $item['vst_role'])) {
                    $radio_attrs['left'] = ' disabled';
                }
                break;
            case 'ok_to_push_with_merge':
                $trclass = 'trbusy';
                $left_extra = ' trok';
                $right_extra = ' trwarning';
                $left_text = formatVLANPackDiff($C[$port_name], $item['left']);
                $right_text = serializeVLANPack($item['right']);
                break;
            case 'none':
                $left_text = '&nbsp;';
                $right_text = '&nbsp;';
                break;
            case 'martian_conflict':
                if ($item['right']['mode'] == 'none') {
                    $right_text = '&nbsp;';
                } else {
                    $right_text = serializeVLANPack($item['right']);
                    $right_extra = ' trerror';
                }
                if ($item['left']['mode'] == 'none') {
                    $left_text = '&nbsp;';
                } else {
                    $left_text = serializeVLANPack($item['left']);
                    $left_extra = ' trerror';
                    $radio_attrs = array('left' => '', 'asis' => ' checked', 'right' => ' disabled');
                    // idem, see above
                    $item['right'] = $default_port;
                }
                break;
            default:
                $trclass = 'trerror';
                $left_text = $right_text = 'internal rendering error';
                break;
        }
        $ancor = '';
        $td_class = '';
        if (isset($hl_port_name) and $hl_port_name == $port_name) {
            $ancor = "name='port-{$hl_port_id}'";
            $td_class = ' border_highlight';
        }
        echo "<tr class='{$trclass}'><td class='tdleft{$td_class}' NOWRAP><a class='interactive-portname port-menu nolink' {$ancor}>{$port_name}</a></td>";
        if (!count($radio_attrs)) {
            echo "<td class='tdleft{$left_extra}'>{$left_text}</td>";
            if ($maxdecisions) {
                echo '<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>';
            }
            echo "<td class='tdleft{$right_extra}'>{$right_text}</td>";
        } else {
            echo "<td class='tdleft{$left_extra}'><label for=i_{$rownum}_left>{$left_text}</label></td>";
            foreach ($radio_attrs as $pos => $attrs) {
                echo "<td><input id=i_{$rownum}_{$pos} name=i_{$rownum} type=radio value={$pos}{$attrs}></td>";
            }
            echo "<td class='tdleft{$right_extra}'><label for=i_{$rownum}_right>{$right_text}</label></td>";
        }
        echo '</tr>';
        if (count($radio_attrs)) {
            echo "<input type=hidden name=rm_{$rownum} value=" . $item['right']['mode'] . '>';
            echo "<input type=hidden name=rn_{$rownum} value=" . $item['right']['native'] . '>';
            foreach ($item['right']['allowed'] as $a) {
                echo "<input type=hidden name=ra_{$rownum}[] value={$a}>";
            }
            echo "<input type=hidden name=pn_{$rownum} value='" . htmlspecialchars($port_name) . "'>";
        }
        $rownum += count($radio_attrs) ? 1 : 0;
    }
    if ($rownum) {
        echo "<input type=hidden name=nrows value={$rownum}>";
        echo '<tr><td colspan=2>&nbsp;</td><td colspan=3 align=center class=tdcenter>';
        printImageHREF('UNLOCK', 'resolve conflicts', TRUE);
        echo '</td><td>&nbsp;</td></tr>';
    }
    echo '</table>';
    echo '</form>';
    finishPortlet();
    echo '</td></tr></table>';
}
Esempio n. 2
0
function renderObject8021QSyncPreview($object, $vswitch, $plan, $C, $R, $maxdecisions)
{
    if (isset($_REQUEST['hl_port_id'])) {
        assertUIntArg('hl_port_id');
        $hl_port_id = intval($_REQUEST['hl_port_id']);
        $hl_port_name = NULL;
        addAutoScrollScript("port-{$hl_port_id}");
        foreach ($object['ports'] as $port) {
            if (mb_strlen($port['name']) && $port['id'] == $hl_port_id) {
                $hl_port_name = $port['name'];
                break;
            }
        }
        unset($object);
    }
    switchportInfoJS($vswitch['object_id']);
    // load JS code to make portnames interactive
    // initialize one of three popups: we've got data already
    $port_config = addslashes(json_encode(formatPortConfigHints($vswitch['object_id'], $R)));
    addJS(<<<END
\$(document).ready(function(){
\tvar confData = \$.parseJSON('{$port_config}');
\tapplyConfData(confData);
\tvar menuItem = \$('.context-menu-item.itemname-conf');
\tmenuItem.addClass(\$.contextMenu.disabledItemClassName);
\tsetItemIcon(menuItem[0], 'ok');
});
END
, TRUE);
    echo '<table cellspacing=0 cellpadding=5 align=center class=widetable width="100%">';
    if ($maxdecisions) {
        echo '<tr><th colspan=2>&nbsp;</th><th colspan=3>discard</th><th>&nbsp;</th></tr>';
    }
    echo '<tr valign=top><th>port</th><th width="40%">last&nbsp;saved&nbsp;version</th>';
    if ($maxdecisions) {
        addJS('js/racktables.js');
        printOpFormIntro('resolve8021QConflicts', array('mutex_rev' => $vswitch['mutex_rev']));
        foreach (array('left', 'asis', 'right') as $pos) {
            echo "<th class=tdcenter><input type=radio name=column_radio value={$pos} " . "onclick=\"checkColumnOfRadios('i_', {$maxdecisions}, '_{$pos}')\"></th>";
        }
    }
    echo '<th width="40%">running&nbsp;version</th></tr>';
    $rownum = 0;
    $plan = sortPortList($plan);
    $domvlans = array_keys(getDomainVLANList($vswitch['domain_id']));
    $default_port = array('mode' => 'access', 'allowed' => array(VLAN_DFL_ID), 'native' => VLAN_DFL_ID);
    foreach ($plan as $port_name => $item) {
        $trclass = $left_extra = $right_extra = $left_text = $right_text = '';
        $radio_attrs = array();
        switch ($item['status']) {
            case 'ok_to_delete':
                $left_text = serializeVLANPack($item['left']);
                $right_text = 'none';
                $left_extra = ' trnull';
                $right_extra = ' trok';
                // no confirmation is necessary
                break;
            case 'delete_conflict':
                $trclass = 'trbusy';
                $left_extra = ' trerror';
                // can be fixed on request
                $right_extra = ' trnull';
                $left_text = formatVLANPackDiff($item['lastseen'], $item['left']);
                $right_text = '&nbsp;';
                $radio_attrs = array('left' => '', 'asis' => ' checked', 'right' => ' disabled');
                // dummy setting to suppress warnings in resolve8021QConflicts()
                $item['right'] = $default_port;
                break;
            case 'add_conflict':
                $trclass = 'trbusy';
                $right_extra = ' trerror';
                $left_text = '&nbsp;';
                $right_text = serializeVLANPack($item['right']);
                break;
            case 'ok_to_add':
                $trclass = 'trbusy';
                $right_extra = ' trok';
                $left_text = '&nbsp;';
                $right_text = serializeVLANPack($item['right']);
                break;
            case 'ok_to_merge':
                $trclass = 'trbusy';
                $left_extra = ' trok';
                $right_extra = ' trok';
                // fall through
            // fall through
            case 'in_sync':
                $trclass = 'trbusy';
                $left_text = $right_text = serializeVLANPack($item['both']);
                break;
            case 'ok_to_pull':
                // at least one of the sides is not in the default state
                $trclass = 'trbusy';
                $right_extra = ' trok';
                $left_text = serializeVLANPack($item['left']);
                $right_text = serializeVLANPack($item['right']);
                break;
            case 'ok_to_push':
                $trclass = ' trbusy';
                $left_extra = ' trok';
                $left_text = formatVLANPackDiff($C[$port_name], $item['left']);
                $right_text = serializeVLANPack($item['right']);
                break;
            case 'merge_conflict':
                $trclass = 'trbusy';
                $left_extra = ' trerror';
                $right_extra = ' trerror';
                $left_text = formatVLANPackDiff($C[$port_name], $item['left']);
                $right_text = serializeVLANPack($item['right']);
                // enable, but consider each option independently
                // Don't accept running VLANs not in domain, and
                // don't offer anything, that VST will deny.
                // Consider domain and template constraints.
                $radio_attrs = array('left' => '', 'asis' => ' checked', 'right' => '');
                if (!acceptable8021QConfig($item['right']) or count(array_diff($item['right']['allowed'], $domvlans)) or !goodModeForVSTRole($item['right']['mode'], $item['vst_role'])) {
                    $radio_attrs['left'] = ' disabled';
                }
                break;
            case 'ok_to_push_with_merge':
                $trclass = 'trbusy';
                $left_extra = ' trok';
                $right_extra = ' trwarning';
                $left_text = formatVLANPackDiff($C[$port_name], $item['left']);
                $right_text = serializeVLANPack($item['right']);
                break;
            case 'none':
                $left_text = '&nbsp;';
                $right_text = '&nbsp;';
                break;
            case 'martian_conflict':
                if ($item['right']['mode'] == 'none') {
                    $right_text = '&nbsp;';
                } else {
                    $right_text = serializeVLANPack($item['right']);
                    $right_extra = ' trerror';
                }
                if ($item['left']['mode'] == 'none') {
                    $left_text = '&nbsp;';
                } else {
                    $left_text = serializeVLANPack($item['left']);
                    $left_extra = ' trerror';
                    $radio_attrs = array('left' => '', 'asis' => ' checked', 'right' => ' disabled');
                    // idem, see above
                    $item['right'] = $default_port;
                }
                break;
            default:
                $trclass = 'trerror';
                $left_text = $right_text = 'internal rendering error';
                break;
        }
        $anchor = '';
        $td_class = '';
        if (isset($hl_port_name) and $hl_port_name == $port_name) {
            $anchor = "name='port-{$hl_port_id}'";
            $td_class = ' border_highlight';
        }
        echo "<tr class='{$trclass}'><td class='tdleft{$td_class}' NOWRAP><a class='interactive-portname port-menu nolink' {$anchor}>{$port_name}</a></td>";
        if (!count($radio_attrs)) {
            echo "<td class='tdleft{$left_extra}'>{$left_text}</td>";
            if ($maxdecisions) {
                echo '<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>';
            }
            echo "<td class='tdleft{$right_extra}'>{$right_text}</td>";
        } else {
            echo "<td class='tdleft{$left_extra}'><label for=i_{$rownum}_left>{$left_text}</label></td>";
            foreach ($radio_attrs as $pos => $attrs) {
                echo "<td><input id=i_{$rownum}_{$pos} name=i_{$rownum} type=radio value={$pos}{$attrs}></td>";
            }
            echo "<td class='tdleft{$right_extra}'><label for=i_{$rownum}_right>{$right_text}</label></td>";
        }
        echo '</tr>';
        if (count($radio_attrs)) {
            echo "<input type=hidden name=rm_{$rownum} value=" . $item['right']['mode'] . '>';
            echo "<input type=hidden name=rn_{$rownum} value=" . $item['right']['native'] . '>';
            foreach ($item['right']['allowed'] as $a) {
                echo "<input type=hidden name=ra_{$rownum}[] value={$a}>";
            }
            echo "<input type=hidden name=pn_{$rownum} value='" . htmlspecialchars($port_name) . "'>";
        }
        $rownum += count($radio_attrs) ? 1 : 0;
    }
    if ($rownum) {
        echo "<input type=hidden name=nrows value={$rownum}>";
        echo '<tr><td colspan=2>&nbsp;</td><td colspan=3 align=center class=tdcenter>';
        printImageHREF('UNLOCK', 'resolve conflicts', TRUE);
        echo '</td><td>&nbsp;</td></tr>';
    }
    echo '</table>';
    echo '</form>';
}
Esempio n. 3
0
function get8021QSyncOptions($vswitch, $D, $C, $R)
{
    $default_port = array('mode' => 'access', 'allowed' => array(VLAN_DFL_ID), 'native' => VLAN_DFL_ID);
    $ret = array();
    $allports = array();
    foreach (array_unique(array_merge(array_keys($C), array_keys($R))) as $pn) {
        $allports[$pn] = array();
    }
    foreach (apply8021QOrder($vswitch['template_id'], $allports) as $pn => $port) {
        // catch anomalies early
        if ($port['vst_role'] == 'none') {
            if ((!array_key_exists($pn, $R) or $R[$pn]['mode'] == 'none') and !array_key_exists($pn, $C)) {
                $ret[$pn] = array('status' => 'none');
            } else {
                $ret[$pn] = array('status' => 'martian_conflict', 'left' => array_key_exists($pn, $C) ? $C[$pn] : array('mode' => 'none'), 'right' => array_key_exists($pn, $R) ? $R[$pn] : array('mode' => 'none'));
            }
            continue;
        } elseif ((!array_key_exists($pn, $R) or $R[$pn]['mode'] == 'none') and array_key_exists($pn, $C)) {
            $ret[$pn] = array('status' => 'martian_conflict', 'left' => array_key_exists($pn, $C) ? $C[$pn] : array('mode' => 'none'), 'right' => array_key_exists($pn, $R) ? $R[$pn] : array('mode' => 'none'));
            continue;
        }
        // (DC_): port missing from device
        if (!array_key_exists($pn, $R)) {
            $ret[$pn] = array('left' => $D[$pn]);
            if (same8021QConfigs($D[$pn], $default_port)) {
                $ret[$pn]['status'] = 'ok_to_delete';
            } else {
                $ret[$pn]['status'] = 'delete_conflict';
                $ret[$pn]['lastseen'] = $C[$pn];
            }
            continue;
        }
        // (__R): port missing from DB
        if (!array_key_exists($pn, $C)) {
            // Allow importing any configuration, which passes basic
            // validation. If port mode doesn't match its VST role,
            // this will be handled later WRT each port.
            $ret[$pn] = array('status' => acceptable8021QConfig($R[$pn]) ? 'ok_to_add' : 'add_conflict', 'right' => $R[$pn]);
            continue;
        }
        $D_eq_C = same8021QConfigs($D[$pn], $C[$pn]);
        $C_eq_R = same8021QConfigs($C[$pn], $R[$pn]);
        // (DCR), D = C = R: data in sync
        if ($D_eq_C and $C_eq_R) {
            $ret[$pn] = array('status' => 'in_sync', 'both' => $R[$pn]);
            continue;
        }
        // (DCR), D = C: no local edit in the way
        if ($D_eq_C) {
            $ret[$pn] = array('status' => 'ok_to_pull', 'left' => $D[$pn], 'right' => $R[$pn]);
        } elseif ($C_eq_R) {
            $ret[$pn] = array('status' => 'ok_to_push', 'left' => $D[$pn], 'right' => $R[$pn]);
        } elseif (same8021QConfigs($D[$pn], $R[$pn])) {
            $ret[$pn] = array('status' => 'ok_to_merge', 'both' => $R[$pn]);
        } else {
            // D != C, C != R, D != R: version conflict
            $ret[$pn] = array('status' => editable8021QPort($port) ? 'merge_conflict' : 'ok_to_push_with_merge', 'left' => $D[$pn], 'right' => $R[$pn]);
        }
    }
    return $ret;
}