def get_ceph_nodes(): hosts = [] for r_id in utils.relation_ids('ceph'): for unit in utils.relation_list(r_id): hosts.append(utils.relation_get('private-address', unit=unit, rid=r_id)) return hosts
def configure_gmond(): juju_log("INFO", "Configuring new ganglia node") _rid = relation_ids("juju-info")[0] principle_unit = get_principle_name() service_name = principle_unit.split('/')[0] _rids = relation_ids("node") masters = [] if _rids: # Configure as head unit and send data to masters for _rid in _rids: for _master in relation_list(_rid): masters.append(relation_get('private-address', _master, _rid)) context = { "service_name": service_name, "masters": masters, "unit_name": principle_unit } before = checksum(GMOND_CONF) with open(GMOND_CONF, "w") as gmond: gmond.write(render_template("gmond.conf", context)) if len(masters) > 0: if before != checksum(GMOND_CONF): control(GMOND, RESTART) else: control(GMOND, STOP)
def configure_haproxy(service_ports): ''' Configure HAProxy based on the current peers in the service cluster using the provided port map: "swift": [ 8080, 8070 ] HAproxy will also be reloaded/started if required service_ports: dict: dict of lists of [ frontend, backend ] ''' cluster_hosts = {} cluster_hosts[os.getenv('JUJU_UNIT_NAME').replace('/', '-')] = \ unit_get('private-address') for r_id in relation_ids('cluster'): for unit in relation_list(r_id): cluster_hosts[unit.replace('/', '-')] = \ relation_get(attribute='private-address', rid=r_id, unit=unit) context = {'units': cluster_hosts, 'service_ports': service_ports} with open(HAPROXY_CONF, 'w') as f: f.write(render_template(os.path.basename(HAPROXY_CONF), context)) with open(HAPROXY_DEFAULT, 'w') as f: f.write('ENABLED=1') reload('haproxy')
def configure_gmetad(): juju_log("INFO", "Configuring gmetad for master unit") data_sources = { "self": ["localhost"] } for _rid in relation_ids("master"): for _unit in relation_list(_rid): # endpoint is set by ganglia-node # subordinate to indicate that # gmond should not be used as a # datasource _datasource = relation_get('datasource', _unit, _rid) if _datasource == "true": service_name = _unit.split('/')[0] if service_name not in data_sources: data_sources[service_name] = [] data_sources[service_name]\ .append(relation_get('private-address', _unit, _rid)) context = { "data_sources": data_sources, "gridname": config_get("gridname") } before = checksum(GMETAD_CONF) with open(GMETAD_CONF, "w") as gmetad: gmetad.write(render_template("gmetad.conf", context)) if before != checksum(GMETAD_CONF): control(GMETAD, RESTART)
def is_clustered(): for r_id in (relation_ids('ha') or []): for unit in (relation_list(r_id) or []): clustered = relation_get('clustered', rid=r_id, unit=unit) if clustered: return True return False
def get_conf(name): for relid in utils.relation_ids('mon'): for unit in utils.relation_list(relid): conf = utils.relation_get(name, unit, relid) if conf: return conf return None
def notify_client(): utils.juju_log('INFO', 'Begin notify_client.') for relid in utils.relation_ids('client'): service_name = utils.relation_list(relid)[0].split('/')[0] utils.relation_set(key=ceph.get_named_key(service_name), auth=utils.config_get('auth-supported'), rid=relid) utils.juju_log('INFO', 'End notify_client.')
def get_ca_cert(): ca_cert = None juju_log('INFO', "Inspecting identity-service relations for CA SSL certificate.") for r_id in relation_ids('identity-service'): for unit in relation_list(r_id): if not ca_cert: ca_cert = relation_get('ca_cert', rid=r_id, unit=unit) return ca_cert
def get_mon_hosts(): hosts = [] for relid in utils.relation_ids('mon'): for unit in utils.relation_list(relid): hosts.append('{}:6789'.format( utils.get_host_ip( utils.relation_get('private-address', unit, relid)))) hosts.sort() return hosts
def get_mon_hosts(): hosts = [] for relid in utils.relation_ids('mon'): for unit in utils.relation_list(relid): hosts.append( '{}:6789'.format(utils.get_host_ip( utils.relation_get('private-address', unit, relid))) ) hosts.sort() return hosts
def get_keystone_conf(): for relid in utils.relation_ids('identity-service'): for unit in utils.relation_list(relid): ks_auth = { 'auth_type': 'keystone', 'auth_protocol': 'http', 'auth_host': utils.relation_get('auth_host', unit, relid), 'auth_port': utils.relation_get('auth_port', unit, relid), 'admin_token': utils.relation_get('admin_token', unit, relid), 'user_roles': utils.config_get('operator-roles'), 'cache_size': utils.config_get('cache-size'), 'revocation_check_interval': utils.config_get('revocation-check-interval') } if None not in ks_auth.itervalues(): return ks_auth return None
def get_cert(): cert = config_get('ssl_cert') key = config_get('ssl_key') if not (cert and key): juju_log('INFO', "Inspecting identity-service relations for SSL certificate.") cert = key = None for r_id in relation_ids('identity-service'): for unit in relation_list(r_id): if not cert: cert = relation_get('ssl_cert', rid=r_id, unit=unit) if not key: key = relation_get('ssl_key', rid=r_id, unit=unit) return (cert, key)
def https(): ''' Determines whether enough data has been provided in configuration or relation data to configure HTTPS . returns: boolean ''' if config_get('use-https') == "yes": return True if config_get('ssl_cert') and config_get('ssl_key'): return True for r_id in relation_ids('identity-service'): for unit in relation_list(r_id): if (relation_get('https_keystone', rid=r_id, unit=unit) and relation_get('ssl_cert', rid=r_id, unit=unit) and relation_get('ssl_key', rid=r_id, unit=unit) and relation_get('ca_cert', rid=r_id, unit=unit)): return True return False
def configure_gmond(): juju_log("INFO", "Configuring ganglia monitoring daemon") service_name = os.environ['JUJU_UNIT_NAME'].split('/')[0] _rids = relation_ids("head") masters = [] if _rids: # Configure as head unit and send data to masters for _rid in _rids: for _master in relation_list(_rid): masters.append(relation_get('private-address', _master, _rid)) context = { "service_name": service_name, "masters": masters, "dead_host_timeout": config_get("dead_host_timeout") } before = checksum(GMOND_CONF) with open(GMOND_CONF, "w") as gmond: gmond.write(render_template("gmond.conf", context)) if before != checksum(GMOND_CONF): control(GMOND, RESTART)
def peer_units(): peers = [] for r_id in (relation_ids('cluster') or []): for unit in (relation_list(r_id) or []): peers.append(unit) return peers