mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
API Call to assign/remove a Portgroup to Ports (#13245)
* API Call to assign/remove a Portgroup to Ports * . * .
This commit is contained in:
@@ -1934,6 +1934,54 @@ function get_port_groups(Illuminate\Http\Request $request)
|
||||
return api_success($groups->makeHidden('pivot')->toArray(), 'groups', 'Found ' . $groups->count() . ' port groups');
|
||||
}
|
||||
|
||||
function assign_port_group(Illuminate\Http\Request $request)
|
||||
{
|
||||
$port_group_id = $request->route('port_group_id');
|
||||
$data = json_decode($request->getContent(), true);
|
||||
$port_id_list = $data['port_ids'];
|
||||
|
||||
if (json_last_error() || ! is_array($data)) {
|
||||
return api_error(400, "We couldn't parse the provided json. " . json_last_error_msg());
|
||||
}
|
||||
|
||||
if (! isset($port_id_list)) {
|
||||
return api_error(400, "Missing data field 'port_ids' " . json_last_error_msg());
|
||||
}
|
||||
|
||||
$port_group = PortGroup::find($port_group_id);
|
||||
if (! isset($port_group)) {
|
||||
return api_error(404, 'Port Group ID ' . $port_group_id . ' not found');
|
||||
}
|
||||
|
||||
$port_group->ports()->attach($port_id_list);
|
||||
|
||||
return api_success(200, 'Port Ids ' . implode(', ', $port_id_list) . ' have been added to Port Group Id ' . $port_group_id);
|
||||
}
|
||||
|
||||
function remove_port_group(Illuminate\Http\Request $request)
|
||||
{
|
||||
$port_group_id = $request->route('port_group_id');
|
||||
$data = json_decode($request->getContent(), true);
|
||||
$port_id_list = $data['port_ids'];
|
||||
|
||||
if (json_last_error() || ! is_array($data)) {
|
||||
return api_error(400, "We couldn't parse the provided json. " . json_last_error_msg());
|
||||
}
|
||||
|
||||
if (! isset($port_id_list)) {
|
||||
return api_error(400, "Missing data field 'port_ids' " . json_last_error_msg());
|
||||
}
|
||||
|
||||
$port_group = PortGroup::find($port_group_id);
|
||||
if (! isset($port_group)) {
|
||||
return api_error(404, 'Port Group ID ' . $port_group_id . ' not found');
|
||||
}
|
||||
|
||||
$port_group->ports()->detach($port_id_list);
|
||||
|
||||
return api_success(200, 'Port Ids ' . implode(', ', $port_id_list) . ' have been removed from Port Group Id ' . $port_group_id);
|
||||
}
|
||||
|
||||
function add_device_group(Illuminate\Http\Request $request)
|
||||
{
|
||||
$data = json_decode($request->getContent(), true);
|
||||
|
||||
Reference in New Issue
Block a user