Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented feature to allocate IPs to an object in bulk. #205

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions wwwroot/inc/interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -1911,6 +1911,21 @@ function printNewItemTR ($default_type, $object_id)

echo "</table><br>\n";
finishPortlet();

startPortlet ('Same OS interface, same type');
printOpFormIntro ('addLotOf');
echo "<table border='0' align='center'><tr><th>IP address</th><th>OS interface</th></tr>";
echo "<tr><td rowspan='3'><textarea name='iplist' cols='40' rows='25'>\n";
echo "</textarea></td><td valign='top'>";
echo "<input type='text' size='10' name='bond_name'>";
echo "</td></tr>";
echo "<tr><th>type</th></tr>";
echo "<tr><td valign='top'>";
printSelect ($aat, array ('name' => 'bond_type'), $most_popular_type); // type
echo "</td></tr>";
echo "<tr><td colspan=2><input type='submit' name='got_very_fast_data' value='Go!'></td></tr></table>\n";
echo "</form>\n";
finishPortlet();
}

// This function is deprecated. Do not rely on its internals,
Expand Down
1 change: 1 addition & 0 deletions wwwroot/inc/navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
$ophandler['object']['ports']['unlinkPort'] = 'unlinkPort';
$ophandler['object']['ip']['upd'] = 'updIPAllocation';
$ophandler['object']['ip']['add'] = 'addIPAllocation';
$ophandler['object']['ip']['addLotOf'] = 'addLotOfIPAllocation';
$ophandler['object']['ip']['del'] = 'delIPAllocation';
$ophandler['object']['edit']['clearSticker'] = 'clearSticker';
$ophandler['object']['edit']['update'] = 'updateObject';
Expand Down
50 changes: 44 additions & 6 deletions wwwroot/inc/ophandlers.php
Original file line number Diff line number Diff line change
Expand Up @@ -973,12 +973,10 @@ function delIPAllocation ()
showFuncMessage (__FUNCTION__, 'OK');
}

function addIPAllocation ()
// Check if IP can be allocated
// Returns false on critical error.
function checkIPAllocation($ip_bin, $alloc_type)
{
setFuncMessages (__FUNCTION__, array ('OK' => 48, 'ERR1' => 170));
$ip_bin = assertIPArg ('ip');
$alloc_type = genericAssertion ('bond_type', 'enum/alloc_type');

// check if address is alread allocated
$address = getIPAddress($ip_bin);

Expand All @@ -988,7 +986,7 @@ function addIPAllocation ()
if (getConfigVar ('IPV4_JAYWALK') != 'yes' && NULL === getIPAddressNetworkId ($ip_bin))
{
showFuncMessage (__FUNCTION__, 'ERR1', array (ip_format ($ip_bin)));
return;
return false;
}

if($address['reserved'] && $address['name'] != '')
Expand All @@ -997,6 +995,18 @@ function addIPAllocation ()
//TODO ask to take reserved IP or not !
}

return true;
}

function addIPAllocation ()
{
setFuncMessages (__FUNCTION__, array ('OK' => 48, 'ERR1' => 170));
$ip_bin = assertIPArg ('ip');
$alloc_type = genericAssertion ('bond_type', 'enum/alloc_type');

if (!checkIPAllocation($ip_bin, $alloc_type))
return;

bindIPToObject
(
$ip_bin,
Expand All @@ -1009,6 +1019,34 @@ function addIPAllocation ()
return buildRedirectURL (NULL, NULL, array ('hl_ip' => ip_format ($ip_bin)));
}

function addLotOfIPAllocation()
{
assertStringArg ('iplist', TRUE);
$object_id = genericAssertion ('object_id', 'uint');
$bond_name = genericAssertion ('bond_name', 'string0');
$alloc_type = genericAssertion ('bond_type', 'enum/alloc_type');

foreach (textareaCooked ($_REQUEST['iplist']) as $ip)
try
{
$ip_bin = ip_parse ($ip);
checkIPAllocation($ip_bin, $alloc_type);
bindIPToObject
(
$ip_bin,
$object_id,
$bond_name,
$alloc_type
);
showSuccess ('Allocated IP '.ip_format ($ip_bin));
}
catch (RackTablesError $e)
{
showError ("Failed to allocate ip '$ip': " . $e->getMessage());
}
return buildRedirectURL (NULL, NULL);
}

function addIPv4Prefix ()
{
global $sic;
Expand Down