/** * Function to delete a lab node. * * @param Lab $lab Lab * @param int $id Node ID * @return Array Return code (JSend data) */ function apiDeleteLabNode($lab, $id, $tenant) { // Delete all tmp files for the node $cmd = 'sudo /opt/unetlab/wrappers/unl_wrapper -a delete -T 0 -D ' . $id . ' -F "' . $lab->getPath() . '/' . $lab->getFilename() . '"'; // Tenant not required for delete operation exec($cmd, $o, $rc); // Stop the node foreach (scandir("/opt/unetlab/tmp/") as $value) { if (is_dir("/opt/unetlab/tmp/" . $value) and intval($value) >= 0) { $output = apiStopLabNode($lab, $id, intval($value)); file_put_contents("/tmp/ade", $value, FILE_APPEND); if ($output['status'] == 400) { return $output; } } } // Deleting the node $rc = $lab->deleteNode($id); if ($rc === 0) { $output['code'] = 200; $output['status'] = 'success'; $output['message'] = $GLOBALS['messages'][60023]; } else { $output['code'] = 400; $output['status'] = 'fail'; $output['message'] = $GLOBALS['messages'][$rc]; } return $output; }
$app->response->setBody(json_encode($output)); return; } $output = apiStartLabNode($lab, $id, $tenant); } else { if (preg_match('/^\\/[A-Za-z0-9_+\\/\\s-]+\\.unl\\/nodes\\/[0-9]+\\/stop$/', $s)) { if ($tenant < 0) { // User does not have an assigned tenant $output['code'] = 400; $output['status'] = 'fail'; $output['message'] = $GLOBALS['messages']['60052']; $app->response->setStatus($output['code']); $app->response->setBody(json_encode($output)); return; } $output = apiStopLabNode($lab, $id, $tenant); } else { if (preg_match('/^\\/[A-Za-z0-9_+\\/\\s-]+\\.unl\\/nodes\\/[0-9]+\\/wipe$/', $s)) { if ($tenant < 0) { // User does not have an assigned tenant $output['code'] = 400; $output['status'] = 'fail'; $output['message'] = $GLOBALS['messages']['60052']; $app->response->setStatus($output['code']); $app->response->setBody(json_encode($output)); return; } $output = apiWipeLabNode($lab, $id, $tenant); } else { if (preg_match('/^\\/[A-Za-z0-9_+\\/\\s-]+\\.unl\\/topology$/', $s)) { if ($tenant < 0) {