blob: dbf8dc4e41d117a04e563edf94fd1bfd35a8b20c [file] [log] [blame]
Iftekharul Islamf157d372017-03-08 11:11:27 -06001/**
2chassis
3/org/openbmc/control/chassis0 —> PowerOn ..PowerOff
4
5host reboot
6/org/openbmc/control/host0 —>reboot
7
8shutdown
9/org/openbmc/control/host0 —> shutdown
10**/
11angular
12 .module('app.services', [])
Iftekharul Islamccfe2452017-03-16 10:47:04 -050013 .service('dataService', ['APIUtils', function(APIUtils){
Iftekharul Islamf157d372017-03-08 11:11:27 -060014 this.app_version = "openBMC V.0.0.1";
Iftekharul Islamccfe2452017-03-16 10:47:04 -050015 this.server_health = 'Error';
16 this.server_state = 'Unreachable';
17 this.server_status = -2;
Iftekharul Islamf157d372017-03-08 11:11:27 -060018 this.chassis_state = 'On';
Iftekharul Islamccfe2452017-03-16 10:47:04 -050019 this.server_id = "Server 9.3.164.147";
Iftekharul Islamf157d372017-03-08 11:11:27 -060020 this.last_updated = new Date();
Iftekharul Islamccfe2452017-03-16 10:47:04 -050021
22 this.loading = false;
23 this.loading_message = "";
Iftekharul Islamf157d372017-03-08 11:11:27 -060024 this.showNavigation = false;
25 this.bodyStyle = {};
26 this.path = '';
27
Iftekharul Islamccfe2452017-03-16 10:47:04 -050028 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 Islamf157d372017-03-08 11:11:27 -060048 .factory('APIUtils', ['$http', function($http){
49 var SERVICE = {
50 LOGIN_CREDENTIALS: {
Iftekharul Islamccfe2452017-03-16 10:47:04 -050051 username: "root",
52 password: "0penBmc",
Iftekharul Islamf157d372017-03-08 11:11:27 -060053 },
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 Islamccfe2452017-03-16 10:47:04 -050063 HOST_STATE_TEXT: {
Iftekharul Islamf157d372017-03-08 11:11:27 -060064 on: 'Running',
65 off: 'Off',
Iftekharul Islamccfe2452017-03-16 10:47:04 -050066 booting: 'Quiesced',
67 unreachable: 'Unreachable'
68 },
69 HOST_STATE: {
70 on: 1,
71 off: -1,
72 booting: 0,
73 unreachable: -2
Iftekharul Islamf157d372017-03-08 11:11:27 -060074 },
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 Islamccfe2452017-03-16 10:47:04 -0500176 /**
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 Islamf157d372017-03-08 11:11:27 -0600182 $http({
Iftekharul Islamccfe2452017-03-16 10:47:04 -0500183 method: 'PUT',
184 url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition",
Iftekharul Islamf157d372017-03-08 11:11:27 -0600185 headers: {
186 'Accept': 'application/json',
187 'Content-Type': 'application/json'
188 },
189 withCredentials: true,
Iftekharul Islamccfe2452017-03-16 10:47:04 -0500190 data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.On"})
Iftekharul Islamf157d372017-03-08 11:11:27 -0600191 }).success(function(response){
192 var json = JSON.stringify(response);
193 var content = JSON.parse(json);
194 if(callback){
Iftekharul Islamccfe2452017-03-16 10:47:04 -0500195 return callback(content.status);
Iftekharul Islamf157d372017-03-08 11:11:27 -0600196 }
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 Islamccfe2452017-03-16 10:47:04 -0500207 method: 'PUT',
208 url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition",
Iftekharul Islamf157d372017-03-08 11:11:27 -0600209 headers: {
210 'Accept': 'application/json',
211 'Content-Type': 'application/json'
212 },
213 withCredentials: true,
Iftekharul Islamccfe2452017-03-16 10:47:04 -0500214 data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.Off"})
Iftekharul Islamf157d372017-03-08 11:11:27 -0600215 }).success(function(response){
216 var json = JSON.stringify(response);
217 var content = JSON.parse(json);
218 if(callback){
Iftekharul Islamccfe2452017-03-16 10:47:04 -0500219 return callback(content.status);
Iftekharul Islamf157d372017-03-08 11:11:27 -0600220 }
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 Islam115984a2017-03-09 09:47:35 -0600279 }])
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 Islamf157d372017-03-08 11:11:27 -0600303 }]);