def leader_init_db_if_ready(skip_acl_check=False, skip_cells_restarts=False, db_rid=None, unit=None): """Initialise db if leader and db not yet intialised. NOTE: must be called from database context. """ if not is_elected_leader(CLUSTER_RES): log("Not leader - skipping db init", level=DEBUG) return if is_db_initialised(): log("Database already initialised - skipping db init", level=DEBUG) return # Bugs 1353135 & 1187508. Dbs can appear to be ready before the units # acl entry has been added. So, if the db supports passing a list of # permitted units then check if we're in the list. allowed_units = relation_get('nova_allowed_units', rid=db_rid, unit=unit) if skip_acl_check or (allowed_units and local_unit() in allowed_units.split()): status_set('maintenance', 'Running nova db migration') migrate_nova_database() log('Triggering remote cloud-compute restarts.') [compute_joined(rid=rid, remote_restart=True) for rid in relation_ids('cloud-compute')] log('Triggering remote neutron-network-service restarts.') [quantum_joined(rid=rid, remote_restart=True) for rid in relation_ids('quantum-network-service')] if not skip_cells_restarts: log('Triggering remote cell restarts.') [nova_cell_relation_joined(rid=rid, remote_restart=True) for rid in relation_ids('cell')] else: log('allowed_units either not presented, or local unit ' 'not in acl list: %s' % repr(allowed_units))
def update_cell_db_if_ready(skip_acl_check=False, db_rid=None, unit=None): """Update the cells db if leader and db's are already intialised""" if not is_leader(): return if not is_db_initialised(): log("Database not initialised - skipping cell db update", level=DEBUG) return allowed_units = relation_get('nova_allowed_units', rid=db_rid, unit=unit) if skip_acl_check or (allowed_units and local_unit() in allowed_units.split()): update_cell_database() else: log('allowed_units either not presented, or local unit ' 'not in acl list: %s' % repr(allowed_units))
def compute_changed(rid=None, unit=None): for r_id in relation_ids('nova-api'): nova_api_relation_joined(rid=r_id) rel_settings = relation_get(rid=rid, unit=unit) if not rel_settings.get('region', None) == config('region'): relation_set(relation_id=rid, region=config('region')) if is_db_initialised(): add_hosts_to_cell() if 'migration_auth_type' not in rel_settings: return if rel_settings['migration_auth_type'] == 'ssh': status_set('maintenance', 'configuring live migration') key = rel_settings.get('ssh_public_key') if not key: log('SSH migration set but peer did not publish key.') return ssh_compute_add(key, rid=rid, unit=unit) index = 0 for line in ssh_known_hosts_lines(unit=unit): relation_set( relation_id=rid, relation_settings={'known_hosts_{}'.format(index): line}) index += 1 relation_set(relation_id=rid, known_hosts_max_index=index) index = 0 for line in ssh_authorized_keys_lines(unit=unit): relation_set( relation_id=rid, relation_settings={'authorized_keys_{}'.format(index): line}) index += 1 relation_set(relation_id=rid, authorized_keys_max_index=index) if 'nova_ssh_public_key' not in rel_settings: return if rel_settings['nova_ssh_public_key']: ssh_compute_add(rel_settings['nova_ssh_public_key'], rid=rid, unit=unit, user='******') index = 0 for line in ssh_known_hosts_lines(unit=unit, user='******'): relation_set(relation_id=rid, relation_settings={ '{}_known_hosts_{}'.format('nova', index): line }) index += 1 relation_set(relation_id=rid, relation_settings={ '{}_known_hosts_max_index'.format('nova'): index }) index = 0 for line in ssh_authorized_keys_lines(unit=unit, user='******'): relation_set(relation_id=rid, relation_settings={ '{}_authorized_keys_{}'.format('nova', index): line }) index += 1 relation_set(relation_id=rid, relation_settings={ '{}_authorized_keys_max_index'.format('nova'): index })