begining of automating tasks
This commit is contained in:
parent
db2c1490b3
commit
dcf0d8b2ba
3 changed files with 117 additions and 2 deletions
|
@ -1,8 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
include('InitTest.php');
|
include('InitTest.php');
|
||||||
include_once("../core/Image.php");
|
include_once("../core/Image.php");
|
||||||
|
include_once("../core/Compute.php");
|
||||||
|
|
||||||
$image = new Image($App);
|
$image = new Image($App);
|
||||||
|
$compute = new Compute($App);
|
||||||
|
|
||||||
$opt = Array();
|
$opt = Array();
|
||||||
$opt['name'] = "Test";
|
$opt['name'] = "Test";
|
||||||
|
@ -22,7 +24,6 @@ $opt['minRam'] = 10;
|
||||||
$image->action("listImage");
|
$image->action("listImage");
|
||||||
$im = $App->show();
|
$im = $App->show();
|
||||||
$images = json_decode($im, true)["Images"];
|
$images = json_decode($im, true)["Images"];
|
||||||
$recup;
|
|
||||||
|
|
||||||
echo "Images présentes :";
|
echo "Images présentes :";
|
||||||
echo "</br>";
|
echo "</br>";
|
||||||
|
@ -33,9 +34,22 @@ foreach($images as $i){
|
||||||
//echo $recup['id'];
|
//echo $recup['id'];
|
||||||
}
|
}
|
||||||
echo "</br>";
|
echo "</br>";
|
||||||
echo "Erreur capturée: ";
|
|
||||||
|
echo "Flavors: ";
|
||||||
echo "</br>";
|
echo "</br>";
|
||||||
|
|
||||||
|
$compute->action("listFlavors");
|
||||||
|
$flavors = json_decode($App->show(), true)["Flavors"];
|
||||||
|
|
||||||
|
foreach($flavors as $f){
|
||||||
|
echo "Id=".$f['id'].", ";
|
||||||
|
echo "name=".$f['name'].", ";
|
||||||
|
echo "ram=".$f['ram'].", ";
|
||||||
|
echo "disk=".$f['disk'].", ";
|
||||||
|
echo "vcpus=".$f['vcpus'];
|
||||||
|
echo "</br>";
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$App->setPostParam('id', 354);
|
$App->setPostParam('id', 354);
|
||||||
$err = $image->action("deleteImage");
|
$err = $image->action("deleteImage");
|
||||||
|
|
|
@ -116,6 +116,12 @@ class App{
|
||||||
return $this->postParams[$name];
|
return $this->postParams[$name];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setPostParam($name, $value){
|
||||||
|
|
||||||
|
$this->postParams[$name]= $value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function setOutput($key, $out){
|
public function setOutput($key, $out){
|
||||||
|
|
||||||
|
|
95
server/core/Automating.php
Normal file
95
server/core/Automating.php
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* File containing the Image Class.
|
||||||
|
*
|
||||||
|
* @version 1.0 Initialisation of this file
|
||||||
|
* @since 1.0 Core application's file
|
||||||
|
*
|
||||||
|
* @author Yogg 'yogg at epsina . com'
|
||||||
|
*
|
||||||
|
* @todo Complete the functions with errors detection and finish the descriptions
|
||||||
|
*/
|
||||||
|
|
||||||
|
include("CoreInterface.php");
|
||||||
|
include("Image.php");
|
||||||
|
include("Network.php");
|
||||||
|
include("Compute.php");
|
||||||
|
|
||||||
|
class automating implements Core{
|
||||||
|
/** @var App $app protected, contains the main app object */
|
||||||
|
protected $app;
|
||||||
|
|
||||||
|
/** @var OpenStack\Identity $libClass protected, contains the library Identity object */
|
||||||
|
protected $libClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Image constructor
|
||||||
|
*
|
||||||
|
* @param App $app the main app object
|
||||||
|
*
|
||||||
|
* @return Image
|
||||||
|
*/
|
||||||
|
public function __construct($app){
|
||||||
|
if(!isset($app)){
|
||||||
|
$this->app->setOutput("Error", "Incorrect parameter app");
|
||||||
|
}
|
||||||
|
$this->app = $app;
|
||||||
|
$this->libClass = $app->getLibClass("Automating");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute an action
|
||||||
|
*
|
||||||
|
* @param String $action name of another function of this class
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function action($action){
|
||||||
|
$this->{$action.""}();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function createImageOnNewServer(){
|
||||||
|
try{
|
||||||
|
$image = new Image($this->app);
|
||||||
|
$compute = new Compute($this->app);
|
||||||
|
|
||||||
|
$name = $this->app->getPostParam("name");
|
||||||
|
$falvor_id = $this->app->getPostParam("falvor_id"); // Compris entre 1 et 5 (1=petit serveur, 5=gros serveur)
|
||||||
|
|
||||||
|
$opt = Array();
|
||||||
|
$opt['name'] = $name;
|
||||||
|
$opt['visibility'] = 'public';
|
||||||
|
$opt['minDisk'] = 100; // A VOIR
|
||||||
|
$opt['minRam'] = 128; // A VOIR
|
||||||
|
$opt['protected'] = false;
|
||||||
|
|
||||||
|
$this->app->setPostParam("opt", $opt);
|
||||||
|
|
||||||
|
$image->action("createImage");
|
||||||
|
$res = json_decode($this->app->show(), true)["Images"];
|
||||||
|
|
||||||
|
|
||||||
|
$this->app->setPostParam("name", $name);
|
||||||
|
$this->app->setPostParam("imageId", $res['id']);
|
||||||
|
$this->app->setPostParam("flavorId", $falvor_id);
|
||||||
|
|
||||||
|
$compute->action("createServer");
|
||||||
|
|
||||||
|
}catch(BadResponseError $e){
|
||||||
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
|
}catch(UserInputError $e){
|
||||||
|
$this->app->getErrorInstance()->UserInputHandler($e);
|
||||||
|
}catch(BaseError $e){
|
||||||
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
|
}catch(NotImplementedError $e){
|
||||||
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
|
}catch(Exception $e){
|
||||||
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Add table
Reference in a new issue