main.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. from openerp import http
  3. from openerp.addons.bus import bus
  4. from openerp.http import request as r
  5. from ..utils import docker_api as docker
  6. class ConfigController(http.Controller):
  7. @http.route('/odoo_management/get_config', auth='user', type='json')
  8. def get_config(self, **kw):
  9. settings = r.env['odoo.management.config'].get_default_settings([])
  10. settings.update({
  11. 'images': docker.get_all_containers(),
  12. 'containers': docker.get_all_containers(),
  13. 'networks': docker.get_all_networks()
  14. })
  15. return settings
  16. @http.route('/odoo_management/save_config', auth='user', type='json')
  17. def save_config(self, **kw):
  18. r.env['odoo.management.config'].set_default_settings(kw)
  19. @http.route('/odoo_management/images', auth='user', methods=['GET'], type='json')
  20. def get_images(self, **kw):
  21. images = docker.get_all_images()
  22. return images
  23. @http.route('/odoo_management/containers', auth='user', methods=['GET'], type='json')
  24. def get_containers(self, **kw):
  25. containers = docker.get_all_containers()
  26. return containers
  27. class InstancesController(bus.Controller):
  28. def _poll(self, dbname, channels, last, options):
  29. if r.session.uid:
  30. registry, cr, uid, context = r.registry, r.cr, r.session.uid, r.context
  31. new_channel = (r.db, 'odoo.instance', r.uid)
  32. channels.append(new_channel)
  33. return super(InstancesController, self)._poll(dbname, channels, last, options)