From 0298591cee4365f82e41c077f799270ba1647e5b Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 2 Mar 2016 16:00:46 +0100 Subject: [PATCH 01/12] Architecture modification --- server/Test/imageTests.php | 89 +++++++++++++------------------------- server/core/Image.php | 71 ++++++++++++++++++++---------- 2 files changed, 79 insertions(+), 81 deletions(-) diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index 94ff7b6..3af12fc 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -1,35 +1,6 @@ "admin", "password"=>"ae5or6cn", "domain"=>["id"=>"Default"]); -$options["scope"] = Array("project"=>Array("name"=>"admin", "domain"=>["id"=>"Default"])); -$options["authUrl"] = "http://148.60.11.31:5000/v3"; - -$openstack = new OpenStack\OpenStack($options); - -//$identity = $openstack->identityV3(); -//var_dump($identity); -// Since usernames will not be unique across an entire OpenStack installation, -// when authenticating with them you must also provide your domain ID. You do -// not have to do this if you authenticate with a user ID. -/*$token = $identity->generateToken([ - 'user' => [ - 'name' => 'admin', - 'password' => 'ae5or6cn', - 'domain' => [ - 'id' => 'Default' - ] - ] - ]); - */ -//$compute = $openstack->computeV2(["region" => "RegionOne"]); -//$image= $openstack->imagesV2(["region" => "RegionOne"]); -//var_dump($compute->client); -//$servers = $compute->listServers(true); -echo 'toto'; +include('InitTest.php'); +include_once("../core/Image.php"); $image = new Image($App); @@ -43,52 +14,54 @@ $opt['minDisk'] = 1; $opt['protected'] = false; $opt['minRam'] = 10; -//$new_image = $image->create_image($opt); - +//$new_image = $image->createImage($opt); //Liste des images -$images = $image->list_images(); - -echo "Images présentes :"; -echo "
"; - -foreach($images as $i){ - echo $i->name; - if($i->name == "Test"){ - $id_image = $i->id; - $list = $i->tags; - echo $i->status; +$image->action("listImage"); +//$images = $image->listImage(); +$im = $App->show(); +$images = json_decode($im, true)["Images"]; +if(isset($images)){ + echo "Images présentes :"; + echo "
"; + foreach($images as $i){ + echo $i['name']; + echo "
"; } echo "
"; -} -echo "
"; -if(isset($list)){ - foreach ($list as $l) { - echo $l; - echo "
"; - } + if(isset($list)){ + foreach ($list as $l) { + echo $l; + echo "
"; + } } +} +else{ + echo "Aucune image présente\n"; +} + + // Détails Image -//$details = $image->image_details($id_image); +//$details = $image->imageDetails($id_image); -//$image->delete_image('123456'); +//$image->deleteImage('123456'); -//$image->desactivate_image($id_image); -//$image->reactivate_image($id_image); +//$image->desactivateImage($id_image); +//$image->reactivateImage($id_image); //$file_name = "/home/yogg/Downloads/TinyCore-6.4.1.iso"; -//$image->upload_image($id_image, $file_name); +//$image->uploadImage($id_image, $file_name); -//$image->download_image($id_image); +//$image->downloadImage($id_image); /* $opt_update = Array(); $opt_update['name'] = "Test"; $opt_update['tags'] = null; -$update = $image->update_image($id_image, $opt_update); +$update = $image->updateImage($id_image, $opt_update); echo $update->name; */ diff --git a/server/core/Image.php b/server/core/Image.php index 4025595..ddd8390 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -14,6 +14,8 @@ use OpenStack\Common\Error\BaseError; use OpenStack\Common\Error\NotImplementedError; use OpenStack\Common\Error\UserInputError; +include("CoreInterface.php"); + /** * Image Class of the back-end application * @@ -77,6 +79,7 @@ class image implements Core{ * **/ private function createImage(array $opt){ + $opt = $this->app->getPostParam("opt"); if(!isset($opt)){ $this->app->setOutput("Error", "Incorrect parameter"); @@ -141,7 +144,7 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $image; + $this->app->setOutput("Images", $image); } /** @@ -151,9 +154,10 @@ class image implements Core{ */ private function listImage(){ try{ + $result = array(); $l = $this->libClass->listImages(); - if(!isset($l)){ // if the list is empty there is no images - $this->app->setOutput("Error", "No image"); + foreach($l as $tmp){ + $result[] = $tmp; } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -164,8 +168,7 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $l; - + $this->app->setOutput("Images", $result); } /** @@ -175,9 +178,10 @@ class image implements Core{ * identifier of the image * **/ - private function detailsImage($id){ + private function detailsImage(){ + $id = $this->app->getPostParam("id"); if(!isset($id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect id parameter"); } try{ $service = $this->libClass; @@ -185,8 +189,7 @@ class image implements Core{ if($image == null){ // if the image don't exists -> error $this->app->setOutput("Error", "Image doesn't exist"); } - - return $image; + $this->app->setOutput("Images", $image); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ @@ -207,7 +210,9 @@ class image implements Core{ * @param array $opt * options for the image creation **/ - private function updateImage($id, array $opt){ + private function updateImage(){ + $id = $this->app->getPostParam("id"); + $opt = $this->app->getPostParam("opt"); if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } @@ -254,7 +259,7 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $image; + $this->app->setOutput("Images", $image); } /** @@ -263,9 +268,10 @@ class image implements Core{ * @param string $id * identifier of the image **/ - private function deleteImage($id){ + private function deleteImage(){ // si protected = true, demander de le mettre a false // vérifier existence image + $id = $this->app->getPostParam("id"); if(!isset($id)){ $this->app->setOutput("Error", "Image doesn't exist"); } @@ -285,8 +291,7 @@ class image implements Core{ $this->app->getErrorInstance->BaseErrorHandler($e); }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); - } - + } } /** @@ -295,7 +300,8 @@ class image implements Core{ * @param string $id * identifier of the image **/ - private function reactivateImage($id){ + private function reactivateImage(){ + $id = $this->app->getPostParam("id"); if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } @@ -324,7 +330,8 @@ class image implements Core{ * @param string $id * identifier of the image **/ - private function desactivateImage($id){ + private function desactivateImage(){ + $id = $this->app->getPostParam("id"); if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } @@ -357,6 +364,9 @@ class image implements Core{ * path of the image **/ private function uploadImage($id, $file_name){ + $id = $this->app->getPostParam("id"); + $file_name = $this->app->getPostParam("file_name"); + if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } @@ -390,6 +400,7 @@ class image implements Core{ * identifier of the image **/ private function downloadImage($id){ + $id = $this->app->getPostParam("id"); if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } @@ -410,7 +421,7 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $stream; + $this->app->setOutput("Images", $stream); } /** @@ -422,7 +433,10 @@ class image implements Core{ * @param string $member_id * identifier of the member **/ - private function addMemberImage($image_id, $member_id){ + private function addMemberImage(){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); + if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect parameter image_id"); } @@ -455,7 +469,9 @@ class image implements Core{ * @param string $image_id * identifier of the image **/ - private function listMemberImage($image_id, $member_id){ + private function listMemberImage(){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect parameter image_id"); } @@ -482,7 +498,7 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $members; + $this->app->setOutput("Images", $member); } /** @@ -494,7 +510,9 @@ class image implements Core{ * @param string $member_id * identifier of the member **/ - private function detailMemberImage($image_id, $member_id){ + private function detailMemberImage(){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect parameter image_id"); } @@ -525,7 +543,7 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $member; + $this->app->setOutput("Images", $member); } /** @@ -537,7 +555,10 @@ class image implements Core{ * @param string $member_id * identifier of the member **/ - private function removeMemberImage($image_id, $member_id){ + private function removeMemberImage(){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); + if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect parameter image_id"); } @@ -580,6 +601,10 @@ class image implements Core{ * new status for the member **/ private function updateMemberImage($image_id, $member_id, $status){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); + $status = $this->app->getPostParam("status"); + if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect parameter image_id"); } From fa5a48bc3a76b109f6611620b6e56f3024def029 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Wed, 2 Mar 2016 17:41:04 +0100 Subject: [PATCH 02/12] Correct bugs --- client/js/controllers/login.js | 3 ++- client/js/controllers/status.js | 6 +++--- client/js/services/Identity.js | 6 +++++- client/partials/nav.html | 26 +++++++------------------- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js index 1a89563..63cb6d1 100644 --- a/client/js/controllers/login.js +++ b/client/js/controllers/login.js @@ -16,10 +16,11 @@ mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$s // Manager logout event $scope.$on('logoutEvent', function(){ - Identity.logout(); $('#loginModal').modal({backdrop: 'static', keyboard: false}); }); + + // Hide loading button and message alert $('#loadingLoginButton').hide(); $('#failedToLoginAlert').hide(); diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js index 940d794..6f398ad 100644 --- a/client/js/controllers/status.js +++ b/client/js/controllers/status.js @@ -11,10 +11,10 @@ mainApp.controller('statusCtrl', ['$scope','Identity', '$rootScope', function ($ // Give profile to model $scope.profile=Identity.getProfile(); - + // Function to logout - $scope.raiseLogoutEvent=function(){ - $rootScope.$broadcast('logoutEvent'); + $scope.logout=function(){ + Identity.logout(); }; }]); diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js index da85ecd..e6a9daf 100644 --- a/client/js/services/Identity.js +++ b/client/js/services/Identity.js @@ -1,5 +1,5 @@ -mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ +mainApp.factory('Identity',[ '$http', '$cookies', '$rootScope', function($http, $cookies, $rootScope){ /* Create profile structure to store informations * about current session @@ -51,6 +51,9 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ token=null; profile.username=null; profile.projectname=null; + + // Reload Page + location.reload(); } @@ -95,6 +98,7 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ else{ requestParserResult.failReason="Please check your username, password and project name !"; } + return requestParserResult; }; diff --git a/client/partials/nav.html b/client/partials/nav.html index b3ef76a..01b9079 100644 --- a/client/partials/nav.html +++ b/client/partials/nav.html @@ -8,7 +8,7 @@ - Status + Status @@ -18,24 +18,12 @@ - +
  • User : {{ profile.username }}
  • +
  • Project Name : {{ profile.projectname }}
  • + - - + + From e2be86814e8ac92778bfa9fc49e1d02946a7efbc Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Wed, 2 Mar 2016 20:46:24 +0100 Subject: [PATCH 03/12] Clean some things --- client/index.html | 27 ++++++++++---------- client/js/controllers/home/machineDetails.js | 10 +++++--- client/partials/home/machineDetails.html | 2 +- client/partials/{nav.html => status.html} | 0 4 files changed, 21 insertions(+), 18 deletions(-) rename client/partials/{nav.html => status.html} (100%) diff --git a/client/index.html b/client/index.html index 8ca2b9f..ca6bbe6 100644 --- a/client/index.html +++ b/client/index.html @@ -11,27 +11,28 @@ - + - + + +
    +
    +
    + + +
    - -
    - -
    -
    - - -
    + +
    @@ -56,7 +57,7 @@
    - + diff --git a/client/js/controllers/home/machineDetails.js b/client/js/controllers/home/machineDetails.js index 24fac42..c015eaa 100644 --- a/client/js/controllers/home/machineDetails.js +++ b/client/js/controllers/home/machineDetails.js @@ -6,23 +6,25 @@ mainApp.controller('machineDetailsCtrl', [ '$scope', 'Compute', '$rootScope', '$timeout', function ($scope, Compute, $rootScope, $timeout) { + // Init scope $scope.machine={}; - $("#waitingForToggleMachine").hide(); + $scope.machineIsStarting=false; // For loading icon + $scope.$on('showMachineDetailsEvent', function(eventName ,machine, axioms){ $scope.machine=machine; $scope.axioms=axioms; - console.log(machine); $('#machineDetailsModal').modal({backdrop: false, keyboard: true}); }); $scope.toggleMachineState=function(){ - $("#waitingForToggleMachine").show(); + // Display gif + $scope.machineIsStarting=true; // Fake timeout $timeout(function(){ - $("#waitingForToggleMachine").hide(); + $scope.machineIsStarting=false; }, 3000); $timeout(function(){ $scope.machine.online=!$scope.machine.online; diff --git a/client/partials/home/machineDetails.html b/client/partials/home/machineDetails.html index 47a65fb..c4c8a38 100644 --- a/client/partials/home/machineDetails.html +++ b/client/partials/home/machineDetails.html @@ -26,7 +26,7 @@   -   +   diff --git a/client/partials/nav.html b/client/partials/status.html similarity index 100% rename from client/partials/nav.html rename to client/partials/status.html From 824382b3ea5902d5e5343d2898232e1521565dff Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Wed, 2 Mar 2016 20:51:04 +0100 Subject: [PATCH 04/12] Clean file name --- client/index.html | 4 ++-- client/js/controllers/home/{main.js => home.js} | 0 .../controllers/network/{main.js => network.js} | 0 client/js/services/Identity.js | 2 +- client/js/services/Loading.js | 15 ++++++++------- 5 files changed, 11 insertions(+), 10 deletions(-) rename client/js/controllers/home/{main.js => home.js} (100%) rename client/js/controllers/network/{main.js => network.js} (100%) diff --git a/client/index.html b/client/index.html index ca6bbe6..48ea4a0 100644 --- a/client/index.html +++ b/client/index.html @@ -86,9 +86,9 @@ - + - + diff --git a/client/js/controllers/home/main.js b/client/js/controllers/home/home.js similarity index 100% rename from client/js/controllers/home/main.js rename to client/js/controllers/home/home.js diff --git a/client/js/controllers/network/main.js b/client/js/controllers/network/network.js similarity index 100% rename from client/js/controllers/network/main.js rename to client/js/controllers/network/network.js diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js index e6a9daf..db93e97 100644 --- a/client/js/services/Identity.js +++ b/client/js/services/Identity.js @@ -1,5 +1,5 @@ -mainApp.factory('Identity',[ '$http', '$cookies', '$rootScope', function($http, $cookies, $rootScope){ +mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ /* Create profile structure to store informations * about current session diff --git a/client/js/services/Loading.js b/client/js/services/Loading.js index b12aaa0..db06194 100644 --- a/client/js/services/Loading.js +++ b/client/js/services/Loading.js @@ -1,22 +1,23 @@ -mainApp.factory('Loading',[ '$http', 'Identity', function($http, Identity){ - - - - +mainApp.factory('Loading',[ function(){ + /** + * Display Loading modal + */ var start=function(){ $('#loadingModal').modal({backdrop: 'static', keyboard: false}); }; + /** + * Hide Loading modal + */ var stop=function(){ $('#loadingModal').modal('hide'); } + // Service returns return { start:start, stop:stop }; - - }]); From f4e59ee82c5947496d1810d53483c5a0afd57fe8 Mon Sep 17 00:00:00 2001 From: stupidon Date: Sat, 5 Mar 2016 13:58:52 +0100 Subject: [PATCH 05/12] - added more details in the listServers, listImages, listFlavors functions - updated all functions to provide basic error-handling - defined updateServer and deleteServer --- server/core/Compute.php | 111 +++++++++++++++++++++++++++++++++------- 1 file changed, 93 insertions(+), 18 deletions(-) diff --git a/server/core/Compute.php b/server/core/Compute.php index a5b8375..4a50f4a 100644 --- a/server/core/Compute.php +++ b/server/core/Compute.php @@ -12,11 +12,11 @@ class compute protected $libClass; - public function __construct($app) - { - $this->app = $app; - $this->libClass = $app->getLibClass("Compute"); - } + public function __construct($app) + { + $this->app = $app; + $this->libClass = $app->getLibClass("Compute"); + } /** * Execute an action * @@ -41,13 +41,26 @@ class compute $servers[$server->id] = Array(); $server->flavor->retrieve(); $server->image->retrieve(); + $server->retrieve(); $servers[$server->id]["id"] = $server->id; $servers[$server->id]["name"] = $server->name; - $servers[$server->id]["imageId"] = $server->image->id; - $servers[$server->id]["flavorId"] = $server->flavor->id; - $servers[$server->id]["status"] = $server->status; + $servers[$server->id]["image"] = $server->image; $servers[$server->id]["ram"] = $server->flavor->ram; $servers[$server->id]["disk"] = $server->flavor->disk; + $servers[$server->id]["flavor"] = $server->flavor; + $servers[$server->id]["status"] = $server->status; + $servers[$server->id]["created"] = $server->created; + $servers[$server->id]["updated"] = $server->updated; + $servers[$server->id]["ipv4"] = $server->ipv4; + $servers[$server->id]["ipv6"] = $server->ipv6; + $servers[$server->id]["progress"] = $server->progress; + $servers[$server->id]["hostId"] = $server->hostId; + $servers[$server->id]["tenantId"] = $server->tenantId; + $servers[$server->id]["userId"] = $server->userId; + $servers[$server->id]["taskState"] = $server->taskState; + $servers[$server->id]["addresses"] = $server->addresses; + $servers[$server->id]["links"] = $server->links; + $servers[$server->id]["metadata"] = $server->metadata; } $this->app->setOutput("Servers", $servers); return; @@ -62,8 +75,13 @@ class compute $flavors = Array(); foreach($flavorList as $flavor){ $flavors[$flavor->id] = Array(); + $flavor->retrieve(); $flavors[$flavor->id]["id"] = $flavor->id; $flavors[$flavor->id]["name"] = $flavor->name; + $flavors[$flavor->id]["ram"] = $flavor->ram; + $flavors[$flavor->id]["disk"] = $flavor->disk; + $flavors[$flavor->id]["vcpus"] = $flavor->vcpus; + $flavors[$flavor->id]["links"] = $flavor->links; } $this->app->setOutput("Flavors", $flavors); return; @@ -78,8 +96,17 @@ class compute $images = Array(); foreach($imageList as $image){ $images[$image->id] = Array(); + $image->retrieve(); $images[$image->id]["id"] = $image->id; $images[$image->id]["name"] = $image->name; + $images[$image->id]["status"] = $image->status; + $images[$image->id]["created"] = $image->created; + $images[$image->id]["updated"] = $image->updated; + $images[$image->id]["minDisk"] = $image->minDisk; + $images[$image->id]["minRam"] = $image->minRam; + $images[$image->id]["progress"] = $image->progress; + $images[$image->id]["links"] = $image->links; + $images[$image->id]["metadata"] = $image->metadata; } $this->app->setOutput("Images", $images); return; @@ -87,11 +114,18 @@ class compute /** * Create server. * @return array - * + */ public function createServer() { - - $server = $this->libClass->createServer(); + $name = $this->app->getPostParam("name"); + $imageId = $this->app->getPostParam("imageId"); + $flavorId = $this->app->getPostParam("flavorId"); + if(!isset($name) || !isset($imageId) || !isset($flavorId)){ + $this->app->setOutput("Error", "No, we don't let you create a server without a name OR image ID OR flavor ID."); + return; + } + $opt = array('name' => $name, 'imageId' => $imageId, 'flavorId' => $flavorId); + $server = $this->libClass->createServer($opt); } */ /** @@ -101,6 +135,10 @@ class compute public function getServer() { $serverId = $this->app->getPostParam("serverId"); + if(!isset($serverId)){ + $this->app->setOutput("Error", "Server ID is missing, son!"); + return; + } $opt = array('id' => $serverId); $server = $this->libClass->getServer($opt); $server->retrieve(); @@ -114,6 +152,10 @@ class compute public function getFlavor() { $flavorId = $this->app->getPostParam("flavorId"); + if(!isset($serverId)){ + $this->app->setOutput("Error", "Flavor ID is missing, son!"); + return; + } $opt = array('id' => $flavorId); $flavor = $this->libClass->getFlavor($opt); $flavor->retrieve(); @@ -127,23 +169,56 @@ class compute public function getImage() { $imageId = $this->app->getPostParam("imageId"); + if(!isset($serverId)){ + $this->app->setOutput("Error", "Image ID is missing, son!"); + return; + } $opt = array('id' => $imageId); $image = $this->libClass->getImage($opt); $image->retrieve(); $this->app->setOutput("MyImage", $image); return; } - /* working on tests - - public function update() + public function updateServer() { - $image = $this->app->getServer(array $options = []); - + $serverId = $this->app->getPostParam("serverId"); + $newName = $this->app->getPostParam("newName"); + $newIpv4 = $this->app->getPostParam("newIpv4"); + $newIpv6 = $this->app->getPostParam("newIpv6"); + if(!isset($serverId)|| !(isset($newName) || isset($newIpv4) || isset($newIpv6)) ){ + $this->app->setOutput("Error", "You'll have to provide server ID and the new attribute(IP(v4/v6)/Name) you desire to update!"); + return; + } + $opt = array('id' => $serverId); + $server = $this->libClass->getServer($opt); + if (isset($newName)){ + if(isset($newIpv4)){ + if(isset($newIpv6){ + $attr = array('name' => $newName, 'accessIPv4' => $newIPv4, 'accessIPv6' => $newIpv6); + } + $attr = array('name' => $newName, 'accessIPv4' => $newIPv4); + } + $attr = array('name' => $newName); + } + $server->update($attr); + $this->app->setOutput("Success", $serverId." has been updated successfully."); + return; } - public function delete() + */ + public function deleteServer() { - //TODO + $serverId = $this->app->getPostParam("serverId"); + if(!isset($serverId)){ + $this->app->setOutput("Error", "Server ID is missing, son!"); + return; + } + $opt = array('id' => $serverId); + $server = $this->libClass->getServer($opt); + $server->delete(); + $this->app->setOutput("Success", $serverId." has been deleted successfully."); + return; } + /* public function changePassword($newPassword) { //TODO From c43e532f766c3f97a34e6fad3dd990f7992e710b Mon Sep 17 00:00:00 2001 From: stupidon Date: Sat, 5 Mar 2016 14:05:52 +0100 Subject: [PATCH 06/12] added createServer and corrected certain minor bugs --- server/core/Compute.php | 43 ++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/server/core/Compute.php b/server/core/Compute.php index 4a50f4a..8524c86 100644 --- a/server/core/Compute.php +++ b/server/core/Compute.php @@ -111,24 +111,7 @@ class compute $this->app->setOutput("Images", $images); return; } - /** - * Create server. - * @return array - */ - public function createServer() - { - $name = $this->app->getPostParam("name"); - $imageId = $this->app->getPostParam("imageId"); - $flavorId = $this->app->getPostParam("flavorId"); - if(!isset($name) || !isset($imageId) || !isset($flavorId)){ - $this->app->setOutput("Error", "No, we don't let you create a server without a name OR image ID OR flavor ID."); - return; - } - $opt = array('name' => $name, 'imageId' => $imageId, 'flavorId' => $flavorId); - $server = $this->libClass->createServer($opt); - } - */ - /** + /** * Get server details. * @return array */ @@ -179,6 +162,27 @@ class compute $this->app->setOutput("MyImage", $image); return; } + /** + * Create server. + * @return array + */ + public function createServer() + { + $name = $this->app->getPostParam("name"); + $imageId = $this->app->getPostParam("imageId"); + $flavorId = $this->app->getPostParam("flavorId"); + if(!isset($name) || !isset($imageId) || !isset($flavorId)){ + $this->app->setOutput("Error", "No, we don't let you create a server without a name OR image ID OR flavor ID."); + return; + } + $opt = array('name' => $name, 'imageId' => $imageId, 'flavorId' => $flavorId); + $server = $this->libClass->createServer($opt); + } + + /** + * update a server + * @return void + */ public function updateServer() { $serverId = $this->app->getPostParam("serverId"); @@ -204,6 +208,9 @@ class compute $this->app->setOutput("Success", $serverId." has been updated successfully."); return; } + /** + * Delete a server + * @return void */ public function deleteServer() { From dad2e1de334b6c8d9e579a0f75272d8661ed2aa3 Mon Sep 17 00:00:00 2001 From: stupidon Date: Sat, 5 Mar 2016 14:12:27 +0100 Subject: [PATCH 07/12] corrected syntax errors --- server/core/Compute.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/core/Compute.php b/server/core/Compute.php index 8524c86..d134b94 100644 --- a/server/core/Compute.php +++ b/server/core/Compute.php @@ -200,9 +200,9 @@ class compute if(isset($newIpv6){ $attr = array('name' => $newName, 'accessIPv4' => $newIPv4, 'accessIPv6' => $newIpv6); } - $attr = array('name' => $newName, 'accessIPv4' => $newIPv4); + else $attr = array('name' => $newName, 'accessIPv4' => $newIPv4); } - $attr = array('name' => $newName); + else $attr = array('name' => $newName); } $server->update($attr); $this->app->setOutput("Success", $serverId." has been updated successfully."); From eb37fe6b4868b280a8173c57500e1cfd3f77c7e7 Mon Sep 17 00:00:00 2001 From: stupidon Date: Sun, 6 Mar 2016 13:50:17 +0100 Subject: [PATCH 08/12] syntax correction --- server/core/Compute.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/core/Compute.php b/server/core/Compute.php index d134b94..f02eb8b 100644 --- a/server/core/Compute.php +++ b/server/core/Compute.php @@ -197,7 +197,7 @@ class compute $server = $this->libClass->getServer($opt); if (isset($newName)){ if(isset($newIpv4)){ - if(isset($newIpv6){ + if(isset($newIpv6)){ $attr = array('name' => $newName, 'accessIPv4' => $newIPv4, 'accessIPv6' => $newIpv6); } else $attr = array('name' => $newName, 'accessIPv4' => $newIPv4); From 3454c71f0523bd6957e10873d0b95bc191b2f283 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Sun, 6 Mar 2016 14:42:50 +0100 Subject: [PATCH 09/12] Test request --- client/js/controllers/home/home.js | 5 +++-- client/js/services/Image.js | 14 ++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/client/js/controllers/home/home.js b/client/js/controllers/home/home.js index f84f625..18133fa 100644 --- a/client/js/controllers/home/home.js +++ b/client/js/controllers/home/home.js @@ -3,7 +3,7 @@ * * @param {$scope} $scope The $scope service from angular */ -mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', 'Loading','Identity', function ($scope, Compute, $rootScope, Loading, Identity) +mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', 'Loading','Identity', 'Image', function ($scope, Compute, $rootScope, Loading, Identity, Image) { var callMeAfterPullData=function(data){ @@ -17,7 +17,8 @@ mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', 'Loading','I Compute.pullData(callMeAfterPullData); } - + + Image.getImages(function(){}); $scope.raiseShowMachineDetailsEvent=function(id){ diff --git a/client/js/services/Image.js b/client/js/services/Image.js index 23b33a8..eccd4af 100644 --- a/client/js/services/Image.js +++ b/client/js/services/Image.js @@ -4,16 +4,22 @@ mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){ var parseUploadImageAnswer=function(response, failedToSendRequest){ - + console.log(response.data.Images[0]) }; var getImages=function(callback){ var result=$http.post('../server/index.php', - $.param({"token" : Identity.profile.token, "task" : "Image"})); + $.param({"token" : Identity.getToken(), "task" : "image", 'action':'listImage'})); + + // Wait and handle the response + result.then(function (response){ + callback(parseUploadImageAnswer(response, false)); + },function(response){ + callback(parseUploadImageAnswer(response, true)); + }); - }; @@ -21,7 +27,7 @@ mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){ // Return services objects return { - uploadImage: uploadImage + getImages:getImages }; From 96094547dd793868092dda4c2699a839287fa175 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Sun, 6 Mar 2016 14:51:50 +0100 Subject: [PATCH 10/12] Add image view, controller. --- client/index.html | 1 + client/js/app.js | 8 ++++++-- client/js/controllers/image/image.js | 9 +++++++++ client/partials/home/{main.html => home.html} | 0 client/partials/image/image.html | 8 ++++++++ client/partials/menu.html | 3 ++- client/partials/network/{main.html => network.html} | 0 7 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 client/js/controllers/image/image.js rename client/partials/home/{main.html => home.html} (100%) create mode 100644 client/partials/image/image.html rename client/partials/network/{main.html => network.html} (100%) diff --git a/client/index.html b/client/index.html index 48ea4a0..a06994c 100644 --- a/client/index.html +++ b/client/index.html @@ -89,6 +89,7 @@ + diff --git a/client/js/app.js b/client/js/app.js index e2d5b9b..1602e65 100644 --- a/client/js/app.js +++ b/client/js/app.js @@ -13,12 +13,16 @@ mainApp.config(['$routeProvider', function($routeProvider){ $routeProvider. when('/home',{ - templateUrl: 'partials/home/main.html', + templateUrl: 'partials/home/home.html', controller: 'homeCtrl' }). when('/network',{ - templateUrl: 'partials/network/main.html', + templateUrl: 'partials/network/network.html', controller: 'networkCtrl' + }). + when('/image',{ + templateUrl: 'partials/image/image.html', + controller: 'imageCtrl' }).otherwise({ redirectTo: '/home' }); diff --git a/client/js/controllers/image/image.js b/client/js/controllers/image/image.js new file mode 100644 index 0000000..036dec3 --- /dev/null +++ b/client/js/controllers/image/image.js @@ -0,0 +1,9 @@ +/** + * The image controller + * + * @param {$scope} $scope The $scope service from angular + */ +mainApp.controller('imageCtrl', function ($scope) +{ + $scope.title="Test"; +}); diff --git a/client/partials/home/main.html b/client/partials/home/home.html similarity index 100% rename from client/partials/home/main.html rename to client/partials/home/home.html diff --git a/client/partials/image/image.html b/client/partials/image/image.html new file mode 100644 index 0000000..586f003 --- /dev/null +++ b/client/partials/image/image.html @@ -0,0 +1,8 @@ +
    +
    + Image +
    +
    + Main Content +
    +
    diff --git a/client/partials/menu.html b/client/partials/menu.html index dfd5842..a473fd8 100644 --- a/client/partials/menu.html +++ b/client/partials/menu.html @@ -1,4 +1,5 @@ \ No newline at end of file + Images + diff --git a/client/partials/network/main.html b/client/partials/network/network.html similarity index 100% rename from client/partials/network/main.html rename to client/partials/network/network.html From b0b2dc9a6451fc1a2d41b255600094da1ece6485 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Sun, 6 Mar 2016 15:04:47 +0100 Subject: [PATCH 11/12] Avalaible images can be display --- client/js/controllers/image/image.js | 10 +++++++--- client/js/services/Image.js | 29 ++++++++++++++++++++++++++-- client/partials/image/image.html | 8 +++++--- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/client/js/controllers/image/image.js b/client/js/controllers/image/image.js index 036dec3..a8346b3 100644 --- a/client/js/controllers/image/image.js +++ b/client/js/controllers/image/image.js @@ -3,7 +3,11 @@ * * @param {$scope} $scope The $scope service from angular */ -mainApp.controller('imageCtrl', function ($scope) +mainApp.controller('imageCtrl', ['$scope', 'Image', function ($scope, Image) { - $scope.title="Test"; -}); + var callbackTest=function(){ + $scope.images=Image.getData().images; + }; + + Image.getImages(callbackTest); +}]); diff --git a/client/js/services/Image.js b/client/js/services/Image.js index eccd4af..2e8c56f 100644 --- a/client/js/services/Image.js +++ b/client/js/services/Image.js @@ -1,10 +1,31 @@ mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){ + var data={}; + data.images=null; var parseUploadImageAnswer=function(response, failedToSendRequest){ - console.log(response.data.Images[0]) + + // Defined return object + var requestParserResult={}; + requestParserResult.status=1; + requestParserResult.failReason=null; + + + if (typeof response.data.Images !== 'undefined') { + // Set status code + requestParserResult.status=0; + data.images=response.data.Images; + + } + else if(failedToSendRequest){ + requestParserResult.failReason="Failed to send request"; + } + else{ + requestParserResult.failReason="Error"; + } + return requestParserResult; }; @@ -24,10 +45,14 @@ mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){ }; + var getData=function(response){ + return data; + }; // Return services objects return { - getImages:getImages + getImages:getImages, + getData:getData }; diff --git a/client/partials/image/image.html b/client/partials/image/image.html index 586f003..8af8af5 100644 --- a/client/partials/image/image.html +++ b/client/partials/image/image.html @@ -1,8 +1,10 @@ -
    +
    - Image + Images disponibles
    - Main Content +
    + {{image.name}} +
    From 3b569b6d008d5b1936ee04948cf5c1cc08790f39 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Sun, 6 Mar 2016 15:10:34 +0100 Subject: [PATCH 12/12] Make some test --- client/js/controllers/home/home.js | 5 +++++ client/js/controllers/image/image.js | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/client/js/controllers/home/home.js b/client/js/controllers/home/home.js index 18133fa..4402e62 100644 --- a/client/js/controllers/home/home.js +++ b/client/js/controllers/home/home.js @@ -16,6 +16,11 @@ mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', 'Loading','I Loading.start(); Compute.pullData(callMeAfterPullData); } + else{ + if(Identity.isAlreadyLogin()){ + callMeAfterPullData(); + } + } Image.getImages(function(){}); diff --git a/client/js/controllers/image/image.js b/client/js/controllers/image/image.js index a8346b3..e298fcc 100644 --- a/client/js/controllers/image/image.js +++ b/client/js/controllers/image/image.js @@ -3,11 +3,19 @@ * * @param {$scope} $scope The $scope service from angular */ -mainApp.controller('imageCtrl', ['$scope', 'Image', function ($scope, Image) +mainApp.controller('imageCtrl', ['$scope', 'Image', 'Loading', function ($scope, Image, Loading) { var callbackTest=function(){ $scope.images=Image.getData().images; + Loading.stop(); }; - Image.getImages(callbackTest); + if(Image.getData().images==null){ + Loading.start(); + Image.getImages(callbackTest); + } + else{ + callbackTest(); + } + }]);