summaryrefslogtreecommitdiff
path: root/server/core
diff options
context:
space:
mode:
Diffstat (limited to 'server/core')
-rwxr-xr-xserver/core/App.php68
-rwxr-xr-xserver/core/CoreInterface.php7
-rwxr-xr-x[-rw-r--r--]server/core/Identity.php27
-rw-r--r--server/core/Image.php195
-rwxr-xr-xserver/core/LibOverride/genTokenOptions.php22
5 files changed, 303 insertions, 16 deletions
diff --git a/server/core/App.php b/server/core/App.php
new file mode 100755
index 0000000..45f6922
--- /dev/null
+++ b/server/core/App.php
@@ -0,0 +1,68 @@
+<?php
+include_once("core/Plugin_Api.php");
+include_once("core/LibOverride/genTokenOptions.php");
+
+class App{
+
+ protected $openstack;
+ protected $pluginsApi;
+ protected $tokenClass;
+ protected $tokenPost;
+ protected $output;
+
+ public function __construct($args){
+
+ $this->tokenPost = NULL;
+ $this->tokenClass = new genTokenOptions($args);
+ $this->openstack = new OpenStack\OpenStack([]);
+ $this->pluginsApi = plugin_api::getInstance();
+ $this->output = array();
+
+ }
+
+ public function setToken($token){
+
+ $this->tokenPost = $token;
+ $this->tokenClass->loadBackup($his->tokenPost);
+
+ }
+
+ public function getLibClass($service){
+
+ switch($service){
+ case "Identity":
+ if($tokenPost == NULL) $tokenClass->genIdentityToken();
+ $opt = $tokenClass->getOptions($service);
+ return $this->openstack->identityV3($opt);
+ break;
+ }
+
+ }
+
+ public function authenticate(){
+
+ try{
+ $this->tokenClass->genIdentityToken();
+ $this->tokenClass->genComputeToken();
+ $this->tokenClass->genImageToken();
+ $this->tokenClass->genNetworkToken();
+
+ $this->setOutput("token", $this->tokenClass->getBackup());
+ }catch(Exception $e){
+ echo $e;
+ exit();
+ }
+
+ }
+
+ public function setOutput($key, $out){
+
+ $this->output[$key] = $out;
+
+ }
+
+ public function show(){
+ echo json_encode($this->output);
+ }
+
+} \ No newline at end of file
diff --git a/server/core/CoreInterface.php b/server/core/CoreInterface.php
new file mode 100755
index 0000000..ed0d959
--- /dev/null
+++ b/server/core/CoreInterface.php
@@ -0,0 +1,7 @@
+<?php
+
+interface Core{
+
+ public function action($action);
+
+} \ No newline at end of file
diff --git a/server/core/Identity.php b/server/core/Identity.php
index 343ed15..d607957 100644..100755
--- a/server/core/Identity.php
+++ b/server/core/Identity.php
@@ -1,19 +1,28 @@
<?php
-class identity {
+class identity implements Core{
- protected $oidentity;
+ protected $app;
+ protected $libClass;
+ protected $action;
- public function __construct($ostack, $apiP){
+ public function __construct($app){
- $this->oidentity = $ostack->identityV3();
- $this->plugins = $apiP;
+ $this->app = $app;
+ if($app->getOptions("Identity"))
+ $this->libClass = $app->getLibClass("Identity");
}
+ public function action($action){
+
+ //To be Complete
+
+ }
+
public function genToken(){
- global $Args;
- $token = $this->oidentity->generateToken($Args);
- return $token;
- }
+
+ //To be Complete
+
+ }
}
diff --git a/server/core/Image.php b/server/core/Image.php
index 8d1c8b6..d345034 100644
--- a/server/core/Image.php
+++ b/server/core/Image.php
@@ -1 +1,194 @@
-
+<?php
+ini_set('display_errors', 1);
+date_default_timezone_set("Europe/Paris");
+
+class Image {
+
+ protected $oidentity;
+ //protected $plugins;
+
+ /**
+ * Constructor
+ *
+ * @param $openstack
+ *
+ * @param $options
+ *
+ **/
+ public function __construct($ostack, $options){ //, $apiP
+ $this->oidentity = $ostack->imagesV2($options);
+ //$this->plugins = $apiP;
+ }
+
+
+ /**
+ * Details about an image
+ *
+ * @param array $opt
+ * options for the image creation
+ *
+ **/
+ public function create_image(array $opt){
+ // VOIR SI MAUVAIS TYPE
+ $options = Array();
+ if(isset($opt['name'])){ // string, rendre le nom obligatoire
+ $options['name'] = $opt['name'];
+ }
+ if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn
+ $options['id'] = $opt['id'];
+ }
+ if(isset($opt['visibility'])){ // public, private
+ $options['visibility'] = $opt['visibility'];
+ }
+ if(isset($opt['tags'])){ // list
+ $options['tags'] = $opt['tags'];
+ }
+ if(isset($opt['containerFormat'])){ // string : ami, ari, aki, bare, ovf, ova, docker
+ $options['containerFormat'] = $opt['containerFormat'];
+ }
+ if(isset($opt['diskFormat'])){ // string : ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, iso
+ $options['diskFormat'] = $opt['diskFormat'];
+ }
+ if(isset($opt['minDisk'])){ //int
+ $options['minDisk'] = $opt['minDisk'];
+ }
+ if(isset($opt['minRam'])){ // int
+ $options['minRam'] = $opt['minRam'];
+ }
+ if(isset($opt['protected'])){ // boolean
+ $options['protected'] = $opt['protected'];
+ }
+ if(isset($opt['properties'])){ // type dict ?
+ $options['properties'] = $opt['properties'];
+ }
+
+ $image = $this->oidentity->createImage($options);
+
+ return $image;
+ }
+
+ /*
+ * List images
+ */
+ public function list_images(){
+ $service = $this->oidentity;
+ $images = $service->listImages();
+ return $images;
+ }
+
+ /**
+ * Details about an image
+ *
+ * @param string $id
+ * identifier of the image
+ *
+ **/
+ public function image_details($id){
+ $service = $this->oidentity;
+ $image = $service->getImage($id);
+ return $image;
+ }
+
+ /**
+ * Details about an image
+ *
+ * @param string $id
+ * id of the image
+ *
+ * @param array $opt
+ * options for the image creation
+ **/
+ public function update_image($id, array $opt){
+ $service = $this->oidentity;
+ $image = $service->getImage($id);
+ $options = Array();
+
+ // Voir vérification des types
+ if(isset($opt['name'])){ //string
+ $options['name'] = $opt['name'];
+ }
+ if(isset($opt['minDisk'])){ //int
+ $options['minDisk'] = $opt['minDisk'];
+ }
+ if(isset($opt['minRam'])){ // int
+ $options['minRam'] = $opt['minRam'];
+ }
+ if(isset($opt['protected'])){ // boolean
+ $options['protected'] = $opt['protected'];
+ }
+ if(isset($opt['visibility'])){ // public, private
+ $options['visibility'] = $opt['visibility'];
+ }
+ if(isset($opt['tags'])){ // list
+ $options['tags'] = $opt['tags'];
+ }
+ $image->update($options);
+
+ return $image;
+ }
+
+ /**
+ * Delete an image
+ *
+ * @param string $id
+ * identifier of the image
+ **/
+ public function delete_image($id){
+ $service = $this->oidentity;
+ $service->getImage($id)->delete();
+ }
+
+ /**
+ * Resactive an image
+ *
+ * @param string $id
+ * identifier of the image
+ **/
+ public function reactivate_image($id){
+ $service = $this->oidentity;
+ $image = $service->getImage($id);
+ $image->reactivate();
+ }
+
+ /**
+ * Desactive an image
+ *
+ * @param string $id
+ * identifier of the image
+ **/
+ public function desactivate_image($id){
+ $service = $this->oidentity;
+ $image = $service->getImage($id);
+ $image->deactivate();
+ }
+
+ /**
+ * Upload an image
+ *
+ * @param string $id
+ * identifier of the image
+ *
+ * @param string $file_name
+ * path of the image
+ **/
+ public function upload_image($id, $file_name){
+ $service = $this->oidentity;
+ $image = $service->getImage($id);
+ $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR
+ $image->uploadData($stream);
+ }
+
+ /**
+ * Download an image
+ *
+ * @param string $id
+ * identifier of the image
+ */
+ public function download_image($id){
+ $service = $this->oidentity;
+ $image = $service->getImage($id);
+ $stream = $image->downloadData();
+ return $stream;
+ }
+}
+?>
diff --git a/server/core/LibOverride/genTokenOptions.php b/server/core/LibOverride/genTokenOptions.php
index 81ecfc8..58b87c1 100755
--- a/server/core/LibOverride/genTokenOptions.php
+++ b/server/core/LibOverride/genTokenOptions.php
@@ -81,7 +81,7 @@ class genTokenOptions
$options['catalogType'] = 'false';
$options['region'] = 'RegionOne';
- $this->backup['Identity'] = unserialize($opt);
+ $this->backup['Identity'] = $opt;
$token = $this->unserializeToken($this->backup['Identity']['token']);
$baseUrl = $this->backup['Identity']['baseUrl'];
@@ -129,7 +129,7 @@ class genTokenOptions
$options['catalogType'] = 'image';
$options['region'] = 'RegionOne';
- $this->backup['Image'] = unserialize($opt);
+ $this->backup['Image'] = $opt;
$token = $this->unserializeToken($this->backup['Image']['token']);
$baseUrl = $this->backup['Image']['baseUrl'];
@@ -176,7 +176,7 @@ class genTokenOptions
$options['catalogType'] = 'network';
$options['region'] = 'RegionOne';
- $this->backup['Network'] = unserialize($opt);
+ $this->backup['Network'] = $opt;
$token = $this->unserializeToken($this->backup['Network']['token']);
$baseUrl = $this->backup['Network']['baseUrl'];
@@ -224,7 +224,7 @@ class genTokenOptions
$options['catalogType'] = 'compute';
$options['region'] = 'RegionOne';
- $this->backup['Compute'] = unserialize($opt);
+ $this->backup['Compute'] = $opt;
$token = $this->unserializeToken($this->backup['Compute']['token']);
$baseUrl = $this->backup['Compute']['baseUrl'];
@@ -242,8 +242,18 @@ class genTokenOptions
$this->optionsGlobal['Compute'] = $options;
}
- public function getBackup($service){
- return serialize($this->backup[$service]);
+ public function getBackup(){
+ return serialize($this->backup);
+ }
+
+ public function loadBackup($back){
+
+ $backup = unserialize($back);
+ loadComputeBackup($backup["Compute"]);
+ loadIdentityBackup($backup["Identity"]);
+ loadImageBackup($backup["Image"]);
+ loadNetworkBackup($backup["Network"]);
+
}
public function getOptions($service){