Add fixes for cold reboot

This fixes the cold reboot issue with the following steps

- It applies the command to shut off the chassis.
- Then verify the chassis is off. It checks for every 5 seconds.
  During this time the spinner displays. A 5min timeout has been
  added.
- Once the chassis is off, it turns on the host.

fixes openbmc/openbmc#2795

Change-Id: I119a1c95e57c10ccee27be1512a1fc38cde307fa
Signed-off-by: Iftekharul Islam <iffy.ryan@ibm.com>
Signed-off-by: CamVan Nguyen <ctnguyen@us.ibm.com>
diff --git a/app/common/services/api-utils.js b/app/common/services/api-utils.js
index 1e28127..25cbec9 100644
--- a/app/common/services/api-utils.js
+++ b/app/common/services/api-utils.js
@@ -33,10 +33,11 @@
               LED_STATE: Constants.LED_STATE,
               LED_STATE_TEXT: Constants.LED_STATE_TEXT,
               HOST_SESSION_STORAGE_KEY: Constants.API_CREDENTIALS.host_storage_key,
-              getChassisState: function(callback){
+              getChassisState: function(){
+                var deferred = $q.defer();
                 $http({
                   method: 'GET',
-                  url: DataService.getHost() + "/xyz/openbmc_project/state/chassis0",
+                  url: DataService.getHost() + "/xyz/openbmc_project/state/chassis0/attr/CurrentPowerState",
                   headers: {
                       'Accept': 'application/json',
                       'Content-Type': 'application/json'
@@ -45,15 +46,18 @@
                 }).then(function(response){
                       var json = JSON.stringify(response.data);
                       var content = JSON.parse(json);
-                      callback(content.data.CurrentPowerState);
+                      deferred.resolve(content.data);
                 }, function(error){
                   console.log(error);
+                  deferred.reject(error);
                 });
+                return deferred.promise;
               },
-              getHostState: function(callback){
+              getHostState: function(){
+                var deferred = $q.defer();
                 $http({
                   method: 'GET',
-                  url: DataService.getHost() + "/xyz/openbmc_project/state/host0",
+                  url: DataService.getHost() + "/xyz/openbmc_project/state/host0/attr/CurrentHostState",
                   headers: {
                       'Accept': 'application/json',
                       'Content-Type': 'application/json'
@@ -62,10 +66,12 @@
                 }).then(function(response){
                       var json = JSON.stringify(response.data);
                       var content = JSON.parse(json);
-                      callback(content.data.CurrentHostState);
+                      deferred.resolve(content.data);
                 }, function(error){
                   console.log(error);
+                  deferred.reject(error);
                 });
+                return deferred.promise;
               },
               getNetworkInfo: function(){
                 var deferred = $q.defer();
@@ -287,7 +293,8 @@
                   }
                 });
               },
-              chassisPowerOff: function(callback){
+              chassisPowerOff: function(){
+                var deferred = $q.defer();
                 $http({
                   method: 'PUT',
                   url: DataService.getHost() + "/xyz/openbmc_project/state/chassis0/attr/RequestedPowerTransition",
@@ -300,16 +307,12 @@
                 }).then(function(response){
                       var json = JSON.stringify(response.data);
                       var content = JSON.parse(json);
-                      if(callback){
-                          return callback(content.status);
-                      }
+                      deferred.resolve(content.status);
                 }, function(error){
-                  if(callback){
-                      callback(error);
-                  }else{
-                      console.log(error);
-                  }
+                  console.log(error);
+                  deferred.reject(error);
                 });
+                return deferred.promise;
               },
               setLEDState: function(state, callback){
                 $http({
@@ -359,7 +362,8 @@
                   }
                 });
               },
-              hostPowerOn: function(callback){
+              hostPowerOn: function(){
+                var deferred = $q.defer();
                 $http({
                   method: 'PUT',
                   url: DataService.getHost() + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition",
@@ -372,18 +376,15 @@
                 }).then(function(response){
                       var json = JSON.stringify(response.data);
                       var content = JSON.parse(json);
-                      if(callback){
-                          return callback(content.status);
-                      }
+                      deferred.resolve(content.status);
                 }, function(error){
-                  if(callback){
-                      callback(error);
-                  }else{
-                      console.log(error);
-                  }
+                  console.log(error);
+                  deferred.reject(error);
                 });
+                return deferred.promise;
               },
-              hostPowerOff: function(callback){
+              hostPowerOff: function(){
+                var deferred = $q.defer();
                 $http({
                   method: 'PUT',
                   url: DataService.getHost() + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition",
@@ -396,18 +397,15 @@
                 }).then(function(response){
                       var json = JSON.stringify(response.data);
                       var content = JSON.parse(json);
-                      if(callback){
-                          return callback(content.status);
-                      }
+                      deferred.resolve(content.status);
                 }, function(error){
-                  if(callback){
-                      callback(error);
-                  }else{
-                      console.log(error);
-                  }
+                  console.log(error);
+                  deferred.reject(error);
                 });
+                return deferred.promise;
               },
-              hostReboot: function(callback){
+              hostReboot: function(){
+                var deferred = $q.defer();
                 $http({
                   method: 'PUT',
                   url: DataService.getHost() + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition",
@@ -420,16 +418,13 @@
                 }).then(function(response){
                       var json = JSON.stringify(response.data);
                       var content = JSON.parse(json);
-                      if(callback){
-                          return callback(content.status);
-                      }
+                      deferred.resolve(content.status);
                 }, function(error){
-                  if(callback){
-                      callback(error);
-                  }else{
-                      console.log(error);
-                  }
+                  console.log(error);
+                  deferred.reject(error);
                 });
+
+                return deferred.promise;
               },
               hostShutdown: function(callback){
                 $http({