Przeglądaj źródła

Re-integrated computation of free IPs into the new data model

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@517 a333f486-631f-4898-b8df-5754b55c2be0
romainq 15 lat temu
rodzic
commit
1022d61dd9

+ 13 - 0
modules/itop-config-mgmt-1.0.0/en.dict.itop-config-mgmt.php

@@ -766,6 +766,19 @@ Dict::Add('EN US', 'English', 'English', array(
 ));
 ));
 
 
 
 
+
+//
+// Class extensions
+//
+
+Dict::Add('EN US', 'English', 'English', array(
+'Class:Subnet/Tab:IPUsage' => 'IP Usage',
+'Class:Subnet/Tab:IPUsage-explain' => 'Interfaces having an IP in the range: <em>%1$s</em> to <em>%2$s</em>',
+'Class:Subnet/Tab:FreeIPs' => 'Free IPs',
+'Class:Subnet/Tab:FreeIPs-count' => 'Free IPs: %1$s',
+'Class:Subnet/Tab:FreeIPs-explain' => 'Here is an extract of 10 free IP addresses',
+));
+
 //
 //
 // Application Menu
 // Application Menu
 //
 //

+ 47 - 0
modules/itop-config-mgmt-1.0.0/model.itop-config-mgmt.php

@@ -382,11 +382,58 @@ class Subnet extends cmdbAbstractObject
 		MetaModel::Init_SetZListItems('standard_search', array('name', 'description', 'ip', 'ip_mask'));
 		MetaModel::Init_SetZListItems('standard_search', array('name', 'description', 'ip', 'ip_mask'));
 		MetaModel::Init_SetZListItems('list', array('description', 'ip', 'ip_mask'));
 		MetaModel::Init_SetZListItems('list', array('description', 'ip', 'ip_mask'));
 	}
 	}
+
 	public function ComputeValues()
 	public function ComputeValues()
 	{
 	{
 		$sName = $this->Get('ip').'/'.$this->Get('ip_mask');
 		$sName = $this->Get('ip').'/'.$this->Get('ip_mask');
 		$this->Set('name', $sName);
 		$this->Set('name', $sName);
 	}
 	}
+
+	function DisplayBareRelations(WebPage $oPage)
+	{
+		parent::DisplayBareRelations($oPage);
+
+		$oPage->SetCurrentTab(Dict::S('Class:Subnet/Tab:IPUsage'));
+
+		$bit_ip = ip2long($this->Get('ip'));
+		$bit_mask = ip2long($this->Get('ip_mask'));
+
+		$iIPMin = $bit_ip & $bit_mask;
+		$iIPMax = ($bit_ip | (~$bit_mask)) - 1;
+
+		$sIPMin = long2ip($iIPMin);
+		$sIPMax = long2ip($iIPMax);
+
+		$oPage->p(Dict::Format('Class:Subnet/Tab:IPUsage-explain', $sIPMin, $sIPMax));
+		
+		$oIfSet = new CMDBObjectSet(DBObjectSearch::FromOQL("SELECT NetworkInterface 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 = $iIPMax - $iIPMin;
+		$iFreeCount =  $iCountRange - $iCountUsed;
+
+		$oPage->SetCurrentTab(Dict::S('Class:Subnet/Tab:FreeIPs'));
+		$oPage->p(Dict::Format('Class:Subnet/Tab:FreeIPs-count', $iFreeCount));
+		$oPage->p(Dict::S('Class:Subnet/Tab:FreeIPs-explain'));
+
+		$aUsedIPs = $oIfSet->GetColumnAsArray('ip_address', false);
+		$iAnIP = $iIPMin;
+		$iFound = 0;
+		while (($iFound < min($iFreeCount, 10)) && ($iAnIP <= $iIPMax))
+		{
+			$sAnIP = long2ip($iAnIP);
+			if (!in_array($sAnIP, $aUsedIPs))
+			{
+				$iFound++;
+				$oPage->p($sAnIP);
+			}
+			else
+			{
+			}
+			$iAnIP++;
+		}
+	}
 }
 }
 class Patch extends cmdbAbstractObject
 class Patch extends cmdbAbstractObject
 {
 {