Connect interfaces to each other (1-1 link)

SVN:trunk[816]
This commit is contained in:
Romain Quetiez
2010-09-10 18:51:09 +00:00
parent dfb1ae83c7
commit 1a4c3c98f1
2 changed files with 51 additions and 1 deletions

View File

@@ -84,6 +84,7 @@ abstract class CMDBObject extends DBObject
{
protected $m_datCreated;
protected $m_datUpdated;
// Note: this value is static, but that could be changed because it is sometimes a real issue (see update of interfaces / connected_to
protected static $m_oCurrChange = null;

View File

@@ -845,7 +845,7 @@ class DatabaseInstance extends FunctionalCI
MetaModel::Init_Params($aParams);
MetaModel::Init_InheritAttributes();
MetaModel::Init_AddAttribute(new AttributeExternalKey("db_server_instance_id", array("targetclass"=>"DBServerInstance", "jointype"=>null, "allowed_values"=>new ValueSetObjects('SELECT DBServerInstance WHERE org_id = :this->org_id'), "sql"=>"db_server_instance_id", "is_null_allowed"=>true, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array("org_id"))));
MetaModel::Init_AddAttribute(new AttributeExternalKey("db_server_instance_id", array("targetclass"=>"DBServerInstance", "jointype"=>null, "allowed_values"=>new ValueSetObjects('SELECT DBServerInstance WHERE org_id = :this->org_id'), "sql"=>"db_server_instance_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array("org_id"))));
MetaModel::Init_AddAttribute(new AttributeExternalField("db_server_instance_name", array("allowed_values"=>null, "extkey_attcode"=>"db_server_instance_id", "target_attcode"=>"name", "is_null_allowed"=>true, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeExternalField("db_server_instance_version", array("allowed_values"=>null, "extkey_attcode"=>"db_server_instance_id", "target_attcode"=>"version", "is_null_allowed"=>true, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeWikiText("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
@@ -1068,6 +1068,55 @@ class NetworkInterface extends ConnectableCI
return parent::GetRelationQueries($sRelCode);
}
}
protected function UpdateConnectedInterface()
{
$oConnIf = MetaModel::GetObject('NetworkInterface', $this->Get('connected_if'), false /* no exception if not found */);
if (!is_null($oConnIf))
{
$sLink = $this->Get('link_type');
$sConnLink = ($sLink == 'uplink') ? 'downlink' : 'uplink';
if (($oConnIf->Get('connected_if') != $this->GetKey()) || ($sConnLink != $oConnIf->Get('link_type')))
{
// Something has to be changed on the connected interface...
if ($oConnIf->Get('connected_if') != $this->GetKey())
{
// It is connected to another interface: reset that third one...
$oThirdIf = MetaModel::GetObject('NetworkInterface', $oConnIf->Get('connected_if'), false);
if (!is_null($oThirdIf))
{
$oThirdIf->Set('connected_if', 0);
// Need to backup the current change, because it is reset when DBUpdateTracked is complete
$oCurrChange = self::$m_oCurrChange;
$oThirdIf->DBUpdateTracked($oCurrChange);
self::$m_oCurrChange = $oCurrChange;
}
}
// Connect the remote interface to the current one
$oConnIf->Set('connected_if', $this->GetKey());
$oConnIf->Set('link_type', $sConnLink);
// Need to backup the current change, because it is reset when DBUpdateTracked is complete
$oCurrChange = self::$m_oCurrChange;
$oConnIf->DBUpdateTracked($oCurrChange);
self::$m_oCurrChange = $oCurrChange;
}
}
}
protected function AfterInsert()
{
$this->UpdateConnectedInterface();
parent::AfterInsert();
}
protected function AfterUpdate()
{
$this->UpdateConnectedInterface();
parent::AfterUpdate();
}
}
abstract class Device extends ConnectableCI
{