How to use the charmhelpers.contrib.openstack.utils.CompareOpenStackReleases function in charmhelpers

To help you get started, we’ve selected a few charmhelpers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / charm-nova-cloud-controller / hooks / nova_cc_utils.py View on Github external
def resolve_services():
    _services = copy.deepcopy(BASE_SERVICES)
    os_rel = ch_utils.os_release('nova-common')
    cmp_os_release = ch_utils.CompareOpenStackReleases(os_rel)
    for release in SERVICE_BLACKLIST:
        if cmp_os_release >= release or hookenv.config('disable-aws-compat'):
            for service in SERVICE_BLACKLIST[release]:
                _services.remove(service)
    return _services
github openstack / charm-nova-cloud-controller / charmhelpers / contrib / openstack / policyd.py View on Github external
"""Check that the charm is running on at least Ubuntu Xenial, and at
    least the queens release.

    :param openstack_release: the release codename that is installed.
    :type openstack_release: str
    :returns: True if okay
    :rtype: bool
    """
    # NOTE(ajkavanagh) circular import!  This is because the status message
    # generation code in utils has to call into this module, but this function
    # needs the CompareOpenStackReleases() function.  The only way to solve
    # this is either to put ALL of this module into utils, or refactor one or
    # other of the CompareOpenStackReleases or status message generation code
    # into a 3rd module.
    import charmhelpers.contrib.openstack.utils as ch_utils
    return ch_utils.CompareOpenStackReleases(openstack_release) >= 'queens'
github openstack / charm-nova-cloud-controller / charmhelpers / contrib / openstack / audits / __init__.py View on Github external
def _since_openstack_release(audit_options=None):
        _release = openstack_utils.get_os_codename_package(pkg)
        return openstack_utils.CompareOpenStackReleases(_release) >= release
github openstack / charm-nova-cloud-controller / hooks / nova_cc_utils.py View on Github external
def online_data_migrations_if_needed():
    '''Runs nova-manage to run online data migrations available since Mitaka'''
    if (hookenv.is_leader() and
            ch_utils.CompareOpenStackReleases(
                ch_utils.os_release('nova-common')) >= 'mitaka'):
        hookenv.log('Running online_data_migrations', level=hookenv.INFO)
        cmd = ['nova-manage', 'db', 'online_data_migrations']
        try:
            subprocess.check_output(cmd)
        except subprocess.CalledProcessError as e:
            hookenv.log('online_data_migrations failed\n{}'.format(e.output),
                        level=hookenv.ERROR)
            raise
github openstack / charm-nova-cloud-controller / charmhelpers / contrib / openstack / utils.py View on Github external
def enable_memcache(source=None, release=None, package=None):
    """Determine if memcache should be enabled on the local unit

    @param release: release of OpenStack currently deployed
    @param package: package to derive OpenStack version deployed
    @returns boolean Whether memcache should be enabled
    """
    _release = None
    if release:
        _release = release
    else:
        _release = os_release(package)
    if not _release:
        _release = get_os_codename_install_source(source)

    return CompareOpenStackReleases(_release) >= 'mitaka'
github openstack / charm-nova-cloud-controller / hooks / nova_cc_utils.py View on Github external
: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 = copy.deepcopy(get_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 = ch_utils.os_release('nova-common')
    cmp_os_release = ch_utils.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 common.console_attributes('services'):
        _resource_map[NOVA_CONF]['services'] += (
            common.console_attributes('services'))

    if is_serial_console_enabled(cmp_os_release):
        _resource_map[NOVA_CONF]['services'] += SERIAL_CONSOLE['services']

    if is_consoleauth_enabled(cmp_os_release):
        _resource_map[NOVA_CONF]['services'] += ['nova-consoleauth']
github openstack / charm-swift-proxy / lib / swift_utils.py View on Github external
def _proxy_manager_call(path, args, kwargs):
    package = dict(path=path,
                   args=args,
                   kwargs=kwargs)
    serialized = json.dumps(package, **JSON_ENCODE_OPTIONS)
    cmp_openstack = CompareOpenStackReleases(os_release('swift'))
    if cmp_openstack >= 'train':
        python = 'python3'
    else:
        python = 'python2'
    script = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                          '..',
                                          'swift_manager',
                                          'manager.py'))
    env = os.environ
    try:
        if sys.version_info < (3, 5):
            # remove this after trusty support is removed.  No subprocess.run
            # in Python 3.4
            process = subprocess.Popen([python, script, serialized],
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
github openstack / charm-nova-cloud-controller / hooks / nova_cc_hooks.py View on Github external
def db_joined(relation_id=None):
    cmp_os_release = ch_utils.CompareOpenStackReleases(
        ch_utils.os_release('nova-common'))
    if hookenv.config('prefer-ipv6'):
        ch_utils.sync_db_with_multi_ipv6_addresses(
            hookenv.config('database'),
            hookenv.config('database-user'),
            relation_prefix='nova')

        if cmp_os_release >= 'mitaka':
            # NOTE: mitaka uses a second nova-api database as well
            ch_utils.sync_db_with_multi_ipv6_addresses(
                'nova_api',
                hookenv.config('database-user'),
                relation_prefix='novaapi')

        if cmp_os_release >= 'ocata':
            # NOTE: ocata requires cells v2
github openstack / charm-nova-cloud-controller / hooks / nova_cc_utils.py View on Github external
def stop_deprecated_services():
    """Stop services that are not used anymore.

    Note: It may be important to also disable the service, see:
    resource_map.
    """
    release = ch_utils.os_release('nova-common')
    if ch_utils.CompareOpenStackReleases(release) >= 'rocky':
        ch_host.service_pause('nova-api-os-compute')
github openstack / charm-nova-compute / hooks / nova_compute_context.py View on Github external
def flat_dhcp_context(self):
        ec2_host = None
        for rid in relation_ids('cloud-compute'):
            for unit in related_units(rid):
                ec2_host = relation_get('ec2_host', rid=rid, unit=unit)

        if not ec2_host:
            return {}

        if config('multi-host').lower() == 'yes':
            cmp_os_release = CompareOpenStackReleases(
                os_release('nova-common'))
            if cmp_os_release <= 'train':
                # nova-network only available until ussuri
                self._ensure_packages(['nova-api', 'nova-network'])
            else:
                self._ensure_packages(['nova-api'])

        return {
            'flat_interface': config('flat-interface'),
            'ec2_dmz_host': ec2_host,
        }