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', []) |
| 13 | .service('dataService', function(){ |
| 14 | this.app_version = "openBMC V.0.0.1"; |
| 15 | this.server_health = 'Error'; |
| 16 | this.server_state = 'On'; |
| 17 | this.chassis_state = 'On'; |
| 18 | this.server_id = "Server BLZ_109284.209.01"; |
| 19 | this.last_updated = new Date(); |
| 20 | |
| 21 | this.showNavigation = false; |
| 22 | this.bodyStyle = {}; |
| 23 | this.path = ''; |
| 24 | |
| 25 | }) |
| 26 | .factory('APIUtils', ['$http', function($http){ |
| 27 | var SERVICE = { |
| 28 | LOGIN_CREDENTIALS: { |
| 29 | username: "test", |
| 30 | password: "testpass", |
| 31 | }, |
| 32 | API_CREDENTIALS: { |
| 33 | user: 'root', |
| 34 | password: '0penBmc', |
| 35 | host: 'https://9.3.164.147' |
| 36 | }, |
| 37 | CHASSIS_POWER_STATE: { |
| 38 | on: 'On', |
| 39 | off: 'Off' |
| 40 | }, |
| 41 | HOST_STATE: { |
| 42 | on: 'Running', |
| 43 | off: 'Off', |
| 44 | booting: 'Quiesced' |
| 45 | }, |
| 46 | getChassisState: function(callback){ |
| 47 | $http({ |
| 48 | method: 'GET', |
| 49 | url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/chassis0", |
| 50 | headers: { |
| 51 | 'Accept': 'application/json', |
| 52 | 'Content-Type': 'application/json' |
| 53 | }, |
| 54 | withCredentials: true |
| 55 | }).success(function(response){ |
| 56 | var json = JSON.stringify(response); |
| 57 | var content = JSON.parse(json); |
| 58 | callback(content.data.CurrentPowerState); |
| 59 | }).error(function(error){ |
| 60 | console.log(error); |
| 61 | }); |
| 62 | }, |
| 63 | getHostState: function(callback){ |
| 64 | $http({ |
| 65 | method: 'GET', |
| 66 | url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", |
| 67 | headers: { |
| 68 | 'Accept': 'application/json', |
| 69 | 'Content-Type': 'application/json' |
| 70 | }, |
| 71 | withCredentials: true |
| 72 | }).success(function(response){ |
| 73 | var json = JSON.stringify(response); |
| 74 | var content = JSON.parse(json); |
| 75 | callback(content.data.CurrentHostState); |
| 76 | }).error(function(error){ |
| 77 | console.log(error); |
| 78 | }); |
| 79 | }, |
| 80 | login: function(callback){ |
| 81 | $http({ |
| 82 | method: 'POST', |
| 83 | url: SERVICE.API_CREDENTIALS.host + "/login", |
| 84 | headers: { |
| 85 | 'Accept': 'application/json', |
| 86 | 'Content-Type': 'application/json' |
| 87 | }, |
| 88 | withCredentials: true, |
| 89 | data: JSON.stringify({"data": [SERVICE.API_CREDENTIALS.user, SERVICE.API_CREDENTIALS.password]}) |
| 90 | }).success(function(response){ |
| 91 | if(callback){ |
| 92 | callback(response); |
| 93 | } |
| 94 | }).error(function(error){ |
| 95 | console.log(error); |
| 96 | }); |
| 97 | }, |
| 98 | chassisPowerOn: function(callback){ |
| 99 | $http({ |
| 100 | method: 'POST', |
| 101 | url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", |
| 102 | headers: { |
| 103 | 'Accept': 'application/json', |
| 104 | 'Content-Type': 'application/json' |
| 105 | }, |
| 106 | withCredentials: true, |
| 107 | data: JSON.stringify({"data": []}) |
| 108 | }).success(function(response){ |
| 109 | var json = JSON.stringify(response); |
| 110 | var content = JSON.parse(json); |
| 111 | if(callback){ |
| 112 | return callback(content.data.CurrentPowerState); |
| 113 | } |
| 114 | }).error(function(error){ |
| 115 | if(callback){ |
| 116 | callback(error); |
| 117 | }else{ |
| 118 | console.log(error); |
| 119 | } |
| 120 | }); |
| 121 | }, |
| 122 | chassisPowerOff: function(callback){ |
| 123 | $http({ |
| 124 | method: 'POST', |
| 125 | url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", |
| 126 | headers: { |
| 127 | 'Accept': 'application/json', |
| 128 | 'Content-Type': 'application/json' |
| 129 | }, |
| 130 | withCredentials: true, |
| 131 | data: JSON.stringify({"data": []}) |
| 132 | }).success(function(response){ |
| 133 | var json = JSON.stringify(response); |
| 134 | var content = JSON.parse(json); |
| 135 | if(callback){ |
| 136 | return callback(content.data.CurrentPowerState); |
| 137 | } |
| 138 | }).error(function(error){ |
| 139 | if(callback){ |
| 140 | callback(error); |
| 141 | }else{ |
| 142 | console.log(error); |
| 143 | } |
| 144 | }); |
| 145 | }, |
| 146 | hostPowerOn: function(callback){ |
| 147 | $http({ |
| 148 | method: 'POST', |
| 149 | url: SERVICE.API_CREDENTIALS.host + "xyz/openbmc_project/state/host0/attr/RequestedHostTransition", |
| 150 | headers: { |
| 151 | 'Accept': 'application/json', |
| 152 | 'Content-Type': 'application/json' |
| 153 | }, |
| 154 | withCredentials: true, |
| 155 | data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.Off"}) |
| 156 | }).success(function(response){ |
| 157 | var json = JSON.stringify(response); |
| 158 | var content = JSON.parse(json); |
| 159 | if(callback){ |
| 160 | return callback(content.data.CurrentHostState); |
| 161 | } |
| 162 | }).error(function(error){ |
| 163 | if(callback){ |
| 164 | callback(error); |
| 165 | }else{ |
| 166 | console.log(error); |
| 167 | } |
| 168 | }); |
| 169 | }, |
| 170 | hostPowerOff: function(callback){ |
| 171 | $http({ |
| 172 | method: 'POST', |
| 173 | url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", |
| 174 | headers: { |
| 175 | 'Accept': 'application/json', |
| 176 | 'Content-Type': 'application/json' |
| 177 | }, |
| 178 | withCredentials: true, |
| 179 | data: JSON.stringify({"data": []}), |
| 180 | }).success(function(response){ |
| 181 | var json = JSON.stringify(response); |
| 182 | var content = JSON.parse(json); |
| 183 | if(callback){ |
| 184 | return callback(content.data.CurrentHostState); |
| 185 | } |
| 186 | }).error(function(error){ |
| 187 | if(callback){ |
| 188 | callback(error); |
| 189 | }else{ |
| 190 | console.log(error); |
| 191 | } |
| 192 | }); |
| 193 | }, |
| 194 | hostReboot: function(callback){ |
| 195 | $http({ |
| 196 | method: 'POST', |
| 197 | url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", |
| 198 | headers: { |
| 199 | 'Accept': 'application/json', |
| 200 | 'Content-Type': 'application/json' |
| 201 | }, |
| 202 | withCredentials: true, |
| 203 | data: JSON.stringify({"data": []}), |
| 204 | }).success(function(response){ |
| 205 | var json = JSON.stringify(response); |
| 206 | var content = JSON.parse(json); |
| 207 | if(callback){ |
| 208 | return callback(content); |
| 209 | } |
| 210 | }).error(function(error){ |
| 211 | if(callback){ |
| 212 | callback(error); |
| 213 | }else{ |
| 214 | console.log(error); |
| 215 | } |
| 216 | }); |
| 217 | }, |
| 218 | hostShutdown: function(callback){ |
| 219 | $http({ |
| 220 | method: 'POST', |
| 221 | url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", |
| 222 | headers: { |
| 223 | 'Accept': 'application/json', |
| 224 | 'Content-Type': 'application/json' |
| 225 | }, |
| 226 | withCredentials: true, |
| 227 | data: JSON.stringify({"data": []}) |
| 228 | }).success(function(response){ |
| 229 | var json = JSON.stringify(response); |
| 230 | var content = JSON.parse(json); |
| 231 | if(callback){ |
| 232 | return callback(content); |
| 233 | } |
| 234 | }).error(function(error){ |
| 235 | if(callback){ |
| 236 | callback(error); |
| 237 | }else{ |
| 238 | console.log(error); |
| 239 | } |
| 240 | }); |
| 241 | } |
| 242 | }; |
| 243 | return SERVICE; |
| 244 | }]); |