Пример #1
0
foreach ($switch_queue as $object) {
    if ($do_fork) {
        // wait for the next free slot
        while ($fork_slots <= $switches_working) {
            pcntl_waitpid(-1, $wait_status);
            --$switches_working;
        }
        $i_am_child = 0 === ($fork_res = pcntl_fork());
    }
    if (!$do_fork or $i_am_child) {
        try {
            // make a separate DB connection for correct concurrent transactions handling
            if ($i_am_child) {
                connectDB();
            }
            $portsdone = exec8021QDeploy($object['id'], $do_push);
            $flags = PML_NOTICE;
            if (!$portsdone) {
                $flags |= PML_VERBOSE;
            }
            print_message_line("Done '{$object['dname']}': {$portsdone}", $flags);
        } catch (RackTablesError $e) {
            print_message_line("FAILED '{$object['dname']}': " . $e->getMessage());
        }
        if ($i_am_child) {
            exit(0);
        }
    }
    if (isset($fork_res) and $fork_res > 0) {
        ++$switches_working;
    }
Пример #2
0
function process8021QSyncRequest()
{
    // behave depending on current operation: exec8021QPull or exec8021QPush
    global $sic, $op;
    if (FALSE === ($done = exec8021QDeploy($sic['object_id'], $op == 'exec8021QPush'))) {
        showFuncMessage(__FUNCTION__, 'ERR');
    } else {
        showFuncMessage(__FUNCTION__, 'OK', array($done));
    }
}
Пример #3
0
function apply8021qChangeRequest($switch_id, $changes, $verbose = TRUE, $mutex_rev = NULL)
{
    global $dbxlink;
    $dbxlink->beginTransaction();
    try {
        if (NULL === ($vswitch = getVLANSwitchInfo($switch_id, 'FOR UPDATE'))) {
            throw new InvalidArgException('object_id', $switch_id, 'VLAN domain is not set for this object');
        }
        if (isset($mutex_rev) and $vswitch['mutex_rev'] != $mutex_rev) {
            throw new InvalidRequestArgException('mutex_rev', $mutex_rev, 'expired form data');
        }
        $after = $before = apply8021QOrder($vswitch['template_id'], getStored8021QConfig($vswitch['object_id'], 'desired'));
        $domain_vlanlist = getDomainVLANs($vswitch['domain_id']);
        $changes = filter8021QChangeRequests($domain_vlanlist, $before, apply8021QOrder($vswitch['template_id'], $changes));
        $desired_ports_count = count($changes);
        $changes = authorize8021QChangeRequests($before, $changes);
        if (count($changes) < $desired_ports_count) {
            showWarning(sprintf("Permission denied to change %d ports", $desired_ports_count - count($changes)));
        }
        foreach ($changes as $port_name => $port) {
            $after[$port_name] = $port;
        }
        $new_uplinks = filter8021QChangeRequests($domain_vlanlist, $after, produceUplinkPorts($domain_vlanlist, $after, $vswitch['object_id']));
        $npulled = replace8021QPorts('desired', $vswitch['object_id'], $before, $changes);
        $nsaved_uplinks = replace8021QPorts('desired', $vswitch['object_id'], $before, $new_uplinks);
        if ($npulled + $nsaved_uplinks) {
            touchVLANSwitch($vswitch['object_id']);
        }
        $dbxlink->commit();
    } catch (Exception $e) {
        $dbxlink->rollBack();
        showError(sprintf("Failed to update switchports: %s", $e->getMessage()));
        return 0;
    }
    $nsaved_downlinks = 0;
    if ($nsaved_uplinks) {
        $nsaved_downlinks = initiateUplinksReverb($vswitch['object_id'], $new_uplinks);
    }
    // instant deploy to that switch if configured
    $done = 0;
    if ($npulled + $nsaved_uplinks > 0 and getConfigVar('8021Q_INSTANT_DEPLOY') == 'yes') {
        try {
            if (FALSE === ($done = exec8021QDeploy($vswitch['object_id'], TRUE))) {
                showError("deploy was blocked due to conflicting configuration versions");
            } elseif ($verbose) {
                showSuccess(sprintf("Configuration for %u port(s) have been deployed", $done));
            }
        } catch (Exception $e) {
            showError(sprintf("Failed to deploy changes to switch: %s", $e->getMessage()));
        }
    }
    // report number of changed ports
    $total = $npulled + $nsaved_uplinks + $nsaved_downlinks;
    if ($verbose) {
        $message = sprintf('%u port(s) have been changed', $total);
        if ($total > 0) {
            showSuccess($message);
        } else {
            showNotice($message);
        }
    }
    return $total;
}