diff --git a/README.md b/README.md index 69525f5..d896902 100644 --- a/README.md +++ b/README.md @@ -138,14 +138,17 @@ Should be active at least on the production server ### Automatic Configuration -Calling - `ctx.env['cloud.platform'].install_exoscale()` -or - `ctx.env['cloud.platform'].install_ovh()` -in an `anthem` song will configure some parameters such as the -`ir_attachment.location` and migrate the existing attachments to the -object storage. +An automatic configuration can be executed from an `anthem` song to configure +some parameters such as the `ir_attachment.location` and migrate the existing +attachments to the object storage. +It can be called like this: + `ctx.env['cloud.platform'].install(cloud_platform_kind)` +Replacing `cloud_platform_kind` with 'exoscale' or 'ovh' + +When there was only Exoscale as a provider of the cloud platform the following +would do the trick and will work until v.11 : + `ctx.env['cloud.platform'].install_exoscale()` ### Startup checks diff --git a/cloud_platform/models/cloud_platform.py b/cloud_platform/models/cloud_platform.py index 1c38ffd..9f9e439 100644 --- a/cloud_platform/models/cloud_platform.py +++ b/cloud_platform/models/cloud_platform.py @@ -61,6 +61,18 @@ class CloudPlatform(models.AbstractModel): self.env['ir.attachment'].sudo().force_storage() _logger.info('cloud platform configured for exoscale') + @api.model + def install(self, platform_kind): + params = self.env['ir.config_parameter'].sudo() + params.set_param('cloud.platform.kind', platform_kind) + environment = config['running_env'] + configs = self._config_by_server_env(environment) + params.set_param('ir_attachment.location', configs.filestore) + self.check() + if configs.filestore in [FilestoreKind.swift, FilestoreKind.s3]: + self.env['ir.attachment'].sudo().force_storage() + _logger.info('cloud platform configured for {}'.format(platform_kind)) + @api.model def _check_swift(self, environment_name): params = self.env['ir.config_parameter'].sudo() diff --git a/cloud_platform/songs.py b/cloud_platform/songs.py index ac62e7e..277c7dd 100644 --- a/cloud_platform/songs.py +++ b/cloud_platform/songs.py @@ -6,4 +6,4 @@ def install_exoscale(ctx): def install_ovh(ctx): - ctx.env['cloud.platform'].install_ovh() + ctx.env['cloud.platform'].install('ovh') diff --git a/cloud_platform_ovh/models/cloud_platform.py b/cloud_platform_ovh/models/cloud_platform.py index 9bbed5e..8c1d96b 100644 --- a/cloud_platform_ovh/models/cloud_platform.py +++ b/cloud_platform_ovh/models/cloud_platform.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- -# Copyright 2016 Camptocamp SA +# Copyright 2017 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) import logging from odoo import api, models -from odoo.tools.config import config _logger = logging.getLogger(__name__) @@ -30,15 +29,3 @@ class CloudPlatform(models.AbstractModel): 'dev': PlatformConfig(filestore=FilestoreKind.db), } return configs.get(environment) or configs['dev'] - - @api.model - def install_ovh(self): - params = self.env['ir.config_parameter'].sudo() - params.set_param('cloud.platform.kind', 'ovh') - environment = config['running_env'] - configs = self._config_by_server_env(environment) - params.set_param('ir_attachment.location', configs.filestore) - self.check() - if configs.filestore == FilestoreKind.swift: - self.env['ir.attachment'].sudo().force_storage() - _logger.info('cloud platform configured for ovh')