From 97a3c346e6328642e6d8bfa9688082e6e6e92684 Mon Sep 17 00:00:00 2001 From: Thomas Massmann Date: Fri, 13 Dec 2013 11:47:30 -0500 Subject: [PATCH] Create missing plone application roles on chef server if missing. --- src/propertyshelf/fabfile/plone/roles.py | 139 ++++++++++++++++++++++- 1 file changed, 138 insertions(+), 1 deletion(-) diff --git a/src/propertyshelf/fabfile/plone/roles.py b/src/propertyshelf/fabfile/plone/roles.py index c94a787..8dca702 100644 --- a/src/propertyshelf/fabfile/plone/roles.py +++ b/src/propertyshelf/fabfile/plone/roles.py @@ -1,9 +1,13 @@ # -*- coding: utf-8 -*- """Manage chef roles.""" +from chef import autoconfigure, Role from fabric import api +from fabric.colors import green from propertyshelf.fabfile.common import roles +PYTHON_MD5 = '3b477554864e616a041ee4d7cef9849751770bc7c39adaf78a94ea145c488059' + @api.task def check(): @@ -14,7 +18,140 @@ def check(): @api.task def create_missing(): """Create missing roles on the chef server.""" - raise NotImplementedError + chef_api = autoconfigure() + required = roles.get_required() + domain = api.env.get('domain', 'example.com') + + # Create the role_base. + if not roles.check(required.get('role_base')): + name = required.get('role_base') + description = 'Plone Application for %s.' % domain + run_list = ( + "recipe[build-essential]", + ) + default_attributes = { + 'domain': domain, + 'haproxy': { + 'app_server_role': required.get('role_worker'), + 'incoming_address': '127.0.0.1', + 'incoming_port': '8300', + 'member_port': '8080', + }, + 'nginx': { + 'client_max_body_size': '150m', + }, + 'plone': { + 'client': { + 'count': 2, + 'eggs': [ + "Products.Doormat == 0.9.1", + "Products.PloneFormGen == 1.7.12", + "Products.RedirectionTool == 1.3.1", + "collective.carousel == 1.6.2", + "collective.contentleadimage == 1.3.4", + "collective.cover == 1.0a6", + "collective.googleanalytics == 1.4.3", + "mls.apiclient == 1.1.1", + "plone.app.multilingual == 1.2.1", + "plone.mls.core == 0.4.2", + "plone.mls.listing == 0.9.7", + "plone.multilingualbehavior == 1.2", + ], + 'extends': [ + 'plone_sites.cfg', + ], + 'zeo_role': required.get('role_database'), + }, + 'version': api.env.get('plone_version', '4.3.2'), + 'vhost_data_bag': api.env.get('vhost_databag', ''), + }, + 'python': { + 'checksum': PYTHON_MD5, + 'configure_options': '--prefix=/usr/local', + 'install_method': 'source', + 'prefix_dir': '/usr/local', + 'version': '2.7.5', + }, + 'varnish': { + 'listen_address': '127.0.0.1', + 'listen_port': '9000', + 'backend_port': '8300', + 'storage': 'malloc', + 'storage_size': '512M', + 'vcl_cookbook': 'plone_hosting', + 'vcl_source': 'varnish.vcl.erb', + } + } + + Role.create( + name, + api=chef_api, + description=description, + run_list=run_list, + default_attributes=default_attributes, + ) + print(green('Created role %s') % name) + + # Create the role_database. + if not roles.check(required.get('role_database')): + name = required.get('role_database') + description = 'ZEO Server for %s.' % domain + run_list = ( + "role[%s]" % required.get('role_base'), + "recipe[plone_hosting::database_server]", + ) + override_attributes = { + 'plone': { + 'client': { + 'count': 2, + } + }, + } + + Role.create( + name, + api=chef_api, + description=description, + run_list=run_list, + override_attributes=override_attributes, + ) + print(green('Created role %s') % name) + + # Create the role_frontend. + if not roles.check(required.get('role_frontend')): + name = required.get('role_frontend') + description = 'Frontend Server for %s.' % domain + run_list = ( + "role[%s]" % required.get('role_base'), + "recipe[plone_hosting::load_balancer]", + "recipe[plone_hosting::cache_server]", + "recipe[plone_hosting::web_server]" + ) + + Role.create( + name, + api=chef_api, + description=description, + run_list=run_list, + ) + print(green('Created role %s') % name) + + # Create the role_worker. + if not roles.check(required.get('role_worker')): + name = required.get('role_worker') + description = 'Application Worker for %s.' % domain + run_list = ( + "role[%s]" % required.get('role_base'), + "recipe[plone_hosting::app_server]", + ) + + Role.create( + name, + api=chef_api, + description=description, + run_list=run_list, + ) + print(green('Created role %s') % name) @api.task