Beispiel #1
0
def resource_map(release=None):
    """
    Dynamically generate a map of resources that will be managed for a single
    hook execution.
    """
    resource_map = deepcopy(BASE_RESOURCE_MAP)
    if relation_ids('backup-backend'):
        resource_map[CINDER_CONF]['services'].append('cinder-backup')
        resource_map[ceph_config_file()]['services'].append('cinder-backup')

    if relation_ids('ceph'):
        # need to create this early, new peers will have a relation during
        # registration # before they've run the ceph hooks to create the
        # directory.
        # !!! FIX: These side effects seem inappropriate for this method
        mkdir(os.path.dirname(CEPH_CONF))
        mkdir(os.path.dirname(ceph_config_file()))

        # Install ceph config as an alternative for co-location with
        # ceph and ceph-osd charm - cinder ceph.conf will be
        # lower priority than both of these but thats OK
        if not os.path.exists(ceph_config_file()):
            # touch file for pre-templated generation
            open(ceph_config_file(), 'w').close()
        install_alternative(os.path.basename(CEPH_CONF),
                            CEPH_CONF, ceph_config_file())
    else:
        resource_map.pop(ceph_config_file())

    if os.path.exists('/etc/apache2/conf-available'):
        resource_map.pop(APACHE_SITE_CONF)
    else:
        resource_map.pop(APACHE_SITE_24_CONF)

    # Remove services from map which are not enabled by user config
    for cfg in resource_map.keys():
        resource_map[cfg]['services'] = \
            filter_services(resource_map[cfg]['services'])

    if enable_memcache(source=config()['openstack-origin']):
        resource_map[MEMCACHED_CONF] = {
            'contexts': [context.MemcacheContext()],
            'services': ['memcached']}

    if run_in_apache():
        for cfile in resource_map:
            svcs = resource_map[cfile]['services']
            if 'cinder-api' in svcs:
                svcs.remove('cinder-api')
                if 'apache2' not in svcs:
                    svcs.append('apache2')
        wsgi_script = "/usr/bin/cinder-wsgi"
        resource_map[WSGI_CINDER_API_CONF] = {
            'contexts': [context.WSGIWorkerConfigContext(name="cinder",
                                                         script=wsgi_script),
                         cinder_contexts.HAProxyContext()],
            'services': ['apache2']
        }

    return resource_map
Beispiel #2
0
def register_configs():
    """
    Register config files with their respective contexts.
    Regstration of some configs may not be required depending on
    existing of certain relations.
    """
    # if called without anything installed (eg during install hook)
    # just default to earliest supported release. configs dont get touched
    # till post-install, anyway.

    release = get_os_codename_package('ceilometer-common', fatal=False)
    configs = templating.OSConfigRenderer(templates_dir=TEMPLATES,
                                          openstack_release=release)
    if not release:
        log("Not installed yet, no way to determine the OS release. "
            "Skipping register configs", DEBUG)
        return configs

    if CompareOpenStackReleases(release) >= 'queens':
        for conf in QUEENS_CONFIG_FILES:
            configs.register(conf, QUEENS_CONFIG_FILES[conf]['hook_contexts'])
        configs.register(PIPELINE_CONF, [RemoteSinksContext()])
    else:
        for conf in (CEILOMETER_CONF, HAPROXY_CONF):
            configs.register(conf, CONFIG_FILES[conf]['hook_contexts'])

        if init_is_systemd():
            configs.register(
                CEILOMETER_API_SYSTEMD_CONF,
                CONFIG_FILES[CEILOMETER_API_SYSTEMD_CONF]['hook_contexts']
            )

        if os.path.exists('/etc/apache2/conf-available'):
            configs.register(
                HTTPS_APACHE_24_CONF,
                CONFIG_FILES[HTTPS_APACHE_24_CONF]['hook_contexts']
            )
        else:
            configs.register(
                HTTPS_APACHE_CONF,
                CONFIG_FILES[HTTPS_APACHE_CONF]['hook_contexts']
            )
        if enable_memcache(release=release):
            configs.register(MEMCACHED_CONF, [context.MemcacheContext()])

        if run_in_apache():
            wsgi_script = "/usr/share/ceilometer/app.wsgi"
            configs.register(
                WSGI_CEILOMETER_API_CONF,
                [context.WSGIWorkerConfigContext(name="ceilometer",
                                                 script=wsgi_script),
                 CeilometerContext(),
                 HAProxyContext()]
            )
        if CompareOpenStackReleases(release) >= 'mitaka':
            configs.register(PIPELINE_CONF, [RemoteSinksContext()])
    return configs
