def cache_env_data(): env = NetworkServiceContext()() if not env: log('Unable to get NetworkServiceContext at this time', level=ERROR) return no_envrc = False envrc_f = '/etc/legacy_ha_envrc' if os.path.isfile(envrc_f): with open(envrc_f, 'r') as f: data = f.read() data = data.strip().split('\n') diff = False for line in data: k = line.split('=')[0] v = line.split('=')[1] if k not in env or v != env[k]: diff = True break else: no_envrc = True if no_envrc or diff: with open(envrc_f, 'w') as f: for k, v in env.items(): f.write(''.join([k, '=', v, '\n']))
def cache_env_data(): env = NetworkServiceContext()() if not env: log("Unable to get NetworkServiceContext at this time", level=ERROR) return no_envrc = False envrc_f = "/etc/legacy_ha_envrc" if os.path.isfile(envrc_f): with open(envrc_f, "r") as f: data = f.read() data = data.strip().split("\n") diff = False for line in data: k = line.split("=")[0] v = line.split("=")[1] if k not in env or v != env[k]: diff = True break else: no_envrc = True if no_envrc or diff: with open(envrc_f, "w") as f: for k, v in env.items(): f.write("".join([k, "=", v, "\n"]))
def cache_env_data(): env = NetworkServiceContext()() if not env: log('Unable to get NetworkServiceContext at this time', level=ERROR) return no_envrc = False envrc_f = '/etc/legacy_ha_envrc' if os.path.isfile(envrc_f): with open(envrc_f, 'r') as f: data = f.read() data = data.strip().split('\n') diff = False for line in data: k = line.split('=')[0] v = line.split('=')[1] if k not in env or v != env[k]: diff = True break else: no_envrc = True if no_envrc or diff: with open(envrc_f, 'w') as f: for k, v in env.items(): f.write(''.join([k, '=', v, '\n']))
def get_nova_config_files(): global __NOVA_CONFIG_FILES if __NOVA_CONFIG_FILES is not None: return __NOVA_CONFIG_FILES NOVA_CONFIG_FILES = { NOVA_CONF: { 'hook_contexts': [ NetworkServiceContext(), NeutronGatewayContext(), SyslogContext(), context.WorkerConfigContext(), context.ZeroMQContext(), context.NotificationDriverContext(), NovaMetadataContext() ], 'services': ['nova-api-metadata'] }, NOVA_API_METADATA_AA_PROFILE_PATH: { 'services': ['nova-api-metadata'], 'hook_contexts': [context.AppArmorContext(NOVA_API_METADATA_AA_PROFILE)], }, VENDORDATA_FILE: { 'services': [], 'hook_contexts': [NovaMetadataJSONContext('neutron-common')], }, } return NOVA_CONFIG_FILES
def reassign_agent_resources(): ''' Use agent scheduler API to detect down agents and re-schedule ''' env = NetworkServiceContext()() if not env: log('Unable to re-assign resources at this time') return try: from quantumclient.v2_0 import client except ImportError: ''' Try to import neutronclient instead for havana+ ''' from neutronclient.v2_0 import client auth_url = '%(auth_protocol)s://%(keystone_host)s:%(auth_port)s/v2.0' % env quantum = client.Client(username=env['service_username'], password=env['service_password'], tenant_name=env['service_tenant'], auth_url=auth_url, region_name=env['region']) partner_gateways = [unit_private_ip().split('.')[0]] for partner_gateway in relations_of_type(reltype='cluster'): gateway_hostname = get_hostname(partner_gateway['private-address']) partner_gateways.append(gateway_hostname.partition('.')[0]) agents = quantum.list_agents(agent_type=DHCP_AGENT) dhcp_agents = [] l3_agents = [] networks = {} for agent in agents['agents']: if not agent['alive']: log('DHCP Agent %s down' % agent['id']) for network in \ quantum.list_networks_on_dhcp_agent( agent['id'])['networks']: networks[network['id']] = agent['id'] else: if agent['host'].partition('.')[0] in partner_gateways: dhcp_agents.append(agent['id']) agents = quantum.list_agents(agent_type=L3_AGENT) routers = {} for agent in agents['agents']: if not agent['alive']: log('L3 Agent %s down' % agent['id']) for router in \ quantum.list_routers_on_l3_agent( agent['id'])['routers']: routers[router['id']] = agent['id'] else: if agent['host'].split('.')[0] in partner_gateways: l3_agents.append(agent['id']) if len(dhcp_agents) == 0 or len(l3_agents) == 0: log('Unable to relocate resources, there are %s dhcp_agents and %s \ l3_agents in this cluster' % (len(dhcp_agents), len(l3_agents))) return index = 0 for router_id in routers: agent = index % len(l3_agents) log('Moving router %s from %s to %s' % (router_id, routers[router_id], l3_agents[agent])) quantum.remove_router_from_l3_agent(l3_agent=routers[router_id], router_id=router_id) quantum.add_router_to_l3_agent(l3_agent=l3_agents[agent], body={'router_id': router_id}) index += 1 index = 0 for network_id in networks: agent = index % len(dhcp_agents) log('Moving network %s from %s to %s' % (network_id, networks[network_id], dhcp_agents[agent])) quantum.remove_network_from_dhcp_agent(dhcp_agent=networks[network_id], network_id=network_id) quantum.add_network_to_dhcp_agent(dhcp_agent=dhcp_agents[agent], body={'network_id': network_id}) index += 1
NEUTRON_L3_AGENT_CONF = "/etc/neutron/l3_agent.ini" NEUTRON_DHCP_AGENT_CONF = "/etc/neutron/dhcp_agent.ini" NEUTRON_DNSMASQ_CONF = "/etc/neutron/dnsmasq.conf" NEUTRON_METADATA_AGENT_CONF = "/etc/neutron/metadata_agent.ini" NEUTRON_METERING_AGENT_CONF = "/etc/neutron/metering_agent.ini" NEUTRON_LBAAS_AGENT_CONF = "/etc/neutron/lbaas_agent.ini" NEUTRON_VPNAAS_AGENT_CONF = "/etc/neutron/vpn_agent.ini" NEUTRON_FWAAS_CONF = "/etc/neutron/fwaas_driver.ini" NOVA_CONF_DIR = '/etc/nova' NOVA_CONF = "/etc/nova/nova.conf" NOVA_CONFIG_FILES = { NOVA_CONF: { 'hook_contexts': [ NetworkServiceContext(), NeutronGatewayContext(), SyslogContext(), context.ZeroMQContext(), context.NotificationDriverContext() ], 'services': ['nova-api-metadata'] }, } NEUTRON_SHARED_CONFIG_FILES = { NEUTRON_DHCP_AGENT_CONF: { 'hook_contexts': [NeutronGatewayContext()], 'services': ['neutron-dhcp-agent'] }, NEUTRON_DNSMASQ_CONF: {
NEUTRON_DHCP_AGENT_CONF = "/etc/neutron/dhcp_agent.ini" NEUTRON_DNSMASQ_CONF = "/etc/neutron/dnsmasq.conf" NEUTRON_METADATA_AGENT_CONF = "/etc/neutron/metadata_agent.ini" NEUTRON_METERING_AGENT_CONF = "/etc/neutron/metering_agent.ini" NEUTRON_LBAAS_AGENT_CONF = "/etc/neutron/lbaas_agent.ini" NEUTRON_VPNAAS_AGENT_CONF = "/etc/neutron/vpn_agent.ini" NEUTRON_FWAAS_CONF = "/etc/neutron/fwaas_driver.ini" NOVA_CONF_DIR = '/etc/nova' NOVA_CONF = "/etc/nova/nova.conf" VENDORDATA_FILE = '%s/vendor_data.json' % NOVA_CONF_DIR NOVA_CONFIG_FILES = { NOVA_CONF: { 'hook_contexts': [ NetworkServiceContext(), NeutronGatewayContext(), SyslogContext(), context.WorkerConfigContext(), context.ZeroMQContext(), context.NotificationDriverContext(), NovaMetadataContext() ], 'services': ['nova-api-metadata'] }, NOVA_API_METADATA_AA_PROFILE_PATH: { 'services': ['nova-api-metadata'], 'hook_contexts': [context.AppArmorContext(NOVA_API_METADATA_AA_PROFILE)], }, VENDORDATA_FILE: {
def get_config_files(): global __CONFIG_FILES if __CONFIG_FILES is not None: return __CONFIG_FILES NOVA_CONFIG_FILES = get_nova_config_files() NEUTRON_SHARED_CONFIG_FILES = { NEUTRON_DHCP_AGENT_CONF: { 'hook_contexts': [DHCPAgentContext()], 'services': ['neutron-dhcp-agent'] }, NEUTRON_DNSMASQ_CONF: { 'hook_contexts': [DHCPAgentContext()], 'services': ['neutron-dhcp-agent'] }, NEUTRON_METADATA_AGENT_CONF: { 'hook_contexts': [ NetworkServiceContext(), DHCPAgentContext(), context.WorkerConfigContext(), NeutronGatewayContext(), NovaMetadataContext() ], 'services': ['neutron-metadata-agent'] }, NEUTRON_DHCP_AA_PROFILE_PATH: { 'services': ['neutron-dhcp-agent'], 'hook_contexts': [context.AppArmorContext(NEUTRON_DHCP_AA_PROFILE)], }, NEUTRON_LBAAS_AA_PROFILE_PATH: { 'services': ['neutron-lbaas-agent'], 'hook_contexts': [context.AppArmorContext(NEUTRON_LBAAS_AA_PROFILE)], }, NEUTRON_LBAASV2_AA_PROFILE_PATH: { 'services': ['neutron-lbaasv2-agent'], 'hook_contexts': [context.AppArmorContext(NEUTRON_LBAASV2_AA_PROFILE)], }, NEUTRON_METADATA_AA_PROFILE_PATH: { 'services': ['neutron-metadata-agent'], 'hook_contexts': [context.AppArmorContext(NEUTRON_METADATA_AA_PROFILE)], }, NEUTRON_METERING_AA_PROFILE_PATH: { 'services': ['neutron-metering-agent'], 'hook_contexts': [context.AppArmorContext(NEUTRON_METERING_AA_PROFILE)], }, } NEUTRON_SHARED_CONFIG_FILES.update(NOVA_CONFIG_FILES) NEUTRON_OVS_CONFIG_FILES = { NEUTRON_CONF: { 'hook_contexts': [ context.AMQPContext(ssl_dir=NEUTRON_CONF_DIR), NeutronGatewayContext(), SyslogContext(), context.ZeroMQContext(), context.WorkerConfigContext(), context.NotificationDriverContext() ], 'services': [ 'neutron-l3-agent', 'neutron-dhcp-agent', 'neutron-metadata-agent', 'neutron-plugin-openvswitch-agent', 'neutron-plugin-metering-agent', 'neutron-metering-agent', 'neutron-lbaas-agent', 'neutron-vpn-agent' ] }, NEUTRON_L3_AGENT_CONF: { 'hook_contexts': [ NetworkServiceContext(), L3AgentContext(), NeutronGatewayContext() ], 'services': ['neutron-l3-agent', 'neutron-vpn-agent'] }, NEUTRON_METERING_AGENT_CONF: { 'hook_contexts': [NeutronGatewayContext()], 'services': ['neutron-plugin-metering-agent', 'neutron-metering-agent'] }, NEUTRON_LBAAS_AGENT_CONF: { 'hook_contexts': [NeutronGatewayContext()], 'services': ['neutron-lbaas-agent'] }, NEUTRON_VPNAAS_AGENT_CONF: { 'hook_contexts': [NeutronGatewayContext()], 'services': ['neutron-vpn-agent'] }, NEUTRON_FWAAS_CONF: { 'hook_contexts': [NeutronGatewayContext()], 'services': ['neutron-l3-agent', 'neutron-vpn-agent'] }, NEUTRON_ML2_PLUGIN_CONF: { 'hook_contexts': [NeutronGatewayContext()], 'services': ['neutron-plugin-openvswitch-agent'] }, NEUTRON_OVS_AGENT_CONF: { 'hook_contexts': [NeutronGatewayContext()], 'services': ['neutron-plugin-openvswitch-agent'] }, NEUTRON_OVS_AA_PROFILE_PATH: { 'services': ['neutron-plugin-openvswitch-agent'], 'hook_contexts': [context.AppArmorContext(NEUTRON_OVS_AA_PROFILE)], }, NEUTRON_L3_AA_PROFILE_PATH: { 'services': ['neutron-l3-agent', 'neutron-vpn-agent'], 'hook_contexts': [context.AppArmorContext(NEUTRON_L3_AA_PROFILE)], }, EXT_PORT_CONF: { 'hook_contexts': [ExternalPortContext()], 'services': ['ext-port'] }, PHY_NIC_MTU_CONF: { 'hook_contexts': [PhyNICMTUContext()], 'services': ['os-charm-phy-nic-mtu'] } } NEUTRON_OVS_CONFIG_FILES.update(NEUTRON_SHARED_CONFIG_FILES) NEUTRON_OVS_ODL_CONFIG_FILES = { NEUTRON_CONF: { 'hook_contexts': [ context.AMQPContext(ssl_dir=NEUTRON_CONF_DIR), NeutronGatewayContext(), SyslogContext(), context.ZeroMQContext(), context.WorkerConfigContext(), context.NotificationDriverContext() ], 'services': [ 'neutron-l3-agent', 'neutron-dhcp-agent', 'neutron-metadata-agent', 'neutron-plugin-metering-agent', 'neutron-metering-agent', 'neutron-lbaas-agent', 'neutron-vpn-agent' ] }, NEUTRON_L3_AGENT_CONF: { 'hook_contexts': [ NetworkServiceContext(), L3AgentContext(), NeutronGatewayContext() ], 'services': ['neutron-l3-agent', 'neutron-vpn-agent'] }, NEUTRON_METERING_AGENT_CONF: { 'hook_contexts': [NeutronGatewayContext()], 'services': ['neutron-plugin-metering-agent', 'neutron-metering-agent'] }, NEUTRON_LBAAS_AGENT_CONF: { 'hook_contexts': [NeutronGatewayContext()], 'services': ['neutron-lbaas-agent'] }, NEUTRON_VPNAAS_AGENT_CONF: { 'hook_contexts': [NeutronGatewayContext()], 'services': ['neutron-vpn-agent'] }, NEUTRON_FWAAS_CONF: { 'hook_contexts': [NeutronGatewayContext()], 'services': ['neutron-l3-agent', 'neutron-vpn-agent'] }, EXT_PORT_CONF: { 'hook_contexts': [ExternalPortContext()], 'services': ['ext-port'] }, PHY_NIC_MTU_CONF: { 'hook_contexts': [PhyNICMTUContext()], 'services': ['os-charm-phy-nic-mtu'] } } NEUTRON_OVS_ODL_CONFIG_FILES.update(NEUTRON_SHARED_CONFIG_FILES) NEUTRON_NSX_CONFIG_FILES = { NEUTRON_CONF: { 'hook_contexts': [ context.AMQPContext(ssl_dir=NEUTRON_CONF_DIR), NeutronGatewayContext(), context.WorkerConfigContext(), SyslogContext() ], 'services': ['neutron-dhcp-agent', 'neutron-metadata-agent'] }, } NEUTRON_NSX_CONFIG_FILES.update(NEUTRON_SHARED_CONFIG_FILES) NEUTRON_N1KV_CONFIG_FILES = { NEUTRON_CONF: { 'hook_contexts': [ context.AMQPContext(ssl_dir=NEUTRON_CONF_DIR), NeutronGatewayContext(), context.WorkerConfigContext(), SyslogContext() ], 'services': [ 'neutron-l3-agent', 'neutron-dhcp-agent', 'neutron-metadata-agent' ] }, NEUTRON_L3_AGENT_CONF: { 'hook_contexts': [ NetworkServiceContext(), L3AgentContext(), NeutronGatewayContext() ], 'services': ['neutron-l3-agent'] }, } NEUTRON_N1KV_CONFIG_FILES.update(NEUTRON_SHARED_CONFIG_FILES) __CONFIG_FILES = { NSX: NEUTRON_NSX_CONFIG_FILES, OVS: NEUTRON_OVS_CONFIG_FILES, N1KV: NEUTRON_N1KV_CONFIG_FILES, OVS_ODL: NEUTRON_OVS_ODL_CONFIG_FILES } return __CONFIG_FILES