コード例 #1
0
function sg_commitUpdatePortl2address($object_id, $port_id, $port_l2address)
{
    $db_l2address = l2addressForDatabase($port_l2address);
    global $dbxlink;
    $dbxlink->exec('LOCK TABLES Port WRITE');
    if (alreadyUsedL2Address($db_l2address, $object_id)) {
        $dbxlink->exec('UNLOCK TABLES');
        // FIXME: it is more correct to throw InvalidArgException here
        // and convert it to InvalidRequestArgException at upper level,
        // when there is a mean to do that.
        throw new InvalidRequestArgException('port_l2address', $db_l2address, 'address belongs to another object');
    }
    usePreparedUpdateBlade('Port', array('l2address' => $db_l2address === '' ? NULL : $db_l2address), array('id' => $port_id, 'object_id' => $object_id));
    $dbxlink->exec('UNLOCK TABLES');
}
コード例 #2
0
ファイル: snmp.php プロジェクト: xtha/salt
function generatePortsForCatModule($object_id, $slotno = 1, $mtype = 'X6748', $mac_address = '')
{
    global $dbxlink;
    $mac_address = l2addressFromDatabase(l2addressForDatabase($mac_address));
    switch ($mtype) {
        case 'WS-X6748-GE-TX':
            $dbxlink->beginTransaction();
            for ($i = 1; $i <= 48; $i++) {
                commitAddPort($object_id, "gi{$slotno}/{$i}", '1-24', "slot {$slotno} port {$i}", $mac_address);
                $mac_address = nextMACAddress($mac_address);
            }
            $dbxlink->commit();
            break;
        case 'WS-X6708-10GE':
            for ($i = 1; $i <= 8; $i++) {
                commitAddPort($object_id, "te{$slotno}/{$i}", '6-1080', "slot {$slotno} port {$i}", $mac_address);
                $mac_address = nextMACAddress($mac_address);
            }
            break;
        case 'WS-X6704-10GE':
            for ($i = 1; $i <= 4; $i++) {
                commitAddPort($object_id, "te{$slotno}/{$i}", '5-1079', "slot {$slotno} port {$i}", $mac_address);
                $mac_address = nextMACAddress($mac_address);
            }
            break;
        case 'VS-S720-10G':
            commitAddPort($object_id, "gi{$slotno}/1", '4-1077', "slot {$slotno} port 1", $mac_address);
            $mac_address = nextMACAddress($mac_address);
            commitAddPort($object_id, "gi{$slotno}/2", '4-1077', "slot {$slotno} port 2", $mac_address);
            $mac_address = nextMACAddress($mac_address);
            commitAddPort($object_id, "gi{$slotno}/3", '1-24', "slot {$slotno} port 3", $mac_address);
            $mac_address = nextMACAddress($mac_address);
            commitAddPort($object_id, "te{$slotno}/4", '6-1080', "slot {$slotno} port 4", $mac_address);
            $mac_address = nextMACAddress($mac_address);
            commitAddPort($object_id, "te{$slotno}/5", '6-1080', "slot {$slotno} port 5", $mac_address);
            break;
        case '3750G-24TS':
            // MAC address of 1st port is the next one after switch's address
            $mac_address = nextMACAddress($mac_address);
            for ($i = 1; $i <= 24; $i++) {
                commitAddPort($object_id, "gi{$slotno}/0/{$i}", '1-24', "unit {$slotno} port {$i}", $mac_address);
                $mac_address = nextMACAddress($mac_address);
            }
            for ($i = 25; $i <= 28; $i++) {
                commitAddPort($object_id, "gi{$slotno}/0/{$i}", '4-1077', "unit {$slotno} port {$i}", $mac_address);
                $mac_address = nextMACAddress($mac_address);
            }
            break;
        case '3750G-24T':
            $mac_address = nextMACAddress($mac_address);
            for ($i = 1; $i <= 24; $i++) {
                commitAddPort($object_id, "gi{$slotno}/0/{$i}", '1-24', "unit {$slotno} port {$i}", $mac_address);
                $mac_address = nextMACAddress($mac_address);
            }
            break;
        case '3750G-16TD':
            $mac_address = nextMACAddress($mac_address);
            for ($i = 1; $i <= 16; $i++) {
                commitAddPort($object_id, "gi{$slotno}/0/{$i}", '1-24', "unit {$slotno} port {$i}", $mac_address);
                $mac_address = nextMACAddress($mac_address);
            }
            commitAddPort($object_id, "te{$slotno}/0/1", '5-1079', "unit {$slotno} port {$i}", $mac_address);
            break;
        case 'LE02G48TA':
            for ($i = 0; $i <= 47; $i++) {
                commitAddPort($object_id, "gi{$slotno}/0/{$i}", '1-24', "slot {$slotno} port {$i}", $mac_address);
            }
            break;
        case 'LE02X12SA':
            for ($i = 0; $i <= 11; $i++) {
                commitAddPort($object_id, "gi{$slotno}/0/{$i}", '9-1084', "slot {$slotno} port {$i}", $mac_address);
            }
            break;
    }
}
コード例 #3
0
ファイル: database.php プロジェクト: rhysm/racktables
function getPortSearchResults($what)
{
    $ret = array();
    $ports = getSearchResultByField('Port', array('object_id', 'id', 'reservation_comment'), 'reservation_comment', $what, 'object_id', 0);
    foreach ($ports as $port) {
        $ret[$port['object_id']]['id'] = $port['object_id'];
        $ret[$port['object_id']]['by_port'][$port['id']] = $port['reservation_comment'];
    }
    $ports = getSearchResultByField('Port', array('object_id', 'id', 'label'), 'label', $what, 'object_id', 0);
    foreach ($ports as $port) {
        $ret[$port['object_id']]['id'] = $port['object_id'];
        $ret[$port['object_id']]['by_port'][$port['id']] = $port['label'];
    }
    try {
        $db_l2address = l2addressForDatabase($what);
    } catch (InvalidArgException $e) {
        return $ret;
    }
    $ports = getSearchResultByField('Port', array('object_id', 'id', 'l2address'), 'l2address', $db_l2address, 'object_id', 2);
    foreach ($ports as $port) {
        $ret[$port['object_id']]['id'] = $port['object_id'];
        $ret[$port['object_id']]['by_port'][$port['id']] = $port['l2address'];
    }
    return $ret;
}
コード例 #4
0
ファイル: functions.php プロジェクト: rhysm/racktables
function genericAssertion($argname, $argtype)
{
    global $sic;
    switch ($argtype) {
        case 'string':
            assertStringArg($argname);
            break;
        case 'string0':
            assertStringArg($argname, TRUE);
            break;
        case 'uint':
            assertUIntArg($argname);
            break;
        case 'uint-uint':
            assertStringArg($argname);
            if (1 != preg_match('/^[1-9][0-9]*-[1-9][0-9]*$/', $_REQUEST[$argname])) {
                throw new InvalidRequestArgException($argname, $_REQUEST[$argname], 'illegal format');
            }
            break;
        case 'uint0':
            assertUIntArg($argname, TRUE);
            break;
        case 'inet':
            assertIPArg($argname);
            break;
        case 'inet4':
            assertIPv4Arg($argname);
            break;
        case 'inet6':
            assertIPv6Arg($argname);
            break;
        case 'l2address':
            assertStringArg($argname);
        case 'l2address0':
            assertStringArg($argname, TRUE);
            try {
                l2addressForDatabase($sic[$argname]);
            } catch (InvalidArgException $e) {
                throw new InvalidRequestArgException($argname, $sic[$argname], 'malformed MAC/WWN address');
            }
            break;
        case 'tag':
            assertStringArg($argname);
            if (!validTagName($sic[$argname])) {
                throw new InvalidRequestArgException($argname, $sic[$argname], 'Invalid tag name');
            }
            break;
        case 'pcre':
            assertPCREArg($argname);
            break;
        case 'json':
            assertStringArg($argname);
            if (NULL === json_decode($sic[$argname], TRUE)) {
                throw new InvalidRequestArgException($argname, '(omitted)', 'Invalid JSON code received from client');
            }
            break;
        case 'array':
            if (!array_key_exists($argname, $_REQUEST)) {
                throw new InvalidRequestArgException($argname, '(missing argument)');
            }
            if (!is_array($_REQUEST[$argname])) {
                throw new InvalidRequestArgException($argname, '(omitted)', 'argument is not an array');
            }
            break;
        case 'enum/attr_type':
            assertStringArg($argname);
            if (!in_array($sic[$argname], array('uint', 'float', 'string', 'dict', 'date'))) {
                throw new InvalidRequestArgException($argname, $sic[$argname], 'Unknown value');
            }
            break;
        case 'enum/vlan_type':
            assertStringArg($argname);
            // "Alien" type is not valid until the logic is fixed to implement it in full.
            if (!in_array($sic[$argname], array('ondemand', 'compulsory'))) {
                throw new InvalidRequestArgException($argname, $sic[$argname], 'Unknown value');
            }
            break;
        case 'enum/wdmstd':
            assertStringArg($argname);
            global $wdm_packs;
            if (!array_key_exists($sic[$argname], $wdm_packs)) {
                throw new InvalidRequestArgException($argname, $sic[$argname], 'Unknown value');
            }
            break;
        case 'enum/ipproto':
            assertStringArg($argname);
            global $vs_proto;
            if (!array_key_exists($sic[$argname], $vs_proto)) {
                throw new InvalidRequestArgException($argname, $sic[$argname], 'Unknown value');
            }
            break;
        case 'enum/alloc_type':
            assertStringArg($argname);
            if (!in_array($sic[$argname], array('regular', 'shared', 'virtual', 'router'))) {
                throw new InvalidRequestArgException($argname, $sic[$argname], 'Unknown value');
            }
            break;
        case 'enum/dqcode':
            assertStringArg($argname);
            global $dqtitle;
            if (!array_key_exists($sic[$argname], $dqtitle)) {
                throw new InvalidRequestArgException($argname, $sic[$argname], 'Unknown value');
            }
            break;
        case 'iif':
            if (!array_key_exists($sic[$argname], getPortIIFOptions())) {
                throw new InvalidRequestArgException($argname, $sic[$argname], 'Unknown value');
            }
            break;
        case 'vlan':
        case 'vlan1':
            genericAssertion($argname, 'uint');
            if ($argtype == 'vlan' and $sic[$argname] == VLAN_DFL_ID) {
                throw new InvalidRequestArgException($argname, $sic[$argname], 'default VLAN cannot be changed');
            }
            if ($sic[$argname] > VLAN_MAX_ID or $sic[$argname] < VLAN_MIN_ID) {
                throw new InvalidRequestArgException($argname, $sic[$argname], 'out of valid range');
            }
            break;
        case 'rackcode/expr':
            genericAssertion($argname, 'string0');
            if ($sic[$argname] == '') {
                return;
            }
            $parse = spotPayload($sic[$argname], 'SYNT_EXPR');
            if ($parse['result'] != 'ACK') {
                throw new InvalidRequestArgException($argname, $sic[$argname], 'RackCode parsing error');
            }
            break;
        default:
            throw new InvalidArgException('argtype', $argtype);
            // comes not from user's input
    }
}