summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/images/spin/128x128/Preloader_1.gifbin0 -> 71831 bytes
-rw-r--r--client/images/spin/128x128/Preloader_10.gifbin0 -> 19793 bytes
-rw-r--r--client/images/spin/128x128/Preloader_2.gifbin0 -> 7879 bytes
-rw-r--r--client/images/spin/128x128/Preloader_3.gifbin0 -> 22053 bytes
-rw-r--r--client/images/spin/128x128/Preloader_4.gifbin0 -> 19963 bytes
-rw-r--r--client/images/spin/128x128/Preloader_5.gifbin0 -> 84698 bytes
-rw-r--r--client/images/spin/128x128/Preloader_6.gifbin0 -> 19299 bytes
-rw-r--r--client/images/spin/128x128/Preloader_7.gifbin0 -> 12651 bytes
-rw-r--r--client/images/spin/128x128/Preloader_8.gifbin0 -> 81985 bytes
-rw-r--r--client/images/spin/128x128/Preloader_9.gifbin0 -> 48009 bytes
-rw-r--r--client/images/spin/32x32/Preloader_1.gifbin0 -> 17796 bytes
-rw-r--r--client/images/spin/32x32/Preloader_10.gifbin0 -> 5943 bytes
-rw-r--r--client/images/spin/32x32/Preloader_2.gifbin0 -> 3551 bytes
-rw-r--r--client/images/spin/32x32/Preloader_3.gifbin0 -> 7980 bytes
-rw-r--r--client/images/spin/32x32/Preloader_4.gifbin0 -> 6852 bytes
-rw-r--r--client/images/spin/32x32/Preloader_5.gifbin0 -> 22755 bytes
-rw-r--r--client/images/spin/32x32/Preloader_6.gifbin0 -> 5965 bytes
-rw-r--r--client/images/spin/32x32/Preloader_7.gifbin0 -> 4217 bytes
-rw-r--r--client/images/spin/32x32/Preloader_8.gifbin0 -> 13706 bytes
-rw-r--r--client/images/spin/32x32/Preloader_9.gifbin0 -> 13661 bytes
-rw-r--r--client/images/spin/64x64/Preloader_1.gifbin0 -> 35166 bytes
-rw-r--r--client/images/spin/64x64/Preloader_10.gifbin0 -> 10015 bytes
-rw-r--r--client/images/spin/64x64/Preloader_2.gifbin0 -> 4799 bytes
-rw-r--r--client/images/spin/64x64/Preloader_3.gifbin0 -> 12080 bytes
-rw-r--r--client/images/spin/64x64/Preloader_4.gifbin0 -> 10456 bytes
-rw-r--r--client/images/spin/64x64/Preloader_5.gifbin0 -> 41405 bytes
-rw-r--r--client/images/spin/64x64/Preloader_6.gifbin0 -> 9959 bytes
-rw-r--r--client/images/spin/64x64/Preloader_7.gifbin0 -> 6225 bytes
-rw-r--r--client/images/spin/64x64/Preloader_8.gifbin0 -> 25056 bytes
-rw-r--r--client/images/spin/64x64/Preloader_9.gifbin0 -> 23767 bytes
-rw-r--r--client/index.html9
-rw-r--r--client/js/controllers/home/machineDetails.js41
-rw-r--r--client/js/controllers/home/main.js31
-rw-r--r--client/js/controllers/login.js9
-rw-r--r--client/js/controllers/status.js6
-rw-r--r--client/js/services/Compute.js127
-rw-r--r--client/js/services/Identity.js92
-rw-r--r--client/js/services/Loading.js22
-rw-r--r--client/partials/home/machineDetails.html70
-rw-r--r--client/partials/home/main.html10
-rw-r--r--client/partials/loading.html18
-rw-r--r--client/partials/nav.html2
-rwxr-xr-xserver/Test/AppTestClass.php36
-rw-r--r--server/Test/computeTest.php20
-rwxr-xr-x[-rw-r--r--]server/core/App.php15
-rw-r--r--server/core/Compute.php200
-rw-r--r--server/core/Image.php571
-rwxr-xr-x[-rw-r--r--]server/core/LibOverride/genTokenOptions.php10
-rw-r--r--server/index.php16
49 files changed, 1100 insertions, 205 deletions
diff --git a/client/images/spin/128x128/Preloader_1.gif b/client/images/spin/128x128/Preloader_1.gif
new file mode 100644
index 0000000..dafe17e
--- /dev/null
+++ b/client/images/spin/128x128/Preloader_1.gif
Binary files differ
diff --git a/client/images/spin/128x128/Preloader_10.gif b/client/images/spin/128x128/Preloader_10.gif
new file mode 100644
index 0000000..cdfa680
--- /dev/null
+++ b/client/images/spin/128x128/Preloader_10.gif
Binary files differ
diff --git a/client/images/spin/128x128/Preloader_2.gif b/client/images/spin/128x128/Preloader_2.gif
new file mode 100644
index 0000000..3cb9003
--- /dev/null
+++ b/client/images/spin/128x128/Preloader_2.gif
Binary files differ
diff --git a/client/images/spin/128x128/Preloader_3.gif b/client/images/spin/128x128/Preloader_3.gif
new file mode 100644
index 0000000..7f7d415
--- /dev/null
+++ b/client/images/spin/128x128/Preloader_3.gif
Binary files differ
diff --git a/client/images/spin/128x128/Preloader_4.gif b/client/images/spin/128x128/Preloader_4.gif
new file mode 100644
index 0000000..78baff6
--- /dev/null
+++ b/client/images/spin/128x128/Preloader_4.gif
Binary files differ
diff --git a/client/images/spin/128x128/Preloader_5.gif b/client/images/spin/128x128/Preloader_5.gif
new file mode 100644
index 0000000..c9c1530
--- /dev/null
+++ b/client/images/spin/128x128/Preloader_5.gif
Binary files differ
diff --git a/client/images/spin/128x128/Preloader_6.gif b/client/images/spin/128x128/Preloader_6.gif
new file mode 100644
index 0000000..3203d7f
--- /dev/null
+++ b/client/images/spin/128x128/Preloader_6.gif
Binary files differ
diff --git a/client/images/spin/128x128/Preloader_7.gif b/client/images/spin/128x128/Preloader_7.gif
new file mode 100644
index 0000000..2eb19be
--- /dev/null
+++ b/client/images/spin/128x128/Preloader_7.gif
Binary files differ
diff --git a/client/images/spin/128x128/Preloader_8.gif b/client/images/spin/128x128/Preloader_8.gif
new file mode 100644
index 0000000..3ba8217
--- /dev/null
+++ b/client/images/spin/128x128/Preloader_8.gif
Binary files differ
diff --git a/client/images/spin/128x128/Preloader_9.gif b/client/images/spin/128x128/Preloader_9.gif
new file mode 100644
index 0000000..7018192
--- /dev/null
+++ b/client/images/spin/128x128/Preloader_9.gif
Binary files differ
diff --git a/client/images/spin/32x32/Preloader_1.gif b/client/images/spin/32x32/Preloader_1.gif
new file mode 100644
index 0000000..b810330
--- /dev/null
+++ b/client/images/spin/32x32/Preloader_1.gif
Binary files differ
diff --git a/client/images/spin/32x32/Preloader_10.gif b/client/images/spin/32x32/Preloader_10.gif
new file mode 100644
index 0000000..f9c462f
--- /dev/null
+++ b/client/images/spin/32x32/Preloader_10.gif
Binary files differ
diff --git a/client/images/spin/32x32/Preloader_2.gif b/client/images/spin/32x32/Preloader_2.gif
new file mode 100644
index 0000000..f23998f
--- /dev/null
+++ b/client/images/spin/32x32/Preloader_2.gif
Binary files differ
diff --git a/client/images/spin/32x32/Preloader_3.gif b/client/images/spin/32x32/Preloader_3.gif
new file mode 100644
index 0000000..bb7c60d
--- /dev/null
+++ b/client/images/spin/32x32/Preloader_3.gif
Binary files differ
diff --git a/client/images/spin/32x32/Preloader_4.gif b/client/images/spin/32x32/Preloader_4.gif
new file mode 100644
index 0000000..117c756
--- /dev/null
+++ b/client/images/spin/32x32/Preloader_4.gif
Binary files differ
diff --git a/client/images/spin/32x32/Preloader_5.gif b/client/images/spin/32x32/Preloader_5.gif
new file mode 100644
index 0000000..7169708
--- /dev/null
+++ b/client/images/spin/32x32/Preloader_5.gif
Binary files differ
diff --git a/client/images/spin/32x32/Preloader_6.gif b/client/images/spin/32x32/Preloader_6.gif
new file mode 100644
index 0000000..9087ded
--- /dev/null
+++ b/client/images/spin/32x32/Preloader_6.gif
Binary files differ
diff --git a/client/images/spin/32x32/Preloader_7.gif b/client/images/spin/32x32/Preloader_7.gif
new file mode 100644
index 0000000..0b1e633
--- /dev/null
+++ b/client/images/spin/32x32/Preloader_7.gif
Binary files differ
diff --git a/client/images/spin/32x32/Preloader_8.gif b/client/images/spin/32x32/Preloader_8.gif
new file mode 100644
index 0000000..6816be3
--- /dev/null
+++ b/client/images/spin/32x32/Preloader_8.gif
Binary files differ
diff --git a/client/images/spin/32x32/Preloader_9.gif b/client/images/spin/32x32/Preloader_9.gif
new file mode 100644
index 0000000..e38dd5a
--- /dev/null
+++ b/client/images/spin/32x32/Preloader_9.gif
Binary files differ
diff --git a/client/images/spin/64x64/Preloader_1.gif b/client/images/spin/64x64/Preloader_1.gif
new file mode 100644
index 0000000..2004c5f
--- /dev/null
+++ b/client/images/spin/64x64/Preloader_1.gif
Binary files differ
diff --git a/client/images/spin/64x64/Preloader_10.gif b/client/images/spin/64x64/Preloader_10.gif
new file mode 100644
index 0000000..944ec82
--- /dev/null
+++ b/client/images/spin/64x64/Preloader_10.gif
Binary files differ
diff --git a/client/images/spin/64x64/Preloader_2.gif b/client/images/spin/64x64/Preloader_2.gif
new file mode 100644
index 0000000..9821827
--- /dev/null
+++ b/client/images/spin/64x64/Preloader_2.gif
Binary files differ
diff --git a/client/images/spin/64x64/Preloader_3.gif b/client/images/spin/64x64/Preloader_3.gif
new file mode 100644
index 0000000..52b81ba
--- /dev/null
+++ b/client/images/spin/64x64/Preloader_3.gif
Binary files differ
diff --git a/client/images/spin/64x64/Preloader_4.gif b/client/images/spin/64x64/Preloader_4.gif
new file mode 100644
index 0000000..3408b5d
--- /dev/null
+++ b/client/images/spin/64x64/Preloader_4.gif
Binary files differ
diff --git a/client/images/spin/64x64/Preloader_5.gif b/client/images/spin/64x64/Preloader_5.gif
new file mode 100644
index 0000000..6f0585d
--- /dev/null
+++ b/client/images/spin/64x64/Preloader_5.gif
Binary files differ
diff --git a/client/images/spin/64x64/Preloader_6.gif b/client/images/spin/64x64/Preloader_6.gif
new file mode 100644
index 0000000..c577f24
--- /dev/null
+++ b/client/images/spin/64x64/Preloader_6.gif
Binary files differ
diff --git a/client/images/spin/64x64/Preloader_7.gif b/client/images/spin/64x64/Preloader_7.gif
new file mode 100644
index 0000000..5f6dd5e
--- /dev/null
+++ b/client/images/spin/64x64/Preloader_7.gif
Binary files differ
diff --git a/client/images/spin/64x64/Preloader_8.gif b/client/images/spin/64x64/Preloader_8.gif
new file mode 100644
index 0000000..b57e4d8
--- /dev/null
+++ b/client/images/spin/64x64/Preloader_8.gif
Binary files differ
diff --git a/client/images/spin/64x64/Preloader_9.gif b/client/images/spin/64x64/Preloader_9.gif
new file mode 100644
index 0000000..fc3ddb7
--- /dev/null
+++ b/client/images/spin/64x64/Preloader_9.gif
Binary files differ
diff --git a/client/index.html b/client/index.html
index ba183df..8ca2b9f 100644
--- a/client/index.html
+++ b/client/index.html
@@ -26,7 +26,11 @@
<div class="col-lg-12">
<!-- Login Overlay -->
<div ng-include="'./partials/login.html'"></div>
- <!-- Nav -->
+ <!-- Machine Details Overlay -->
+ <div ng-include="'./partials/home/machineDetails.html'"></div>
+ <div ng-include="'./partials/loading.html'"></div>
+
+ <!-- Nav -->
<div ng-include="'./partials/nav.html'"></div>
</div>
</div>
@@ -76,12 +80,15 @@
<script src="./js/services/Identity.js"></script>
<script src="./js/services/Image.js"></script>
<script src="./js/services/Compute.js"></script>
+ <script src="./js/services/Loading.js"></script>
<!-- Include controller -->
<script src="./js/controllers/login.js"></script>
<script src="./js/controllers/status.js"></script>
<script src="./js/controllers/home/main.js"></script>
+ <script src="./js/controllers/home/machineDetails.js"></script>
<script src="./js/controllers/network/main.js"></script>
+
diff --git a/client/js/controllers/home/machineDetails.js b/client/js/controllers/home/machineDetails.js
new file mode 100644
index 0000000..24fac42
--- /dev/null
+++ b/client/js/controllers/home/machineDetails.js
@@ -0,0 +1,41 @@
+/**
+ * The home controller
+ *
+ * @param {$scope} $scope The $scope service from angular
+ */
+mainApp.controller('machineDetailsCtrl', [ '$scope', 'Compute', '$rootScope', '$timeout', function ($scope, Compute, $rootScope, $timeout)
+{
+
+ $scope.machine={};
+ $("#waitingForToggleMachine").hide();
+
+ $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();
+
+ // Fake timeout
+ $timeout(function(){
+ $("#waitingForToggleMachine").hide();
+ }, 3000);
+ $timeout(function(){
+ $scope.machine.online=!$scope.machine.online;
+
+ }, 3000);
+
+
+ };
+
+ $scope.applyModifications=function(){
+ //Todo
+ }
+
+
+
+}]);
diff --git a/client/js/controllers/home/main.js b/client/js/controllers/home/main.js
index d25bfad..f84f625 100644
--- a/client/js/controllers/home/main.js
+++ b/client/js/controllers/home/main.js
@@ -3,15 +3,34 @@
*
* @param {$scope} $scope The $scope service from angular
*/
-mainApp.controller('homeCtrl', [ '$scope', 'Compute', function ($scope, Compute)
+mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', 'Loading','Identity', function ($scope, Compute, $rootScope, Loading, Identity)
{
+ var callMeAfterPullData=function(data){
+ $scope.machines=Compute.getData().machines;
+ Loading.stop();
+ }
- var updatePage=function(){
- // TODO Update graph etc...
+ ;
+ if(Compute.getData().machines == null && Identity.isAlreadyLogin()){
+ Loading.start();
+ Compute.pullData(callMeAfterPullData);
}
- // Retrieve all Data
- Compute.pullData(updatePage);
-
+
+
+
+ $scope.raiseShowMachineDetailsEvent=function(id){
+
+ var callback=function(){
+ Loading.stop();
+ var data=Compute.getData();
+ $rootScope.$broadcast("showMachineDetailsEvent", data.machines[id], data.axioms);
+
+ }
+ Loading.start();
+ Compute.pullMachines(callback);
+ }
+
+
}]);
diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js
index 829fc1d..1a89563 100644
--- a/client/js/controllers/login.js
+++ b/client/js/controllers/login.js
@@ -13,14 +13,19 @@ mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$s
if(!Identity.isAlreadyLogin()){
$('#loginModal').modal({backdrop: 'static', keyboard: false});
}
+
+ // 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();
-
+
+ // Defined function for login
$scope.loginAction=function(){
// Begin login state for template
diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js
index e01df34..940d794 100644
--- a/client/js/controllers/status.js
+++ b/client/js/controllers/status.js
@@ -10,13 +10,11 @@ mainApp.controller('statusCtrl', ['$scope','Identity', '$rootScope', function ($
{
// Give profile to model
- $scope.profile=Identity.profile;
+ $scope.profile=Identity.getProfile();
// Function to logout
- $scope.logout=function(){
- Identity.logout();
+ $scope.raiseLogoutEvent=function(){
$rootScope.$broadcast('logoutEvent');
-
};
}]);
diff --git a/client/js/services/Compute.js b/client/js/services/Compute.js
index c5c8da9..36ddc16 100644
--- a/client/js/services/Compute.js
+++ b/client/js/services/Compute.js
@@ -2,38 +2,139 @@
mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
-
+ // Init data
var data={};
- data.machines={};
+ data.machines=null;
+ data.axioms={} // Contain static data
+ data.axioms.ram=[128,512,1024,2048,4096];
+ data.axioms.disk=[1,2,5,10,25,50,100,150,200]
+ data.axioms.images={}; // Retrieve after
- // Parser
- var parseGetMachinesAnswer=function(response, failedToSendRequest){
+ /**
+ * Parse pullMachines answer
+ * @param {response} the server response
+ * @param {boolean} false if the request as been send true else
+ * @return {requestParserResult} the result of parsing
+ */
+ var parsePullMachinesAnswer=function(response, failedToSendRequest){
+
+ // Defined return object
+ var requestParserResult={};
+ requestParserResult.status=1;
+ requestParserResult.failReason=null;
+
- };
+ if (typeof response.data.Servers !== 'undefined') {
+ // Set status code
+ requestParserResult.status=0;
+ data.machines=response.data.Servers;
+ }
+ else if(failedToSendRequest){
+ requestParserResult.failReason="Failed to send request";
+ }
+ else{
+ requestParserResult.failReason="Error";
+ }
+ return requestParserResult;
+ };
- // Get Machine
- var getMachines=function(callback){
+ /**
+ * Retrieve machine list
+ * @param {callback} function to call after request complete
+ */
+ var pullMachines=function(callback){
+ // Send listServers request
var result=$http.post('../server/index.php',
- $.param({"token" : Identity.profile.token, "task" : "Compute"}));
+ $.param({"token" : Identity.getToken(), "task" : "compute", "action":"listServers"}));
+
+ // Wait and handle the response
+ result.then(function (response){
+ callback(parsePullMachinesAnswer(response, false));
+ },function(response){
+ callback(parsePullMachinesAnswer(response, true));
+ });
+ };
+
+
+ /**
+ * Parse pullImages answer
+ * @param {response} the server response
+ * @param {boolean} false if the request as been send true else
+ * @return {requestParserResult} the result of parsing
+ */
+ var parsePullImagesAnswer=function(response, failedToSendRequest){
+
+ // Defined return object
+ var requestParserResult={};
+ requestParserResult.status=1;
+ requestParserResult.failReason=null;
+ if (typeof response.data.Images !== 'undefined') {
+ // Set status code
+ requestParserResult.status=0;
+ data.axioms.images=response.data.Images;
+ }
+ else if(failedToSendRequest){
+ requestParserResult.failReason="Failed to send request";
+ }
+ else{
+ requestParserResult.failReason="Error";
+ }
+ return requestParserResult;
};
+
+
+
+ /**
+ * Retrieve machine list
+ * @param {callback} function to call after request complete
+ */
+ var pullImages=function(callback){
+ // Send listServers request
+ var result=$http.post('../server/index.php',
+ $.param({"token" : Identity.getToken(), "task" : "compute", "action":"listImages"}));
+
+ // Wait and handle the response
+ result.then(function (response){
+ callback(parsePullImagesAnswer(response, false));
+ },function(response){
+ callback(parsePullImagesAnswer(response, true));
+ });
+ };
+ /**
+ * Retrieve all data
+ * @param {callback} function to call after request complete
+ */
var pullData=function(callback){
- // TODO call getMachines etc...
+ var nextFunction=function(response){
+ if(response.status==0){
+ pullMachines(callback);
+ }
+ }
+ pullImages(nextFunction);
}
-
+
+ /**
+ * Get Data
+ * @return {data} return the data object
+ */
+ var getData=function(){
+ return data;
+ }
+
// Return services objects
return {
- getMachines: getMachines
- pullData: pullData
- data:data
+ pullMachines: pullMachines,
+ pullData: pullData,
+ getData: getData
};
diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js
index 8ee664c..da85ecd 100644
--- a/client/js/services/Identity.js
+++ b/client/js/services/Identity.js
@@ -7,37 +7,50 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
var profile={};
profile.username=null;
profile.projectname=null;
- profile.token=null;
-
-
- /**
- * Save profile in cookies
- */
- var saveCookieForSession=function(){
- $cookies.putObject('profile', 5);
- };
-
+ var token=null;
+
/*
* @returns {boolean} Return true if a cookie is found (and load it in profile) false else
*/
var isAlreadyLogin=function(){
+
+ // Load cookies
var profileInCookie=$cookies.getObject('profile');
- console.log(profileInCookie);
+ var tokenPart_0InCookie=$cookies.getObject('token.part_0');
+ var tokenPart_1InCookie=$cookies.getObject('token.part_1');
+
- if(typeof profileInCookie !== 'undefined'){
+ // Check if cookie is defined
+ if(typeof profileInCookie !== 'undefined'
+ && typeof tokenPart_0InCookie !== 'undefined'
+ && typeof tokenPart_1InCookie !== 'undefined'
+ ){
+
+ // If yes, put it into variables
angular.extend(profile, profileInCookie);
+ token=tokenPart_0InCookie+tokenPart_1InCookie;
+
+ // Return I'm Login
return true;
}
+ // Return I'm not Login
return false;
}
+
+
/*
* Destroy profile cookies
*/
var logout=function(){
$cookies.remove('profile');
+ $cookies.remove('token.part_0');
+ $cookies.remove('token.part_1');
+ token=null;
+ profile.username=null;
+ profile.projectname=null;
}
@@ -49,15 +62,32 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
*/
var parseLoginAnswer=function(response, failedToSendRequest){
-
+ // Defined return object
var requestParserResult={};
requestParserResult.status=1;
requestParserResult.failReason=null;
if (typeof response.data.token !== 'undefined') {
+ // Set status code
requestParserResult.status=0;
- profile.token=response.data.token;
- saveCookieForSession();
+
+ // Find the middle of the token to split it
+ var middle=parseInt(response.data.token.length/2);
+
+ // Create expire date (cookie expire in 55 mins)
+ var expireDate=new Date();
+ expireDate.setMinutes(expireDate.getMinutes()+55);
+
+ // Save profile
+ $cookies.putObject('profile', profile, {'expires': expireDate});
+ // Save first part of token
+ $cookies.putObject('token.part_0', response.data.token.substring(0, middle), {'expires': expireDate});
+ // Save second part of token
+ $cookies.putObject('token.part_1', response.data.token.substring(middle, response.data.token.length), {'expires': expireDate});
+
+ // Put token in var
+ token=response.data.token;
+
}
else if(failedToSendRequest){
requestParserResult.failReason="Failed to send request";
@@ -69,7 +99,6 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
return requestParserResult;
};
-
/**
* Function to connect to OpenStack
@@ -80,31 +109,50 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
* @param {string} projectname The user project name
* @param {function} function to call when data is avalaible
*/
- var login=function(username, password,projectname, callback){
+ var login=function(username, password,projectname,callback){
// Set profile information (early)
profile.username=username;
profile.projectname=projectname;
var result=$http.post('../server/index.php',
- $.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname}));
+ $.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname}));
// Wait and handle the response
result.then(function (response){
- callback(parseLoginAnswer(response), false);
+ callback(parseLoginAnswer(response, false));
},function(response){
- callback(parseLoginAnswer(response), true)
+ callback(parseLoginAnswer(response, true));
});
};
+
+
+ /*
+ * Get the profile
+ */
+ var getProfile=function(){
+ return profile;
+ }
+
+ /*
+ * Get the token
+ */
+ var getToken=function(){
+ return token;
+ }
+
+
+
// Return services objects
return {
login: login,
- profile: profile,
+ getProfile: getProfile,
isAlreadyLogin: isAlreadyLogin,
- logout:logout
+ logout:logout,
+ getToken:getToken
};
diff --git a/client/js/services/Loading.js b/client/js/services/Loading.js
new file mode 100644
index 0000000..b12aaa0
--- /dev/null
+++ b/client/js/services/Loading.js
@@ -0,0 +1,22 @@
+
+mainApp.factory('Loading',[ '$http', 'Identity', function($http, Identity){
+
+
+
+
+ var start=function(){
+ $('#loadingModal').modal({backdrop: 'static', keyboard: false});
+ };
+
+ var stop=function(){
+ $('#loadingModal').modal('hide');
+ }
+
+
+ return {
+ start:start,
+ stop:stop
+ };
+
+
+}]);
diff --git a/client/partials/home/machineDetails.html b/client/partials/home/machineDetails.html
new file mode 100644
index 0000000..47a65fb
--- /dev/null
+++ b/client/partials/home/machineDetails.html
@@ -0,0 +1,70 @@
+<div class="modal" id="machineDetailsModal" ng-controller="machineDetailsCtrl" >
+ <div class="modal-dialog">
+ <div class="modal-content"></div>
+ </div>
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <!--<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>-->
+ <h4 class="modal-title">Machine</h4>
+
+ </div>
+ <div class="modal-body">
+
+ <form class="form-horizontal" role="form">
+ <div class="form-group">
+ <label class="control-label col-sm-2" for="email">Name</label>
+ <div class="col-sm-10">
+ <p class="form-control-static">{{ machine.name }}</p>
+ </div>
+ </div>
+ <div class="form-group">
+ <label class="control-label col-sm-2" for="pwd">State</label>
+ <div class="col-sm-10">
+ <span ng-if="machine.status=='ACTIVE'">Online</span>
+ <span ng-if="machine.status!=='ACTIVE'">Offline</span>
+ &nbsp;
+ <button class="btn btn-danger" ng-if="machine.status=='ACTIVE'" ng-click="toggleMachineState()">Turn Off</button>
+ <button class="btn btn-success" ng-if="machine.status!=='ACTIVE'" ng-click="toggleMachineState()">Turn On</button>
+ &nbsp;<img src="images/spin/32x32/Preloader_1.gif" id="waitingForToggleMachine"></span>
+
+
+ </div>
+ </div>
+ <fieldset class="form-group">
+ <label class="control-label col-sm-2">RAM</label>
+ <select class="col-sm-20" id="ramSelected">
+ <option ng-repeat="ram in axioms.ram" ng-selected="machine.ram == ram">{{ ram }}</option>
+ </select>
+ <span>MB</span>
+ </fieldset>
+
+ <fieldset class="form-group">
+ <label class="control-label col-sm-2">Disk</label>
+ <select class="col-sm-20" id="ramSelected">
+ <option ng-repeat="disk in axioms.disk" ng-selected="machine.disk == disk">{{ disk }}</option>
+ </select>
+ </fieldset>
+
+ <fieldset class="form-group">
+ <label class="control-label col-sm-2">Image</label>
+ <select class="col-sm-20" id="ramSelected">
+ <option ng-repeat="image in axioms.images" ng-selected="machine.imageId == Object.keys(image)">{{ image.name }}</option>
+ </select>
+ </fieldset>
+
+
+
+
+
+ </form>
+
+
+ </div>
+ <div class="modal-footer">
+ <a href="#" data-dismiss="modal" class="btn btn-primary">Apply</a>
+ <a href="#" data-dismiss="modal" class="btn btn-default">Cancel</a>
+ </div>
+ </div>
+ </div>
+</div>
diff --git a/client/partials/home/main.html b/client/partials/home/main.html
index 7a5045a..f9f8878 100644
--- a/client/partials/home/main.html
+++ b/client/partials/home/main.html
@@ -1,8 +1,12 @@
- <div class="panel panel-default">
+ <div class="panel panel-default" ng-controller="homeCtrl">
<div class="panel-heading">
Home
</div>
<div class="panel-body">
- Main Content
+
+ Pour charger les machines, recharger la page (temporaire)<br />
+ Selectionner une machine:
+ <div ng-repeat="machine in machines"> <a ng-click="raiseShowMachineDetailsEvent(machine.id)"> {{ machine.name }}</a></div>
+
</div>
-</div> \ No newline at end of file
+</div>
diff --git a/client/partials/loading.html b/client/partials/loading.html
new file mode 100644
index 0000000..c978190
--- /dev/null
+++ b/client/partials/loading.html
@@ -0,0 +1,18 @@
+<div class="modal fade" id="loadingModal" ng-controller="loginCtrl">
+ <div class="modal-dialog">
+ <div class="modal-content"></div>
+ </div>
+ <div class="modal-dialog" style="width:200px;">
+ <div class="modal-content">
+
+ <div class="modal-body" >
+ <div align="center">
+ <img src="images/spin/128x128/Preloader_8.gif" />
+ </div>
+
+
+ </div>
+
+ </div>
+ </div>
+</div>
diff --git a/client/partials/nav.html b/client/partials/nav.html
index 3c72844..b3ef76a 100644
--- a/client/partials/nav.html
+++ b/client/partials/nav.html
@@ -32,7 +32,7 @@
<li><a href="#">Informations</a></li>
<li><a href="#">Settings</a></li>
<li role="separator" class="divider"></li>
- <li><a href="#" ng-click="logout()">Logout</a></li>
+ <li><a href="#" ng-click="raiseLogoutEvent()">Logout</a></li>
</ul>
</li>
</ul>
diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php
index 311b9bf..4d7cab5 100755
--- a/server/Test/AppTestClass.php
+++ b/server/Test/AppTestClass.php
@@ -6,6 +6,7 @@ class AppTest{
protected $openstack;
protected $pluginsApi;
+ protected $postParams;
protected $tokenClass;
protected $tokenPost;
protected $output;
@@ -16,7 +17,9 @@ class AppTest{
$this->tokenClass = new genTokenOptions($args);
$this->openstack = new OpenStack\OpenStack([]);
$this->pluginsApi = plugin_api::getInstance();
+ $this->errorClass = new errorManagement($this);
$this->output = array();
+ $this->postParams = $_POST;
}
@@ -40,6 +43,16 @@ class AppTest{
$opt = $this->tokenClass->getOptions($service);
return $this->openstack->imagesV2($opt);
break;
+ case "Compute":
+ if($this->tokenPost == NULL) $this->tokenClass->genComputeToken();
+ $opt = $this->tokenClass->getOptions($service);
+ return $this->openstack->computeV2($opt);
+ break;
+ case "Network":
+ if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken();
+ $opt = $this->tokenClass->getOptions($service);
+ return $this->openstack->networkingV2($opt);
+ break;
}
}
@@ -53,10 +66,21 @@ class AppTest{
$this->tokenClass->genNetworkToken();
$this->setOutput("token", $this->tokenClass->getBackup());
- }catch(Exception $e){
- echo $e;
- exit();
- }
+ }catch(BadResponseError $e){
+ $this->errorClass->BadResponseHandler($e);
+ }catch(UserInputError $e){
+ $this->errorClass->UserInputHandler($e);
+ }catch(BaseError $e){
+ $this->errorClass->BaseErrorHandler($e);
+ }catch(NotImplementedError $e){
+ $this->errorClass->NotImplementedHandler($e);
+ }
+
+ }
+
+ public function getPostParam($name){
+
+ return $this->postParams[$name];
}
@@ -67,7 +91,7 @@ class AppTest{
}
public function show(){
- echo json_encode($this->output);
+ return json_encode($this->output);
}
-} \ No newline at end of file
+}
diff --git a/server/Test/computeTest.php b/server/Test/computeTest.php
new file mode 100644
index 0000000..3ce1f2e
--- /dev/null
+++ b/server/Test/computeTest.php
@@ -0,0 +1,20 @@
+re '../vendor/autoload.php';
+include('/istic-openstack/server/init.php');
+include_once("../core/Compute.php");
+$compute = new compute($App);
+
+$servers = $compute->listServers();
+
+$servers= $compute->listServers(true);
+foreach($servers as $server){
+ //print_r($server);
+ echo $server->name." ".$server->id."<br>";
+
+//$opt = Array();
+//$opt['name'] = "Test";
+//$serverid = Array("id"=>"69d5bcc4-2fab-4634-b0d2-f455fee5b7bd");
+//$serverid["id"] = "{69d5bcc4-2fab-4634-b0d2-f455fee5b7bd}";
+//unset($server);
+//$server = $compute->getServer($serverid);
+//echo $server->name." ".$server->image;
+//$server->update(array('name' => 'test'));
diff --git a/server/core/App.php b/server/core/App.php
index babb3d9..edb75f6 100644..100755
--- a/server/core/App.php
+++ b/server/core/App.php
@@ -33,7 +33,7 @@ class App{
public function setToken($token){
$this->tokenPost = $token;
- $this->tokenClass->loadBackup($his->tokenPost);
+ $this->tokenClass->loadBackup($this->tokenPost);
}
@@ -50,6 +50,16 @@ class App{
$opt = $this->tokenClass->getOptions($service);
return $this->openstack->imagesV2($opt);
break;
+ case "Network":
+ if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken();
+ $opt = $this->tokenClass->getOptions($service);
+ return $this->openstack->networkingV2($opt);
+ break;
+ case "Compute":
+ if($this->tokenPost == NULL) $this->tokenClass->genComputeToken();
+ $opt = $this->tokenClass->getOptions($service);
+ return $this->openstack->computeV2($opt);
+ break;
}
}
@@ -95,6 +105,7 @@ class App{
public function show(){
echo json_encode($this->output);
+ //error_log(var_dump(json_encode($this->output), true), 0);
}
-} \ No newline at end of file
+}
diff --git a/server/core/Compute.php b/server/core/Compute.php
index 8d1c8b6..a5b8375 100644
--- a/server/core/Compute.php
+++ b/server/core/Compute.php
@@ -1 +1,201 @@
+<?php
+//namespace istic-openstack\Server\core;
+// TODO introduce error-handling based on errors specific to the compute module
+use OpenStack\Common\Error;
+
+class compute
+{
+ /** @var App $app protected, contains the main app object */
+ protected $app;
+
+ /** @var OpenStack\Identity $libClass protected, contains the library Compute object */
+ protected $libClass;
+
+
+ public function __construct($app)
+ {
+ $this->app = $app;
+ $this->libClass = $app->getLibClass("Compute");
+ }
+ /**
+ * Execute an action
+ *
+ * @param String $action name of another function of this class
+ *
+ * @return void
+ */
+ public function action($action){
+
+ $this->{$action.""}();
+
+ }
+ /**
+ * List servers.
+ * @return array
+ */
+ public function listServers()
+ {
+ $serverList = $this->libClass->listServers(true);
+ $servers = Array();
+ foreach($serverList as $server){
+ $servers[$server->id] = Array();
+ $server->flavor->retrieve();
+ $server->image->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]["ram"] = $server->flavor->ram;
+ $servers[$server->id]["disk"] = $server->flavor->disk;
+ }
+ $this->app->setOutput("Servers", $servers);
+ return;
+ }
+ /**
+ * List flavors.
+ * @return array
+ */
+ public function listFlavors()
+ {
+ $flavorList = $this->libClass->listFlavors();
+ $flavors = Array();
+ foreach($flavorList as $flavor){
+ $flavors[$flavor->id] = Array();
+ $flavors[$flavor->id]["id"] = $flavor->id;
+ $flavors[$flavor->id]["name"] = $flavor->name;
+ }
+ $this->app->setOutput("Flavors", $flavors);
+ return;
+ }
+ /**
+ * List images.
+ * @return array
+ */
+ public function listImages()
+ {
+ $imageList = $this->libClass->listImages();
+ $images = Array();
+ foreach($imageList as $image){
+ $images[$image->id] = Array();
+ $images[$image->id]["id"] = $image->id;
+ $images[$image->id]["name"] = $image->name;
+ }
+ $this->app->setOutput("Images", $images);
+ return;
+ }
+ /**
+ * Create server.
+ * @return array
+ *
+ public function createServer()
+ {
+
+ $server = $this->libClass->createServer();
+ }
+ */
+ /**
+ * Get server details.
+ * @return array
+ */
+ public function getServer()
+ {
+ $serverId = $this->app->getPostParam("serverId");
+ $opt = array('id' => $serverId);
+ $server = $this->libClass->getServer($opt);
+ $server->retrieve();
+ $this->app->setOutput("MyServer", $server);
+ return;
+ }
+ /**
+ * Get flavor details.
+ * @return array
+ */
+ public function getFlavor()
+ {
+ $flavorId = $this->app->getPostParam("flavorId");
+ $opt = array('id' => $flavorId);
+ $flavor = $this->libClass->getFlavor($opt);
+ $flavor->retrieve();
+ $this->app->setOutput("MyFlavor", $flavor);
+ return;
+ }
+ /**
+ * Get image details.
+ * @return array
+ */
+ public function getImage()
+ {
+ $imageId = $this->app->getPostParam("imageId");
+ $opt = array('id' => $imageId);
+ $image = $this->libClass->getImage($opt);
+ $image->retrieve();
+ $this->app->setOutput("MyImage", $image);
+ return;
+ }
+ /* working on tests
+
+ public function update()
+ {
+ $image = $this->app->getServer(array $options = []);
+
+ }
+ public function delete()
+ {
+ //TODO
+ }
+ public function changePassword($newPassword)
+ {
+ //TODO
+ }
+ public function reboot($type = Enum::REBOOT_SOFT)
+ {
+ //TODO
+ }
+ public function rebuild(array $options)
+ {
+ //TODO
+ }
+ public function resize($flavorId)
+ {
+ //TODO
+ }
+ public function confirmResize()
+ {
+ //TODO
+ }
+ public function revertResize()
+ {
+ //TODO
+ }
+ public function createImage(array $options)
+ {
+ //TODO
+ }
+ public function listAddresses(array $options = [])
+ {
+ //TODO
+ }
+ public function getMetadata()
+ {
+ //TODO
+ }
+ public function resetMetadata(array $metadata)
+ {
+ //TODO
+ }
+ public function mergeMetadata(array $metadata)
+ {
+ //TODO
+ }
+ public function getMetadataItem($key)
+ {
+ //TODO
+ }
+ public function deleteMetadataItem($key)
+ {
+ //TODO
+ }
+*/
+}
diff --git a/server/core/Image.php b/server/core/Image.php
index 3001eea..4025595 100644
--- a/server/core/Image.php
+++ b/server/core/Image.php
@@ -1,7 +1,4 @@
<?php
-
-//require 'CoreInterface.php';
-
/**
* File containing the Image Class.
*
@@ -12,16 +9,18 @@
*
* @todo Complete the functions with errors detection and finish the descriptions
*/
-
-
+use OpenStack\Common\Error\BadResponseError;
+use OpenStack\Common\Error\BaseError;
+use OpenStack\Common\Error\NotImplementedError;
+use OpenStack\Common\Error\UserInputError;
+
/**
* Image Class of the back-end application
*
* ADD CLASS DESCRIPTION
*
*/
-class image{
- //implements Core
+class image implements Core{
/** @var App $app protected, contains the main app object */
protected $app;
@@ -29,10 +28,6 @@ class image{
/** @var OpenStack\Identity $libClass protected, contains the library Identity object */
protected $libClass;
- /** @var array $actions protected, contains the functions which can be call by the front-end */
- protected $actions = array();
-
-
/**
* Image constructor
*
@@ -43,12 +38,36 @@ class image{
* @return Image
*/
public function __construct($app){
- $this->app = $app;
- $this->libClass = $app->getLibClass("Image");
+ if(!isset($app)){
+ $this->app->setOutput("Error", "Incorrect parameter");
+ }
+ try{
+ $this->app = $app;
+ $this->libClass = $app->getLibClass("Image");
+ }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);
+ }
}
-
+ /**
+ * Execute an action
+ *
+ * @param String $action name of another function of this class
+ *
+ * @return void
+ */
+ public function action($action){
+
+ $this->{$action.""}();
+
+ }
/**
* Details about an image
@@ -57,55 +76,96 @@ class image{
* 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, vérifier nom pas déjà pris
- }
- else{
- //ERROR
- }
- 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'];
+ private function createImage(array $opt){
+
+ if(!isset($opt)){
+ $this->app->setOutput("Error", "Incorrect parameter");
}
- if(isset($opt['properties'])){ // type dict ?
- $options['properties'] = $opt['properties'];
- }
- $image = $this->oidentity->createImage($options);
+ try{
+ // VOIR SI MAUVAIS TYPE
+ $options = Array();
+ if(isset($opt['name'])){ // if the image name already exists -> error
+ $imagesList = listImage();
+ if(isset($images)){
+ foreach($imagesList as $image){
+ if(strcmp($image->name, $opt['name']) == 0){
+
+ }
+ }
+ }
+
+ }
+ else{
+ $this->app->setOutput("Error", "Image name already exists");
+ }
+ if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn
+ if($this->libClass->getImage($opt['id']) != null){ // if the id already exists -> error
+
+ }
+ $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->libClass->createImage($options);
+ }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);
+ }
return $image;
}
- /*
- * List images
+ /**
+ * List the images of the server
+ *
+ * @return the list with all images on the server
*/
- public function list_images(){
- // vérifier si au moins une image
- $service = $this->oidentity;
- $images = $service->listImages();
- return $images;
+ private function listImage(){
+ try{
+ $l = $this->libClass->listImages();
+ if(!isset($l)){ // if the list is empty there is no images
+ $this->app->setOutput("Error", "No image");
+ }
+ }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);
+ }
+ return $l;
+
}
/**
@@ -115,11 +175,27 @@ class image{
* identifier of the image
*
**/
- public function image_details($id){
- //vérifier existence image
- $service = $this->oidentity;
- $image = $service->getImage($id);
- return $image;
+ private function detailsImage($id){
+ if(!isset($id)){
+ // Renvoyer erreur
+ }
+ try{
+ $service = $this->libClass;
+ $image = $service->getImage($id);
+ if($image == null){ // if the image don't exists -> error
+ $this->app->setOutput("Error", "Image doesn't exist");
+ }
+
+ return $image;
+ }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);
+ }
}
/**
@@ -131,33 +207,53 @@ class image{
* @param array $opt
* options for the image creation
**/
- public function update_image($id, array $opt){
- //vérifier existence image
- $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'];
+ private function updateImage($id, array $opt){
+ if(!isset($id)){
+ $this->app->setOutput("Error", "Incorrect id parameter");
}
- if(isset($opt['visibility'])){ // public, private
- $options['visibility'] = $opt['visibility'];
+ if(!isset($opt)){
+ $this->app->setOutput("Error", "Incorrect opt parameter");
}
- if(isset($opt['tags'])){ // list
- $options['tags'] = $opt['tags'];
- }
- $image->update($options);
+ try{
+ //vérifier existence image
+ $service = $this->libClass;
+ $image = $service->getImage($id);
+ if($image == null){ // if the image don't exists -> error
+ $this->app->setOutput("Error", "Image doesn't exist");
+ }
+
+ $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);
+ }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);
+ }
return $image;
}
@@ -167,11 +263,30 @@ class image{
* @param string $id
* identifier of the image
**/
- public function delete_image($id){
+ private function deleteImage($id){
// si protected = true, demander de le mettre a false
// vérifier existence image
- $service = $this->oidentity;
- $service->getImage($id)->delete();
+ if(!isset($id)){
+ $this->app->setOutput("Error", "Image doesn't exist");
+ }
+
+ try{
+ $service = $this->libClass;
+ $image = $this->libClass->getImage($id);
+ if($image == null){ // if the image don't exists -> error
+ $this->app->setOutput("Error", "Image doesn't exist");
+ }
+ $image->delete();
+ }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);
+ }
+
}
/**
@@ -180,11 +295,27 @@ class image{
* @param string $id
* identifier of the image
**/
- public function reactivate_image($id){
- // vérifier existence image
- $service = $this->oidentity;
- $image = $service->getImage($id);
- $image->reactivate();
+ private function reactivateImage($id){
+ if(!isset($id)){
+ $this->app->setOutput("Error", "Incorrect parameter");
+ }
+ try{
+ // vérifier existence image
+ $service = $this->libClass;
+ $image = $service->getImage($id);
+ if($image == null){ // if the image don't exists -> error
+ $this->app->setOutput("Error", "Image doesn't exist");
+ }
+ $image->reactivate();
+ }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);
+ }
}
/**
@@ -193,11 +324,27 @@ class image{
* @param string $id
* identifier of the image
**/
- public function desactivate_image($id){
- // vérifier existence image
- $service = $this->oidentity;
- $image = $service->getImage($id);
- $image->deactivate();
+ private function desactivateImage($id){
+ if(!isset($id)){
+ $this->app->setOutput("Error", "Incorrect parameter");
+ }
+ try{
+ // vérifier existence image
+ $service = $this->libClass;
+ $image = $service->getImage($id);
+ if($image == null){ // if the image don't exists -> error
+ $this->app->setOutput("Error", "Image doesn't exist");
+ }
+ $image->deactivate();
+ }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);
+ }
}
/**
@@ -209,12 +356,31 @@ class image{
* @param string $file_name
* path of the image
**/
- public function upload_image($id, $file_name){
- // vérifier existence image
- $service = $this->oidentity;
- $image = $service->getImage($id);
- $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR
- $image->uploadData($stream);
+ private function uploadImage($id, $file_name){
+ if(!isset($id)){
+ $this->app->setOutput("Error", "Incorrect id parameter");
+ }
+ if(!isset($file_name)){
+ $this->app->setOutput("Error", "Incorrect file_name parameter");
+ }
+ try{
+ // vérifier existence image
+ $service = $this->libClass;
+ $image = $service->getImage($id);
+ if($image == null){ // if the image don't exists -> error
+ $this->app->setOutput("Error", "Image doesn't exist");
+ }
+ $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r'));
+ $image->uploadData($stream);
+ }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);
+ }
}
/**
@@ -223,12 +389,28 @@ class image{
* @param string $id
* identifier of the image
**/
- public function download_image($id){
- // vérifier existence image
- $service = $this->oidentity;
- $image = $service->getImage($id);
- $stream = $image->downloadData();
- return $stream;
+ private function downloadImage($id){
+ if(!isset($id)){
+ $this->app->setOutput("Error", "Incorrect parameter");
+ }
+ try{
+ // vérifier existence image
+ $service = $this->libClass;
+ $image = $service->getImage($id);
+ if($image == null){ // if the image don't exists -> error
+ $this->app->setOutput("Error", "Image doesn't exist");
+ }
+ $stream = $image->downloadData();
+ }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);
+ }
+ return $stream;
}
/**
@@ -240,12 +422,30 @@ class image{
* @param string $member_id
* identifier of the member
**/
- public function add_member($image_id, $member_id){
- // vérifier existence image
- // on doit être le proprio de l'image
- // vérifier membre existe
- $service = $this->oidentity;
- $member_id = $service>getImage($image_id)->addMember($member_id);
+ private function addMemberImage($image_id, $member_id){
+ if(!isset($image_id)){
+ $this->app->setOutput("Error", "Incorrect parameter image_id");
+ }
+ if(!isset($member_id)){
+ $this->app->setOutput("Error", "Incorrect parameter member_id");
+ }
+ try{
+ $service = $this->libClass;
+
+ $image = $service->getImage($id);
+ if($image == null){ // if the image don't exists -> error
+ $this->app->setOutput("Error", "Image doesn't exist");
+ }
+ $member_id = $image->addMember($member_id);
+ }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);
+ }
}
@@ -255,11 +455,33 @@ class image{
* @param string $image_id
* identifier of the image
**/
- public function list_member($image_id, $member_id){
- // vérifier existence image
- $service = $this->oidentity;
- $image = $service->getImage($image_id);
- $members = $image->listMembers();
+ private function listMemberImage($image_id, $member_id){
+ if(!isset($image_id)){
+ $this->app->setOutput("Error", "Incorrect parameter image_id");
+ }
+ if(!isset($member_id)){
+ $this->app->setOutput("Error", "Incorrect parameter member_id");
+ }
+ try{
+ // vérifier existence image
+ $service = $this->libClass;
+ $image = $service->getImage($image_id);
+ if($image == null){ // if the image don't exists -> error
+ $this->app->setOutput("Error", "Image doesn't exist");
+ }
+ $members = $image->listMembers();
+ if($member == null){ // if the image don't exists -> error
+ $this->app->setOutput("Error", "No member");
+ }
+ }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);
+ }
return $members;
}
@@ -272,12 +494,37 @@ class image{
* @param string $member_id
* identifier of the member
**/
- public function detail_member($image_id, $member_id){
- // vérifier existence image
- // on doit être le proprio de l'image
- // vérifier membre existe
- $service = $this->oidentity;
- $member = $service>getImage($image_id)->getMember($member_id);
+ private function detailMemberImage($image_id, $member_id){
+ if(!isset($image_id)){
+ $this->app->setOutput("Error", "Incorrect parameter image_id");
+ }
+ if(!isset($member_id)){
+ $this->app->setOutput("Error", "Incorrect parameter member_id");
+ }
+ try{
+ // vérifier existence image
+ // on doit être le proprio de l'image
+ // vérifier membre existe
+ $service = $this->libClass;
+
+ $image = $service->getImage($id);
+ if($image == null){ // if the image don't exists -> error
+ $this->app->setOutput("Error", "Image doesn't exist");
+ }
+
+ $member = $image->getMember($member_id);
+ if($member == null){ // if the member don't exists -> error
+ $this->app->setOutput("Error", "Member doesn't exist");
+ }
+ }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);
+ }
return $member;
}
@@ -290,12 +537,34 @@ class image{
* @param string $member_id
* identifier of the member
**/
- public function remove_member($image_id, $member_id){
- // vérifier existence image
- // on doit être le proprio de l'image
- // vérifier membre existe
- $service = $this->oidentity;
- $service>getImage($image_id)->getMember($member_id)->delete();
+ private function removeMemberImage($image_id, $member_id){
+ if(!isset($image_id)){
+ $this->app->setOutput("Error", "Incorrect parameter image_id");
+ }
+ if(!isset($member_id)){
+ $this->app->setOutput("Error", "Incorrect parameter member_id");
+ }
+ try{
+ $service = $this->libClass;
+
+ $image = $service->getImage($id);
+ if($image == null){ // if the image don't exists -> error
+ $this->app->setOutput("Error", "Image doesn't exist");
+ }
+ $member = $image->getMember($member_id);
+ if($member == null){ // if the image don't exists -> error
+ $this->app->setOutput("Error", "Member doesn't exist");
+ }
+ $member->delete();
+ }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);
+ }
}
/**
@@ -310,13 +579,35 @@ class image{
* @param string $status
* new status for the member
**/
- public function update_member($image_id, $member_id, $status){
- // vérifier existence image
- // on doit être le proprio de l'image
- // vérifier membre existe
- $service = $this->oidentity;
- $member = $service>getImage($image_id)->getMember($member_id)->updateStatus($status);
+ private function updateMemberImage($image_id, $member_id, $status){
+ if(!isset($image_id)){
+ $this->app->setOutput("Error", "Incorrect parameter image_id");
+ }
+ if(!isset($member_id)){
+ $this->app->setOutput("Error", "Incorrect parameter member_id");
+ }
+ try{
+ $service = $this->libClass;
+
+ $image = $service->getImage($id);
+ if($image == null){ // if the image don't exists -> error
+ $this->app->setOutput("Error", "Image doesn't exist");
+ }
+ $member = $image->getMember($member_id);
+ if($member == null){ // if the member don't exists -> error
+ $this->app->setOutput("Error", "Member doesn't exist");
+ }
+ $member->updateStatus($status);
+ }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);
+ }
}
}
-?>
+?> \ No newline at end of file
diff --git a/server/core/LibOverride/genTokenOptions.php b/server/core/LibOverride/genTokenOptions.php
index b71defa..50826ed 100644..100755
--- a/server/core/LibOverride/genTokenOptions.php
+++ b/server/core/LibOverride/genTokenOptions.php
@@ -260,13 +260,14 @@ class genTokenOptions
public function loadBackup($back){
$backup = unserialize($back);
+
$this->backup["roles"] = $backup["roles"];
$this->backup["project"] = $backup["project"];
$this->backup["user"] = $backup["user"];
- loadComputeBackup($backup["Compute"]);
- loadIdentityBackup($backup["Identity"]);
- loadImageBackup($backup["Image"]);
- loadNetworkBackup($backup["Network"]);
+ $this->loadComputeBackup($backup["Compute"]);
+ $this->loadIdentityBackup($backup["Identity"]);
+ $this->loadImageBackup($backup["Image"]);
+ $this->loadNetworkBackup($backup["Network"]);
}
@@ -324,6 +325,7 @@ class genTokenOptions
private function unserializeToken($tokenSerialized){
$Saved = file_get_contents("core/LibOverride/projectTokenData/".$this->backup["project"]);
+ $Saved = unserialize($Saved);
$api = new Api();
$token = new Models\Token($this->httpClient, $api);
$token->methods = unserialize($tokenSerialized["methods"]);
diff --git a/server/index.php b/server/index.php
index 166e82e..f888671 100644
--- a/server/index.php
+++ b/server/index.php
@@ -27,12 +27,26 @@
$identityObject->action($action);
$App->show();
break;
-
+
+ case "network":
+ include_once("core/Network.php");
+ $networkObject = new network($App);
+ $networkObject->action($action);
+ $App->show();
+ break;
+
case "image":
include_once("core/Image.php");
$imageObject = new image($App);
$imageObject->action($action);
$App->show();
break;
+
+ case "compute":
+ include_once("core/Compute.php");
+ $computeObject = new compute($App);
+ $computeObject->action($action);
+ $App->show();
+ break;
}