Basic allocation information

Allows deleting ports, nothing else yet
This commit is contained in:
Dane Everitt 2016-01-08 20:01:18 -05:00
parent 2160613163
commit 54bef1e7d5
3 changed files with 114 additions and 1 deletions

View file

@ -67,6 +67,23 @@ class NodesController extends Controller
public function getView(Request $request, $id)
{
$node = Models\Node::findOrFail($id);
$allocations = [];
$alloc = Models\Allocation::select('ip', 'port', 'assigned_to')->where('node', $node->id)->get();
if ($alloc) {
foreach($alloc as &$alloc) {
if (!array_key_exists($alloc->ip, $allocations)) {
$allocations[$alloc->ip] = [[
'port' => $alloc->port,
'assigned_to' => $alloc->assigned_to
]];
} else {
array_push($allocations[$alloc->ip], [
'port' => $alloc->port,
'assigned_to' => $alloc->assigned_to
]);
}
}
}
return view('admin.nodes.view', [
'node' => $node,
'servers' => Models\Server::select('servers.*', 'users.email as a_ownerEmail', 'services.name as a_serviceName')
@ -75,6 +92,7 @@ class NodesController extends Controller
->where('node', $id)->paginate(10),
'stats' => Models\Server::select(DB::raw('SUM(memory) as memory, SUM(disk) as disk'))->where('node', $node->id)->first(),
'locations' => Models\Location::all(),
'allocations' => json_decode(json_encode($allocations), false),
]);
}
@ -104,4 +122,16 @@ class NodesController extends Controller
])->withInput();
}
public function deletePortAllocation(Request $request, $id, $ip, $port)
{
$allocation = Models\Allocation::where('node', $id)->whereNull('assigned_to')->where('ip', $ip)->where('port', $port)->first();
if (!$allocation) {
return response()->json([
'error' => 'Unable to find an allocation matching those details to delete.'
], 400);
}
$allocation->delete();
return response('', 204);
}
}

View file

@ -172,6 +172,10 @@ class AdminRoutes {
'uses' => 'Admin\NodesController@postView'
]);
$router->delete('/view/{id}/allocation/{ip}/{port}', [
'uses' => 'Admin\NodesController@deletePortAllocation'
]);
});
}