-
Notifications
You must be signed in to change notification settings - Fork 17
[12.0][ADD] cie_infra (wip) #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 12.0
Are you sure you want to change the base?
Changes from all commits
b29b5f4
68d91f7
bdd43ea
6cda94d
ebef15c
5b85c7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| from . import controllers | ||
| from . import models | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # -*- coding: utf-8 -*- | ||
| { | ||
| 'name': "Coop IT Easy Infrastructure", | ||
|
|
||
| 'summary': """ | ||
| this module allows to visualize our servers throught an inventary. """, | ||
|
|
||
| 'description': """ | ||
| The purpose of this module is to visualize all the information | ||
| contains on our server. It means the datacenter, the location, | ||
| the different instance on it and finally the different module. | ||
| """, | ||
|
|
||
| 'author': "CoopItEasy", | ||
elioexe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 'website': "http://coopiteasy.be", | ||
| "license": "AGPL-3", | ||
|
|
||
| # Categories can be used to filter modules in modules listing | ||
| # Check https://github.com/odoo/odoo/blob/12.0/odoo/addons/base/data/ir_module_category_data.xml | ||
| # for the full list | ||
| #'category': 'Uncategorized', | ||
| #'version': '12.0.1.0.0', | ||
|
|
||
| # any module necessary for this one to work correctly | ||
| 'depends': ['base'], | ||
|
|
||
| # always loaded | ||
| 'data': [ | ||
| 'security/cie_infra_security.xml', | ||
| 'security/ir.model.access.csv', | ||
| 'views/views.xml', | ||
| 'views/cie_infra_server_views.xml', | ||
| 'views/cie_infra_instance_view.xml', | ||
| 'views/cie_infra_database_view.xml', | ||
| 'views/cie_infra_module_view.xml', | ||
| 'views/cie_infra_datacenter_view.xml', | ||
| 'views/server_list_template.xml' | ||
| ], | ||
| # only loaded in demonstration mode | ||
| #'demo': [ | ||
| # 'demo/demo.xml', | ||
| #], | ||
| } | ||
elioexe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| from . import controllers |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| from odoo import http | ||
elioexe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| class CieInfra(http.Controller): | ||
| #@http.route('/cie_infra/index', auth='public') | ||
| #def index(self, **kw): | ||
| # return "Hello, world" | ||
|
|
||
| @http.route('/cie_infra/server/', auth='public') | ||
| def list_server(self, **kw): | ||
| server=http.request.env['infra.server'] | ||
| servers=server.search([]) | ||
| return http.request.render('cie_infra.server_list_template', { | ||
| 'servers': servers | ||
| }) | ||
| # @http.route('/cie_infra/cie_infra/objects/<model("cie_infra.cie_infra"):obj>/', auth='public') | ||
| # def object(self, obj, **kw): | ||
| # return http.request.render('cie_infra.object', { | ||
| # 'object': obj | ||
| # }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo noupdate="1"> | ||
| <data> | ||
|
|
||
| <record id="server_localhost:0101" model="cie_infra.server"> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. J'ai un petit doute sur l'utilisation des |
||
| <field name="name">localhost:0101</field> | ||
| <field name="ipv4">192.168.1.1</field> | ||
| <field name="datacenter_info">OVH plus grand base de serveur d'EUROPE</field> | ||
| <field name="ovh_address"> [email protected]</field> | ||
| <field name="cie_address">[email protected]</field> | ||
| <field name="note">pas de pb depuis 6mois</field> | ||
| </record> | ||
|
|
||
| <record id="location_france" model="infra.location"> | ||
| <field name="name">France</field> | ||
elioexe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <field name="country_id">208</field> | ||
| </record> | ||
|
|
||
| <record id="datacenter_OVH1" model="cie_infra.datacenter"> | ||
| <field name="name">OVH Compiegne</field> | ||
| <field name="location_id" | ||
| eval="[(4, ref('location_france'))]"/> | ||
| </record> | ||
| <record id="instance1" model="cie_infra.instance"> | ||
| <field name="name">OdooV1</field> | ||
| <field name="URL">CoopItEasy/odooV1</field> | ||
elioexe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <field name="note">Instance utilisé par coopvelib et coopvrap</field> | ||
| <field name="server_id" | ||
| eval="[(4,ref('server_localhost:0101')]"/> | ||
| </record> | ||
| <!-- <record id="object4" model="cie_infra.cie_infra"> --> | ||
| <!-- <field name="name">Object 4</field> --> | ||
| <!-- <field name="value">40</field> --> | ||
| <!-- </record> --> | ||
| <!-- --> | ||
elioexe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </data> | ||
| </odoo> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from . import infra_server | ||
| from . import infra_datacenter | ||
| from . import infra_location | ||
| from . import infra_instance | ||
| from . import infra_instance_database | ||
| from . import infra_instance_module_info | ||
| from . import infra_instance_module | ||
| from . import infra_server_shortname |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from odoo import models, fields | ||
|
|
||
|
|
||
| class Datacenter(models.Model): | ||
| _name = 'infra.datacenter' | ||
| _description = 'datacenter' | ||
| name = fields.Char('Datacenter', required=True) | ||
| location_id = fields.Many2one('infra.location', string='location') | ||
| server_ids = fields.One2many('infra.server', 'datacenter_id', string='Server') |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| from odoo import models | ||
| from odoo import fields | ||
| from odoo import api | ||
| from odoo import _ | ||
| import requests | ||
| import json | ||
| from werkzeug.exceptions import BadRequest, InternalServerError, NotFound | ||
| from odoo.exceptions import AccessDenied, Warning as UserError | ||
|
|
||
|
|
||
| class Instance(models.Model): | ||
| _name='infra.instance' | ||
| _description='instance' | ||
| name=fields.Char('name', required=True) | ||
| url=fields.Char('URL') | ||
| note=fields.Text('text') | ||
| server_id=fields.Many2one('infra.server', string='server') | ||
| database_ids=fields.One2many('infra.instance.database','instance_id', string="database") | ||
|
|
||
| @api.multi | ||
| def http_get(self, url, params, headers): | ||
| self.ensure_one() | ||
| if url.startswith("/"): | ||
| url = self.url + url | ||
| return requests.get(url,params,headers) | ||
|
|
||
| def _process_response(self, response): | ||
| if response.status_code == 200: | ||
| content = response.content.decode("utf-8") | ||
| return json.loads(content) | ||
| elif response.status_code == 400: | ||
| content = response.content.decode("utf-8") | ||
| raise BadRequest("%s" % content) | ||
| elif response.status_code == 403: | ||
| raise AccessDenied( | ||
| _("You are not allowed to access this resource") | ||
| ) | ||
| elif response.status_code == 404: | ||
| raise NotFound( | ||
| _("Resource not found %s on server" % response.status_code) | ||
| ) | ||
| else: # 500 et al. | ||
| content = response.content.decode("utf-8") | ||
| raise InternalServerError(_("%s" % content)) | ||
|
|
||
| @api.multi | ||
| def http_get_content(self, url, params=None, headers=None): | ||
| self.ensure_one() | ||
| response = self.http_get(url, params=params, headers=headers) | ||
| return self._process_response(response) | ||
|
|
||
|
|
||
| def cron_get_database(self): | ||
| """ | ||
| thanks to http request, the cron will recover daily | ||
| the different database based on a odoo's instance | ||
| """ | ||
|
|
||
| route="/web/databases" | ||
| instances = self.env['infra.instance'].search([]) | ||
| for instance in instances: | ||
| databases = instance.http_get_content(route) | ||
| for db in databases["databases"]: | ||
| if not instance.is_db_already_exist(db) : | ||
| self.env["infra.instance.database"].create({ | ||
| "name": db, | ||
| "instance_id": instance.id, | ||
| }) | ||
| instance.write({ | ||
| "database_ids": db, | ||
| }) | ||
|
Comment on lines
+64
to
+71
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Il manque un traitement
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. est ce possible qu'on supprime une db d'une instance ? Si oui il faut aussi que je gere le cas ou une db a été supprimer et ainsi supprimer le lien entre cette instance et la db
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a checker
elioexe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def is_db_already_exist(self, new_db): | ||
| databases=self.env["infra.instance.database"].search([]) | ||
| for old_db in databases: | ||
| if new_db == old_db.name : | ||
| return 1 | ||
| return 0 | ||
|
Comment on lines
+75
to
+78
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tu peux simplement écrire : return new_db in databases
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. je ne comprends pas trop cette manière d'écrire, pour moi ce n'est pas l'équivalent de ce que j'ai écrit plus haut. |
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| from odoo import models | ||
| from odoo import fields | ||
| from odoo import api | ||
| from odoo import _ | ||
| import requests | ||
| import json | ||
| from werkzeug.exceptions import BadRequest, InternalServerError, NotFound | ||
| from odoo.exceptions import AccessDenied, Warning as UserError | ||
|
|
||
| class Database(models.Model): | ||
| _name = 'infra.instance.database' | ||
| _description = 'database' | ||
| name=fields.Char('name', required=True) | ||
| instance_id=fields.Many2one('infra.instance', string='instance') | ||
| installed_module_ids=fields.One2many( | ||
| comodel_name='infra.instance.module.info', | ||
| inverse_name='database_id', | ||
| string='installed_module') | ||
|
|
||
| @api.multi | ||
| def http_get(self, url, params, headers): | ||
| self.ensure_one() | ||
| if url.startswith("/"): | ||
| url = self.url + url | ||
| return requests.get(url,params,headers) | ||
|
|
||
| def _process_response(self, response): | ||
| if response.status_code == 200: | ||
| content = response.content.decode("utf-8") | ||
| return json.loads(content) | ||
| elif response.status_code == 400: | ||
| content = response.content.decode("utf-8") | ||
| raise BadRequest("%s" % content) | ||
| elif response.status_code == 403: | ||
| raise AccessDenied( | ||
| _("You are not allowed to access this resource") | ||
| ) | ||
| elif response.status_code == 404: | ||
| raise NotFound( | ||
| _("Resource not found %s on server" % response.status_code) | ||
| ) | ||
| else: # 500 et al. | ||
| content = response.content.decode("utf-8") | ||
| raise InternalServerError(_("%s" % content)) | ||
|
Comment on lines
+27
to
+44
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On pourrait réfléchir pour n'avoir ce code que dans un seul modèle, ou dans un fichier python à part. Car pas besoin de répéter le même code dans chaque modèle. |
||
|
|
||
| @api.multi | ||
| def http_get_content(self, url, params=None, headers=None): | ||
| self.ensure_one() | ||
| response = self.http_get(url, params=params, headers=headers) | ||
| return self._process_response(response) | ||
|
|
||
|
|
||
| def cron_get_module(self): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Il faudra traiter dans cette fonction le cas ou le |
||
| """ | ||
| thanks to http request, the cron will recover daily | ||
| the different database based on a odoo's instance | ||
| """ | ||
|
|
||
| databases = self.env['infra.instance.database'].search([]) | ||
| for database in databases: | ||
| route = "/server-info/databases/"+database.name+"/modules" | ||
| modules = database.http_get_content(route) | ||
| for module in modules: | ||
| if not self.is_module_already_installed(module): | ||
| new_module = self.env['infra.instance.module'].create({ | ||
| "name": module["name"], | ||
| }) | ||
| module_info=self.env["infra.instance.module.info"].create({ | ||
| "installed_version": module["published_version"], | ||
| }) | ||
| new_module.write({ | ||
| "module_info_ids": module_info.id, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Attention, ici Aussi, tu dois passer l'objet directement et pas juste l'id de l'objet. :)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. d'apres la documentation odoo, je trouve cette options pour la fonction write : est ce la solution ou je dois override la function write pour lui donner le bon comportement? |
||
| }) | ||
| module_info.write({ | ||
| "module_id":new_module.id, | ||
| }) | ||
| database.write({ | ||
| "installed_module_ids": module_info.id, | ||
| }) | ||
elioexe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return | ||
|
|
||
| def is_module_already_installed(self,module): | ||
| modules = self.env["infra.instance.module"].search([]) | ||
| for old_module in modules: | ||
| if module["name"] == old_module.name: | ||
| return 1 | ||
| return 0 | ||
|
Comment on lines
+83
to
+87
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem que pour l'aurtre fonction similaire. return module in modules |
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from odoo import fields, models | ||
|
|
||
| class Module(models.Model): | ||
| _name='infra.instance.module' | ||
| _description='module' | ||
| name=fields.Char('name',required=True) | ||
| module_info_ids=fields.One2many('infra.instance.module.info','module_id',string='module_info') | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from odoo import fields , models | ||
|
|
||
| class ModuleInfo(models.Model): | ||
| _name='infra.instance.module.info' | ||
| _description='module.info' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We used to leave a empty line between |
||
| installed_version=fields.Char('installed_version',required=True) | ||
| available_version=fields.Char('available_version') | ||
| database_id=fields.Many2one('infra.instance.database',string='database') | ||
| module_id=fields.Many2one('infra.instance.module',string='module') | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from odoo import fields, models | ||
|
|
||
| class Location(models.Model): | ||
| _name='infra.location' | ||
| _description='location' | ||
| name=fields.Char('name', required=True) | ||
| country_id=fields.Many2one('res.country', string='country') | ||
| datacenter_ids=fields.One2many('infra.datacenter','location_id', string='datacenter') |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| from odoo import fields, models, api | ||
| from odoo.exceptions import Warning | ||
|
|
||
|
|
||
| class Server(models.Model): | ||
| _name = 'infra.server' | ||
| _description = 'server' | ||
| name = fields.Char('name', required=True) | ||
| ipv4 = fields.Char('ipv4') | ||
| ipv6 = fields.Char('ipv6') | ||
| datacenter_info = fields.Char('Datacenter info') | ||
| ovh_address = fields.Char('OVH\'s adress', required=True) | ||
| cie_address = fields.Char('cie adress', required=True) | ||
| note = fields.Text('Note') | ||
| datacenter_id = fields.Many2one('infra.datacenter', string='Datacenter') | ||
| shortname_ids = fields.One2many('infra.server.shortname', 'server_id', string='shortname') | ||
| instance_ids = fields.One2many('infra.instance', 'server_id', string='instance') | ||
|
|
||
| @api.multi | ||
| def _check_ipv4(self, IP): | ||
elioexe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def isIPv4(s): | ||
| try: | ||
| return str(int(s)) == s and 0 <= int(s) <= 255 | ||
| except: | ||
| return False | ||
|
|
||
| if IP.count(".") == 3 and all(isIPv4(i) for i in IP.split(".")): | ||
| return True | ||
| return False | ||
|
Comment on lines
+27
to
+29
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Écrit simplement : return IP.count(".") == 3 and all(isIPv4(i) for i in IP.split(".")) |
||
|
|
||
| @api.multi | ||
| def _check_ipv6(self, IP): | ||
| def isIPv6(s): | ||
| if len(s) > 4: | ||
| return False | ||
| try: | ||
| return int(s, 16) >= 0 and s[0] != '-' | ||
| except: | ||
| return False | ||
|
|
||
| if IP.count(":") == 7 and all(isIPv6(i) for i in IP.split(":")): | ||
| return True | ||
| return False | ||
elioexe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @api.multi | ||
| def button_check_ipv(self): | ||
| for server in self: | ||
| if not server.ipv4 and not server.ipv6: | ||
| raise Warning('Please provide an ipv4 or ipv6 for %s' % server.name) | ||
| if server.ipv6 and not server._check_ipv6(self.ipv6): | ||
| raise Warning('%s is an invalid ipv6 address' % server.ipv6) | ||
| if server.ipv4 and not server._check_ipv4(self.ipv4): | ||
| raise Warning('%s is an invalid ipv4 address' % server.ipv4) | ||
| return True | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from odoo import fields, models | ||
|
|
||
| class ServerShortName(models.Model): | ||
| _name='infra.server.shortname' | ||
| _description='server.shortname' | ||
| name=fields.Char('name') | ||
| server_id=fields.Many2one('infra.server',string='server') | ||
|
|
Uh oh!
There was an error while loading. Please reload this page.