structure of Automating
This commit is contained in:
parent
7e5b9f3a72
commit
0fc14b5761
2 changed files with 56 additions and 71 deletions
|
@ -1,48 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
include('InitTest.php');
|
include('InitTest.php');
|
||||||
include_once("../core/Image.php");
|
include_once("../core/Automating.php");
|
||||||
include_once("../core/Compute.php");
|
|
||||||
include_once("../core/Network.php");
|
|
||||||
//include_once("../core/Automating.php");
|
|
||||||
include_once("../core/NetworkLayer3.php");
|
|
||||||
|
|
||||||
$image = new Image($App);
|
$automating = new Automating($App);
|
||||||
$compute = new Compute($App);
|
|
||||||
$networkLayer3 = new NetworkLayer3($App);
|
|
||||||
//$automating = new Automating($App);
|
|
||||||
|
|
||||||
// Liste des serveurs
|
//$id = // id du réseau
|
||||||
echo "Liste des serveurs : </br>";
|
|
||||||
$compute->action("listServers");
|
|
||||||
$servers = json_decode($App->show(), true)["Servers"];
|
|
||||||
$id = null;
|
|
||||||
foreach($servers as $server){
|
|
||||||
echo $server['name']." ".$server['id']." ".$server['ipv4']."<br>";
|
|
||||||
if(strcmp($server['name'], "bob")){
|
|
||||||
$id = $server['id'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
echo "</br>";
|
|
||||||
|
|
||||||
|
|
||||||
//Liste des networks
|
|
||||||
echo "Liste des network : </br>";
|
|
||||||
$network->action("list_network_ids");
|
|
||||||
$servers = json_decode($App->show(), true)["ListNetworkIds"];
|
|
||||||
$id = null;
|
|
||||||
foreach($servers as $server){
|
|
||||||
echo $server."<br>";
|
|
||||||
}
|
|
||||||
echo "</br>";
|
|
||||||
|
|
||||||
|
|
||||||
// liste des floatingip
|
|
||||||
echo "Liste des floatingip : </br>";
|
|
||||||
$networkLayer3->action("listFloatingIp");
|
|
||||||
$listFloatingIp = json_decode($App->show(), true)["NetworkLayer3"];
|
|
||||||
foreach ($listFloatingIp as $floatIp){
|
|
||||||
echo $floatIp['floatingIpAddress']." ".$floatIp['id']." ".$floatIp["status"]."<br>";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Création serveur avec ip publique
|
||||||
|
echo "Test création serveur avec ip publique : </br>";
|
||||||
|
$App->setPostParam('networkId', $id);
|
||||||
|
$App->setPostParam('imageName', "ImageTest");
|
||||||
|
$App->setPostParam('serverName', "ServerTest");
|
||||||
|
$App->setPostParam('flavor', 1);
|
||||||
|
$compute->action("createPublicServer");
|
||||||
|
$servers = json_decode($App->show(), true)["Automating"];
|
||||||
|
*/
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -10,20 +10,18 @@
|
||||||
* @todo Complete the functions with errors detection and finish the descriptions
|
* @todo Complete the functions with errors detection and finish the descriptions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
include("CoreInterface.php");
|
|
||||||
include("Image.php");
|
include("Image.php");
|
||||||
include("Network.php");
|
include("Network.php");
|
||||||
include("Compute.php");
|
include("Compute.php");
|
||||||
include("NetworkLayer3");
|
include("NetworkLayer3.php");
|
||||||
|
|
||||||
class automating implements Core{
|
class automating{
|
||||||
|
|
||||||
/** @var App $app protected, contains the main app object */
|
/** @var App $app protected, contains the main app object */
|
||||||
protected $appCompute;
|
protected $compute;
|
||||||
protected $appImage;
|
protected $image;
|
||||||
protected $appNetwork;
|
protected $network;
|
||||||
protected $appIdentity;
|
protected $networkLayer3;
|
||||||
protected $appNetworkLayer3;
|
|
||||||
protected $app;
|
protected $app;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,15 +32,11 @@ class automating implements Core{
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public function __construct($app){
|
public function __construct($app){
|
||||||
if(!isset($app)){
|
|
||||||
$this->app->setOutput("Error", "Parameter app missing.");
|
|
||||||
}
|
|
||||||
$this->appCompute = $appCompute;
|
|
||||||
$this->appImage = $appImage;
|
|
||||||
$this->appNetwork = $appNetwork;
|
|
||||||
$this->appIdentity = $appIdentity;
|
|
||||||
$this->appNetworkLayer3 = $appNetworkLayer3;
|
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
|
$compute = new Compute($app);
|
||||||
|
$image = new Image($app);
|
||||||
|
$network = new Network($app);
|
||||||
|
$networkLayer3 = new NetworkLayer3($app);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,14 +53,16 @@ class automating implements Core{
|
||||||
/**
|
/**
|
||||||
* create a new server and associate a public ip
|
* create a new server and associate a public ip
|
||||||
*
|
*
|
||||||
|
* @param String $networkId the id of the network where the server will be created
|
||||||
* @param String $imageName name of the new image
|
* @param String $imageName name of the new image
|
||||||
* @param String $serverName name ofthe new server
|
* @param String $serverName name ofthe new server
|
||||||
* @param String $flavor kind of server
|
* @param String $flavor kind of server
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function createServer()
|
private function createPublicServer()
|
||||||
{
|
{
|
||||||
|
$networkId = $this->app->getPostParam('networkId');
|
||||||
$imageName = $this->app->getPostParam('imageName');
|
$imageName = $this->app->getPostParam('imageName');
|
||||||
$serverName = $this->app->getPostParam('serverName');
|
$serverName = $this->app->getPostParam('serverName');
|
||||||
$flavor = $this->app->getPostParam('flavor');
|
$flavor = $this->app->getPostParam('flavor');
|
||||||
|
@ -84,27 +80,44 @@ class automating implements Core{
|
||||||
// Création image
|
// Création image
|
||||||
$opt = array();
|
$opt = array();
|
||||||
$opt['name'] = $imageName;
|
$opt['name'] = $imageName;
|
||||||
$this->appImage->setPostParam('opt' $opt);
|
$image->setPostParam('opt', $opt);
|
||||||
$this->appImage->createImage();
|
$image->action("createImage");
|
||||||
$image = json_decode($this->app->show(), true)["Images"];
|
$image = json_decode($this->app->show(), true)["Images"];
|
||||||
|
|
||||||
// Création server
|
// Création server
|
||||||
$this->appCompute->setPostParam('name', $serverName);
|
$compute->setPostParam('name', $serverName);
|
||||||
$this->appCompute->setPostParam('imageId', $image['id']);
|
$compute->setPostParam('imageId', $image['id']);
|
||||||
$this->appCompute->setPostParam('flavorId', $flavor);
|
$compute->setPostParam('flavorId', $flavor);
|
||||||
$this->appCompute->createServer();
|
$compute->action("createServer");
|
||||||
$server = json_decode($this->app->show(), true)["Compute"];
|
$server = json_decode($this->app->show(), true)["Compute"];
|
||||||
|
|
||||||
// Ajout adresse IP public
|
// liste des adresses ip publiques diponibles
|
||||||
$optIp = array();
|
$networkLayer3->action("listFloatingIp");
|
||||||
$opt['floatingip'] = null; //new floatingip(); ???
|
$listFloatingIp = json_decode($App->show(), true)["NetworkLayer3"];
|
||||||
$opt['floating_network_id'] = $server['id'];
|
$ip = null;
|
||||||
$this->appFloatingIp->setPostParam('opt', $optIp);
|
foreach ($listFloatingIp as $f) {
|
||||||
$this->appFloatingIp->create();
|
if(strcmp($f['status'], "DOWN")){
|
||||||
|
$ip = $f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si pas d'ip publique disponible on en créé une
|
||||||
|
if(!isset($ip)){
|
||||||
|
// Ajout adresse IP public
|
||||||
|
$optIp = array();
|
||||||
|
$opt['floatingNetworkId'] = $networkId;
|
||||||
|
$floatingIp->setPostParam('opt', $optIp);
|
||||||
|
$networkLayer3->action("createFloatingIp");
|
||||||
|
$ip = json_decode($App->show(), true)["NetworkLayer3"];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Association de l'ip publique au serveur
|
||||||
|
/*
|
||||||
|
* API non diponible pour le moment
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Add table
Reference in a new issue