示例#1
0
 def __call__(self):
     for relid in relation_ids('ceilometer-service'):
         for unit in related_units(relid):
             conf = relation_get(unit=unit, rid=relid)
             if context_complete(conf):
                 return conf
     return {}
 def __call__(self):
     for rid in relation_ids('quantum-network-service'):
         for unit in related_units(rid):
             ctxt = {
                 'keystone_host': relation_get('keystone_host',
                                               rid=rid, unit=unit),
                 'service_port': relation_get('service_port', rid=rid,
                                              unit=unit),
                 'auth_port': relation_get('auth_port', rid=rid, unit=unit),
                 'service_tenant': relation_get('service_tenant',
                                                rid=rid, unit=unit),
                 'service_username': relation_get('service_username',
                                                  rid=rid, unit=unit),
                 'service_password': relation_get('service_password',
                                                  rid=rid, unit=unit),
                 'quantum_host': relation_get('quantum_host',
                                              rid=rid, unit=unit),
                 'quantum_port': relation_get('quantum_port',
                                              rid=rid, unit=unit),
                 'quantum_url': relation_get('quantum_url',
                                             rid=rid, unit=unit),
                 'region': relation_get('region',
                                        rid=rid, unit=unit),
                 # XXX: Hard-coded http.
                 'service_protocol': 'http',
                 'auth_protocol': 'http',
             }
             if context_complete(ctxt):
                 return ctxt
     return {}
 def __call__(self):
     for relid in relation_ids('ceilometer-service'):
         for unit in related_units(relid):
             conf = relation_get(unit=unit, rid=relid)
             if context_complete(conf):
                 return conf
     return {}
    def __call__(self):
        log('Generating template context for identity-service')
        ctxt = {}
        regions = set()

        for rid in relation_ids('identity-service'):
            for unit in related_units(rid):
                rdata = relation_get(rid=rid, unit=unit)
                serv_host = rdata.get('service_host')
                serv_host = format_ipv6_addr(serv_host) or serv_host
                region = rdata.get('region')

                local_ctxt = {
                    'service_port': rdata.get('service_port'),
                    'service_host': serv_host,
                    'service_protocol':
                    rdata.get('service_protocol') or 'http',
                    'api_version': rdata.get('api_version', '2')
                }
                # If using keystone v3 the context is incomplete without the
                # admin domain id
                if local_ctxt['api_version'] == '3':
                    if not config('default_domain'):
                        local_ctxt['admin_domain_id'] = rdata.get(
                            'admin_domain_id')
                if not context_complete(local_ctxt):
                    continue

                # Update the service endpoint and title for each available
                # region in order to support multi-region deployments
                if region is not None:
                    endpoint = ("%(service_protocol)s://%(service_host)s"
                                ":%(service_port)s/v2.0") % local_ctxt
                    for reg in region.split():
                        regions.add((endpoint, reg))

                if len(ctxt) == 0:
                    ctxt = local_ctxt

        if len(regions) > 1:
            avail_regions = map(lambda r: {'endpoint': r[0], 'title': r[1]},
                                regions)
            ctxt['regions'] = sorted(avail_regions,
                                     key=lambda k: k['endpoint'])

        # Allow the endpoint types to be specified via a config parameter.
        # The config parameter accepts either:
        #  1. a single endpoint type to be specified, in which case the
        #     primary endpoint is configured
        #  2. a list of endpoint types, in which case the primary endpoint
        #     is taken as the first entry and the secondary endpoint is
        #     taken as the second entry. All subsequent entries are ignored.
        ep_types = config('endpoint-type')
        if ep_types:
            ep_types = [self.normalize(e) for e in ep_types.split(',')]
            ctxt['primary_endpoint'] = ep_types[0]
            if len(ep_types) > 1:
                ctxt['secondary_endpoint'] = ep_types[1]

        return ctxt
