Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 1 | /** |
| 2 | chassis |
| 3 | /org/openbmc/control/chassis0 —> PowerOn ..PowerOff |
| 4 | |
| 5 | host reboot |
| 6 | /org/openbmc/control/host0 —>reboot |
| 7 | |
| 8 | shutdown |
| 9 | /org/openbmc/control/host0 —> shutdown |
| 10 | **/ |
| 11 | angular |
| 12 | .module('app.services', []) |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 13 | .service('dataService', ['APIUtils', function(APIUtils){ |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 14 | this.app_version = "openBMC V.0.0.1"; |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 15 | this.server_health = 'Error'; |
| 16 | this.server_state = 'Unreachable'; |
| 17 | this.server_status = -2; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 18 | this.chassis_state = 'On'; |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 19 | this.server_id = "Server 9.3.164.147"; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 20 | this.last_updated = new Date(); |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 21 | |
| 22 | this.loading = false; |
| 23 | this.loading_message = ""; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 24 | this.showNavigation = false; |
| 25 | this.bodyStyle = {}; |
| 26 | this.path = ''; |
| 27 | |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 28 | this.setPowerOnState = function(){ |
| 29 | this.server_state = APIUtils.HOST_STATE_TEXT.on; |
| 30 | this.server_status = APIUtils.HOST_STATE.on; |
| 31 | }, |
| 32 | |
| 33 | this.setPowerOffState = function(){ |
| 34 | this.server_state = APIUtils.HOST_STATE_TEXT.off; |
| 35 | this.server_status = APIUtils.HOST_STATE.off; |
| 36 | }, |
| 37 | |
| 38 | this.setBootingState = function(){ |
| 39 | this.server_state = APIUtils.HOST_STATE_TEXT.booting; |
| 40 | this.server_status = APIUtils.HOST_STATE.booting; |
| 41 | }, |
| 42 | |
| 43 | this.setUnreachableState = function(){ |
| 44 | this.server_state = APIUtils.HOST_STATE_TEXT.unreachable; |
| 45 | this.server_status = APIUtils.HOST_STATE.unreachable; |
| 46 | } |
| 47 | }]) |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 48 | .factory('APIUtils', ['$http', function($http){ |
| 49 | var SERVICE = { |
| 50 | LOGIN_CREDENTIALS: { |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 51 | username: "root", |
| 52 | password: "0penBmc", |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 53 | }, |
| 54 | API_CREDENTIALS: { |
| 55 | user: 'root', |
| 56 | password: '0penBmc', |
| 57 | host: 'https://9.3.164.147' |
| 58 | }, |
| 59 | CHASSIS_POWER_STATE: { |
| 60 | on: 'On', |
| 61 | off: 'Off' |
| 62 | }, |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 63 | HOST_STATE_TEXT: { |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 64 | on: 'Running', |
| 65 | off: 'Off', |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 66 | booting: 'Quiesced', |
| 67 | unreachable: 'Unreachable' |
| 68 | }, |
| 69 | HOST_STATE: { |
| 70 | on: 1, |
| 71 | off: -1, |
| 72 | booting: 0, |
| 73 | unreachable: -2 |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 74 | }, |
| 75 | getChassisState: function(callback){ |
| 76 | $http({ |
| 77 | method: 'GET', |
| 78 | url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/chassis0", |
| 79 | headers: { |
| 80 | 'Accept': 'application/json', |
| 81 | 'Content-Type': 'application/json' |
| 82 | }, |
| 83 | withCredentials: true |
| 84 | }).success(function(response){ |
| 85 | var json = JSON.stringify(response); |
| 86 | var content = JSON.parse(json); |
| 87 | callback(content.data.CurrentPowerState); |
| 88 | }).error(function(error){ |
| 89 | console.log(error); |
| 90 | }); |
| 91 | }, |
| 92 | getHostState: function(callback){ |
| 93 | $http({ |
| 94 | method: 'GET', |
| 95 | url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", |
| 96 | headers: { |
| 97 | 'Accept': 'application/json', |
| 98 | 'Content-Type': 'application/json' |
| 99 | }, |
| 100 | withCredentials: true |
| 101 | }).success(function(response){ |
| 102 | var json = JSON.stringify(response); |
| 103 | var content = JSON.parse(json); |
| 104 | callback(content.data.CurrentHostState); |
| 105 | }).error(function(error){ |
| 106 | console.log(error); |
| 107 | }); |
| 108 | }, |
| 109 | login: function(callback){ |
| 110 | $http({ |
| 111 | method: 'POST', |
| 112 | url: SERVICE.API_CREDENTIALS.host + "/login", |
| 113 | headers: { |
| 114 | 'Accept': 'application/json', |
| 115 | 'Content-Type': 'application/json' |
| 116 | }, |
| 117 | withCredentials: true, |
| 118 | data: JSON.stringify({"data": [SERVICE.API_CREDENTIALS.user, SERVICE.API_CREDENTIALS.password]}) |
| 119 | }).success(function(response){ |
| 120 | if(callback){ |
| 121 | callback(response); |
| 122 | } |
| 123 | }).error(function(error){ |
| 124 | console.log(error); |
| 125 | }); |
| 126 | }, |
| 127 | chassisPowerOn: function(callback){ |
| 128 | $http({ |
| 129 | method: 'POST', |
| 130 | url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", |
| 131 | headers: { |
| 132 | 'Accept': 'application/json', |
| 133 | 'Content-Type': 'application/json' |
| 134 | }, |
| 135 | withCredentials: true, |
| 136 | data: JSON.stringify({"data": []}) |
| 137 | }).success(function(response){ |
| 138 | var json = JSON.stringify(response); |
| 139 | var content = JSON.parse(json); |
| 140 | if(callback){ |
| 141 | return callback(content.data.CurrentPowerState); |
| 142 | } |
| 143 | }).error(function(error){ |
| 144 | if(callback){ |
| 145 | callback(error); |
| 146 | }else{ |
| 147 | console.log(error); |
| 148 | } |
| 149 | }); |
| 150 | }, |
| 151 | chassisPowerOff: function(callback){ |
| 152 | $http({ |
| 153 | method: 'POST', |
| 154 | url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", |
| 155 | headers: { |
| 156 | 'Accept': 'application/json', |
| 157 | 'Content-Type': 'application/json' |
| 158 | }, |
| 159 | withCredentials: true, |
| 160 | data: JSON.stringify({"data": []}) |
| 161 | }).success(function(response){ |
| 162 | var json = JSON.stringify(response); |
| 163 | var content = JSON.parse(json); |
| 164 | if(callback){ |
| 165 | return callback(content.data.CurrentPowerState); |
| 166 | } |
| 167 | }).error(function(error){ |
| 168 | if(callback){ |
| 169 | callback(error); |
| 170 | }else{ |
| 171 | console.log(error); |
| 172 | } |
| 173 | }); |
| 174 | }, |
| 175 | hostPowerOn: function(callback){ |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 176 | /** |
| 177 | curl -c cjar -b cjar -k -H "Content-Type: application/json" -d |
| 178 | "{\"data\": \"xyz.openbmc_project.State.Host.Transition.Off\"}" |
| 179 | -X PUT |
| 180 | https://9.3.164.147/xyz/openbmc_project/state/host0/attr/RequestedHostTransition |
| 181 | **/ |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 182 | $http({ |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 183 | method: 'PUT', |
| 184 | url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition", |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 185 | headers: { |
| 186 | 'Accept': 'application/json', |
| 187 | 'Content-Type': 'application/json' |
| 188 | }, |
| 189 | withCredentials: true, |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 190 | data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.On"}) |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 191 | }).success(function(response){ |
| 192 | var json = JSON.stringify(response); |
| 193 | var content = JSON.parse(json); |
| 194 | if(callback){ |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 195 | return callback(content.status); |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 196 | } |
| 197 | }).error(function(error){ |
| 198 | if(callback){ |
| 199 | callback(error); |
| 200 | }else{ |
| 201 | console.log(error); |
| 202 | } |
| 203 | }); |
| 204 | }, |
| 205 | hostPowerOff: function(callback){ |
| 206 | $http({ |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 207 | method: 'PUT', |
| 208 | url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition", |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 209 | headers: { |
| 210 | 'Accept': 'application/json', |
| 211 | 'Content-Type': 'application/json' |
| 212 | }, |
| 213 | withCredentials: true, |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 214 | data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.Off"}) |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 215 | }).success(function(response){ |
| 216 | var json = JSON.stringify(response); |
| 217 | var content = JSON.parse(json); |
| 218 | if(callback){ |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 219 | return callback(content.status); |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 220 | } |
| 221 | }).error(function(error){ |
| 222 | if(callback){ |
| 223 | callback(error); |
| 224 | }else{ |
| 225 | console.log(error); |
| 226 | } |
| 227 | }); |
| 228 | }, |
| 229 | hostReboot: function(callback){ |
| 230 | $http({ |
| 231 | method: 'POST', |
| 232 | url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", |
| 233 | headers: { |
| 234 | 'Accept': 'application/json', |
| 235 | 'Content-Type': 'application/json' |
| 236 | }, |
| 237 | withCredentials: true, |
| 238 | data: JSON.stringify({"data": []}), |
| 239 | }).success(function(response){ |
| 240 | var json = JSON.stringify(response); |
| 241 | var content = JSON.parse(json); |
| 242 | if(callback){ |
| 243 | return callback(content); |
| 244 | } |
| 245 | }).error(function(error){ |
| 246 | if(callback){ |
| 247 | callback(error); |
| 248 | }else{ |
| 249 | console.log(error); |
| 250 | } |
| 251 | }); |
| 252 | }, |
| 253 | hostShutdown: function(callback){ |
| 254 | $http({ |
| 255 | method: 'POST', |
| 256 | url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", |
| 257 | headers: { |
| 258 | 'Accept': 'application/json', |
| 259 | 'Content-Type': 'application/json' |
| 260 | }, |
| 261 | withCredentials: true, |
| 262 | data: JSON.stringify({"data": []}) |
| 263 | }).success(function(response){ |
| 264 | var json = JSON.stringify(response); |
| 265 | var content = JSON.parse(json); |
| 266 | if(callback){ |
| 267 | return callback(content); |
| 268 | } |
| 269 | }).error(function(error){ |
| 270 | if(callback){ |
| 271 | callback(error); |
| 272 | }else{ |
| 273 | console.log(error); |
| 274 | } |
| 275 | }); |
| 276 | } |
| 277 | }; |
| 278 | return SERVICE; |
Iftekharul Islam | 115984a | 2017-03-09 09:47:35 -0600 | [diff] [blame] | 279 | }]) |
| 280 | .factory('userModel',['APIUtils',function(APIUtils){ |
| 281 | return { |
| 282 | login : function(username, password){ |
| 283 | if(username == APIUtils.LOGIN_CREDENTIALS.username && |
| 284 | password == APIUtils.LOGIN_CREDENTIALS.password){ |
| 285 | sessionStorage.setItem('LOGIN_ID', username); |
| 286 | return true; |
| 287 | }else{ |
| 288 | return false; |
| 289 | } |
| 290 | }, |
| 291 | isLoggedIn : function(){ |
| 292 | if(sessionStorage.getItem('LOGIN_ID') === null){ |
| 293 | return false; |
| 294 | } |
| 295 | |
| 296 | return true; |
| 297 | }, |
| 298 | logout : function(){ |
| 299 | sessionStorage.removeItem('LOGIN_ID'); |
| 300 | return true; |
| 301 | } |
| 302 | }; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 303 | }]); |