Skip to content

Commit

Permalink
Add OVH as an option for the cloud platform
Browse files Browse the repository at this point in the history
  • Loading branch information
TDu authored and guewen committed Sep 19, 2017
1 parent 5d30207 commit 6674853
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 8 deletions.
43 changes: 38 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ On the platform we want to achieve having:
* Logs sent to ElasticSearch-Kibana structured as JSON for better searching

For the storage, we store all the attachments on a object storage such as S3 or
a S3 compatible one, and we store the werkzeug sessions on Redis.
Swift, and we store the werkzeug sessions on Redis.

Two providers are available for the Cloud Platform, Exoscale based in
Switzerland and OVH in France.

The main difference between the two is the Object Store they use :

* Exoscale uses S3
* OVH uses Swift

## Setup

Expand All @@ -21,7 +29,10 @@ a S3 compatible one, and we store the werkzeug sessions on Redis.
Libraries that must be added in ``requirements.txt``:

```
# For S3 object store
boto==2.42.0
# For Swift object store
python-swiftclient==3.0.0
redis==2.10.5
python-json-logger==0.1.5
statsd==3.2.1
Expand All @@ -31,7 +42,7 @@ statsd==3.2.1

The `--load` option of Odoo must contains the following addons:

* `attachment_s3`
* `attachment_s3` or `attachment_swift` depending of the provider used.
* `session_redis`
* `logging_json`

Expand All @@ -51,7 +62,7 @@ The server environments in `server_environment_files` must be at least:
The exact naming is important, because the `cloud_platform` addon rely on these keys to know and check the running environment.


### Attachments in the Object Storage
### Attachments in the Object Storage S3

* prod: stored RW in the object storage
* `AWS_HOST`: depends of the platform
Expand All @@ -69,6 +80,25 @@ Besides, the attachment location should be set to `s3` (but this is
automatically done by the `install` methods of the `cloud_platform` module.
* `ir.config_parameter` `ir_attachment.location`: `s3`


### Attachments in the Object Storage Swift

* prod: stored RW in the object storage
* `SWIFT_HOST`: depends of the platform
* `SWIFT_ACCOUNT`: depends of the platform
* `SWIFT_PASSWORD`: depends of the platform
* `SWIFT_WRITE_CONTAINER`: `<client>-odoo-prod`
* integration:
* `SWIFT_HOST`: depends of the platform
* `SWIFT_ACCOUNT`: depends of the platform
* `SWIFT_PASSWORD`: depends of the platform
* `SWIFT_WRITE_CONTAINER`: `<client>-odoo-integration`
* test: attachments are stored in database

Besides, the attachment location should be set to `swift` (but this is
automatically done by the `install` methods of the `cloud_platform` module.
* `ir.config_parameter` `ir_attachment.location`: `swift`

### Sessions in Redis

* prod:
Expand Down Expand Up @@ -108,8 +138,11 @@ Should be active at least on the production server

### Automatic Configuration

Calling `ctx.env['cloud.platform'].install_exoscale()` in an
`anthem` song will configure some parameters such as the
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.

Expand Down
3 changes: 2 additions & 1 deletion cloud_platform/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Cloud Platform
==============

Install addons required for the Camptocamp Cloud platform.
Install addons required for the Camptocamp Cloud platform, and that are
common to all platform providers.

* Provide a quick install that we can call at the setup / migration
of a database
Expand Down
1 change: 0 additions & 1 deletion cloud_platform/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
'license': 'AGPL-3',
'category': 'Extra Tools',
'depends': [
'attachment_s3',
'session_redis',
'monitoring_status',
'logging_json',
Expand Down
56 changes: 55 additions & 1 deletion cloud_platform/models/cloud_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def is_true(strval):
class FilestoreKind(object):
db = 'db'
s3 = 's3' # or compatible s3 object storage
swift = 'swift'
file = 'file'


Expand All @@ -46,6 +47,8 @@ def _config_by_server_env(self, environment):
}
return configs.get(environment) or configs['dev']

# Due to the addition of the ovh cloud platform
# This will be moved to cloud_platform_exoscale on v11
@api.model
def install_exoscale(self):
params = self.env['ir.config_parameter'].sudo()
Expand All @@ -58,6 +61,54 @@ def install_exoscale(self):
self.env['ir.attachment'].sudo().force_storage()
_logger.info('cloud platform configured for exoscale')

@api.model
def _check_swift(self, environment_name):
params = self.env['ir.config_parameter'].sudo()
use_swift = (params.get_param('ir_attachment.location') ==
FilestoreKind.swift)
if environment_name in ('prod', 'integration'):
assert use_swift, (
"Swift must be used on production and integration instances. "
"It is activated, setting 'ir_attachment.location.' to 'swift'"
" The 'install_exoscale()' function sets this option "
"automatically."
)
if use_swift:
assert os.environ.get('SWIFT_HOST'), (
"SWIFT_HOST environment variable is required when "
"ir_attachment.location is 'swift'."
)
assert os.environ.get('SWIFT_ACCOUNT'), (
"SWIFT_ACCOUNT environment variable is required when "
"ir_attachment.location is 'swift'."
)
assert os.environ.get('SWIFT_PASSWORD'), (
"SWIFT_PASSWORD environment variable is required when "
"ir_attachment.location is 'swift'."
)
container_name = os.environ['SWIFT_WRITE_CONTAINER']
prod_container = bool(re.match(r'[a-z]+-odoo-prod',
container_name))
if environment_name == 'prod':
assert prod_container, (
"SWIFT_WRITE_CONTAINER should match '<client>-odoo-prod', "
"we got: '%s'" % (container_name,)
)
else:
# if we are using the prod bucket on another instance
# such as an integration, we must be sure to be in read only!
assert not prod_container, (
"SWIFT_WRITE_CONTAINER should not match "
"'<client>-odoo-prod', we got: '%s'" % (container_name,)
)
elif environment_name == 'test':
# store in DB so we don't have files local to the host
assert params.get_param('ir_attachment.location') == 'db', (
"In test instances, files must be stored in the database with "
"'ir_attachment.location' set to 'db'. This is "
"automatically set by the function 'install_ovh()'."
)

@api.model
def _check_s3(self, environment_name):
params = self.env['ir.config_parameter'].sudo()
Expand Down Expand Up @@ -148,7 +199,10 @@ def check(self):
)
return
environment_name = config['running_env']
self._check_s3(environment_name)
if kind == 'exoscale':
self._check_s3(environment_name)
elif kind == 'ovh':
self._check_swift(environment_name)
self._check_redis(environment_name)

@api.model_cr
Expand Down
4 changes: 4 additions & 0 deletions cloud_platform/songs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@

def install_exoscale(ctx):
ctx.env['cloud.platform'].install_exoscale()


def install_ovh(ctx):
ctx.env['cloud.platform'].install_ovh()
6 changes: 6 additions & 0 deletions cloud_platform_exoscale/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Cloud Platform Exoscale
=======================

Install addons specific to the Exoscale setup.

* The object storage is S3
1 change: 1 addition & 0 deletions cloud_platform_exoscale/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions cloud_platform_exoscale/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)


{'name': 'Cloud Platform Exoscale',
'summary': 'Addons required for the Camptocamp Cloud Platform on Exoscale',
'version': '10.0.1.1.0',
'author': 'Camptocamp,Odoo Community Association (OCA)',
'license': 'AGPL-3',
'category': 'Extra Tools',
'depends': [
'cloud_platform',
'attachment_s3',
],
'website': 'http://www.camptocamp.com',
'data': [],
'installable': True,
}
1 change: 1 addition & 0 deletions cloud_platform_exoscale/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import cloud_platform
13 changes: 13 additions & 0 deletions cloud_platform_exoscale/models/cloud_platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

import logging

from odoo import models

_logger = logging.getLogger(__name__)


class CloudPlatform(models.AbstractModel):
_inherit = 'cloud.platform'
7 changes: 7 additions & 0 deletions cloud_platform_ovh/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Cloud Platform OVH
==================

Install addons specific to the OVH setup.

* The object storage is Swift

1 change: 1 addition & 0 deletions cloud_platform_ovh/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions cloud_platform_ovh/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)


{'name': 'Cloud Platform OVH',
'summary': 'Addons required for the Camptocamp Cloud Platform on OVH',
'version': '10.0.1.1.0',
'author': 'Camptocamp,Odoo Community Association (OCA)',
'license': 'AGPL-3',
'category': 'Extra Tools',
'depends': [
'cloud_platform',
'attachment_swift',
],
'website': 'http://www.camptocamp.com',
'data': [],
'installable': True,
}
1 change: 1 addition & 0 deletions cloud_platform_ovh/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import cloud_platform
44 changes: 44 additions & 0 deletions cloud_platform_ovh/models/cloud_platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
# Copyright 2016 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__)

try:
from ...cloud_platform.models.cloud_platform import FilestoreKind
from ...cloud_platform.models.cloud_platform import PlatformConfig
except ImportError:
FilestoreKind = None
PlatformConfig = None
_logger.debug("Cannot 'import from cloud_platform'")


class CloudPlatform(models.AbstractModel):
_inherit = 'cloud.platform'

@api.model
def _config_by_server_env(self, environment):
configs = {
'prod': PlatformConfig(filestore=FilestoreKind.swift),
'integration': PlatformConfig(filestore=FilestoreKind.swift),
'test': PlatformConfig(filestore=FilestoreKind.db),
'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')

0 comments on commit 6674853

Please sign in to comment.