Merge branch 'develop'
This commit is contained in:
commit
eb38e10d6f
3 changed files with 236 additions and 41 deletions
|
@ -22,6 +22,7 @@ class automating implements Core{
|
||||||
protected $appImage;
|
protected $appImage;
|
||||||
protected $appNetwork;
|
protected $appNetwork;
|
||||||
protected $appIdentity;
|
protected $appIdentity;
|
||||||
|
protected $appFloatingIp;
|
||||||
protected $app;
|
protected $app;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,6 +40,7 @@ class automating implements Core{
|
||||||
$this->appImage = $appImage;
|
$this->appImage = $appImage;
|
||||||
$this->appNetwork = $appNetwork;
|
$this->appNetwork = $appNetwork;
|
||||||
$this->appIdentity = $appIdentity;
|
$this->appIdentity = $appIdentity;
|
||||||
|
$this->appFloatingIp = $appFloatingIp;
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,51 +54,56 @@ class automating implements Core{
|
||||||
public function action($action){
|
public function action($action){
|
||||||
$this->{$action.""}();
|
$this->{$action.""}();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function script()
|
|
||||||
{
|
|
||||||
$opt = Array();
|
|
||||||
$opt['name'] = getPostParam('name');
|
|
||||||
|
|
||||||
appImage->setPostParam('opt' $opt);
|
|
||||||
appImage->createImage();
|
|
||||||
|
|
||||||
appNetwork->create_network();
|
|
||||||
appnetwork->list_network_ids();
|
|
||||||
appNetwork->create_subnet();
|
|
||||||
|
|
||||||
appCompute->listFlavors(); //to show all flavors with detail.
|
|
||||||
appCompute->listImages(); //to show all images with detail and to verify that the image was created successfully by the call above.
|
|
||||||
|
|
||||||
appCompute->setPostParam("name","Test");
|
|
||||||
appCompute->setPostParam("imageId","CREATED_ABOVE");
|
|
||||||
appCompute->setPostParam("flavorId","1");
|
|
||||||
appCompute->createServer();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
private function createServer()
|
private function createServer()
|
||||||
{
|
{
|
||||||
$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');
|
||||||
|
|
||||||
// Création image
|
if(!isset($imageName)){
|
||||||
$opt = Array();
|
$this->app->setOutput("Error", "Incorrect imageName parameter");
|
||||||
$opt['name'] = $imageName;
|
}
|
||||||
$this->app->setPostParam('opt' $opt);
|
else if(!isset($serverName)){
|
||||||
$this->appImage->createImage();
|
$this->app->setOutput("Error", "Incorrect serverName parameter");
|
||||||
$image = json_decode($this->app->show(), true)["Images"];
|
}
|
||||||
|
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"];
|
||||||
|
|
||||||
// Création server
|
// Création server
|
||||||
$this->app->setPostParam('name', $serverName);
|
$this->appCompute->setPostParam('name', $serverName);
|
||||||
$this->app->setPostParam('imageId', $image['id']);
|
$this->appCompute->setPostParam('imageId', $image['id']);
|
||||||
$this->app->setPostParam('flavorId', $flavor);
|
$this->appCompute->setPostParam('flavorId', $flavor);
|
||||||
$this->appNetwork->createServer();
|
$this->appCompute->createServer();
|
||||||
|
$server = json_decode($this->app->show(), true)["Compute"];
|
||||||
|
|
||||||
// Ajout adresse IP public
|
// 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();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
195
server/core/FloatingIp.php
Normal file
195
server/core/FloatingIp.php
Normal file
|
@ -0,0 +1,195 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* File containing the FloatingIp Class.
|
||||||
|
*
|
||||||
|
* @version 1.0 Initialisation of this file
|
||||||
|
* @since 1.0 Core application's file
|
||||||
|
*
|
||||||
|
* @author Evan Pisani 'yogg at epsina . com'
|
||||||
|
*
|
||||||
|
* @todo Complete the functions with errors detection and finish the descriptions
|
||||||
|
*/
|
||||||
|
use OpenCloud\Common\Error\BadResponseError;
|
||||||
|
use OpenCloud\Common\Error\BaseError;
|
||||||
|
use OpenCloud\Common\Error\NotImplementedError;
|
||||||
|
use OpenCloud\Common\Error\UserInputError;
|
||||||
|
|
||||||
|
include("CoreInterface.php");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Image Class of the back-end application
|
||||||
|
*
|
||||||
|
* Management of images
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class FloatingIp 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("FloatingIp");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute an action
|
||||||
|
*
|
||||||
|
* @param String $action name of another function of this class
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function action($action){
|
||||||
|
$this->{$action.""}();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new floating IP adress
|
||||||
|
*
|
||||||
|
* @param array $opt Options for the floating ip creation (floatingipo and floating network id are required, others are optionals)
|
||||||
|
*
|
||||||
|
* @return floatingip
|
||||||
|
*/
|
||||||
|
private function createFloatingIp(){
|
||||||
|
$opt = $this->app->getPostParam("opt");
|
||||||
|
|
||||||
|
if(!isset($opt)){
|
||||||
|
$this->app->setOutput("Error", "Incorrect parameter opt");
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
$floatingip = $this->libClass->create($opt);
|
||||||
|
if(!isset){
|
||||||
|
$this->app->setOutput("Error", "Unknowing error during floating ip creation");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$this->app->setOutput("FloatingIp", $floatingip);
|
||||||
|
}
|
||||||
|
}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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update floating ip
|
||||||
|
*
|
||||||
|
* @param id the id of the floatingip to update
|
||||||
|
*
|
||||||
|
* @return Image
|
||||||
|
*/
|
||||||
|
private function updateFloatingIp(){
|
||||||
|
$id = $this->app->getPostParam("id");
|
||||||
|
|
||||||
|
if(!isset($id)){
|
||||||
|
$this->app->setOutput("Error", "Incorrect parameter opt");
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
$floatingip = null; //obtenir ip
|
||||||
|
|
||||||
|
$floatingip->update();
|
||||||
|
|
||||||
|
if(!isset){
|
||||||
|
$this->app->setOutput("Error", "Unknowing error during floating ip creation");
|
||||||
|
}
|
||||||
|
}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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a floating ip
|
||||||
|
*
|
||||||
|
* @param string floatingip_id the floating-ip id to delete
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function deleteFloatingIp(){
|
||||||
|
$id = $this->app->getPostParam("id");
|
||||||
|
|
||||||
|
if(!isset($id)){
|
||||||
|
$this->app->setOutput("Error", "Incorrect parameter opt");
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
$floatingip = null; //obtenir ip
|
||||||
|
|
||||||
|
$floatingip->delete();
|
||||||
|
|
||||||
|
if(!isset){
|
||||||
|
$this->app->setOutput("Error", "Unknowing error during floating ip creation");
|
||||||
|
}
|
||||||
|
}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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a floating ip
|
||||||
|
*
|
||||||
|
* @param string floatingip_id the floating-ip id to retrieve
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function retrieveFloatingIp(){
|
||||||
|
$id = $this->app->getPostParam("id");
|
||||||
|
|
||||||
|
if(!isset($id)){
|
||||||
|
$this->app->setOutput("Error", "Incorrect parameter opt");
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
$floatingip = null; //obtenir ip
|
||||||
|
|
||||||
|
$floatingip->retrieve();
|
||||||
|
|
||||||
|
if(!isset){
|
||||||
|
$this->app->setOutput("Error", "Unknowing error during floating ip creation");
|
||||||
|
}
|
||||||
|
}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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -224,7 +224,6 @@ class image implements Core{
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
try{
|
try{
|
||||||
//vérifier existence image
|
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
$image = $service->getImage($id);
|
$image = $service->getImage($id);
|
||||||
if($image == null){ // if the image don't exists -> error
|
if($image == null){ // if the image don't exists -> error
|
||||||
|
@ -276,8 +275,6 @@ class image implements Core{
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function deleteImage(){
|
private function deleteImage(){
|
||||||
// si protected = true, demander de le mettre a false
|
|
||||||
// vérifier existence image
|
|
||||||
$id = $this->app->getPostParam("id");
|
$id = $this->app->getPostParam("id");
|
||||||
if(!isset($id)){
|
if(!isset($id)){
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
|
@ -357,7 +354,6 @@ class image implements Core{
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
// vérifier existence image
|
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
$image = $service->getImage($id);
|
$image = $service->getImage($id);
|
||||||
if($image == null){ // if the image don't exists -> error
|
if($image == null){ // if the image don't exists -> error
|
||||||
|
@ -400,7 +396,6 @@ class image implements Core{
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
try{
|
try{
|
||||||
// vérifier existence image
|
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
$image = $service->getImage($id);
|
$image = $service->getImage($id);
|
||||||
if($image == null){ // if the image don't exists -> error
|
if($image == null){ // if the image don't exists -> error
|
||||||
|
@ -437,7 +432,6 @@ class image implements Core{
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
try{
|
try{
|
||||||
// vérifier existence image
|
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
$image = $service->getImage($id);
|
$image = $service->getImage($id);
|
||||||
if($image == null){ // if the image don't exists -> error
|
if($image == null){ // if the image don't exists -> error
|
||||||
|
@ -521,7 +515,6 @@ class image implements Core{
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
try{
|
try{
|
||||||
// vérifier existence image
|
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
$image = $service->getImage($image_id);
|
$image = $service->getImage($image_id);
|
||||||
if($image == null){ // if the image don't exists -> error
|
if($image == null){ // if the image don't exists -> error
|
||||||
|
|
Loading…
Add table
Reference in a new issue