448 lines
7.9 KiB
PHP
448 lines
7.9 KiB
PHP
<?php
|
|
|
|
class network{
|
|
|
|
protected $app;
|
|
|
|
protected $libClass;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct($app){
|
|
$this->app = $app;
|
|
$this->libClass = $app->getLibClass("network");
|
|
|
|
}
|
|
|
|
|
|
public function action($action){
|
|
|
|
$this->{$action.""}();
|
|
|
|
}
|
|
|
|
|
|
public function create_network($name,$adminStateUp,$shared,$tenantId)
|
|
{
|
|
$options = array();
|
|
if (!is_null($name))
|
|
{
|
|
$options['name'] = $name;
|
|
}
|
|
if (!is_null($adminStateUp))
|
|
{
|
|
$options['adminStateUp'] = $adminStateUp;
|
|
}
|
|
if (!is_null($shared))
|
|
{
|
|
$options['shared'] = $shared;
|
|
}
|
|
if (!is_null($tenantId))
|
|
{
|
|
$options['tenantId'] = $tenantId;
|
|
}
|
|
$network = $this->libClass->createNetworks($options);
|
|
|
|
|
|
return $network;
|
|
}
|
|
|
|
public function create_subnet($networkId,$ipVersion,$cidr,$name,$gatewayIp,$dnsNameservers,$allocationPools,$hostRoutes,$enableDhcp,$tenantId)
|
|
{ $options = array();
|
|
if (!is_null($networkId))
|
|
{
|
|
$options['networkId'] = $networkId;
|
|
}
|
|
if (!is_null($ipVersion))
|
|
{
|
|
$options['ipVersion'] = $ipVersion;
|
|
}
|
|
if (!is_null($cidr))
|
|
{
|
|
$options['cidr'] = $cidr;
|
|
}
|
|
if (!is_null($tenantId))
|
|
{
|
|
$options['tenantId'] = $tenantId;
|
|
}
|
|
if (!is_null($name))
|
|
{
|
|
$options['name'] = $name;
|
|
}
|
|
if (!is_null($gatewayIp))
|
|
{
|
|
$options['gatewayIp'] = $gatewayIp;
|
|
}
|
|
if (!is_null($dnsNameservers))
|
|
{
|
|
$options['dnsNameservers'] = $dnsNameservers;
|
|
}
|
|
if (!is_null($allocationPools))
|
|
{
|
|
$options['allocationPools'] = $allocationPools;
|
|
}
|
|
if (!is_null($hostRoutes))
|
|
{
|
|
$options['hostRoutes'] = $hostRoutes;
|
|
}
|
|
if (!is_null($enableDhcp))
|
|
{
|
|
$options['enableDhcp'] = $enableDhcp;
|
|
}
|
|
if (!is_null($tenantId))
|
|
{
|
|
$options['tenantId'] = $tenantId;
|
|
}
|
|
$subnet = $this->libClass->createSubnet($options);
|
|
|
|
|
|
return $subnet;
|
|
}
|
|
|
|
public function list_network_ids()
|
|
{
|
|
|
|
$ln = $this->libClass->listNetworks();
|
|
|
|
$list_ids = array();
|
|
|
|
|
|
foreach($ln as $n)
|
|
{
|
|
|
|
$list_ids[] = $n->id;
|
|
|
|
|
|
}
|
|
|
|
return $list_ids;
|
|
}
|
|
|
|
public function list_network_names()
|
|
{
|
|
|
|
$ln = $this->libClass->listNetworks();
|
|
|
|
$list_names = array();
|
|
|
|
|
|
foreach($ln as $n)
|
|
{
|
|
|
|
$list_names[] = $n->name;
|
|
|
|
|
|
}
|
|
|
|
return $list_names;
|
|
}
|
|
|
|
public function list_cidr()
|
|
{
|
|
|
|
$ls = $this->libClass->listSubnets();
|
|
$list_cidr = array();
|
|
foreach ($ls as $subnet)
|
|
{
|
|
|
|
$list_cidr[] = $subnet->cidr;
|
|
}
|
|
|
|
return $list_names;
|
|
}
|
|
//option array()
|
|
public function getNetwork($idNet)
|
|
{
|
|
$network="";
|
|
|
|
try
|
|
{ $newtork = $this->libClass->getNetwork($idNet);
|
|
$network->retrieve();
|
|
|
|
|
|
}
|
|
|
|
catch (OpenStack\Common\Error\BadResponseError $e)
|
|
{
|
|
$network = "Id non existant ";
|
|
}
|
|
catch (Exception $e)
|
|
{
|
|
$network = 'Exception reçue : ', $e->getMessage(), "\n";
|
|
}
|
|
|
|
return $network;
|
|
}
|
|
|
|
public function getSubnet($idSub)
|
|
{
|
|
$sbnet="";
|
|
|
|
try
|
|
{ $subnet = $this->libClass->getSubnet($idSub);
|
|
$subnet->retrieve();
|
|
|
|
return $sbnet;
|
|
}
|
|
|
|
catch (OpenStack\Common\Error\BadResponseError $e)
|
|
{
|
|
echo "Id non existant ";
|
|
}
|
|
catch (Exception $e)
|
|
{
|
|
echo 'Exception reçue : ', $e->getMessage(), "\n";
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public function updateNetwork($idNet,$name,$shared,$adminStateUp)
|
|
{
|
|
$network = getNetwork($idNet);
|
|
if(!is_null($name))
|
|
{
|
|
$network->name = $name;
|
|
}
|
|
if(!is_null($shared))
|
|
{
|
|
$network->shared = $shared;
|
|
}
|
|
if(!is_null($adminStateUp))
|
|
{
|
|
$network->adminStateUp = $shared;
|
|
}
|
|
$network->update();
|
|
}
|
|
|
|
public function updateSubnet($idSub,$name,$networkId,$ipVersion,$cidr)
|
|
{
|
|
$subnet = getNetwork($idSub);
|
|
if(!is_null($name))
|
|
{
|
|
$subnet->name = $name;
|
|
}
|
|
if(!is_null($networkId))
|
|
{
|
|
$subnet->networkId = $networkId;
|
|
}
|
|
if(!is_null($ipVersion))
|
|
{
|
|
$subnet->ipVersion = $ipVersion;
|
|
}
|
|
if(!is_null($cidr))
|
|
{
|
|
$subnet->cidr = $cidr;
|
|
}
|
|
$subnet->update();
|
|
}
|
|
|
|
public function deleteNetwork($idNet)
|
|
{
|
|
$network = getNetwork($idNet);
|
|
$network->delete();
|
|
}
|
|
|
|
public function deleteSubnet($idSub)
|
|
{
|
|
$subnet = getNetwork($idSub);
|
|
$subnet->delete();
|
|
}
|
|
|
|
public function createPort($networkId,$name,$adminStateUp,$macAddress,$fixedIps,$deviceId,$deviceOwner,$securityGroups,$tenantId)
|
|
{
|
|
$options = array();
|
|
if (!is_null($networkId))
|
|
{
|
|
$options['networkId'] = $networkId;
|
|
}
|
|
if (!is_null($name))
|
|
{
|
|
$options['name'] = $name;
|
|
}
|
|
if (!is_null($adminStateUp))
|
|
{
|
|
$options['adminStateUp'] = $adminStateUp;
|
|
}
|
|
if (!is_null($macAddress))
|
|
{
|
|
$options['macAddress'] = $macAddress;
|
|
}
|
|
if (!is_null($fixedIps))
|
|
{
|
|
$options['fixedIps'] = $fixedIps;
|
|
}
|
|
if (!is_null($deviceId))
|
|
{
|
|
$options['deviceId'] = $deviceId;
|
|
}
|
|
if (!is_null($deviceOwner))
|
|
{
|
|
$options['deviceOwner'] = $deviceOwner;
|
|
}
|
|
if (!is_null($securityGroups))
|
|
{
|
|
$options['securityGroups'] = $securityGroups;
|
|
}
|
|
if (!is_null($tenantId))
|
|
{
|
|
$options['tenantId'] = $tenantId;
|
|
}
|
|
|
|
$this->libClass->createPort($options);
|
|
}
|
|
|
|
public function listPorts()
|
|
{
|
|
return $this->libClass->listPorts();
|
|
}
|
|
|
|
public function getPort($portId)
|
|
{
|
|
try
|
|
{
|
|
$port = $this->libClass->getport($portId);
|
|
return $port;
|
|
}
|
|
catch (Exception $e)
|
|
{
|
|
echo 'id fourni non disponible';
|
|
}
|
|
|
|
}
|
|
|
|
public function updatePort($networkId,$name,$adminStateUp,$macAddress,$fixedIps,$deviceId,$deviceOwner,$securityGroups,$tenantId)
|
|
{
|
|
$options = array();
|
|
if (!is_null($networkId))
|
|
{
|
|
$options['networkId'] = $networkId;
|
|
}
|
|
if (!is_null($name))
|
|
{
|
|
$options['name'] = $name;
|
|
}
|
|
if (!is_null($adminStateUp))
|
|
{
|
|
$options['adminStateUp'] = $adminStateUp;
|
|
}
|
|
if (!is_null($macAddress))
|
|
{
|
|
$options['macAddress'] = $macAddress;
|
|
}
|
|
if (!is_null($fixedIps))
|
|
{
|
|
$options['fixedIps'] = $fixedIps;
|
|
}
|
|
if (!is_null($deviceId))
|
|
{
|
|
$options['deviceId'] = $deviceId;
|
|
}
|
|
if (!is_null($deviceOwner))
|
|
{
|
|
$options['deviceOwner'] = $deviceOwner;
|
|
}
|
|
if (!is_null($securityGroups))
|
|
{
|
|
$options['securityGroups'] = $securityGroups;
|
|
}
|
|
if (!is_null($tenantId))
|
|
{
|
|
$options['tenantId'] = $tenantId;
|
|
}
|
|
|
|
$this->libClass->update($options);
|
|
}
|
|
|
|
public function deletePort($portId)
|
|
{
|
|
$port = getPort($portId);
|
|
$port->delete();
|
|
}
|
|
|
|
public function createSecurityGroup($name,$description)
|
|
{
|
|
$options = array();
|
|
if (!is_null($name))
|
|
{
|
|
$options['name'] = $name;
|
|
}
|
|
if (!is_null($description))
|
|
{
|
|
$options['description'] = $description;
|
|
}
|
|
|
|
$this->libClass->createSecurityGroup($options);
|
|
}
|
|
|
|
public function createSecurityGroupRule($securityGroupId,$direction,$ethertype,$portRangeMin,$portRangeMax,$protocol,$remoteGroupId,$remoteIpPrefix)
|
|
{
|
|
$options = array();
|
|
if (!is_null($securityGroupId))
|
|
{
|
|
$options['securityGroupId'] = $securityGroupId;
|
|
}
|
|
if (!is_null($direction))
|
|
{
|
|
$options['direction'] = $direction;
|
|
}
|
|
if (!is_null($ethertype))
|
|
{
|
|
$options['ethertype'] = $ethertype;
|
|
}
|
|
if (!is_null($portRangeMin))
|
|
{
|
|
$options['portRangeMin'] = $portRangeMin;
|
|
}
|
|
if (!is_null($portRangeMax))
|
|
{
|
|
$options['portRangeMax'] = $portRangeMax;
|
|
}
|
|
if (!is_null($protocol))
|
|
{
|
|
$options['protocol'] = $protocol;
|
|
}
|
|
if (!is_null($remoteGroupId))
|
|
{
|
|
$options['remoteGroupId'] = $remoteGroupId;
|
|
}
|
|
if (!is_null($remoteIpPrefix))
|
|
{
|
|
$options['remoteIpPrefix'] = $remoteIpPrefix;
|
|
}
|
|
$this->libClass->createSecurityGroupRule($options);
|
|
}
|
|
|
|
|
|
public function listSecurityGroupe()
|
|
{
|
|
return $this->libClass->listSecurityGroups();
|
|
}
|
|
|
|
public function listSecurityGroupeRule()
|
|
{
|
|
return $this->libClass->listSecurityGroupRules();
|
|
}
|
|
|
|
public function getSecurityGroupe($securityGroupeId)
|
|
{
|
|
try
|
|
{
|
|
$securityGroupe = $this->libClass->getSecurityGroupe($securityGroupeId);
|
|
return $securityGroupe;
|
|
}
|
|
catch (Exception $e)
|
|
{
|
|
echo 'id fourni non disponible';
|
|
}
|
|
|
|
}
|
|
|
|
public function deleteSecurityGroupe($securityGroupeId)
|
|
{
|
|
$securityGroupe = getSecurityGroupe($securityGroupeId);
|
|
$securityGroupe->delete();
|
|
}
|