From f2f6bbd521e80685aa81fc436be3f7b0cd10bd50 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Sat, 5 Jan 2013 19:39:43 -0800 Subject: [PATCH] Update horizon after working with it at yahoo --- anvil/components/glance.py | 7 +- anvil/components/horizon.py | 69 +++-------- conf/personas/in-a-box/basic-web.yaml | 1 - conf/personas/solo/horizon.yaml | 2 +- .../{horizon.conf => horizon_apache.conf} | 0 conf/templates/horizon/horizon_settings.py | 107 ---------------- conf/templates/horizon/local_settings.py | 115 ++++++++++++++++++ 7 files changed, 138 insertions(+), 163 deletions(-) rename conf/templates/horizon/{horizon.conf => horizon_apache.conf} (100%) delete mode 100644 conf/templates/horizon/horizon_settings.py create mode 100644 conf/templates/horizon/local_settings.py diff --git a/anvil/components/glance.py b/anvil/components/glance.py index 666fd293..17b4fe4a 100644 --- a/anvil/components/glance.py +++ b/anvil/components/glance.py @@ -16,11 +16,6 @@ import io -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict - from anvil import cfg from anvil import colorizer from anvil import components as comp @@ -28,6 +23,8 @@ from anvil import log as logging from anvil import shell as sh from anvil import utils +from anvil.utils import OrderedDict + from anvil.components.helpers import db as dbhelper from anvil.components.helpers import glance as ghelper from anvil.components.helpers import keystone as khelper diff --git a/anvil/components/horizon.py b/anvil/components/horizon.py index c44d6f03..b5312f89 100644 --- a/anvil/components/horizon.py +++ b/anvil/components/horizon.py @@ -26,35 +26,25 @@ from anvil.packaging import yum from tempfile import NamedTemporaryFile +import binascii import os import re -from anvil.components.helpers import db as dbhelper - LOG = logging.getLogger(__name__) -# Actual dir names -ROOT_HORIZON = 'horizon' -ROOT_DASH = 'openstack_dashboard' +# See https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SECRET_KEY +# +# Needs to be a multiple of 2 for our usage... +SECRET_KEY_LEN = 10 -# Name used for python install trace -HORIZON_NAME = ROOT_HORIZON -DASH_NAME = 'dashboard' - -# Config files messed with -HORIZON_PY_CONF = "horizon_settings.py" -HORIZON_APACHE_CONF = 'horizon.conf' -CONFIGS = [HORIZON_PY_CONF, HORIZON_APACHE_CONF] - -# DB sync that needs to happen for horizon -DB_SYNC_CMD = ['python', 'manage.py', 'syncdb', '--noinput'] +# Config files messed with... +HORIZON_LOCAL_SETTINGS_CONF = "local_settings.py" +HORIZON_APACHE_CONF = 'horizon_apache.conf' +CONFIGS = [HORIZON_LOCAL_SETTINGS_CONF, HORIZON_APACHE_CONF] # Users which apache may not like starting as.. BAD_APACHE_USERS = ['root'] -# This db will be dropped and created -DB_NAME = 'horizon' - class HorizonUninstaller(comp.PythonUninstallComponent): def __init__(self, *args, **kargs): @@ -88,6 +78,10 @@ class HorizonInstaller(comp.PythonInstallComponent): def _install_node_repo(self): repo_url = self.get_option('nodejs_repo') if not repo_url: + # Ok then, hope node js is in your path for when horizon attempts + # to use it... if not possibly follow: + # + # http://www.chrisabernethy.com/installing-node-js-on-centos-redhat/ return # Download the said url and install it so that we can actually install # the node.js requirement which seems to be needed by horizon for css compiling?? @@ -112,7 +106,7 @@ class HorizonInstaller(comp.PythonInstallComponent): elif fn_ext == ".rpm": # Install it instead from said rpm (which likely is a # file that contains said repo location)... - packager = yum.YumPackager(self.distro).direct_install(temp_fh.name) + yum.YumPackager(self.distro).direct_install(temp_fh.name) @property def symlinks(self): @@ -136,9 +130,8 @@ class HorizonInstaller(comp.PythonInstallComponent): raise excp.ConfigException(msg) def target_config(self, config_name): - if config_name == HORIZON_PY_CONF: - # FIXME(harlowja) don't write to checked out locations... - return sh.joinpths(self.get_option('app_dir'), ROOT_DASH, 'local', 'local_settings.py') + if config_name == HORIZON_LOCAL_SETTINGS_CONF: + return sh.joinpths(self.get_option('app_dir'), 'openstack_dashboard', 'local', config_name) else: return comp.PythonInstallComponent.target_config(self, config_name) @@ -162,24 +155,6 @@ class HorizonInstaller(comp.PythonInstallComponent): sh.chmod(fn, 0666) return len(log_fns) - def _sync_db(self): - # Initialize the horizon database (it stores sessions and notices shown to users). - # The user system is external (keystone). - LOG.info("Syncing horizon to database: %s", colorizer.quote(DB_NAME)) - sh.execute(*DB_SYNC_CMD, cwd=self.get_option('app_dir')) - - def _setup_db(self): - dbhelper.drop_db(distro=self.distro, - dbtype=self.get_option('db', 'type'), - dbname=DB_NAME, - **utils.merge_dicts(self.get_option('db'), - dbhelper.get_shared_passwords(self))) - dbhelper.create_db(distro=self.distro, - dbtype=self.get_option('db', 'type'), - dbname=DB_NAME, - **utils.merge_dicts(self.get_option('db'), - dbhelper.get_shared_passwords(self))) - def _configure_files(self): am = comp.PythonInstallComponent._configure_files(self) am += self._setup_logs(self.get_bool_option('clear-logs')) @@ -187,9 +162,6 @@ class HorizonInstaller(comp.PythonInstallComponent): def post_install(self): comp.PythonInstallComponent.post_install(self) - if self.get_bool_option('db-sync'): - self._setup_db() - self._sync_db() if self.get_bool_option('make-blackhole'): self._setup_blackhole() @@ -212,11 +184,10 @@ class HorizonInstaller(comp.PythonInstallComponent): mp['BLACK_HOLE_DIR'] = self.blackhole_dir else: mp['OPENSTACK_HOST'] = self.get_option('ip') - mp['DB_NAME'] = DB_NAME - mp['DB_USER'] = self.get_option('db', 'user') - mp['DB_PASSWORD'] = dbhelper.get_shared_passwords(self)['pw'] - mp['DB_HOST'] = self.get_option("db", "host") - mp['DB_PORT'] = self.get_option("db", "port") + if SECRET_KEY_LEN <= 0: + mp['SECRET_KEY'] = '' + else: + mp['SECRET_KEY'] = binascii.b2a_hex(os.urandom(SECRET_KEY_LEN / 2)) return mp diff --git a/conf/personas/in-a-box/basic-web.yaml b/conf/personas/in-a-box/basic-web.yaml index 483ba515..9057cc1e 100644 --- a/conf/personas/in-a-box/basic-web.yaml +++ b/conf/personas/in-a-box/basic-web.yaml @@ -35,7 +35,6 @@ options: do-init: true enable-pki: false horizon: - db-sync: true make-blackhole: true subsystems: glance: diff --git a/conf/personas/solo/horizon.yaml b/conf/personas/solo/horizon.yaml index ac8f6beb..b5ae9189 100644 --- a/conf/personas/solo/horizon.yaml +++ b/conf/personas/solo/horizon.yaml @@ -7,11 +7,11 @@ components: - nova-client - quantum-client - swift-client +- cinder-client - horizon options: horizon: db-sync: true - make-blackhole: true supports: - rhel ... diff --git a/conf/templates/horizon/horizon.conf b/conf/templates/horizon/horizon_apache.conf similarity index 100% rename from conf/templates/horizon/horizon.conf rename to conf/templates/horizon/horizon_apache.conf diff --git a/conf/templates/horizon/horizon_settings.py b/conf/templates/horizon/horizon_settings.py deleted file mode 100644 index 9822f0d3..00000000 --- a/conf/templates/horizon/horizon_settings.py +++ /dev/null @@ -1,107 +0,0 @@ -#* - This is a cheetah template! -*# - -import os - -DEBUG = True -TEMPLATE_DEBUG = DEBUG -PROD = False -USE_SSL = False - -LOCAL_PATH = os.path.dirname(os.path.abspath(__file__)) - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.mysql', - 'NAME': '${DB_NAME}', - 'USER': '${DB_USER}', - 'PASSWORD': '${DB_PASSWORD}', - 'HOST': '${DB_HOST}', - 'PORT': '${DB_PORT}', - 'TEST_NAME': '${DB_NAME}_test', - }, -} - -# The default values for these two settings seem to cause issues with apache -CACHE_BACKEND = 'dummy://' -SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db' - -# Send email to the console by default -EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' - -# django-mailer uses a different settings attribute -MAILER_EMAIL_BACKEND = EMAIL_BACKEND - -# Set a secure and unique SECRET_KEY (the Django default is '') -from horizon.utils import secret_key -SECRET_KEY = secret_key.generate_or_read_from_file(os.path.join(LOCAL_PATH, '.secret_key_store')) - -HORIZON_CONFIG = { - 'dashboards': ('nova', 'syspanel', 'settings',), - 'default_dashboard': 'nova', -} - -# TODO(tres): Remove these once Keystone has an API to identify auth backend. -OPENSTACK_KEYSTONE_BACKEND = { - 'name': 'native', - 'can_edit_user': True -} - -OPENSTACK_HOST = "${OPENSTACK_HOST}" -OPENSTACK_KEYSTONE_URL = "http://%s:5000/v2.0" % OPENSTACK_HOST - -# FIXME: this is only needed until keystone fixes its GET /tenants call -# so that it doesn't return everything for admins -OPENSTACK_KEYSTONE_ADMIN_URL = "http://%s:35357/v2.0" % OPENSTACK_HOST -OPENSTACK_KEYSTONE_DEFAULT_ROLE = "Member" - -# If you have external monitoring links, eg: -# EXTERNAL_MONITORING = [ -# ['Nagios','http://foo.com'], -# ['Ganglia','http://bar.com'], -# ] - -#LOGGING = { -# 'version': 1, -# # When set to True this will disable all logging except -# # for loggers specified in this configuration dictionary. Note that -# # if nothing is specified here and disable_existing_loggers is True, -# # django.db.backends will still log unless it is disabled explicitly. -# 'disable_existing_loggers': False, -# 'handlers': { -# 'null': { -# 'level': 'DEBUG', -# 'class': 'django.utils.log.NullHandler', -# }, -# 'console': { -# # Set the level to "DEBUG" for verbose output logging. -# 'level': 'INFO', -# 'class': 'logging.StreamHandler', -# }, -# }, -# 'loggers': { -# # Logging from django.db.backends is VERY verbose, send to null -# # by default. -# 'django.db.backends': { -# 'handlers': ['null'], -# 'propagate': False, -# }, -# 'horizon': { -# 'handlers': ['console'], -# 'propagate': False, -# }, -# 'novaclient': { -# 'handlers': ['console'], -# 'propagate': False, -# }, -# 'keystoneclient': { -# 'handlers': ['console'], -# 'propagate': False, -# }, -# 'nose.plugins.manager': { -# 'handlers': ['console'], -# 'propagate': False, -# } -# } -#} diff --git a/conf/templates/horizon/local_settings.py b/conf/templates/horizon/local_settings.py new file mode 100644 index 00000000..5116d359 --- /dev/null +++ b/conf/templates/horizon/local_settings.py @@ -0,0 +1,115 @@ +#* + This is a cheetah template! +*# + +# These settings are good for dev-like environments (or ci) +# When moving to production it is likely some more thought should +# be given here... +# +# See: https://docs.djangoproject.com/en/dev/ref/settings/ +# +# This file overrides other defaults in openstack_dashboard/settings.py + +import os + +DEBUG = True +TEMPLATE_DEBUG = DEBUG +PROD = False +USE_SSL = False + +LOCAL_PATH = os.path.dirname(os.path.abspath(__file__)) + +# See: https://docs.djangoproject.com/en/dev/topics/cache/?from=olddocs +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.dummy.DummyCache', + } +} + +# Use session cookies for any user-specific horizon session data +SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies' + +# Send email to the console by default +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' + +# See: https://code.google.com/p/django-mailer/ +# +# django-mailer uses a different settings attribute +MAILER_EMAIL_BACKEND = EMAIL_BACKEND + +# Set a secure and unique SECRET_KEY (the Django default is '') +# +# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SECRET_KEY +SECRET_KEY = "${SECRET_KEY}" + +# The OPENSTACK_KEYSTONE_BACKEND settings can be used to identify the +# capabilities of the auth backend for Keystone. +# If Keystone has been configured to use LDAP as the auth backend then set +# can_edit_user to False and name to 'ldap'. +# +# TODO(tres): Remove these once Keystone has an API to identify auth backend. +OPENSTACK_KEYSTONE_BACKEND = { + 'name': 'native', + 'can_edit_user': True +} + +OPENSTACK_HOST = "${OPENSTACK_HOST}" +OPENSTACK_KEYSTONE_URL = "http://%s:5000/v2.0" % OPENSTACK_HOST +OPENSTACK_KEYSTONE_DEFAULT_ROLE = "Member" + +# The timezone of the server. This should correspond with the timezone +# of your entire OpenStack installation, and hopefully be in UTC. +TIME_ZONE = "UTC" + +LOGGING = { + 'version': 1, + # When set to True this will disable all logging except + # for loggers specified in this configuration dictionary. Note that + # if nothing is specified here and disable_existing_loggers is True, + # django.db.backends will still log unless it is disabled explicitly. + 'disable_existing_loggers': False, + 'handlers': { + 'null': { + 'level': 'DEBUG', + 'class': 'django.utils.log.NullHandler', + }, + 'console': { + # Set the level to "DEBUG" for verbose output logging. + 'level': 'INFO', + 'class': 'logging.StreamHandler', + }, + }, + 'loggers': { + # Logging from django.db.backends is VERY verbose, send to null + # by default. + 'django.db.backends': { + 'handlers': ['null'], + 'propagate': False, + }, + 'horizon': { + 'handlers': ['console'], + 'propagate': False, + }, + 'openstack_dashboard': { + 'handlers': ['console'], + 'propagate': False, + }, + 'novaclient': { + 'handlers': ['console'], + 'propagate': False, + }, + 'keystoneclient': { + 'handlers': ['console'], + 'propagate': False, + }, + 'glanceclient': { + 'handlers': ['console'], + 'propagate': False, + }, + 'nose.plugins.manager': { + 'handlers': ['console'], + 'propagate': False, + }, + }, +} +