Пример #1
0
/**
 * Creates or loads physical interface for port
 *
 * @param \Entities\SwitchPort $dbPort Port to create or load Physical interface
 * @param array                $port    Parsed port data from csv to check if is LAG or simple port
 * @param \Entities\Customer   $cust   Customer to get next monitor index
 * @param object               $em     Entity manager
 * @return \Entities\PhysicalInterface
 */
function createLoadPhysicalInterface($dbPort, $port, $cust, $em)
{
    $phInt = $dbPort->getPhysicalInterface();
    if (!$phInt) {
        $phInt = new \Entities\PhysicalInterface();
        $em->persist($phInt);
        $phInt->setStatus(\Entities\PhysicalInterface::STATUS_CONNECTED);
        $phInt->setDuplex('full');
        $phInt->setMonitorindex($em->getRepository("\\Entities\\PhysicalInterface")->getNextMonitorIndex($cust));
        $phInt->setSwitchPort($dbPort);
        $dbPort->setPhysicalInterface($phInt);
    }
    if ($port['port_type']) {
        $speed = split("base", strtolower($port['port_type']));
        switch ($speed[0]) {
            case '10gig':
                $phInt->setSpeed(10000);
                break;
            case '1000':
                $phInt->setSpeed(1000);
                break;
            case '100':
                $phInt->setSpeed(100);
                break;
            case '10':
                $phInt->setSpeed(10);
                break;
            default:
                echo "Uh oh: could not parse speed {$port['port_type']}\n";
                break;
        }
    } else {
        echo "Uh oh: no port type for switchport {$dbPort->getSwitcher()->getName()}:{$dbPort->getName()}\n";
    }
    return $phInt;
}
 public function getPhysicalInterface()
 {
     $this->__load();
     return parent::getPhysicalInterface();
 }