コード例 #1
0
ファイル: assets.inc.php プロジェクト: ghasedak/openDCIM
 static function createPorts($DeviceID, $update_existing = false)
 {
     // If $update_existing is true then we'll try to create all the ports and as a by product
     // create any new ports.  The setting here will ensure we don't log any errors from the
     // ports that already exist.
     $dev = new Device();
     $dev->DeviceID = $DeviceID;
     if (!$dev->GetDevice()) {
         return false;
     }
     // Check the user's permissions to modify this device
     if ($dev->Rights != 'Write') {
         return false;
     }
     $portList = array();
     if ($dev->DeviceType == "Switch") {
         $nameList = SwitchInfo::getPortNames($dev->DeviceID);
         $aliasList = SwitchInfo::getPortAlias($dev->DeviceID);
     }
     // Build the DevicePorts from the existing info in the following priority:
     //  - Template ports table
     //  - SNMP data (if it exists)
     //  - Placeholders
     //Search template ports
     $tports = array();
     if ($dev->TemplateID > 0) {
         $tport = new TemplatePorts();
         $tport->TemplateID = $dev->TemplateID;
         $tports = $tport->getPorts();
     }
     if ($dev->DeviceType == "Switch") {
         for ($n = 0; $n < $dev->Ports; $n++) {
             $i = $n + 1;
             $portList[$i] = new DevicePorts();
             $portList[$i]->DeviceID = $dev->DeviceID;
             $portList[$i]->PortNumber = $i;
             if (isset($tports[$i])) {
                 // Get any attributes from the device template
                 foreach ($tports[$i] as $key => $value) {
                     if (array_key_exists($key, $portList[$i])) {
                         $portList[$i]->{$key} = $value;
                     }
                 }
             }
             // pull port name first from snmp then from template then just call it port x
             $portList[$i]->Label = isset($nameList[$n]) ? $nameList[$n] : isset($tports[$i]) && $tports[$i]->Label ? $tports[$i]->Label : __("Port") . $i;
             $portList[$i]->Notes = isset($aliasList[$n]) ? $aliasList[$n] : '';
             $portList[$i]->createPort($update_existing);
         }
     } else {
         for ($n = 0; $n < $dev->Ports; $n++) {
             $i = $n + 1;
             $portList[$i] = new DevicePorts();
             $portList[$i]->DeviceID = $dev->DeviceID;
             $portList[$i]->PortNumber = $i;
             if (isset($tports[$i])) {
                 // Get any attributes from the device template
                 foreach ($tports[$i] as $key => $value) {
                     if (array_key_exists($key, $portList[$i])) {
                         $portList[$i]->{$key} = $value;
                     }
                 }
             }
             $portList[$i]->Label = $portList[$i]->Label == "" ? __("Port") . $i : $portList[$i]->Label;
             $portList[$i]->createPort($update_existing);
             if ($dev->DeviceType == "Patch Panel") {
                 $label = $portList[$i]->Label;
                 $i = $i * -1;
                 $portList[$i] = new DevicePorts();
                 $portList[$i]->DeviceID = $dev->DeviceID;
                 $portList[$i]->PortNumber = $i;
                 $portList[$i]->Label = $label;
                 $portList[$i]->createPort($update_existing);
             }
         }
     }
     return $portList;
 }
コード例 #2
0
ファイル: index.php プロジェクト: mnibbelink/openDCIM
            $response['errorcode'] = 200;
            $response['template'] = $dt;
        }
    }
    echoResponse(200, $response);
});
//
//	URL:	/api/v1/devicetemplate/:templateid/dataport
//	Method:	GET
//	Params: templateid
//	Returns: Data ports defined for device template with templateid
//
$app->get('/devicetemplate/:templateid/dataport', function ($templateid) use($app) {
    $tp = new TemplatePorts();
    $tp->TemplateID = $templateid;
    if (!($ports = $tp->getPorts())) {
        $response['error'] = true;
        $response['errorcode'] = 404;
        $response['message'] = __("No ports found for TemplateID: ") . " {$templateid}";
    } else {
        $response['error'] = false;
        $response['errorcode'] = 200;
        $response['dataport'] = $ports;
    }
    echoResponse(200, $response);
});
//
//	URL:	/api/v1/devicetemplate/:templateid/dataport/:portnumber
//	Method:	GET
//	Params: templateid. portnumber
//	Returns: Single data port defined for device template with templateid and portnum
コード例 #3
0
ファイル: repository_sync.php プロジェクト: sengkoil/openDCIM
curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_COOKIEFILE, "/tmp/repocookies.txt");
curl_setopt($c, CURLOPT_COOKIEJAR, "/tmp/repocookies.txt");
curl_setopt($c, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($c, CURLOPT_HTTPHEADER, array("UserID: " . $config->ParameterArray["APIUserID"], "APIKey: " . $config->ParameterArray["APIKey"], "Content-Type: application/json"));
foreach ($tList as $temp) {
    if ($temp->ManufacturerID != $m->ManufacturerID) {
        $m->ManufacturerID = $temp->ManufacturerID;
        $m->GetManufacturerByID();
    }
    $temp->ManufacturerID = $m->GlobalID;
    $tp = new TemplatePorts();
    $tp->TemplateID = $temp->TemplateID;
    $tpList = $tp->getPorts();
    // Convert the base template object to an associative array for easier manipulation
    $postData["template"] = json_decode(json_encode($temp), true);
    $postData["templateports"] = array();
    foreach ($tpList as $tport) {
        array_push($postData["templateports"], json_decode(json_encode($tport), true));
    }
    $tpp = new TemplatePowerPorts();
    $tpp->TemplateID = $temp->TemplateID;
    $tppList = $tpp->getPorts();
    $postData["templatepowerports"] = array();
    foreach ($tppList as $pport) {
        array_push($postData["templatepowerports"], json_decode(json_encode($pport), true));
    }
    if ($temp->DeviceType == "Chassis") {
        $sList = Slot::getSlots($temp->TemplateID);