Пример #1
0
$config = $application->getOption('resources');
array_shift($argv);
$vlans = $argv;
if (!count($vlans)) {
    die("USAGE: private-vlans.php \$vlan1 \$vlan2 \$vlan3 ...\n\n");
}
// get all switches
$switches = $em->getRepository('\\Entities\\Switcher')->getAndCache(true, \Entities\Switcher::TYPE_SWITCH);
foreach ($switches as $switch) {
    $sw = new \OSS_SNMP\SNMP($switch->getHostname(), $switch->getSnmppasswd());
    foreach ($vlans as $tag) {
        if (VERBOSE) {
            echo "Polling {$switch->getName()} for VLAN {$tag}\n";
        }
        // get ports for the given VLAN(s)
        $vlanIfIndex = $sw->useExtreme_Vlan()->ifVlanIdsToIfIndexes()[$tag];
        // does our VLAN exist?
        if (!($vlan = $em->getRepository('\\Entities\\Vlan')->findOneBy(['number' => $tag]))) {
            $vlan = new \Entities\Vlan();
            $vlan->setName($sw->useExtreme_Vlan()->ifDescriptions()[$vlanIfIndex]);
            $vlan->setNumber($tag);
            $vlan->setPrivate(true);
            if (DBWRITE) {
                if (VERBOSE) {
                    echo "Adding VLAN {$tag} to database\n";
                }
                $em->persist($vlan);
                $em->flush();
            }
        }
        // find all ports tagged / untagged for the given VLAN