istic-openstack/server/core/Automating.php

111 lines
2.8 KiB
PHP
Raw Normal View History

2016-03-23 15:46:57 +01:00
<?php
/**
2016-03-27 19:40:36 +02:00
* File containing the Automating Class.
2016-03-23 15:46:57 +01:00
*
* @version 1.0 Initialisation of this file
* @since 1.0 Core application's file
*
* @author Evan Pisani 'yogg at epsina . com' et bhupi
2016-03-23 15:46:57 +01:00
*
* @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");
2016-03-23 15:46:57 +01:00
class automating implements Core{
2016-03-23 15:46:57 +01:00
/** @var App $app protected, contains the main app object */
protected $appCompute;
protected $appImage;
protected $appNetwork;
protected $appIdentity;
protected $appNetworkLayer3;
2016-03-30 18:30:44 +02:00
protected $app;
2016-03-23 15:46:57 +01:00
/**
* Our library's app constructor for all server app objects
2016-03-23 15:46:57 +01:00
*
* @param App $app the main app object, e.g. compute, image, network, etc.
2016-03-23 15:46:57 +01:00
*
* @return
2016-03-23 15:46:57 +01:00
*/
public function __construct($app){
if(!isset($app)){
$this->app->setOutput("Error", "Parameter app missing.");
2016-03-23 15:46:57 +01:00
}
$this->appCompute = $appCompute;
$this->appImage = $appImage;
$this->appNetwork = $appNetwork;
$this->appIdentity = $appIdentity;
$this->appNetworkLayer3 = $appNetworkLayer3;
2016-03-30 18:30:44 +02:00
$this->app = $app;
2016-03-23 15:46:57 +01:00
}
/**
* Execute an action
*
* @param String $action name of another function of this class
*
* @return void
*/
public function action($action){
$this->{$action.""}();
}
2016-03-30 18:30:44 +02:00
2016-04-18 17:38:25 +02:00
/**
* create a new server and associate a public ip
*
* @param String $imageName name of the new image
* @param String $serverName name ofthe new server
* @param String $flavor kind of server
*
* @return void
*/
2016-03-30 18:30:44 +02:00
private function createServer()
{
$imageName = $this->app->getPostParam('imageName');
$serverName = $this->app->getPostParam('serverName');
$flavor = $this->app->getPostParam('flavor');
2016-03-23 15:46:57 +01:00
2016-04-18 17:38:25 +02:00
if(!isset($imageName)){
$this->app->setOutput("Error", "Incorrect imageName parameter");
}
else if(!isset($serverName)){
$this->app->setOutput("Error", "Incorrect serverName parameter");
}
else if(!isset($flavor)){
$this->app->setOutput("Error", "Incorrect flavor parameter");
}
else{
// Création image
$opt = array();
$opt['name'] = $imageName;
$this->appImage->setPostParam('opt' $opt);
$this->appImage->createImage();
$image = json_decode($this->app->show(), true)["Images"];
2016-03-23 15:46:57 +01:00
2016-04-18 17:38:25 +02:00
// Création server
$this->appCompute->setPostParam('name', $serverName);
$this->appCompute->setPostParam('imageId', $image['id']);
$this->appCompute->setPostParam('flavorId', $flavor);
$this->appCompute->createServer();
$server = json_decode($this->app->show(), true)["Compute"];
2016-03-27 19:54:38 +02:00
2016-04-18 17:38:25 +02:00
// 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();
2016-03-27 19:54:38 +02:00
2016-04-18 17:38:25 +02:00
}
2016-03-23 15:46:57 +01:00
}
2016-04-18 17:38:25 +02:00
2016-03-23 15:46:57 +01:00
}
?>