New class: bizSubnet, implementing a dedicated view for IP management

SVN:trunk[147]
This commit is contained in:
Romain Quetiez
2009-09-11 16:38:12 +00:00
parent 455d9b23be
commit cc9420f009
4 changed files with 115 additions and 1 deletions

View File

@@ -980,6 +980,89 @@ class lnkInterfaces extends cmdbAbstractObject
}
}
////////////////////////////////////////////////////////////////////////////////////
/**
* A subnet
*/
////////////////////////////////////////////////////////////////////////////////////
class bizSubnet extends logInfra
{
public static function Init()
{
$aParams = array
(
"category" => "bizmodel,searchable",
"name" => "Subnet",
"description" => "Logical or physical subnet",
"key_type" => "",
"key_label" => "id",
"name_attcode" => "name",
"state_attcode" => "",
"reconc_keys" => array("org_name", "name"), // inherited attributes
"db_table" => "subnets",
"db_key_field" => "id",
"db_finalclass_field" => "",
"display_template" => "",
);
MetaModel::Init_Params($aParams);
MetaModel::Init_InheritAttributes();
MetaModel::Init_AddAttribute(new AttributeString("ip", array("label"=>"IP", "description"=>"IP", "allowed_values"=>null, "sql"=>"ip", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeString("mask", array("label"=>"IP mask", "description"=>"IP mask", "allowed_values"=>null, "sql"=>"mask", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
MetaModel::Init_InheritFilters();
MetaModel::Init_AddFilterFromAttribute("ip");
MetaModel::Init_AddFilterFromAttribute("mask");
// Display lists
MetaModel::Init_SetZListItems('details', array('name', 'ip','mask')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('list', array('name', 'ip', 'mask')); // Attributes to be displayed for a list
// Search criteria
MetaModel::Init_SetZListItems('standard_search', array('name', 'ip','mask')); // Criteria of the std search form
MetaModel::Init_SetZListItems('advanced_search', array('name', 'ip','mask')); // Criteria of the advanced search form
}
function DisplayBareRelations(web_page $oPage)
{
parent::DisplayBareRelations($oPage);
$oPage->SetCurrentTabContainer('Related Objects');
$oPage->SetCurrentTab('IP Usage');
$bit_ip = ip2long($this->Get('ip'));
$bit_mask = ip2long($this->Get('mask'));
$sIPMin = long2ip($bit_ip & $bit_mask);
$sIPMax = long2ip(($bit_ip | (~$bit_mask)) - 1);
$oPage->p("Interfaces having an IP in the range: <em>$sIPMin</em> to <em>$sIPMax</em>");
$oIfSet = new CMDBObjectSet(DBObjectSearch::FromOQL("SELECT bizInterface AS if WHERE INET_ATON(if.ip_address) >= INET_ATON('$sIPMin') AND INET_ATON(if.ip_address) <= INET_ATON('$sIPMax')"));
self::DisplaySet($oPage, $oIfSet);
$iCountUsed = $oIfSet->Count();
$iCountRange = ip2long($sIPMax) - ip2long($sIPMin);
$iFreeCount = $iCountRange - $iCountUsed;
$oPage->SetCurrentTab('Free IPs');
$oPage->p("Free IPs: $iFreeCount");
$oPage->p("Here is an extract of 10 free IP addresses");
$aUsedIPs = $oIfSet->GetColumnAsArray('ip_address', false);
$i = 0;
while ($i < min($iFreeCount, 10))
{
$i++;
$iAnIP = ip2long($sIPMin) + $i;
if (in_array($iAnIP, $aUsedIPs)) continue;
$sAnIP = long2ip($iAnIP);
$oPage->p($sAnIP);
}
}
}
////////////////////////////////////////////////////////////////////////////////////
/**
* Any electronic device

11
setup/data/21.subnets.xml Normal file
View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<Set>
<bizSubnet id="500">
<org_id>3</org_id>
<name>my subnet</name>
<status>implementation</status>
<criticity>low</criticity>
<ip>10.22.0.0</ip>
<mask>255.255.0.0</mask>
</bizSubnet>
</Set>

View File

@@ -26,3 +26,4 @@ wget --output-document=17.contactchangetickets.xml --post-data="auth_user=%USER%
wget --output-document=18.contracts.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT bizContract&format=xml"
wget --output-document=19.infracontracts.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT lnkInfraContract&format=xml"
wget --output-document=20.contactcontracts.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT lnkContactContract&format=xml"
wget --output-document=21.subnets.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT bizSubnet&format=xml"

View File

@@ -155,7 +155,26 @@
&lt;p&gt;&lt;/p&gt;
&lt;p style=&quot;text-align:center; font-family:Georgia, &apos;Times New Roman&apos;, Times, serif; font-size:24px;&quot;&gt;All Servers&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;itopblock BlockClass=&quot;DisplayBlock&quot; objectclass=&quot;bizContact&quot; type=&quot;list&quot; asynchronous=&quot;false&quot; encoding=&quot;text/sibusql&quot;&gt;bizServer&lt;/itopblock&gt;
&lt;itopblock BlockClass=&quot;DisplayBlock&quot; objectclass=&quot;bizServer&quot; type=&quot;list&quot; asynchronous=&quot;false&quot; encoding=&quot;text/sibusql&quot;&gt;bizServer&lt;/itopblock&gt;
&lt;/div&gt;
</template>
<type>application</type>
<rank>999</rank>
<parent_id>14</parent_id>
<user_id>0</user_id>
</menuNode>
<menuNode id="90">
<name>All Subnets</name>
<label>All subnets</label>
<hyperlink>UI.php</hyperlink>
<icon_path></icon_path>
<template>&lt;itopblock BlockClass=&quot;DisplayBlock&quot; objectclass=&quot;bizSubnet&quot; type=&quot;search&quot; asynchronous=&quot;false&quot; encoding=&quot;text/sibusql&quot;&gt;bizSubnet&lt;/itopblock&gt;
&lt;div id=&quot;BottomPane&quot;&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style=&quot;text-align:center; font-family:Georgia, &apos;Times New Roman&apos;, Times, serif; font-size:24px;&quot;&gt;All Subnets&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;itopblock BlockClass=&quot;DisplayBlock&quot; objectclass=&quot;bizSubnet&quot; type=&quot;list&quot; asynchronous=&quot;false&quot; encoding=&quot;text/sibusql&quot;&gt;bizSubnet&lt;/itopblock&gt;
&lt;/div&gt;
</template>
<type>application</type>