def __init__(self, config, graph_db): """ Agent consumer constructor :param config: config file instance :param graph_db: Graph db instance """ logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.CRITICAL) super(AgentsConsumer, self).__init__() self.config = config rb_usr = config_section_map('RabbitMQ', config)['rb_name'] rb_pwd = config_section_map('RabbitMQ', config)['rb_password'] rb_host = config_section_map('RabbitMQ', config)['rb_host'] rb_port = config_section_map('RabbitMQ', config)['rb_port'] agents_queue = config_section_map('RabbitMQ', config)['agents_queue'] self.conn_string = 'amqp://' + \ rb_usr + ':' \ + rb_pwd + '@' \ + rb_host + ':' \ + rb_port + '/%2F' self.queue = agents_queue self.graph_db = graph_db
def get_neutron_connection(self): """ create and return the connection to the Neutron DB :return NeutronDb: """ neutron_db_label = config_section_map('OpenstackDB', self.config)['neutron_db'] neutron_db_usr = config_section_map('OpenstackDB', self.config)['neutron_db_username'] neutron_db_pwd = config_section_map('OpenstackDB', self.config)['neutron_db_password'] neutron_db = NeutronDb(self.os_db_host, neutron_db_usr, neutron_db_pwd, neutron_db_label) return neutron_db
def get_heat_connection(self, config): """ create and return the connection to the Heat DB :param config: Configuration file :return HeatDb: """ heat_db_name = config_section_map('OpenstackDB', config)['heat_db'] heat_db_usr = config_section_map('OpenstackDB', config)['heat_db_username'] heat_db_pwd = config_section_map('OpenstackDB', config)['heat_db_password'] heat_db = HeatDb(self.os_db_host, heat_db_usr, heat_db_pwd, heat_db_name) return heat_db
def get_keystone_db(self, config): """ create and return the connection to the Keystone DB :param config: Configuration file :return KeystoneDb: """ keystone_db_name = config_section_map('OpenstackDB', config)['keystone_db'] keystone_db_usr = config_section_map('OpenstackDB', config)['keystone_db_username'] keystone_db_pwd = config_section_map('OpenstackDB', config)['keystone_db_password'] keystone_db = KeystoneDb(self.os_db_host, keystone_db_usr, keystone_db_pwd, keystone_db_name) return keystone_db
def __init__(self, config, db_label, graph_db): """ To init the class pass following params :param config: Config file :param db_label: name of OS Db where get info :param graph_db: Neo4j Graph """ self.config = config self.pop = config_section_map('PoP', config)['name'] self.os_db_host = config_section_map('OpenstackDB', config)['host'] self.os_db_usr = config_section_map('OpenstackDB', config)[db_label + '_username'] self.os_db_pwd = config_section_map('OpenstackDB', config)[db_label + '_password'] self.os_db = config_section_map('OpenstackDB', config)[db_label] self.graph_db = graph_db
def handle_volume_update(self, graph_db, body): """ Handle the volume update events :param graph_db: Instance of Graph DB :param body: event body """ timestamp = time.time() uuid = body['payload']['volume_id'] cinder_db = self.get_cinder_connection() volume = OpenstackResource(uuid) stack_uuid = volume.get_stack(graph_db) heat_db = None if stack_uuid: heat_db = self.get_heat_connection(self.config) keystone_db = self.get_keystone_db(self.config) OpenstackResource(uuid).remove_resource(graph_db) virtual_resources.add_cinder_volumes(cinder_db, graph_db, self.pop, timestamp, uuid=uuid) controller_hostname = config_section_map( 'Openstack', self.config)['controller_hostname'] if heat_db: virtual_resources.add_heat_stacks(heat_db, keystone_db, graph_db, self.pop, timestamp, controller_hostname, uuid=stack_uuid)
def add_new_machine(self, hostname, data_path): """ Handle the notification received starting the adding process of the new machine :param hostname: hostname of the machine tobe added :param data_path: path where files describing the machine are stored """ pop_name = config_section_map('PoP', self.config)['name'] hw_resources = HostHwResources(hostname, pop_name, self.graph_db) hwloc_file = dpdk_file = sriov_file = cpu_file = None for my_file in os.listdir(data_path): hostname_file = my_file.split('_')[0] file_type = my_file.split('_')[1] if hostname_file == hostname: if 'hwloc' in file_type: hwloc_file = my_file if 'dpdk' in file_type: dpdk_file = my_file if 'sriov' in file_type: sriov_file = my_file if 'cpuinfo' in file_type: cpu_file = my_file hw_resources.store(data_path, hwloc_file, cpu_file, sriov_file, dpdk_file)
def add_new_machine(self, hostname, data_path): """ Handle the notification received starting the adding process of the new machine :param hostname: hostname of the machine tobe added :param data_path: path where files describing the machine are stored """ pop_name = config_section_map("PoP", self.config)["name"] hw_resources = HostHwResources(hostname, pop_name, self.graph_db) hwloc_file = dpdk_file = sriov_file = cpu_file = None for my_file in os.listdir(data_path): hostname_file = my_file.split("_")[0] file_type = my_file.split("_")[1] if hostname_file == hostname: if "hwloc" in file_type: hwloc_file = my_file if "dpdk" in file_type: dpdk_file = my_file if "sriov" in file_type: sriov_file = my_file if "cpuinfo" in file_type: cpu_file = my_file hw_resources.store(data_path, hwloc_file, cpu_file, sriov_file, dpdk_file)
def __init__(self, config, graph_db): """ Agent consumer constructor :param config: config file instance :param graph_db: Graph db instance """ logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.CRITICAL) super(AgentsConsumer, self).__init__() self.config = config rb_usr = config_section_map("RabbitMQ", config)["rb_name"] rb_pwd = config_section_map("RabbitMQ", config)["rb_password"] rb_host = config_section_map("RabbitMQ", config)["rb_host"] rb_port = config_section_map("RabbitMQ", config)["rb_port"] agents_queue = config_section_map("RabbitMQ", config)["agents_queue"] self.conn_string = "amqp://" + rb_usr + ":" + rb_pwd + "@" + rb_host + ":" + rb_port + "/%2F" self.queue = agents_queue self.graph_db = graph_db
def handle_stack_create(self, graph_db, body): """ Handle the stack create events :param graph_db: Instance of Graph DB :param body: event body """ timestamp = time.time() uuid = body['payload']['stack_identity'].rsplit('/', 1)[1] heat_db = self.get_heat_connection() keystone_db = self.get_keystone_db(self.config) controller_hostname = config_section_map('Openstack', self.config)['controller_hostname'] virtual_resources.add_heat_stacks(heat_db, keystone_db, graph_db, self.pop, timestamp, controller_hostname, uuid=uuid)
def handle_stack_create(self, graph_db, body): """ Handle the stack create events :param graph_db: Instance of Graph DB :param body: event body """ timestamp = time.time() uuid = body['payload']['stack_identity'].rsplit('/', 1)[1] heat_db = self.get_heat_connection() keystone_db = self.get_keystone_db(self.config) controller_hostname = config_section_map( 'Openstack', self.config)['controller_hostname'] virtual_resources.add_heat_stacks(heat_db, keystone_db, graph_db, self.pop, timestamp, controller_hostname, uuid=uuid)
def handle_volume_update(self, graph_db, body): """ Handle the volume update events :param graph_db: Instance of Graph DB :param body: event body """ timestamp = time.time() uuid = body['payload']['volume_id'] cinder_db = self.get_cinder_connection() volume = OpenstackResource(uuid) stack_uuid = volume.get_stack(graph_db) heat_db = None if stack_uuid: heat_db = self.get_heat_connection(self.config) keystone_db = self.get_keystone_db(self.config) OpenstackResource(uuid).remove_resource(graph_db) virtual_resources.add_cinder_volumes(cinder_db, graph_db, self.pop, timestamp, uuid=uuid) controller_hostname = config_section_map('Openstack', self.config)['controller_hostname'] if heat_db: virtual_resources.add_heat_stacks(heat_db, keystone_db, graph_db, self.pop, timestamp, controller_hostname, uuid=stack_uuid)
def __init__(self, config_file='config/epa_controller.cfg'): # Reading configuration config = ConfigParser.ConfigParser() config.read(config_file) rb_usr = config_section_map('RabbitMQ', config)['rb_name'] rb_pwd = config_section_map('RabbitMQ', config)['rb_password'] rb_host = config_section_map('RabbitMQ', config)['rb_host'] rb_port = config_section_map('RabbitMQ', config)['rb_port'] agents_queue = config_section_map('RabbitMQ', config)['agents_queue'] self.conn_string = 'amqp://' + \ rb_usr + ':' \ + rb_pwd + '@' \ + rb_host + ':' \ + rb_port + '/%2F' # Creating agents.info queue parameters = pika.URLParameters(self.conn_string) connection = pika.BlockingConnection(parameters) channel = connection.channel() channel.queue_declare(queue=agents_queue) # Creating connection with neo4j db and init. graph_url = config_section_map('EpaDB', config)['epa_url'] self.graph_db = neo4j.Graph(graph_url) self.graph_db.delete_all() # Starting AgentsConsumer agents_consumer = AgentsConsumer(config, self.graph_db) agents_consumer.start() # DumpOpenStackDB VirtualResources(self.graph_db, config) # Starting NotificationsConsumer notifications_consumer = NotificationsConsumer(rb_usr, rb_pwd, rb_host, rb_port, config, self.graph_db) notifications_consumer.start()
def __init__(self, graph_db, config, timestamp=None): """ Initialize Epa DB with Virtual resources """ if timestamp is not None: now = timestamp else: now = time.time() self.graph_db = graph_db # Remove all virtual resources neo_resource.remove_nodes_by_property( graph_db, 'virtual_resource', property_key='index_type', property_value='virtual_resource') neo_resource.remove_nodes_by_property(graph_db, 'virtual_resource', property_key='resource_type', property_value='virtual') neo_resource.remove_nodes_by_property(graph_db, 'virtual_resource', property_key='resource_type', property_value='vnf') neo_resource.remove_nodes_by_property(graph_db, 'virtual_resource', property_key='resource_type', property_value='service') neo_resource.remove_nodes_by_property(graph_db, 'controller_service', property_key='resource_type', property_value='service') neo_resource.remove_nodes_by_property(graph_db, 'hypervisor', property_key='resource_type', property_value='service') # Collect PoP information from config file self.pop = config_section_map('PoP', config)['name'] # Collect controller information from config file self.controller_hostname = config_section_map( 'Openstack', config)['controller_hostname'] self.controller_ip = config_section_map('Openstack', config)['controller_ip'] # Collect Openstack DBs information from configuration file os_db_host = config_section_map('OpenstackDB', config)['host'] os_db_nova_usr = config_section_map('OpenstackDB', config)['nova_db_username'] os_db_nova_pwd = config_section_map('OpenstackDB', config)['nova_db_password'] os_db_cinder_usr = config_section_map('OpenstackDB', config)['cinder_db_username'] os_db_cinder_pwd = config_section_map('OpenstackDB', config)['cinder_db_password'] os_db_neutron_usr = config_section_map('OpenstackDB', config)['neutron_db_username'] os_db_neutron_pwd = config_section_map('OpenstackDB', config)['neutron_db_password'] os_db_glance_usr = config_section_map('OpenstackDB', config)['glance_db_username'] os_db_glance_pwd = config_section_map('OpenstackDB', config)['glance_db_password'] os_db_keystone_usr = config_section_map('OpenstackDB', config)['keystone_db_username'] os_db_keystone_pwd = config_section_map('OpenstackDB', config)['keystone_db_password'] os_db_heat_usr = config_section_map('OpenstackDB', config)['heat_db_username'] os_db_heat_pwd = config_section_map('OpenstackDB', config)['heat_db_password'] os_nova_db = config_section_map('OpenstackDB', config)['nova_db'] os_cinder_db = config_section_map('OpenstackDB', config)['cinder_db'] os_neutron_db = config_section_map('OpenstackDB', config)['neutron_db'] os_glance_db = config_section_map('OpenstackDB', config)['glance_db'] os_keystone_db = config_section_map('OpenstackDB', config)['keystone_db'] os_heat_db = config_section_map('OpenstackDB', config)['heat_db'] nova_enabled = config_section_map('Openstack', config)['nova_enabled'] cinder_enabled = config_section_map('Openstack', config)['cinder_enabled'] glance_enabled = config_section_map('Openstack', config)['glance_enabled'] heat_enabled = config_section_map('Openstack', config)['heat_enabled'] keystone_enabled = config_section_map('Openstack', config)['keystone_enabled'] neutron_enabled = config_section_map('Openstack', config)['neutron_enabled'] # Openstack DB wrappers if keystone_enabled.lower() == 'true': self.keystone_db = KeystoneDb(os_db_host, os_db_keystone_usr, os_db_keystone_pwd, os_keystone_db) # Controller Service add_controller_service(self.keystone_db, self.graph_db, self.pop, self.controller_hostname, self.controller_ip, now) if cinder_enabled.lower() == 'true': self.cinder_db = CinderDb(os_db_host, os_db_cinder_usr, os_db_cinder_pwd, os_cinder_db) # Cinder Volume Services add_cinder_volume_services(self.cinder_db, self.graph_db, self.pop, now) # Cinder Snapshots add_cinder_snapshots(self.cinder_db, self.graph_db, self.pop, now) # Cinder Volumes add_cinder_volumes(self.cinder_db, self.graph_db, self.pop, now) if glance_enabled.lower() == 'true': self.glance_db = GlanceDb(os_db_host, os_db_glance_usr, os_db_glance_pwd, os_glance_db) if heat_enabled.lower() == 'true' and keystone_enabled.lower( ) == 'true': self.heat_db = HeatDb(os_db_host, os_db_heat_usr, os_db_heat_pwd, os_heat_db) # Heat Stacks add_heat_stacks(self.heat_db, self.keystone_db, self.graph_db, self.pop, now, self.controller_hostname) if neutron_enabled.lower() == 'true': self.neutron_db = NeutronDb(os_db_host, os_db_neutron_usr, os_db_neutron_pwd, os_neutron_db) # Neutron Networks add_networks(self.neutron_db, self.graph_db, self.pop, now) # Neutron Floating IPs add_neutron_floating_ips(self.neutron_db, self.graph_db, self.pop, now) # Neutron Routers add_neutron_routers(self.neutron_db, self.graph_db, self.pop, now) # Neutron Ports add_ports(self.neutron_db, self.graph_db, self.pop, now) if nova_enabled.lower() == 'true': self.nova_db = NovaDb(os_db_host, os_db_nova_usr, os_db_nova_pwd, os_nova_db) # Hypervisors add_nova_hypervisors(self.nova_db, self.graph_db, self.pop, now) if neutron_enabled.lower() == 'true': # Nova Virtual Machines add_nova_instances(self.nova_db, self.neutron_db, self.graph_db, self.pop, now)
def __init__(self, graph_db, config, timestamp=None): """ Initialize Epa DB with Virtual resources """ if timestamp is not None: now = timestamp else: now = time.time() self.graph_db = graph_db # Remove all virtual resources neo_resource.remove_nodes_by_property(graph_db, 'virtual_resource', property_key='index_type', property_value='virtual_resource') neo_resource.remove_nodes_by_property(graph_db, 'virtual_resource', property_key='resource_type', property_value='virtual') neo_resource.remove_nodes_by_property(graph_db, 'virtual_resource', property_key='resource_type', property_value='vnf') neo_resource.remove_nodes_by_property(graph_db, 'virtual_resource', property_key='resource_type', property_value='service') neo_resource.remove_nodes_by_property(graph_db, 'controller_service', property_key='resource_type', property_value='service') neo_resource.remove_nodes_by_property(graph_db, 'hypervisor', property_key='resource_type', property_value='service') # Collect PoP information from config file self.pop = config_section_map('PoP', config)['name'] # Collect controller information from config file self.controller_hostname = config_section_map('Openstack', config)['controller_hostname'] self.controller_ip = config_section_map('Openstack', config)['controller_ip'] # Collect Openstack DBs information from configuration file os_db_host = config_section_map('OpenstackDB', config)['host'] os_db_nova_usr = config_section_map('OpenstackDB', config)['nova_db_username'] os_db_nova_pwd = config_section_map('OpenstackDB', config)['nova_db_password'] os_db_cinder_usr = config_section_map('OpenstackDB', config)['cinder_db_username'] os_db_cinder_pwd = config_section_map('OpenstackDB', config)['cinder_db_password'] os_db_neutron_usr = config_section_map('OpenstackDB', config)['neutron_db_username'] os_db_neutron_pwd = config_section_map('OpenstackDB', config)['neutron_db_password'] os_db_glance_usr = config_section_map('OpenstackDB', config)['glance_db_username'] os_db_glance_pwd = config_section_map('OpenstackDB', config)['glance_db_password'] os_db_keystone_usr = config_section_map('OpenstackDB', config)['keystone_db_username'] os_db_keystone_pwd = config_section_map('OpenstackDB', config)['keystone_db_password'] os_db_heat_usr = config_section_map('OpenstackDB', config)['heat_db_username'] os_db_heat_pwd = config_section_map('OpenstackDB', config)['heat_db_password'] os_nova_db = config_section_map('OpenstackDB', config)['nova_db'] os_cinder_db = config_section_map('OpenstackDB', config)['cinder_db'] os_neutron_db = config_section_map('OpenstackDB', config)['neutron_db'] os_glance_db = config_section_map('OpenstackDB', config)['glance_db'] os_keystone_db = config_section_map('OpenstackDB', config)['keystone_db'] os_heat_db = config_section_map('OpenstackDB', config)['heat_db'] nova_enabled = config_section_map('Openstack', config)['nova_enabled'] cinder_enabled = config_section_map('Openstack', config)['cinder_enabled'] glance_enabled = config_section_map('Openstack', config)['glance_enabled'] heat_enabled = config_section_map('Openstack', config)['heat_enabled'] keystone_enabled = config_section_map('Openstack', config)['keystone_enabled'] neutron_enabled = config_section_map('Openstack', config)['neutron_enabled'] # Openstack DB wrappers if keystone_enabled.lower() == 'true': self.keystone_db = KeystoneDb(os_db_host, os_db_keystone_usr, os_db_keystone_pwd, os_keystone_db) # Controller Service add_controller_service(self.keystone_db, self.graph_db, self.pop, self.controller_hostname, self.controller_ip, now) if cinder_enabled.lower() == 'true': self.cinder_db = CinderDb(os_db_host, os_db_cinder_usr, os_db_cinder_pwd, os_cinder_db) # Cinder Volume Services add_cinder_volume_services(self.cinder_db, self.graph_db, self.pop, now) # Cinder Snapshots add_cinder_snapshots(self.cinder_db, self.graph_db, self.pop, now) # Cinder Volumes add_cinder_volumes(self.cinder_db, self.graph_db, self.pop, now) if glance_enabled.lower() == 'true': self.glance_db = GlanceDb(os_db_host, os_db_glance_usr, os_db_glance_pwd, os_glance_db) if heat_enabled.lower() == 'true' and keystone_enabled.lower() == 'true': self.heat_db = HeatDb(os_db_host, os_db_heat_usr, os_db_heat_pwd, os_heat_db) # Heat Stacks add_heat_stacks(self.heat_db, self.keystone_db, self.graph_db, self.pop, now, self.controller_hostname) if neutron_enabled.lower() == 'true': self.neutron_db = NeutronDb(os_db_host, os_db_neutron_usr, os_db_neutron_pwd, os_neutron_db) # Neutron Networks add_networks(self.neutron_db, self.graph_db, self.pop, now) # Neutron Floating IPs add_neutron_floating_ips(self.neutron_db, self.graph_db, self.pop, now) # Neutron Routers add_neutron_routers(self.neutron_db, self.graph_db, self.pop, now) # Neutron Ports add_ports(self.neutron_db, self.graph_db, self.pop, now) if nova_enabled.lower() == 'true': self.nova_db = NovaDb(os_db_host, os_db_nova_usr, os_db_nova_pwd, os_nova_db) # Hypervisors add_nova_hypervisors(self.nova_db, self.graph_db, self.pop, now) if neutron_enabled.lower() == 'true': # Nova Virtual Machines add_nova_instances(self.nova_db, self.neutron_db, self.graph_db, self.pop, now)