summaryrefslogtreecommitdiff
path: root/iotronic/conductor/endpoints.py
diff options
context:
space:
mode:
Diffstat (limited to 'iotronic/conductor/endpoints.py')
-rw-r--r--iotronic/conductor/endpoints.py189
1 files changed, 175 insertions, 14 deletions
diff --git a/iotronic/conductor/endpoints.py b/iotronic/conductor/endpoints.py
index 73226c8..5e10c49 100644
--- a/iotronic/conductor/endpoints.py
+++ b/iotronic/conductor/endpoints.py
@@ -39,6 +39,26 @@ def get_best_agent(ctx):
39 return agent.hostname 39 return agent.hostname
40 40
41 41
42def random_public_port():
43 return random.randint(6000, 7000)
44
45
46def manage_result(res, wamp_rpc_call, board_uuid):
47 if res.result == wm.SUCCESS:
48 return res.message
49 elif res.result == wm.WARNING:
50 LOG.warning('Warning in the execution of %s on %s', wamp_rpc_call,
51 board_uuid)
52 return res.message
53 elif res.result == wm.ERROR:
54 LOG.error('Error in the execution of %s on %s: %s', wamp_rpc_call,
55 board_uuid, res.message)
56 raise exception.ErrorExecutionOnBoard(call=wamp_rpc_call,
57 board=board_uuid,
58 error=res.message)
59 return res.message
60
61
42class ConductorEndpoint(object): 62class ConductorEndpoint(object):
43 def __init__(self, ragent): 63 def __init__(self, ragent):
44 transport = oslo_messaging.get_transport(cfg.CONF) 64 transport = oslo_messaging.get_transport(cfg.CONF)
@@ -119,10 +139,12 @@ class ConductorEndpoint(object):
119 board_id, 139 board_id,
120 'destroyBoard', 140 'destroyBoard',
121 (p,)) 141 (p,))
142
122 except exception: 143 except exception:
123 return exception 144 return exception
124 board.destroy() 145 board.destroy()
125 if result: 146 if result:
147 result = manage_result(result, 'destroyBoard', board_id)
126 LOG.debug(result) 148 LOG.debug(result)
127 return result 149 return result
128 return 150 return
@@ -164,18 +186,7 @@ class ConductorEndpoint(object):
164 data=wamp_rpc_args) 186 data=wamp_rpc_args)
165 res = wm.deserialize(res) 187 res = wm.deserialize(res)
166 188
167 if res.result == wm.SUCCESS: 189 return res
168 return res.message
169 elif res.result == wm.WARNING:
170 LOG.warning('Warning in the execution of %s on %s', wamp_rpc_call,
171 board_uuid)
172 return res.message
173 elif res.result == wm.ERROR:
174 LOG.error('Error in the execution of %s on %s: %s', wamp_rpc_call,
175 board_uuid, res.message)
176 raise exception.ErrorExecutionOnBoard(call=wamp_rpc_call,
177 board=board.uuid,
178 error=res.message)
179 190
180 def destroy_plugin(self, ctx, plugin_id): 191 def destroy_plugin(self, ctx, plugin_id):
181 LOG.info('Destroying plugin with id %s', 192 LOG.info('Destroying plugin with id %s',
@@ -231,7 +242,9 @@ class ConductorEndpoint(object):
231 injection = objects.InjectionPlugin(ctx, **inj_data) 242 injection = objects.InjectionPlugin(ctx, **inj_data)
232 injection.create() 243 injection.create()
233 244
245 result = manage_result(result, 'PluginInject', board_uuid)
234 LOG.debug(result) 246 LOG.debug(result)
247
235 return result 248 return result
236 249
237 def remove_plugin(self, ctx, plugin_uuid, board_uuid): 250 def remove_plugin(self, ctx, plugin_uuid, board_uuid):
@@ -247,7 +260,7 @@ class ConductorEndpoint(object):
247 (plugin.uuid,)) 260 (plugin.uuid,))
248 except exception: 261 except exception:
249 return exception 262 return exception
250 263 result = manage_result(result, 'PluginRemove', board_uuid)
251 LOG.debug(result) 264 LOG.debug(result)
252 injection.destroy() 265 injection.destroy()
253 return result 266 return result
@@ -267,7 +280,7 @@ class ConductorEndpoint(object):
267 (plugin.uuid,)) 280 (plugin.uuid,))
268 except exception: 281 except exception:
269 return exception 282 return exception
270 283 result = manage_result(result, action, board_uuid)
271 LOG.debug(result) 284 LOG.debug(result)
272 return result 285 return result
273 286
@@ -290,3 +303,151 @@ class ConductorEndpoint(object):
290 LOG.debug('Updating service %s', service.name) 303 LOG.debug('Updating service %s', service.name)
291 service.save() 304 service.save()
292 return serializer.serialize_entity(ctx, service) 305 return serializer.serialize_entity(ctx, service)
306
307 def action_service(self, ctx, service_uuid, board_uuid, action):
308 LOG.info('Enable service with id %s into the board %s',
309 service_uuid, board_uuid)
310 service = objects.Service.get(ctx, service_uuid)
311 objects.service.is_valid_action(action)
312
313 if action == "ServiceEnable":
314 try:
315 objects.ExposedService.get(ctx,
316 board_uuid,
317 service_uuid)
318 return exception.ServiceAlreadyExposed(uuid=service_uuid)
319 except Exception:
320 name = service.name
321 public_port = random_public_port()
322 port = service.port
323
324 res = self.execute_on_board(ctx, board_uuid, action,
325 (name, public_port, port))
326
327 if res.result == wm.SUCCESS:
328 pid = res.message[0]
329
330 exp_data = {
331 'board_uuid': board_uuid,
332 'service_uuid': service_uuid,
333 'public_port': public_port,
334 'pid': pid,
335 }
336 exposed = objects.ExposedService(ctx, **exp_data)
337 exposed.create()
338
339 res.message = res.message[1]
340 elif res.result == wm.ERROR:
341 LOG.error('Error in the execution of %s on %s: %s',
342 action,
343 board_uuid, res.message)
344 raise exception.ErrorExecutionOnBoard(call=action,
345 board=board_uuid,
346 error=res.message)
347 LOG.debug(res.message)
348 return res.message
349
350 elif action == "ServiceDisable":
351 exposed = objects.ExposedService.get(ctx,
352 board_uuid,
353 service_uuid)
354
355 res = self.execute_on_board(ctx, board_uuid, action,
356 (service.name, exposed.pid))
357
358 result = manage_result(res, action, board_uuid)
359 LOG.debug(res.message)
360 exposed.destroy()
361 return result
362
363 elif action == "ServiceRestore":
364
365 exposed = objects.ExposedService.get(ctx, board_uuid,
366 service_uuid)
367
368 print(exposed)
369
370 res = self.execute_on_board(ctx, board_uuid, action,
371 (service.name, exposed.public_port,
372 service.port, exposed.pid))
373
374 if res.result == wm.SUCCESS:
375 pid = res.message[0]
376
377 exp_data = {
378 'id': exposed.id,
379 'board_uuid': board_uuid,
380 'service_uuid': service_uuid,
381 'public_port': exposed.public_port,
382 'pid': pid,
383 }
384
385 exposed = objects.ExposedService(ctx, **exp_data)
386 exposed.save()
387
388 res.message = res.message[1]
389 elif res.result == wm.ERROR:
390 LOG.error('Error in the execution of %s on %s: %s',
391 action,
392 board_uuid, res.message)
393 raise exception.ErrorExecutionOnBoard(call=action,
394 board=board_uuid,
395 error=res.message)
396 LOG.debug(res.message)
397 return res.message
398
399 # try:
400 #
401 #
402 # return exception.ServiceAlreadyExposed(uuid=service_uuid)
403 # except:
404 # name=service.name
405 # public_port=random_public_port()
406 # port=service.port
407 #
408 # res = self.execute_on_board(ctx, board_uuid, action,
409 # (name, public_port, port))
410 #
411 # if res.result == wm.SUCCESS:
412 # pid = res.message[0]
413 #
414 # exp_data = {
415 # 'board_uuid': board_uuid,
416 # 'service_uuid': service_uuid,
417 # 'public_port': public_port,
418 # 'pid': pid,
419 # }
420 # exposed = objects.ExposedService(ctx, **exp_data)
421 # exposed.create()
422 #
423 # res.message = res.message[1]
424 # elif res.result == wm.ERROR:
425 # LOG.error('Error in the execution of %s on %s: %s',
426 # action,
427 # board_uuid, res.message)
428 # raise exception.ErrorExecutionOnBoard(call=action,
429 # board=board_uuid,
430 # error=res.message)
431 # LOG.debug(res.message)
432 # return res.message
433 #
434 #
435 #
436 #
437 #
438 #
439 #
440 #
441 #
442 #
443 #
444 # exposed = objects.ExposedService.get(ctx, board_uuid,
445 # service_uuid)
446 #
447 # res = self.execute_on_board(ctx, board_uuid, action,
448 # (service.name, exposed.pid))
449 #
450 # result=manage_result(res,action,board_uuid)
451 # LOG.debug(res.message)
452 # exposed.destroy()
453 # return result