Skip to content

Commit

Permalink
[IM] Allow IP addresses to be removed from disabled interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
barryo committed Aug 24, 2014
1 parent 9980cfe commit c427348
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions library/IXP/Controller/Trait/Interfaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,22 @@ private function setIp( $form, $vi, $vli, $ipv6 = false )
$iptype = $ipv6 ? "ipv6" : "ipv4";
$ipVer = $ipv6 ? "IPv6" : "IPv4";
$setter = "set{$ipVer}Address";
$getter = "get{$ipVer}Address";
$entity = "\\Entities\\{$ipVer}Address";
$vlan = $vli->getVlan();

if( $form->getValue( $iptype . "enabled" ) )
{
if( !$form->getElement( $iptype . 'addressid' )->getValue() )
{
$form->getElement( $iptype . 'addressid' )->setErrors( ["Please select or enter an {$ipVer} address."] );
return false;
}

$ip = $this->getD2EM()->getRepository( $entity )->findOneBy(
[ "Vlan" => $vlan->getId(), 'address' => $form->getElement( $iptype . 'addressid' )->getValue() ]
);

if( !$ip )
{
$ip = new $entity();
Expand All @@ -83,10 +84,19 @@ private function setIp( $form, $vi, $vli, $ipv6 = false )
$form->getElement( $iptype . 'addressid' )->setErrors( ["{$ipVer} address '{$address}' is already in use." ] );
return false;
}

$vli->$setter( $ip );
}

else
{
// ipvX has been disabled - see if we need to remove an assigned IP address
if( !$form->getElement( $iptype . 'addressid' )->getValue() && $vli->$getter() )
{
// need to unset the IP address
$vli->$setter( null );
}
}

return true;
}

Expand Down Expand Up @@ -119,25 +129,25 @@ protected function processFanoutPhysicalInterface( $form, $pi, $vi )
$this->removeRelatedInterface( $pi );
$pi->setFanoutPhysicalInterface( null );
}

return true;
}

// from here on, we assume $form->getValue( 'fanout' ) is true

if( !$form->getValue( 'fn_switchid' ) )
{
$form->getElement( 'fn_switchid' )->setErrorMessages( ['Please select a switch'] )->markAsError();
$form->getElement( 'fn_switchportid' )->setErrorMessages( ['Please select a switchport'] )->markAsError();
return false;
}

if( !$form->getValue( 'fn_switchportid' ) )
{
$form->getElement( 'fn_switchportid' )->setErrorMessages( ['Please select a switchport'] )->markAsError();
return false;
}

if( $form->getElement( 'fn_monitorindex' ) )
{
if( !$form->getValue( 'fn_monitorindex' ) )
Expand All @@ -156,11 +166,11 @@ protected function processFanoutPhysicalInterface( $form, $pi, $vi )

$fnsp = $this->getD2R( '\\Entities\\SwitchPort' )->find( $form->getElement( 'fn_switchportid' )->getValue() );
$fnsp->setType( \Entities\SwitchPort::TYPE_FANOUT );

// if switchport does not have a physical interface then create one for it
if( !$fnsp->getPhysicalInterface() )
{

$fnphi = new \Entities\PhysicalInterface();
$fnphi->setSwitchPort( $fnsp );
$fnsp->setPhysicalInterface( $fnphi );
Expand All @@ -170,15 +180,15 @@ protected function processFanoutPhysicalInterface( $form, $pi, $vi )
else
{
$fnphi = $fnsp->getPhysicalInterface();

// checking if the fanout port already has physical interface and it is not this one
if( $fnsp->getPhysicalInterface()->getRelatedInterface() && $fnsp->getPhysicalInterface()->getRelatedInterface()->getId() != $pi->getId() )
{
$this->addMesssage( "Selected fanout port already has a related physical interface.", OSS_Message::ERROR );
return false;
}
}

// if the physical interace already has a related physical interface and it's not the same as the fanout physical interface
if( $pi->getRelatedInterface() && $pi->getRelatedInterface()->getId() != $fnphi->getId() )
{
Expand All @@ -188,7 +198,7 @@ protected function processFanoutPhysicalInterface( $form, $pi, $vi )
$pi->getRelatedInterface()->getVirtualInterface()->addPhysicalInterface( $fnphi );
$fnphi->setVirtualInterface( $pi->getRelatedInterface()->getVirtualInterface() );
}

$this->removeRelatedInterface( $pi );
}
else if( !$fnphi->getVirtualInterface() )
Expand Down Expand Up @@ -235,4 +245,3 @@ private function removeRelatedInterface( $pi )
}
}
}

0 comments on commit c427348

Please sign in to comment.