示例#5
0
    def __call__(self):
        log('Generating template context for identity-service')
        ctxt = {}
        regions = set()

        for rid in relation_ids('identity-service'):
            for unit in related_units(rid):
                rdata = relation_get(rid=rid, unit=unit)
                serv_host = rdata.get('service_host')
                serv_host = format_ipv6_addr(serv_host) or serv_host
                region = rdata.get('region')

                local_ctxt = {
                    'service_port': rdata.get('service_port'),
                    'service_host': serv_host,
                    'service_protocol': rdata.get('service_protocol')
                    or 'http',
                    'api_version': rdata.get('api_version', '2')
                }
                # If using keystone v3 the context is incomplete without the
                # admin domain id
                if local_ctxt['api_version'] == '3':
                    local_ctxt['admin_domain_id'] = rdata.get(
                        'admin_domain_id')
                if not context_complete(local_ctxt):
                    continue

                # Update the service endpoint and title for each available
                # region in order to support multi-region deployments
                if region is not None:
                    endpoint = ("%(service_protocol)s://%(service_host)s"
                                ":%(service_port)s/v2.0") % local_ctxt
                    for reg in region.split():
                        regions.add((endpoint, reg))

                if len(ctxt) == 0:
                    ctxt = local_ctxt

        if len(regions) > 1:
            avail_regions = map(lambda r: {
                'endpoint': r[0],
                'title': r[1]
            }, regions)
            ctxt['regions'] = sorted(avail_regions)

        # Allow the endpoint types to be specified via a config parameter.
        # The config parameter accepts either:
        #  1. a single endpoint type to be specified, in which case the
        #     primary endpoint is configured
        #  2. a list of endpoint types, in which case the primary endpoint
        #     is taken as the first entry and the secondary endpoint is
        #     taken as the second entry. All subsequent entries are ignored.
        ep_types = config('endpoint-type')
        if ep_types:
            ep_types = [self.normalize(e) for e in ep_types.split(',')]
            ctxt['primary_endpoint'] = ep_types[0]
            if len(ep_types) > 1:
                ctxt['secondary_endpoint'] = ep_types[1]

        return ctxt
    def __call__(self):
        bind_port = config('bind-port')
        workers = config('workers')
        if workers == '0':
            import multiprocessing
            workers = multiprocessing.cpu_count()
        ctxt = {
            'proxy_ip': get_host_ip(unit_get('private-address')),
            'bind_port': determine_api_port(bind_port),
            'workers': workers,
            'operator_roles': config('operator-roles'),
            'delay_auth_decision': config('delay-auth-decision')
        }

        ctxt['ssl'] = False

        auth_type = config('auth-type')
        auth_host = config('keystone-auth-host')
        admin_user = config('keystone-admin-user')
        admin_password = config('keystone-admin-user')
        if (auth_type == 'keystone' and auth_host
            and admin_user and admin_password):
            log('Using user-specified Keystone configuration.')
            ks_auth = {
                'auth_type': 'keystone',
                'auth_protocol': config('keystone-auth-protocol'),
                'keystone_host': auth_host,
                'auth_port': config('keystone-auth-port'),
                'service_user': admin_user,
                'service_password': admin_password,
                'service_tenant': config('keystone-admin-tenant-name')
            }
            ctxt.update(ks_auth)

        for relid in relation_ids('identity-service'):
            log('Using Keystone configuration from identity-service.')
            for unit in related_units(relid):
                ks_auth = {
                    'auth_type': 'keystone',
                    'auth_protocol': 'http',  # TODO: http hardcode
                    'keystone_host': relation_get('auth_host',
                                                  unit, relid),
                    'auth_port': relation_get('auth_port',
                                              unit, relid),
                    'service_user': relation_get('service_username',
                                                 unit, relid),
                    'service_password': relation_get('service_password',
                                                     unit, relid),
                    'service_tenant': relation_get('service_tenant',
                                                   unit, relid),
                    'service_port': relation_get('service_port',
                                                 unit, relid),
                    'admin_token': relation_get('admin_token',
                                                unit, relid),
                }
                if context_complete(ks_auth):
                    ctxt.update(ks_auth)
        return ctxt
示例#7
0
 def __call__(self):
     log('Generating template context for cell')
     ctxt = {}
     for rid in relation_ids('cell'):
         for unit in related_units(rid):
             rdata = relation_get(rid=rid, unit=unit)
             ctxt = {
                 'cell_type': rdata.get('cell_type'),
                 'cell_name': rdata.get('cell_name'),
             }
             if context.context_complete(ctxt):
                 return ctxt
     return {}
 def __call__(self):
     log('Generating template context for cell')
     ctxt = {}
     for rid in relation_ids('cell'):
         for unit in related_units(rid):
             rdata = relation_get(rid=rid, unit=unit)
             ctxt = {
                 'cell_type': rdata.get('cell_type'),
                 'cell_name': rdata.get('cell_name'),
             }
             if context.context_complete(ctxt):
                 return ctxt
     return {}
 def __call__(self):
     ''' Provide context for Identity Service relation '''
     ctxt = {}
     for r_id in relation_ids('identity-service'):
         for unit in related_units(r_id):
             ctxt['service_host'] = relation_get('service_host',
                                                 rid=r_id,
                                                 unit=unit)
             ctxt['service_port'] = relation_get('service_port',
                                                 rid=r_id,
                                                 unit=unit)
             if context_complete(ctxt):
                 return ctxt
     return {}
 def __call__(self):
     hookenv.log('Generating template context for cell v2 share-db')
     ctxt = {}
     for rid in hookenv.relation_ids('shared-db'):
         for unit in hookenv.related_units(rid):
             rdata = hookenv.relation_get(rid=rid, unit=unit)
             ctxt = {
                 'novaapi_password': rdata.get('novaapi_password'),
                 'novacell0_password': rdata.get('novacell0_password'),
                 'nova_password': rdata.get('nova_password'),
             }
             if ch_context.context_complete(ctxt):
                 return ctxt
     return {}
