Ejemplo n.º 1
0
function translateDeviceCommands($object_id, $crq, $vlan_names = NULL)
{
    $breed = assertDeviceBreed($object_id);
    $funcname = assertBreedFunction($breed, 'xlatepushq');
    require_once 'deviceconfig.php';
    if (!is_callable($funcname)) {
        throw new RTGatewayError("undeclared function '{$funcname}'");
    }
    return $funcname($object_id, $crq, $vlan_names);
}
Ejemplo n.º 2
0
function gwRetrieveDeviceConfig($object_id, $command)
{
    require_once 'deviceconfig.php';
    global $breedfunc;
    $breed = detectDeviceBreed($object_id);
    assertBreedFunction($breed, $command);
    $objectInfo = spotEntity('object', $object_id);
    $endpoints = findAllEndpoints($object_id, $objectInfo['name']);
    if (count($endpoints) == 0) {
        throw new RTGatewayError('no management address set');
    }
    if (count($endpoints) > 1) {
        throw new RTGatewayError('cannot pick management address');
    }
    $endpoint = str_replace(' ', '\\ ', str_replace(' ', '+', $endpoints[0]));
    $tmpfilename = tempnam('', 'RackTables-deviceconfig-');
    try {
        queryGateway('deviceconfig', array("{$command} {$endpoint} {$breed} {$tmpfilename}"));
        $configtext = file_get_contents($tmpfilename);
        unlink($tmpfilename);
    } catch (RTGatewayError $e) {
        unlink($tmpfilename);
        throw $e;
    }
    if ($configtext === FALSE) {
        throw new RTGatewayError('failed to read temporary file');
    }
    // Being here means it was alright.
    return $breedfunc["{$breed}-{$command}-main"](dos2unix($configtext));
}
Ejemplo n.º 3
0
function translateDeviceCommands($object_id, $crq, $vlan_names = NULL)
{
    $breed = assertDeviceBreed($object_id);
    $funcname = assertBreedFunction($breed, 'xlatepushq');
    require_once 'deviceconfig.php';
    if (!is_callable($funcname)) {
        throw new RTGatewayError("undeclared function '{$funcname}'");
    }
    global $current_query_breed;
    $current_query_breed = $breed;
    // this global is used to auto-detect breed in shortenIfName
    try {
        $ret = $funcname($object_id, $crq, $vlan_names);
    } catch (Exception $e) {
        $current_query_breed = NULL;
        throw $e;
    }
    $current_query_breed = NULL;
    return $ret;
}