summaryrefslogtreecommitdiff
path: root/server/core/Automating.php
diff options
context:
space:
mode:
authorYoggzo <yogg@epsina.com>2016-04-21 23:57:37 +0200
committerYoggzo <yogg@epsina.com>2016-04-21 23:57:37 +0200
commit0fc14b5761e558680aecc57e4d1ae8075121f01e (patch)
treee54f60c8729892a16ba590d797a73e9f1ef2b7b6 /server/core/Automating.php
parent7e5b9f3a729b676c4efcf40769ed1631bf9fc0ba (diff)
structure of Automating
Diffstat (limited to 'server/core/Automating.php')
-rwxr-xr-xserver/core/Automating.php73
1 files changed, 43 insertions, 30 deletions
diff --git a/server/core/Automating.php b/server/core/Automating.php
index 4e212e7..fb42702 100755
--- a/server/core/Automating.php
+++ b/server/core/Automating.php
@@ -10,20 +10,18 @@
* @todo Complete the functions with errors detection and finish the descriptions
*/
-include("CoreInterface.php");
include("Image.php");
include("Network.php");
include("Compute.php");
-include("NetworkLayer3");
+include("NetworkLayer3.php");
-class automating implements Core{
+class automating{
/** @var App $app protected, contains the main app object */
- protected $appCompute;
- protected $appImage;
- protected $appNetwork;
- protected $appIdentity;
- protected $appNetworkLayer3;
+ protected $compute;
+ protected $image;
+ protected $network;
+ protected $networkLayer3;
protected $app;
/**
@@ -34,15 +32,11 @@ class automating implements Core{
* @return
*/
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;
+ $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
*
+ * @param String $networkId the id of the network where the server will be created
* @param String $imageName name of the new image
* @param String $serverName name ofthe new server
* @param String $flavor kind of server
*
* @return void
*/
- private function createServer()
+ private function createPublicServer()
{
+ $networkId = $this->app->getPostParam('networkId');
$imageName = $this->app->getPostParam('imageName');
$serverName = $this->app->getPostParam('serverName');
$flavor = $this->app->getPostParam('flavor');
@@ -84,27 +80,44 @@ class automating implements Core{
// Création image
$opt = array();
$opt['name'] = $imageName;
- $this->appImage->setPostParam('opt' $opt);
- $this->appImage->createImage();
+ $image->setPostParam('opt', $opt);
+ $image->action("createImage");
$image = json_decode($this->app->show(), true)["Images"];
// Création server
- $this->appCompute->setPostParam('name', $serverName);
- $this->appCompute->setPostParam('imageId', $image['id']);
- $this->appCompute->setPostParam('flavorId', $flavor);
- $this->appCompute->createServer();
+ $compute->setPostParam('name', $serverName);
+ $compute->setPostParam('imageId', $image['id']);
+ $compute->setPostParam('flavorId', $flavor);
+ $compute->action("createServer");
$server = json_decode($this->app->show(), true)["Compute"];
- // Ajout adresse IP public
- $optIp = array();
- $opt['floatingip'] = null; //new floatingip(); ???
- $opt['floating_network_id'] = $server['id'];
- $this->appFloatingIp->setPostParam('opt', $optIp);
- $this->appFloatingIp->create();
+ // liste des adresses ip publiques diponibles
+ $networkLayer3->action("listFloatingIp");
+ $listFloatingIp = json_decode($App->show(), true)["NetworkLayer3"];
+ $ip = null;
+ foreach ($listFloatingIp as $f) {
+ 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
+ */
}
}
-
}
?>