示例#11
0
 def __call__(self):
     hookenv.log('Generating template context for cell v2 share-db')
     ctxt = {}
     for rid in hookenv.relation_ids('shared-db'):
         for unit in hookenv.related_units(rid):
             rdata = hookenv.relation_get(rid=rid, unit=unit)
             ctxt = {
                 'novaapi_password': rdata.get('novaapi_password'),
                 'novacell0_password': rdata.get('novacell0_password'),
                 'nova_password': rdata.get('nova_password'),
             }
             if ch_context.context_complete(ctxt):
                 return ctxt
     return {}
 def __call__(self):
     for rid in relation_ids('shared-db'):
         for unit in related_units(rid):
             ctxt = {
                 'database_host': relation_get('db_host', rid=rid,
                                               unit=unit),
                 'quantum_db': QUANTUM_DB,
                 'quantum_user': DB_USER,
                 'quantum_password': relation_get('quantum_password',
                                                  rid=rid, unit=unit),
                 'nova_db': NOVA_DB,
                 'nova_user': NOVA_DB_USER,
                 'nova_password': relation_get('nova_password', rid=rid,
                                               unit=unit)
             }
             if context_complete(ctxt):
                 return ctxt
     return {}
示例#13
0
 def __call__(self):
     for relid in relation_ids('ceilometer-service'):
         for unit in related_units(relid):
             conf = {}
             for attr in self.keys:
                 conf[attr] = relation_get(attr, unit=unit, rid=relid)
             if (conf['api_version'] is not None
                     and float(conf['api_version']) > 2):
                 self.keys.append('admin_domain_name')
                 conf['admin_domain_name'] = relation_get(
                     'admin_domain_name', unit=unit, rid=relid)
             if context_complete(conf):
                 for attr in self.optional_keys:
                     conf[attr] = relation_get(attr, unit=unit, rid=relid)
                 if conf.get('rabbit_ssl_ca') is not None:
                     ca_path = os.path.join(self.ssl_dir,
                                            'rabbit-client-ca.pem')
                     with open(ca_path, 'w') as fh:
                         fh.write(base64.b64decode(conf['rabbit_ssl_ca']))
                         conf['rabbit_ssl_ca'] = ca_path
                 return conf
     return {}
    def __call__(self):
        mongo_servers = []
        replset = None
        _release = os_release('ceilometer-common')
        use_replset = CompareOpenStackReleases(_release) >= 'icehouse'

        for relid in relation_ids('shared-db'):
            rel_units = related_units(relid)
            use_replset = use_replset and (len(rel_units) > 1)

            for unit in rel_units:
                host = relation_get('hostname', unit, relid)
                port = relation_get('port', unit, relid)

                conf = {
                    "db_host": host,
                    "db_port": port,
                    "db_name": CEILOMETER_DB
                }

                if not context_complete(conf):
                    continue

                if not use_replset:
                    return conf

                if replset is None:
                    replset = relation_get('replset', unit, relid)

                mongo_servers.append('{}:{}'.format(host, port))

        if mongo_servers and replset:
            return {
                'db_mongo_servers': ','.join(mongo_servers),
                'db_name': CEILOMETER_DB,
                'db_replset': replset
            }

        return {}
示例#15
0
    def __call__(self):
        mongo_servers = []
        replset = None
        _release = os_release('ceilometer-common')
        use_replset = CompareOpenStackReleases(_release) >= 'icehouse'

        for relid in relation_ids('shared-db'):
            rel_units = related_units(relid)
            use_replset = use_replset and (len(rel_units) > 1)

            for unit in rel_units:
                host = relation_get('hostname', unit, relid)
                port = relation_get('port', unit, relid)

                conf = {
                    "db_host": host,
                    "db_port": port,
                    "db_name": CEILOMETER_DB
                }

                if not context_complete(conf):
                    continue

                if not use_replset:
                    return conf

                if replset is None:
                    replset = relation_get('replset', unit, relid)

                mongo_servers.append('{}:{}'.format(host, port))

        if mongo_servers and replset:
            return {
                'db_mongo_servers': ','.join(mongo_servers),
                'db_name': CEILOMETER_DB,
                'db_replset': replset
            }

        return {}
