mirror of
https://github.com/bringout/oca-technical.git
synced 2026-04-18 16:12:08 +02:00
Initial commit: OCA Technical packages (595 packages)
This commit is contained in:
commit
2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions
|
|
@ -0,0 +1,42 @@
|
|||
# Copyright 2018 Creu Blanca
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
import logging
|
||||
import socket
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class ResRemote(models.Model):
|
||||
_name = "res.remote"
|
||||
_description = "Remotes"
|
||||
|
||||
name = fields.Char(required=True, string="Hostname", index=True, readonly=True)
|
||||
ip = fields.Char(required=True)
|
||||
in_network = fields.Boolean(
|
||||
required=True, help="Shows if the remote can be found through the socket"
|
||||
)
|
||||
|
||||
_sql_constraints = [("name_unique", "unique(name)", "Hostname must be unique")]
|
||||
|
||||
@api.model
|
||||
def _create_vals(self, addr, hostname):
|
||||
return {
|
||||
"name": hostname or addr,
|
||||
"ip": addr,
|
||||
"in_network": bool(hostname),
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _get_remote(self, addr):
|
||||
try:
|
||||
hostname, alias, ips = socket.gethostbyaddr(addr)
|
||||
except socket.herror:
|
||||
logging.warning("Remote with ip %s could not be found" % addr)
|
||||
hostname = False
|
||||
remote = self.search([("name", "=ilike", hostname or addr)])
|
||||
if not remote:
|
||||
remote = self.create(self._create_vals(addr, hostname))
|
||||
if remote.ip != addr:
|
||||
# IPs can change through time, but hostname should not change
|
||||
remote.write({"ip": addr})
|
||||
return remote
|
||||
Loading…
Add table
Add a link
Reference in a new issue