$response['errorcode'] = 200; $response['devicetemplate'] = $d; } } echoResponse(200, $response); }); // // URL: /api/v1/devicetemplate/:templateid/dataport/:portnum // Method: PUT // Params: // Required: templateid, portnum, portlabel // Optional: everything else // Returns: record as created // $app->put('/devicetemplate/:templateid/dataport/:portnum', function ($templateid, $portnum) use($app, $person) { $tp = new TemplatePorts(); foreach ($app->request->put() as $prop => $val) { $tp->{$prop} = $val; } // This should be in the commit data but if we get a smartass saying it's in the URL $tp->TemplateID = $templateid; $tp->PortNumber = $portnum; if (!$person->WriteAccess) { $response['error'] = true; $response['errorcode'] = 403; $response['message'] = __("Unauthorized"); } else { if (!$tp->CreatePort()) { $response['error'] = true; $response['errorcode'] = 404; $response['message'] = __("Device template port creation failed");
function UpdateSlotsPorts($template, $status) { //Update slots $template->DeleteSlots(); for ($i = 1; $i <= $template->ChassisSlots; $i++) { $slot = new Slot(); $slot->TemplateID = $template->TemplateID; $slot->Position = $i; $slot->BackSide = False; $slot->X = isset($_POST["XF" . $i]) ? $_POST["XF" . $i] : 0; $slot->Y = isset($_POST["YF" . $i]) ? $_POST["YF" . $i] : 0; $slot->W = isset($_POST["WF" . $i]) ? $_POST["WF" . $i] : 0; $slot->H = isset($_POST["HF" . $i]) ? $_POST["HF" . $i] : 0; $status = $slot->CreateSlot() ? $status : __("Error updating front slots"); } for ($i = 1; $i <= $template->RearChassisSlots; $i++) { $slot = new Slot(); $slot->TemplateID = $template->TemplateID; $slot->Position = $i; $slot->BackSide = True; $slot->X = isset($_POST["XR" . $i]) ? $_POST["XR" . $i] : 0; $slot->Y = isset($_POST["YR" . $i]) ? $_POST["YR" . $i] : 0; $slot->W = isset($_POST["WR" . $i]) ? $_POST["WR" . $i] : 0; $slot->H = isset($_POST["HR" . $i]) ? $_POST["HR" . $i] : 0; $status = $slot->CreateSlot() ? $status : __("Error updating rear slots"); } //update template ports $template->DeletePorts(); for ($i = 1; $i <= $template->NumPorts; $i++) { $tport = new TemplatePorts(); $tport->TemplateID = $template->TemplateID; $tport->PortNumber = $i; $tport->Label = isset($_POST["label" . $i]) ? $_POST["label" . $i] : ""; $tport->MediaID = isset($_POST["mt" . $i]) && $_POST["mt" . $i] > 0 ? $_POST["mt" . $i] : 0; $tport->ColorID = isset($_POST["cc" . $i]) && $_POST["cc" . $i] > 0 ? $_POST["cc" . $i] : 0; $tport->PortNotes = isset($_POST["portnotes" . $i]) ? $_POST["portnotes" . $i] : ""; $status = $tport->CreatePort() ? $status : __("Error updating template ports"); } $template->DeletePowerPorts(); //update template power connections for ($i = 1; $i <= $template->PSCount; $i++) { $tport = new TemplatePowerPorts(); $tport->TemplateID = $template->TemplateID; $tport->PortNumber = $i; $tport->Label = isset($_POST["powerlabel" . $i]) ? $_POST["powerlabel" . $i] : ""; $tport->PortNotes = isset($_POST["powerportnotes" . $i]) ? $_POST["powerportnotes" . $i] : ""; $status = $tport->CreatePort() ? $status : __("Error updating template power connections"); } return $status; }
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; }
static function RowToObject($dbRow) { $tp = new TemplatePorts(); $tp->TemplateID = $dbRow['TemplateID']; $tp->PortNumber = $dbRow['PortNumber']; $tp->Label = $dbRow['Label']; $tp->PortNotes = $dbRow['PortNotes']; $tp->MakeDisplay(); return $tp; }
} } } } $mList = $m->getSubscriptionList(); foreach ($mList as $man) { curl_setopt($c, CURLOPT_URL, 'https://repository.opendcim.org/api/template/bymanufacturer/' . $man->GlobalID); curl_setopt($c, CURLOPT_CUSTOMREQUEST, 'GET'); $result = curl_exec($c); $jr = json_decode($result); if (@$jr->errorcode == 200) { if (is_array($jr->templates)) { foreach ($jr->templates as $tem) { $tm = new Manufacturer(); $cs = new Slot(); $tp = new TemplatePorts(); $tpp = new TemplatePowerPorts(); foreach ($t as $prop => $val) { @($t->{$prop} = $tem->{$prop}); } $m->GlobalID = $t->ManufacturerID; $m->getManufacturerByGlobalID(); $t->ManufacturerID = $m->ManufacturerID; // Snag the images if ($t->FrontPictureFile != "") { $tmpname = explode(".", basename($t->FrontPictureFile), 2); $frontname = $picturedir . $tmpname[1]; grab_image($t->FrontPictureFile, $frontname); $t->FrontPictureFile = $tmpname[1]; } if ($t->RearPictureFile != "") {
} } } } } } // Push templates that you wish to share curl_setopt($c, CURLOPT_URL, "https://repository.opendcim.org/api/template"); curl_setopt($c, CURLOPT_CUSTOMREQUEST, "PUT"); 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)); }