示例#16
0
def _auth_args():
    """Get current service credentials from the identity-service relation"""
    rel_ctxt = context.IdentityServiceContext()
    rel_data = rel_ctxt()
    if not rel_data or not context.context_complete(rel_data):
        juju_log('identity-service context not complete')
        return

    auth_url = '%s://%s:%s/v2.0' % (
        rel_data['service_protocol'],
        rel_data['service_host'],
        rel_data['service_port'])

    auth_args = {
        'username': rel_data['admin_user'],
        'password': rel_data['admin_password'],
        'tenant_name': rel_data['admin_tenant_name'],
        'auth_url': auth_url,
        'auth_strategy': 'keystone',
        'region': config('region'),
    }
    return auth_args
 def __call__(self):
     for relid in relation_ids('ceilometer-service'):
         for unit in related_units(relid):
             conf = {}
             for attr in self.keys:
                 conf[attr] = relation_get(
                     attr, unit=unit, rid=relid)
             if (conf['api_version'] is not None and
                     float(conf['api_version']) > 2):
                 self.keys.append('admin_domain_name')
                 conf['admin_domain_name'] = relation_get(
                     'admin_domain_name', unit=unit, rid=relid)
             if context_complete(conf):
                 for attr in self.optional_keys:
                     conf[attr] = relation_get(attr, unit=unit, rid=relid)
                 if conf.get('rabbit_ssl_ca') is not None:
                     ca_path = os.path.join(
                         self.ssl_dir, 'rabbit-client-ca.pem')
                     with open(ca_path, 'wb') as fh:
                         fh.write(base64.b64decode(conf['rabbit_ssl_ca']))
                         conf['rabbit_ssl_ca'] = ca_path
                 return conf
     return {}
示例#18
0
    def __call__(self):
        bind_port = config('bind-port')
        workers = config('workers')
        if workers == 0:
            import multiprocessing
            workers = multiprocessing.cpu_count()
        if config('prefer-ipv6'):
            proxy_ip = '[%s]' % get_ipv6_addr(exc_list=[config('vip')])[0]
            memcached_ip = 'ip6-localhost'
        else:
            proxy_ip = get_host_ip(unit_get('private-address'))
            memcached_ip = get_host_ip(unit_get('private-address'))

        ctxt = {
            'proxy_ip': proxy_ip,
            'memcached_ip': memcached_ip,
            'bind_port': determine_api_port(bind_port, singlenode_mode=True),
            'workers': workers,
            'operator_roles': config('operator-roles'),
            'delay_auth_decision': config('delay-auth-decision'),
            'node_timeout': config('node-timeout'),
            'recoverable_node_timeout': config('recoverable-node-timeout'),
            'log_headers': config('log-headers')
        }

        if config('debug'):
            ctxt['log_level'] = 'DEBUG'
        else:
            ctxt['log_level'] = 'INFO'

        # Instead of duplicating code lets use charm-helpers to set signing_dir
        # TODO(hopem): refactor this context handler to use charm-helpers
        #              code.
        _ctxt = IdentityServiceContext(service='swift', service_user='******')()
        signing_dir = _ctxt.get('signing_dir')
        if signing_dir:
            ctxt['signing_dir'] = signing_dir

        ctxt['ssl'] = False

        auth_type = config('auth-type')
        auth_host = config('keystone-auth-host')
        admin_user = config('keystone-admin-user')
        admin_password = config('keystone-admin-user')
        if (auth_type == 'keystone' and auth_host and
                admin_user and admin_password):
            log('Using user-specified Keystone configuration.')
            ks_auth = {
                'auth_type': 'keystone',
                'auth_protocol': config('keystone-auth-protocol'),
                'keystone_host': auth_host,
                'auth_port': config('keystone-auth-port'),
                'service_user': admin_user,
                'service_password': admin_password,
                'service_tenant': config('keystone-admin-tenant-name')
            }
            ctxt.update(ks_auth)

        for relid in relation_ids('identity-service'):
            log('Using Keystone configuration from identity-service.')
            for unit in related_units(relid):
                ks_auth = {
                    'auth_type': 'keystone',
                    'auth_protocol': relation_get('auth_protocol',
                                                  unit, relid) or 'http',
                    'service_protocol': relation_get('service_protocol',
                                                     unit, relid) or 'http',
                    'keystone_host': relation_get('auth_host',
                                                  unit, relid),
                    'service_host': relation_get('service_host',
                                                 unit, relid),
                    'auth_port': relation_get('auth_port',
                                              unit, relid),
                    'service_user': relation_get('service_username',
                                                 unit, relid),
                    'service_password': relation_get('service_password',
                                                     unit, relid),
                    'service_tenant': relation_get('service_tenant',
                                                   unit, relid),
                    'service_port': relation_get('service_port',
                                                 unit, relid),
                    'admin_token': relation_get('admin_token',
                                                unit, relid),
                }
                if context_complete(ks_auth):
                    ctxt.update(ks_auth)

        if config('prefer-ipv6'):
            for key in ['keystone_host', 'service_host']:
                host = ctxt.get(key)
                if host:
                    ctxt[key] = format_ipv6_addr(host)

        return ctxt