Beispiel #3
0
    def wsgi_worker_context(self):
        """Return a WSGIWorkerConfigContext dictionary.

        This is used to configure a WSGI worker.  The charm_instance class can
        define some attributes (or properties - anything getattr(...) will work
        against for:

            wsgi_script: a script/name to pass to the WSGIW... constructor
            wsgi_admin_script: a script/name to pass to the WSGIW...
                constructor
            wsgi_public_script: a script/name to pass to the WSGIW...
                constructor
            wsgi_process_weight: an float between 0.0 and 1.0 to split the
                share of all workers between main, admin and public workers.
            wsgi_admin_process_weight: an float between 0.0 and 1.0 to split
                the share of all workers between main, admin and public workers
            wsgi_public_process_weight: an float between 0.0 and 1.0 to split
                the share of all workers between main, admin and public workers

            The sum of the process weights should equal 1 to make sense.

        :returns: WSGIWorkerConfigContext dictionary.
        """
        charm_instance = self.charm_instance or {}
        kwargs = dict(
            name=getattr(charm_instance, 'name', None),
            script=getattr(charm_instance, 'wsgi_script', None),
            admin_script=getattr(charm_instance, 'wsgi_admin_script', None),
            public_script=getattr(charm_instance, 'wsgi_public_script', None),
            process_weight=getattr(charm_instance, 'wsgi_process_weight',
                                   None),
            admin_process_weight=getattr(charm_instance,
                                         'wsgi_admin_process_weight', None),
            public_process_weight=getattr(charm_instance,
                                          'wsgi_public_process_weight', None),
        )
        # filtering the kwargs of Nones allows the default arguments on
        # WSGIWorkerConfigContext.__init__(...) to be used.
        filtered_kwargs = dict(
            (k, v) for k, v in kwargs.items() if v is not None)
        return ch_context.WSGIWorkerConfigContext(**filtered_kwargs)()
Beispiel #4
0
def resource_map(actual_services=True):
    '''
    Dynamically generate a map of resources that will be managed for a single
    hook execution.

    :param actual_services: Whether to return the actual services that run on a
        unit (ie. apache2) or the services defined in BASE_SERVICES
        (ie.nova-placement-api).
    '''
    resource_map = deepcopy(BASE_RESOURCE_MAP)

    if os.path.exists('/etc/apache2/conf-available'):
        resource_map.pop(APACHE_CONF)
    else:
        resource_map.pop(APACHE_24_CONF)

    resource_map[NOVA_CONF]['contexts'].append(
        nova_cc_context.NeutronCCContext())

    release = os_release('nova-common')
    cmp_os_release = CompareOpenStackReleases(release)
    if cmp_os_release >= 'mitaka':
        resource_map[NOVA_CONF]['contexts'].append(
            nova_cc_context.NovaAPISharedDBContext(relation_prefix='novaapi',
                                                   database='nova_api',
                                                   ssl_dir=NOVA_CONF_DIR))

    if console_attributes('services'):
        resource_map[NOVA_CONF]['services'] += console_attributes('services')
        # nova-consoleauth will be managed by pacemaker, if
        # single-nova-consoleauth is used, then don't monitor for the
        # nova-consoleauth service to be started (LP: #1660244).
        if config('single-nova-consoleauth') and relation_ids('ha'):
            services = resource_map[NOVA_CONF]['services']
            if 'nova-consoleauth' in services:
                services.remove('nova-consoleauth')

    if (config('enable-serial-console') and cmp_os_release >= 'juno'):
        resource_map[NOVA_CONF]['services'] += SERIAL_CONSOLE['services']

    # also manage any configs that are being updated by subordinates.
    vmware_ctxt = context.SubordinateConfigContext(interface='nova-vmware',
                                                   service='nova',
                                                   config_file=NOVA_CONF)
    vmware_ctxt = vmware_ctxt()
    if vmware_ctxt and 'services' in vmware_ctxt:
        for s in vmware_ctxt['services']:
            if s not in resource_map[NOVA_CONF]['services']:
                resource_map[NOVA_CONF]['services'].append(s)

    if enable_memcache(release=release):
        resource_map[MEMCACHED_CONF] = {
            'contexts': [context.MemcacheContext()],
            'services': ['memcached']
        }

    if actual_services and placement_api_enabled():
        for cfile in resource_map:
            svcs = resource_map[cfile]['services']
            if 'nova-placement-api' in svcs:
                svcs.remove('nova-placement-api')
                if 'apache2' not in svcs:
                    svcs.append('apache2')
        wsgi_script = "/usr/bin/nova-placement-api"
        resource_map[WSGI_NOVA_PLACEMENT_API_CONF] = {
            'contexts': [
                context.WSGIWorkerConfigContext(name="nova",
                                                script=wsgi_script),
                nova_cc_context.HAProxyContext()
            ],
            'services': ['apache2']
        }
    elif not placement_api_enabled():
        for cfile in resource_map:
            svcs = resource_map[cfile]['services']
            if 'nova-placement-api' in svcs:
                svcs.remove('nova-placement-api')

    return resource_map
Beispiel #5
0
     'hook_contexts': [
         horizon_contexts.HorizonContext(),
         horizon_contexts.IdentityServiceContext(),
         context.SyslogContext(),
         horizon_contexts.LocalSettingsContext(),
         horizon_contexts.ApacheSSLContext(),
         horizon_contexts.WebSSOFIDServiceProviderContext(),
         horizon_contexts.PolicydContext(lambda: read_policyd_dirs())
     ],
     'services': ['apache2', 'memcached']
 }),
 (APACHE_CONF, {
     'hook_contexts': [
         horizon_contexts.HorizonContext(),
         context.SyslogContext(),
         context.WSGIWorkerConfigContext()
     ],
     'services': ['apache2', 'memcached'],
 }),
 (APACHE_24_CONF, {
     'hook_contexts': [
         horizon_contexts.HorizonContext(),
         context.SyslogContext(),
         context.WSGIWorkerConfigContext()
     ],
     'services': ['apache2', 'memcached'],
 }),
 (APACHE_SSL, {
     'hook_contexts': [
         horizon_contexts.ApacheSSLContext(),
         horizon_contexts.ApacheContext()